fix: track max player count reached to correctly determine lobby phase, this is to prevent old lobbies reappearing when someone leaves before the game starts

This commit is contained in:
evanpelle
2026-03-12 11:25:02 -07:00
parent 4cfefdfb02
commit ebe7f76cd3
+10 -5
View File
@@ -51,6 +51,7 @@ export class GameServer {
private clientsDisconnectedStatus: Map<ClientID, boolean> = new Map();
private _hasStarted = false;
private _startTime: number | null = null;
private hasReachedMaxPlayerCount: boolean = false;
private endTurnIntervalID: ReturnType<typeof setInterval> | 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;