end game when all clients disconnected or 1 hour

This commit is contained in:
evanpelle
2024-09-01 03:54:04 -07:00
parent a1e5419c19
commit 735a2ae57b
+11 -4
View File
@@ -13,7 +13,7 @@ export enum GamePhase {
export class GameServer {
private gameDuration = 30 * 60 * 1000 // TODO!!! fix this
private maxGameDuration = 60 * 60 * 1000 // 1 hour
private turns: Turn[] = []
private intents: Intent[] = []
@@ -126,10 +126,17 @@ export class GameServer {
if (Date.now() - this.createdAt < this.config.lobbyLifetime()) {
return GamePhase.Lobby
}
if (Date.now() - this.createdAt < this.config.lobbyLifetime() + this.gameDuration) {
return GamePhase.Active
if (this.clients.length == 0) {
return GamePhase.Finished
}
return GamePhase.Finished
if (Date.now() > this.createdAt + this.config.lobbyLifetime() + this.maxGameDuration) {
console.warn(`game past max duration ${this.id}`)
return GamePhase.Finished
}
return GamePhase.Active
}
hasStarted(): boolean {