diff --git a/src/server/GameServer.ts b/src/server/GameServer.ts index 3efff38ab..a65dee4e9 100644 --- a/src/server/GameServer.ts +++ b/src/server/GameServer.ts @@ -51,6 +51,7 @@ export class GameServer { private clientsDisconnectedStatus: Map = new Map(); private _hasStarted = false; private _startTime: number | null = null; + private hasReachedMaxPlayerCount: boolean = false; private endTurnIntervalID: ReturnType | undefined; @@ -247,6 +248,10 @@ export class GameServer { this.addListeners(client); this.startLobbyInfoBroadcast(); + if (this.activeClients.length >= (this.gameConfig.maxPlayers ?? Infinity)) { + this.hasReachedMaxPlayerCount = true; + } + // In case a client joined the game late and missed the start message. if (this._hasStarted) { this.sendStartGameMsg(client.ws, 0); @@ -813,11 +818,11 @@ export class GameServer { // Public Games const lessThanLifetime = this.startsAt ? Date.now() < this.startsAt : true; - const notEnoughPlayers = - this.gameConfig.gameType === GameType.Public && - this.gameConfig.maxPlayers && - this.activeClients.length < this.gameConfig.maxPlayers; - if (lessThanLifetime && notEnoughPlayers && !this.hasStarted()) { + if ( + lessThanLifetime && + !this.hasStarted() && + !this.hasReachedMaxPlayerCount + ) { return GamePhase.Lobby; } const warmupOver = now > this.startsAt! + 30 * 1000;