20 lines
591 B
JavaScript
20 lines
591 B
JavaScript
const Game = require("../../../Game/Game");
|
|
|
|
const isAuthenticated = require("../../../Utility/isAuthenticated");
|
|
|
|
module.exports = async (res, req) => {
|
|
res.onAborted(() => res.isAborted = true);
|
|
|
|
const state = req.getQuery("state");
|
|
|
|
const hasPermission = await isAuthenticated(res, req);
|
|
if (!hasPermission) return;
|
|
|
|
if (!state) return res.cork(() => res.writeStatus("400").end("Missing new game state!"));
|
|
|
|
Game.state = parseInt(state);
|
|
|
|
res.cork(() => res
|
|
.writeStatus("200")
|
|
.end(`New game state is set to be ${state}`));
|
|
}; |