From 17f9cd314738ad46aacace57ebb67fb6686a0f96 Mon Sep 17 00:00:00 2001 From: babyboucher <48159308+babyboucher@users.noreply.github.com> Date: Sun, 12 Apr 2026 16:00:46 -0500 Subject: [PATCH] Fix public lobby max player bypass (#3650) If this PR fixes an issue, link it below. If not, delete these two lines. Resolves #3649 ## Description: Removes the persistentIdToClientId for Clients that leave before the game starts. This prevents the rejoin path from being taken which ignores max player count. See issue for details on why this is important. ## Please complete the following: - [X] I have added screenshots for all UI updates - [X] I process any text displayed to the user through translateText() and I've added it to the en.json file - [X] I have added relevant tests to the test directory - [X] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: babyboucher --- src/server/GameServer.ts | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/server/GameServer.ts b/src/server/GameServer.ts index 7f17974b7..05a5bf0b1 100644 --- a/src/server/GameServer.ts +++ b/src/server/GameServer.ts @@ -548,19 +548,23 @@ export class GameServer { this.activeClients = this.activeClients.filter( (c) => c.clientID !== client.clientID, ); - // Close lobby when host leaves before game starts - if ( - !this._hasStarted && - !this.isPublic() && - client.persistentID === this.creatorPersistentID - ) { - this.log.info("Host left, closing lobby", { - gameID: this.id, - }); - for (const c of [...this.activeClients]) { - this.kickClient(c.clientID, KICK_REASON_HOST_LEFT); + + if (!this._hasStarted) { + // Remove persistentId if the game has not started to prevent going over max players + this.persistentIdToClientId.delete(client.persistentID); + // Close lobby when host leaves before game starts + if ( + !this.isPublic() && + client.persistentID === this.creatorPersistentID + ) { + this.log.info("Host left, closing lobby", { + gameID: this.id, + }); + for (const c of [...this.activeClients]) { + this.kickClient(c.clientID, KICK_REASON_HOST_LEFT); + } + this._hasEnded = true; } - this._hasEnded = true; } }); client.ws.on("error", (error: Error) => { @@ -578,6 +582,10 @@ export class GameServer { this.activeClients = this.activeClients.filter( (c) => c.clientID !== client.clientID, ); + // Remove persistentId if the game has not started to prevent going over max players + if (!this._hasStarted) { + this.persistentIdToClientId.delete(client.persistentID); + } } }