fix decompress game record function, start at -1 (#203)

This commit is contained in:
evanpelle
2025-03-10 07:21:24 -07:00
committed by GitHub
parent e2f18df426
commit 6a24bce213
2 changed files with 9 additions and 2 deletions
+8 -1
View File
@@ -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({
+1 -1
View File
@@ -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++;