mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-16 21:22:00 +00:00
feat: replay archived games, gamestate hash verification (#195)
create endpoint to load archived game. when joining game client first checks if the game is active, if not it requests the game archive from the server. the archive is sent to LocalServer to replay the game locally. Every 10 ticks a hash is stored on the archive, and during replay the LocalServer verifies this hash.
This commit is contained in:
+21
-2
@@ -255,7 +255,7 @@ export function onlyImages(html: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function CreateGameRecord(
|
||||
export function createGameRecord(
|
||||
id: GameID,
|
||||
gameConfig: GameConfig,
|
||||
// username does not need to be set.
|
||||
@@ -278,7 +278,7 @@ export function CreateGameRecord(
|
||||
};
|
||||
|
||||
for (const turn of turns) {
|
||||
if (turn.intents.length != 0) {
|
||||
if (turn.intents.length != 0 || turn.hash != undefined) {
|
||||
record.turns.push(turn);
|
||||
for (const intent of turn.intents) {
|
||||
if (intent.type == "spawn") {
|
||||
@@ -300,6 +300,25 @@ export function CreateGameRecord(
|
||||
return record;
|
||||
}
|
||||
|
||||
export function decompressGameRecord(gameRecord: GameRecord) {
|
||||
const turns = [];
|
||||
let lastTurnNum = 0;
|
||||
for (const turn of gameRecord.turns) {
|
||||
while (lastTurnNum < turn.turnNumber - 1) {
|
||||
lastTurnNum++;
|
||||
turns.push({
|
||||
gameID: gameRecord.id,
|
||||
turnNumber: lastTurnNum,
|
||||
intents: [],
|
||||
});
|
||||
}
|
||||
turns.push(turn);
|
||||
lastTurnNum = turn.turnNumber;
|
||||
}
|
||||
gameRecord.turns = turns;
|
||||
return gameRecord;
|
||||
}
|
||||
|
||||
export function assertNever(x: never): never {
|
||||
throw new Error("Unexpected value: " + x);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user