diff --git a/src/client/LocalServer.ts b/src/client/LocalServer.ts index 3f8fdba09..fe90a90cb 100644 --- a/src/client/LocalServer.ts +++ b/src/client/LocalServer.ts @@ -53,6 +53,7 @@ export class LocalServer { this.clientConnect(); if (this.lobbyConfig.gameRecord) { this.turns = decompressGameRecord(this.lobbyConfig.gameRecord).turns; + console.log(`loaded turns: ${JSON.stringify(this.turns)}`); } this.clientMessage( ServerStartGameMessageSchema.parse({ @@ -96,8 +97,14 @@ export class LocalServer { return; } const archivedHash = this.turns[clientMsg.turnNumber].hash; - if (archivedHash && archivedHash != clientMsg.hash) { + if (!archivedHash) { console.warn( + `no archived hash found for turn ${clientMsg.turnNumber}, client hash: ${clientMsg.hash}`, + ); + return; + } + if (archivedHash != clientMsg.hash) { + console.error( `desync detected on turn ${clientMsg.turnNumber}, client hash: ${clientMsg.hash}, server hash: ${archivedHash}`, ); this.clientMessage({ diff --git a/src/core/Util.ts b/src/core/Util.ts index 1d6caef67..982ff453c 100644 --- a/src/core/Util.ts +++ b/src/core/Util.ts @@ -302,7 +302,7 @@ export function createGameRecord( export function decompressGameRecord(gameRecord: GameRecord) { const turns = []; - let lastTurnNum = 0; + let lastTurnNum = -1; for (const turn of gameRecord.turns) { while (lastTurnNum < turn.turnNumber - 1) { lastTurnNum++;