first draft restarting of games

This commit is contained in:
AlecM33
2022-05-08 22:44:25 -04:00
parent 6ce5cbe59d
commit 04aa708f34
8 changed files with 170 additions and 28 deletions

View File

@@ -89,6 +89,29 @@ router.patch('/:code/players', function (req, res) {
}
});
router.patch('/:code/restart', function (req, res) {
if (
req.body === null
|| !validateAccessCode(req.body.accessCode)
|| !validateName(req.body.playerName)
|| !validateCookie(req.body.localCookie)
|| !validateCookie(req.body.sessionCookie)
) {
res.status(400).send();
} else {
const game = gameManager.activeGameRunner.activeGames[req.body.accessCode];
if (game) {
gameManager.restartGame(game, gameManager.namespace).then((data) => {
res.status(200).send();
}).catch((code) => {
res.status(code).send();
});
} else {
res.status(404).send();
}
}
});
router.get('/environment', function (req, res) {
res.status(200).send(gameManager.environment);
});