diff --git a/plugins/influxdb-log/index.js b/plugins/influxdb-log/index.js index a11b617..4ef1871 100644 --- a/plugins/influxdb-log/index.js +++ b/plugins/influxdb-log/index.js @@ -16,6 +16,8 @@ export default function influxdbLog(server, influxDB, options = {}) { if (!influxDB) throw new Error('InfluxDBLog must be provided with a InfluxDB connection.'); + + const serverID = options.overrideServerID || server.id; let points = []; setInterval(() => { @@ -26,7 +28,7 @@ export default function influxdbLog(server, influxDB, options = {}) { server.on(LOG_PARSER_SERVER_TICK_RATE, info => { points.push({ measurement: 'ServerTickRate', - tags: { server: server.id }, + tags: { server: serverID }, fields: { tick_rate: info.tickRate }, timestamp: info.time }); @@ -35,7 +37,7 @@ export default function influxdbLog(server, influxDB, options = {}) { server.on(SERVER_PLAYERS_UPDATED, players => { points.push({ measurement: 'PlayerCount', - tags: { server: server.id }, + tags: { server: serverID }, fields: { player_count: players.length }, timestamp: new Date() }); @@ -44,7 +46,7 @@ export default function influxdbLog(server, influxDB, options = {}) { server.on(LOG_PARSER_NEW_GAME, info => { points.push({ measurement: 'Match', - tags: { server: server.id }, + tags: { server: serverID }, fields: { dlc: info.dlc, mapClassname: info.mapClassname, @@ -59,7 +61,7 @@ export default function influxdbLog(server, influxDB, options = {}) { server.on(LOG_PARSER_PLAYER_WOUNDED, info => { points.push({ measurement: 'PlayerWounded', - tags: { server: server.id }, + tags: { server: serverID }, fields: { victim: info.victim ? info.victim.steamID : null, victimName: info.victim ? info.victim.name : null, @@ -80,7 +82,7 @@ export default function influxdbLog(server, influxDB, options = {}) { server.on(LOG_PARSER_PLAYER_DIED, info => { points.push({ measurement: 'PlayerDied', - tags: { server: server.id }, + tags: { server: serverID }, fields: { victim: info.victim ? info.victim.steamID : null, victimName: info.victim ? info.victim.name : null, @@ -101,7 +103,7 @@ export default function influxdbLog(server, influxDB, options = {}) { server.on(LOG_PARSER_PLAYER_REVIVED, info => { points.push({ measurement: 'PlayerRevived', - tags: { server: server.id }, + tags: { server: serverID }, fields: { victim: info.victim ? info.victim.steamID : null, victimName: info.victim ? info.victim.name : null, diff --git a/plugins/mysql-log/index.js b/plugins/mysql-log/index.js index 59af36d..da8a8b8 100644 --- a/plugins/mysql-log/index.js +++ b/plugins/mysql-log/index.js @@ -7,7 +7,7 @@ import { } from 'squad-server/events/log-parser'; import { SERVER_PLAYERS_UPDATED } from 'squad-server/events/server'; -export default function mysqlLog(server, mysqlPool) { +export default function mysqlLog(server, mysqlPool, options = {}) { if (!server) throw new Error( 'MySQLLog must be provided with a reference to the server.' @@ -16,23 +16,25 @@ export default function mysqlLog(server, mysqlPool) { if (!mysqlPool) throw new Error('MySQLLog must be provided with a mysql Pool.'); + const serverID = options.overrideServerID || server.id; + server.on(LOG_PARSER_SERVER_TICK_RATE, info => { mysqlPool.query( 'INSERT INTO ServerTickRate(time, server, tick_rate) VALUES (?,?,?)', - [info.time, server.id, info.tickRate] + [info.time, serverID, info.tickRate] ); }); server.on(SERVER_PLAYERS_UPDATED, players => { mysqlPool.query( 'INSERT INTO PlayerCount(time, server, player_count) VALUES (NOW(),?,?)', - [server.id, players.length] + [serverID, players.length] ); }); server.on(LOG_PARSER_NEW_GAME, info => { mysqlPool.query('call NewMatch(?,?,?,?,?,?,?)', [ - server.id, + serverID, info.time, info.dlc, info.mapClassname, @@ -44,7 +46,7 @@ export default function mysqlLog(server, mysqlPool) { server.on(LOG_PARSER_PLAYER_WOUNDED, info => { mysqlPool.query('call InsertPlayerWounded(?,?,?,?,?,?,?,?,?,?,?,?,?)', [ - server.id, + serverID, info.time, info.victim ? info.victim.steamID : null, info.victim ? info.victim.name : null, @@ -62,7 +64,7 @@ export default function mysqlLog(server, mysqlPool) { server.on(LOG_PARSER_PLAYER_DIED, info => { mysqlPool.query('call InsertPlayerDied(?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [ - server.id, + serverID, info.time, info.woundTime, info.victim ? info.victim.steamID : null, @@ -83,7 +85,7 @@ export default function mysqlLog(server, mysqlPool) { mysqlPool.query( 'call InsertPlayerRevived(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [ - server.id, + serverID, info.time, info.woundTime, info.victim ? info.victim.steamID : null,