From 5743415ff00b64d1aa8db61bb95e1e3dc8bcbd72 Mon Sep 17 00:00:00 2001 From: Skillet Date: Sun, 12 Nov 2023 13:59:48 -0500 Subject: [PATCH 1/2] fix player disconnect race condition bug --- squad-server/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/squad-server/index.js b/squad-server/index.js index 490f0a7d..643a5dce 100644 --- a/squad-server/index.js +++ b/squad-server/index.js @@ -29,6 +29,7 @@ export default class SquadServer extends EventEmitter { this.layerHistoryMaxLength = options.layerHistoryMaxLength || 20; this.players = []; + this.oldplayers = []; this.squads = []; @@ -218,8 +219,7 @@ export default class SquadServer extends EventEmitter { this.logParser.on('PLAYER_DISCONNECTED', async (data) => { data.player = await this.getPlayerBySteamID(data.steamID); - - delete data.steamID; + if (!data.player) data.player = this.oldplayers.filter((player) => player.steamID === data.steamID)[0]; this.emit('PLAYER_DISCONNECTED', data); }); @@ -363,6 +363,7 @@ export default class SquadServer extends EventEmitter { }); this.players = players; + this.oldplayers = oldPlayerInfo; for (const player of this.players) { if (typeof oldPlayerInfo[player.steamID] === 'undefined') continue; From 3b96bfae0b6d92ea2d70fd63c3587e49f1074ce2 Mon Sep 17 00:00:00 2001 From: Skillet Date: Sun, 12 Nov 2023 14:07:15 -0500 Subject: [PATCH 2/2] fix player disconnect race condition bug --- squad-server/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/squad-server/index.js b/squad-server/index.js index 643a5dce..85da11a8 100644 --- a/squad-server/index.js +++ b/squad-server/index.js @@ -219,7 +219,10 @@ export default class SquadServer extends EventEmitter { this.logParser.on('PLAYER_DISCONNECTED', async (data) => { data.player = await this.getPlayerBySteamID(data.steamID); - if (!data.player) data.player = this.oldplayers.filter((player) => player.steamID === data.steamID)[0]; + if (!data.player){ + const foundoldplayers = this.oldplayers.filter((player) => player.steamID === data.steamID); + data.player = foundoldplayers[0] ? foundoldplayers[0] : null; + } this.emit('PLAYER_DISCONNECTED', data); });