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
+1 -1
View File
@@ -131,7 +131,7 @@ export class Transport {
gameID: this.gameID,
})))
}
}, 10000);
}, 5 * 1000);
}
}
+1 -1
View File
@@ -28,7 +28,7 @@
</svg>
</a>
<h1 class="text-7xl sm:text-5xl md:text-6xl lg:text-7xl mb-2">OpenFront.io</h1>
<h2 class="text-3xl sm:text-4xl md:text-5xl lg:text-6xl mb-4">(v0.12.2)</h2>
<h2 class="text-3xl sm:text-4xl md:text-5xl lg:text-6xl mb-4">(v0.12.3)</h2>
<div class="flex justify-center items-start">
<div class="w-full max-w-3xl p-4 space-y-4">
<br />
+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
}