diff --git a/src/server/Worker.ts b/src/server/Worker.ts index 4c4c3ac4d..ba29131a9 100644 --- a/src/server/Worker.ts +++ b/src/server/Worker.ts @@ -78,9 +78,8 @@ export function startWorker() { const id = req.params.id; if (!id) { log.warn(`cannot create game, id not found`); - return; + return res.status(400).json({ error: "Game ID is required" }); } - // TODO: if game is public make sure request came from localhohst!!! const clientIP = req.ip || req.socket.remoteAddress || "unknown"; const gc = req.body?.gameConfig as GameConfig; if ( @@ -90,7 +89,9 @@ export function startWorker() { log.warn( `cannot create public game ${id}, ip ${clientIP} incorrect admin token`, ); - return res.status(400); + return res + .status(400) + .json({ error: "Invalid admin token for public game creation" }); } // Double-check this worker should host this game @@ -99,7 +100,7 @@ export function startWorker() { log.warn( `This game ${id} should be on worker ${expectedWorkerId}, but this is worker ${workerId}`, ); - return res.status(400); + return res.status(400).json({ error: "Worker, game id mismatch" }); } const game = gm.createGame(id, gc); @@ -139,20 +140,22 @@ export function startWorker() { const lobbyID = req.params.id; if (req.body.gameType == GameType.Public) { log.info(`cannot update game ${lobbyID} to public`); - return res.status(400); + return res.status(400).json({ error: "Cannot update public game" }); } const game = gm.game(lobbyID); if (!game) { - return res.status(400); + return res.status(400).json({ error: "Game not found" }); } if (game.isPublic()) { const clientIP = req.ip || req.socket.remoteAddress || "unknown"; log.warn(`cannot update public game ${game.id}, ip: ${clientIP}`); - return res.status(400); + return res.status(400).json({ error: "Cannot update public game" }); } if (game.hasStarted()) { log.warn(`cannot update game ${game.id} after it has started`); - return res.status(400); + return res + .status(400) + .json({ error: "Cannot update game after it has started" }); } game.updateGameConfig({ gameMap: req.body.gameMap,