update version, ping every 5 seconds, only end game if no pings for 20 seconds

This commit is contained in:
Evan
2024-12-15 13:24:05 -08:00
parent 1762161b83
commit 1576a2c744
3 changed files with 10 additions and 3 deletions
+8 -1
View File
@@ -30,6 +30,8 @@ export class GameServer {
private endTurnIntervalID
private lastPingUpdate = 0
constructor(
public readonly id: string,
public readonly createdAt: number,
@@ -77,6 +79,7 @@ export class GameServer {
}
}
if (clientMsg.type == "ping") {
this.lastPingUpdate = Date.now()
client.lastPing = Date.now()
}
})
@@ -210,7 +213,11 @@ export class GameServer {
return GamePhase.Lobby
}
if (this.activeClients.length == 0 && now > this.createdAt + this.config.lobbyLifetime() + 30 * 1000) { // wait at least 30s before ending game
const noActive = this.activeClients.length
const warmupOver = now > this.createdAt + this.config.lobbyLifetime() + 30 * 1000
const noRecentPings = now > this.lastPingUpdate + 20 * 1000
if (noActive && warmupOver && noRecentPings) {
return GamePhase.Finished
}