mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-12 00:43:57 +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:
@@ -1,4 +1,4 @@
|
||||
import { GameRecord, GameID } from "../core/Schemas";
|
||||
import { GameRecord, GameID, GameRecordSchema } from "../core/Schemas";
|
||||
import { S3 } from "@aws-sdk/client-s3";
|
||||
import { RedshiftData } from "@aws-sdk/client-redshift-data";
|
||||
import {
|
||||
@@ -107,27 +107,29 @@ async function archiveFullGameToS3(gameRecord: GameRecord) {
|
||||
console.log(`${gameRecord.id}: game record successfully written to S3`);
|
||||
}
|
||||
|
||||
export async function readGameRecord(gameId: GameID): Promise<GameRecord> {
|
||||
export async function readGameRecord(
|
||||
gameId: GameID,
|
||||
): Promise<GameRecord | null> {
|
||||
try {
|
||||
// Check if file exists and download in one operation
|
||||
const response = await s3.getObject({
|
||||
Bucket: gameBucket,
|
||||
Key: gameId,
|
||||
});
|
||||
|
||||
// Parse the response body
|
||||
const bodyContents = await response.Body.transformToString();
|
||||
const gameRecord = JSON.parse(bodyContents);
|
||||
|
||||
return gameRecord as GameRecord;
|
||||
return JSON.parse(bodyContents) as GameRecord;
|
||||
} catch (error) {
|
||||
// Log the error for monitoring purposes
|
||||
console.error(`${gameId}: Error reading game record from S3: ${error}`, {
|
||||
message: error?.message || error,
|
||||
stack: error?.stack,
|
||||
name: error?.name,
|
||||
...(error && typeof error === "object" ? error : {}),
|
||||
});
|
||||
throw error;
|
||||
|
||||
// Return null instead of throwing the error
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user