archive full game on crash (#251)

This commit is contained in:
evanpelle
2025-03-14 14:08:16 -07:00
committed by GitHub
parent d82191308e
commit 4a6ce12988
3 changed files with 10 additions and 8 deletions
+3 -3
View File
@@ -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) {
+5 -3
View File
@@ -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",
+2 -2
View File
@@ -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();