From a469af2719a0088a7ff1bd7f3e85651d44ad6071 Mon Sep 17 00:00:00 2001 From: Thomas Smyth Date: Mon, 18 May 2020 16:34:43 +0100 Subject: [PATCH 1/5] Improve the way the A2S player count is collected --- plugins/discord-server-status/index.js | 4 ++-- squad-server/events/server.js | 1 + squad-server/index.js | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/discord-server-status/index.js b/plugins/discord-server-status/index.js index 7757b440..9b3ce118 100644 --- a/plugins/discord-server-status/index.js +++ b/plugins/discord-server-status/index.js @@ -3,7 +3,7 @@ import { COPYRIGHT_MESSAGE } from 'core/config'; import { SERVER_A2S_UPDATED } from 'squad-server/events/server'; function makeEmbed(server, options) { - let players = `${server.a2sPlayerCount}`; + let players = `${server.playerCount}`; if (server.publicQueue + server.reserveQueue > 0) players += ` (+${server.publicQueue + server.reserveQueue})`; players += ` / ${server.publicSlots}`; @@ -82,6 +82,6 @@ export default async function plugin(server, discordClient, options = {}) { }); server.on(SERVER_A2S_UPDATED, () => { - if(!options.disableStatus) discordClient.user.setActivity(`(${server.a2sPlayerCount}/${server.publicSlots}) ${server.currentLayer}`, { type: 'WATCHING' }); + if(!options.disableStatus) discordClient.user.setActivity(`(${server.playerCount}/${server.publicSlots}) ${server.currentLayer}`, { type: 'WATCHING' }); }); } diff --git a/squad-server/events/server.js b/squad-server/events/server.js index 6998869f..2bc24a2a 100644 --- a/squad-server/events/server.js +++ b/squad-server/events/server.js @@ -32,6 +32,7 @@ const SERVER_LAYERS_UPDATED = 'SERVER_LAYERS_UPDATED'; * - maxPlayers - Maximum number of players on the server. * - publicSlots - Maximum number of public slots. * - reserveSlots - Maximum number of reserved slots. + * - playerCount - Player count as per A2S query. * - publicQueue - Length of the public queue. * - reserveQueue - Length of the reserved queue. * - matchTimeout - Time until match ends? diff --git a/squad-server/index.js b/squad-server/index.js index 2dc9efda..8d249e96 100644 --- a/squad-server/index.js +++ b/squad-server/index.js @@ -76,7 +76,7 @@ export default class Server extends EventEmitter { this.publicSlots = parseInt(data.raw.rules.NUMPUBCONN); this.reserveSlots = parseInt(data.raw.rules.NUMPRIVCONN); - this.a2sPlayerCount = Math.min(data.players.length, this.maxPlayers); + this.playerCount = parseInt(data.raw.rules.PlayerCount_i); this.publicQueue = parseInt(data.raw.rules.PublicQueue_i); this.reserveQueue = parseInt(data.raw.rules.ReservedQueue_i); @@ -88,6 +88,7 @@ export default class Server extends EventEmitter { maxPlayers: this.maxPlayers, publicSlots: this.publicSlots, reserveSlots: this.reserveSlots, + playerCount: this.playerCount, publicQueue: this.publicQueue, reserveQueue: this.reserveQueue, matchTimeout: this.matchTimeout, From 57ed25f07fdca8a8ef365f4ea32d61faf7f4476a Mon Sep 17 00:00:00 2001 From: Thomas Smyth Date: Mon, 18 May 2020 16:41:32 +0100 Subject: [PATCH 2/5] Attempt to resolve memory leaks --- squad-server/rcon/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/squad-server/rcon/index.js b/squad-server/rcon/index.js index 55db03da..1c00f5fe 100644 --- a/squad-server/rcon/index.js +++ b/squad-server/rcon/index.js @@ -35,6 +35,8 @@ export default class Rcon { this.requestQueue = []; this.currentMultiPacket = []; this.ignoreNextEndPacket = false; + + this.onData = this.onData.bind(this); } /* RCON functionality */ @@ -96,7 +98,7 @@ export default class Rcon { // setup socket this.client = new net.Socket(); - this.client.on('data', this.onData.bind(this)); + this.client.on('data', this.onData); this.client.on('error', err => { this.verbose(`Socket Error: ${err.message}`); @@ -106,6 +108,7 @@ export default class Rcon { this.client.on('close', async hadError => { this.verbose(`Socket Closed. AutoReconnect: ${this.autoReconnect}`); this.connected = false; + this.client.removeListener('data', this.onData); if (!this.autoReconnect) return; if (this.reconnectInterval !== null) return; this.reconnectInterval = setInterval(async () => { @@ -228,7 +231,7 @@ export default class Rcon { this.requestQueue.push(handleAuthMultiPacket); else this.requestQueue.push(handleMultiPacket); - this.client.on('error', reject); + this.client.once('error', reject); // send packets this.client.write(encodedPacket); From e6b1824db5ea4d2ced7652e854a012fcf6f35abc Mon Sep 17 00:00:00 2001 From: Thomas Smyth Date: Mon, 18 May 2020 16:45:58 +0100 Subject: [PATCH 3/5] Add option to override server ID in logging plugins --- plugins/influxdb-log/index.js | 14 ++++++++------ plugins/mysql-log/index.js | 16 +++++++++------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/plugins/influxdb-log/index.js b/plugins/influxdb-log/index.js index a11b617e..4ef18712 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 59af36da..da8a8b87 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, From a59b6dab8cd25df0856323b9911e085bc2798924 Mon Sep 17 00:00:00 2001 From: Thomas Smyth Date: Mon, 18 May 2020 17:33:54 +0100 Subject: [PATCH 4/5] Fix LOG_PARSER_PLAYER_WOUNDED event on Linux --- squad-server/log-parser/rules/player-wounded.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/squad-server/log-parser/rules/player-wounded.js b/squad-server/log-parser/rules/player-wounded.js index c1025ed9..0072109f 100644 --- a/squad-server/log-parser/rules/player-wounded.js +++ b/squad-server/log-parser/rules/player-wounded.js @@ -4,7 +4,7 @@ import { } from '../../events/log-parser.js'; export default { - regex: /^\[([0-9.:-]+)]\[([ 0-9]*)]LogSquadTrace: \[DedicatedServer]ASQSoldier::Wound\(\): Player:(.+) KillingDamage=(?:-)*([0-9.]+) from ([A-z_0-9]+) caused by ([A-z_0-9]+)_C/, + regex: /^\[([0-9.:-]+)]\[([ 0-9]*)]LogSquadTrace: \[DedicatedServer](?:ASQSoldier::)?Wound\(\): Player:(.+) KillingDamage=(?:-)*([0-9.]+) from ([A-z_0-9]+) caused by ([A-z_0-9]+)_C/, onMatch: async (args, logParser) => { const data = { ...logParser.eventStore[args[3]], From cf7cfab6c29a1806e92ea3f0a8b70eb699c2ad74 Mon Sep 17 00:00:00 2001 From: Thomas Smyth Date: Mon, 18 May 2020 17:34:30 +0100 Subject: [PATCH 5/5] SquadJS v1.0.6 Release --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d7dee232..57730e30 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "SquadJS", - "version": "1.0.5", + "version": "1.0.6", "repository": "https://github.com/Thomas-Smyth/SquadJS.git", "author": "Thomas Smyth ", "license": "MIT",