can creater & join lobby

This commit is contained in:
evanpelle
2024-10-14 20:45:31 -07:00
parent e490e23add
commit 42a6a2fcef
12 changed files with 481 additions and 347 deletions
+17 -5
View File
@@ -26,6 +26,7 @@ export class GameServer {
constructor(
public readonly id: string,
public readonly createdAt: number,
public readonly isPublic: boolean,
private config: Config,
) { }
@@ -129,6 +130,22 @@ export class GameServer {
}
phase(): GamePhase {
if (Date.now() > this.createdAt + this.config.lobbyLifetime() + this.maxGameDuration) {
console.warn(`game past max duration ${this.id}`)
return GamePhase.Finished
}
if (!this.isPublic) {
if (this._hasStarted) {
if (this.clients.length == 0) {
return GamePhase.Finished
} else {
return GamePhase.Active
}
} else {
return GamePhase.Lobby
}
}
if (Date.now() - this.createdAt < this.config.lobbyLifetime()) {
return GamePhase.Lobby
}
@@ -137,11 +154,6 @@ export class GameServer {
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
}