mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-25 02:14:38 +00:00
use git commit hash verification when replaying archived games (#204)
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user