fix(protocol/gamespy1): ignore stale player list entries (#744)

closes #743
This commit is contained in:
cetteup 2025-11-16 16:47:29 +01:00 committed by GitHub
parent 35433cd03f
commit 3f1a06638f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 12 deletions

View file

@ -1,6 +1,7 @@
## To Be Released...
## 5.X.Y
* Fix: ignore stale player list entries (By @cetteup #744)
## 5.3.2
* Fix: detect BFBC2 Vietnam DLC as BFBC2 (By @cetteup #713)

View file

@ -86,19 +86,7 @@ export default class gamespy1 extends Core {
const players = Object.values(playersById)
const seenHashes = new Set()
for (const player of players) {
// Some servers (bf1942) report the same player multiple times (bug?)
// Ignore these duplicates
if (player.keyhash) {
if (seenHashes.has(player.keyhash)) {
this.logger.debug('Rejected player with hash ' + player.keyhash + ' (Duplicate keyhash)')
continue
} else {
seenHashes.add(player.keyhash)
}
}
// Convert player's team ID to team name if possible
if (Object.prototype.hasOwnProperty.call(player, 'teamId')) {
if (Object.keys(teamNamesById).length) {
@ -112,6 +100,12 @@ export default class gamespy1 extends Core {
state.players.push(player)
}
// Some servers (bf1942) send stale player entries when players leave the server (including duplicates)
// Ignore any player list entries beyond the indicated number of players
if (!isNaN(state.raw.numplayers) && state.players.length > state.raw.numplayers) {
state.players = state.players.slice(0, state.raw.numplayers)
}
state.numplayers = state.players.length
state.version = state.raw.gamever
}