use git commit hash verification when replaying archived games (#204)

This commit is contained in:
evanpelle
2025-03-10 12:40:36 -07:00
committed by GitHub
parent 6a24bce213
commit 5dc00bc3ab
10 changed files with 138 additions and 59 deletions
+1
View File
@@ -15,6 +15,7 @@ const analyticsBucket = "openfront-analytics";
export async function archive(gameRecord: GameRecord) {
try {
gameRecord.gitCommit = config.gitCommit();
// Archive to Redshift Serverless
await archiveAnalyticsToS3(gameRecord);
-1
View File
@@ -478,7 +478,6 @@ export class GameServer {
for (const client of this.activeClients) {
if (client.hashes.has(turnNumber)) {
const clientHash = client.hashes.get(turnNumber)!;
console.log(`clientHash: ${clientHash}`);
counts.set(clientHash, (counts.get(clientHash) || 0) + 1);
}
}
+29 -4
View File
@@ -4,7 +4,10 @@ import { WebSocketServer } from "ws";
import path from "path";
import { fileURLToPath } from "url";
import { GameManager } from "./GameManager";
import { getServerConfigFromServer } from "../core/configuration/Config";
import {
GameEnv,
getServerConfigFromServer,
} from "../core/configuration/Config";
import { WebSocket } from "ws";
import { Client } from "./Client";
import rateLimit from "express-rate-limit";
@@ -185,13 +188,35 @@ export function startWorker() {
"/api/archived_game/:id",
gatekeeper.httpHandler(LimiterType.Get, async (req, res) => {
const gameRecord = await readGameRecord(req.params.id);
if (!gameRecord) {
res.json({
return res.status(404).json({
success: false,
error: "Game not found",
exists: false,
});
return;
}
res.json({
if (
config.env() != GameEnv.Dev &&
gameRecord.gitCommit != config.gitCommit()
) {
console.warn(
`git commit mismatch for game ${req.params.id}, expected ${config.gitCommit()}, got ${gameRecord.gitCommit}`,
);
return res.status(409).json({
success: false,
error: "Version mismatch",
exists: true,
details: {
expectedCommit: config.gitCommit(),
actualCommit: gameRecord.gitCommit,
},
});
}
return res.status(200).json({
success: true,
exists: true,
gameRecord: gameRecord,
});