mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 09:40:44 +00:00
fix decompress game record function, start at -1 (#203)
This commit is contained in:
@@ -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
@@ -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++;
|
||||
|
||||
Reference in New Issue
Block a user