mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 12:00:44 +00:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user