mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-04 20:36:06 +00:00
use git commit hash verification when replaying archived games (#204)
This commit is contained in:
+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