From 74d38352c57bfc009aa6534fa10e0f80ca9b72da Mon Sep 17 00:00:00 2001 From: evanpelle Date: Tue, 3 Jun 2025 17:35:00 -0700 Subject: [PATCH] ensure that player records maintain the same order as in start info, this caused replay issues, as players were assigned to the wrong team --- src/server/GameServer.ts | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/server/GameServer.ts b/src/server/GameServer.ts index caf67e0a1..003542bd8 100644 --- a/src/server/GameServer.ts +++ b/src/server/GameServer.ts @@ -538,20 +538,23 @@ export class GameServer { gameID: this.id, winner: this.winner?.winner, }); - const playerRecords: PlayerRecord[] = Array.from( - this.allClients.values(), - ).map((client) => { - const stats = this.winner?.allPlayersStats[client.clientID]; - if (stats === undefined) { - this.log.warn(`Unable to find stats for clientID ${client.clientID}`); - } - return { - clientID: client.clientID, - username: client.username, - persistentID: client.persistentID, - stats, - } satisfies PlayerRecord; - }); + + // Players must stay in the same order as the game start info. + const playerRecords: PlayerRecord[] = this.gameStartInfo.players.map( + (player) => { + const stats = this.winner?.allPlayersStats[player.clientID]; + if (stats === undefined) { + this.log.warn(`Unable to find stats for clientID ${player.clientID}`); + } + return { + clientID: player.clientID, + username: player.username, + persistentID: + this.allClients.get(player.clientID)?.persistentID ?? "", + stats, + } satisfies PlayerRecord; + }, + ); archive( createGameRecord( this.id,