From 4a6ce12988b9d1241a61af5bf1087f3e1a5bc8ff Mon Sep 17 00:00:00 2001 From: evanpelle Date: Fri, 14 Mar 2025 14:08:16 -0700 Subject: [PATCH] archive full game on crash (#251) --- src/client/ClientGameRunner.ts | 6 +++--- src/client/LocalServer.ts | 8 +++++--- src/client/Transport.ts | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/client/ClientGameRunner.ts b/src/client/ClientGameRunner.ts index b5b414b3c..4eb89980a 100644 --- a/src/client/ClientGameRunner.ts +++ b/src/client/ClientGameRunner.ts @@ -193,7 +193,7 @@ export class ClientGameRunner { this.lobby.gameID, this.lobby.clientID, ); - this.stop(); + this.stop(true); return; } gu.updates[GameUpdateType.Hash].forEach((hu: HashUpdate) => { @@ -265,10 +265,10 @@ export class ClientGameRunner { this.transport.connect(onconnect, onmessage); } - public stop() { + public stop(saveFullGame: boolean = false) { this.worker.cleanup(); this.isActive = false; - this.transport.leaveGame(); + this.transport.leaveGame(saveFullGame); } private inputEvent(event: MouseUpEvent) { diff --git a/src/client/LocalServer.ts b/src/client/LocalServer.ts index fe90a90cb..333ade8ba 100644 --- a/src/client/LocalServer.ts +++ b/src/client/LocalServer.ts @@ -144,7 +144,7 @@ export class LocalServer { }); } - public endGame() { + public endGame(saveFullGame: boolean = false) { consolex.log("local server ending game"); clearInterval(this.endTurnIntervalID); const players: PlayerRecord[] = [ @@ -165,8 +165,10 @@ export class LocalServer { this.winner, this.allPlayersStats, ); - // Clear turns because beacon only supports up to 64kb - record.turns = []; + if (!saveFullGame) { + // Clear turns because beacon only supports up to 64kb + record.turns = []; + } // For unload events, sendBeacon is the only reliable method const blob = new Blob([JSON.stringify(GameRecordSchema.parse(record))], { type: "application/json", diff --git a/src/client/Transport.ts b/src/client/Transport.ts index e6058e5a6..98213d866 100644 --- a/src/client/Transport.ts +++ b/src/client/Transport.ts @@ -319,9 +319,9 @@ export class Transport { ); } - leaveGame() { + leaveGame(saveFullGame: boolean = false) { if (this.isLocal) { - this.localServer.endGame(); + this.localServer.endGame(saveFullGame); return; } this.stopPing();