From 4d3f690c454059d106e4f384cbc274a97dfd1c27 Mon Sep 17 00:00:00 2001 From: Evan Date: Mon, 16 Dec 2024 21:12:55 -0800 Subject: [PATCH] bugfix: private game ending when no clients connected (disconnects caused games to end), so check for no recent pings as well --- src/server/GameServer.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/server/GameServer.ts b/src/server/GameServer.ts index 40e9e4d68..b3a11fe47 100644 --- a/src/server/GameServer.ts +++ b/src/server/GameServer.ts @@ -18,7 +18,7 @@ export enum GamePhase { export class GameServer { - private maxGameDuration = 2 * 60 * 60 * 1000 // 2 hours + private maxGameDuration = 5 * 60 * 60 * 1000 // 5 hours private turns: Turn[] = [] private intents: Intent[] = [] @@ -196,9 +196,13 @@ export class GameServer { console.warn(`game past max duration ${this.id}`) return GamePhase.Finished } + + const noRecentPings = now > this.lastPingUpdate + 20 * 1000 + const noActive = this.activeClients.length == 0 + if (!this.isPublic) { if (this._hasStarted) { - if (this.activeClients.length == 0) { + if (noActive && noRecentPings) { console.log(`private game: ${this.id} complete`) return GamePhase.Finished } else { @@ -212,11 +216,7 @@ export class GameServer { if (now - this.createdAt < this.config.lobbyLifetime()) { return GamePhase.Lobby } - - const noActive = this.activeClients.length == 0 const warmupOver = now > this.createdAt + this.config.lobbyLifetime() + 30 * 1000 - const noRecentPings = now > this.lastPingUpdate + 20 * 1000 - if (noActive && warmupOver && noRecentPings) { return GamePhase.Finished }