mirror of
https://github.com/AlecM33/Werewolf.git
synced 2025-12-26 15:57:50 +01:00
further redis effort
This commit is contained in:
@@ -3,7 +3,7 @@ const router = express.Router();
|
||||
const debugMode = Array.from(process.argv.map((arg) => arg.trim().toLowerCase())).includes('debug');
|
||||
const logger = require('../modules/Logger')(debugMode);
|
||||
const socketManager = (require('../modules/singletons/SocketManager.js')).instance;
|
||||
const gameManager = (require('../modules/singletons/GameManager.js')).instance;
|
||||
const activeGameRunner = (require('../modules/singletons/ActiveGameRunner.js')).instance;
|
||||
const globals = require('../config/globals.js');
|
||||
const cors = require('cors');
|
||||
|
||||
@@ -22,8 +22,8 @@ router.post('/sockets/broadcast', function (req, res) {
|
||||
|
||||
router.get('/games/state', async (req, res) => {
|
||||
const gamesArray = [];
|
||||
await this.client.hGetAll('activeGames').then(async (r) => {
|
||||
Object.values(r).forEach((v) => gamesArray.push(v));
|
||||
await activeGameRunner.client.keys('*').then(async (r) => {
|
||||
Object.values(r).forEach((v) => gamesArray.push(JSON.parse(v)));
|
||||
});
|
||||
res.status(200).send(gamesArray);
|
||||
});
|
||||
|
||||
@@ -91,7 +91,7 @@ router.patch('/:code/players', async function (req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.patch('/:code/restart', function (req, res) {
|
||||
router.patch('/:code/restart', async function (req, res) {
|
||||
if (
|
||||
req.body === null
|
||||
|| !validateAccessCode(req.body.accessCode)
|
||||
@@ -101,7 +101,7 @@ router.patch('/:code/restart', function (req, res) {
|
||||
) {
|
||||
res.status(400).send();
|
||||
} else {
|
||||
const game = gameManager.activeGameRunner.getActiveGame(req.body.accessCode);
|
||||
const game = await gameManager.activeGameRunner.getActiveGame(req.body.accessCode);
|
||||
if (game) {
|
||||
gameManager.restartGame(game, gameManager.namespace).then((data) => {
|
||||
res.status(200).send();
|
||||
@@ -123,11 +123,11 @@ function validateName (name) {
|
||||
}
|
||||
|
||||
function validateCookie (cookie) {
|
||||
return cookie === null || cookie === false || (typeof cookie === 'string' && cookie.length === globals.USER_SIGNATURE_LENGTH);
|
||||
return cookie === null || cookie === false || (typeof cookie === 'string' && cookie.length === globals.INSTANCE_ID_LENGTH);
|
||||
}
|
||||
|
||||
function validateAccessCode (accessCode) {
|
||||
return /^[a-zA-Z0-9]+$/.test(accessCode) && accessCode.length === globals.ACCESS_CODE_LENGTH;
|
||||
return /^[a-zA-Z0-9]+$/.test(accessCode) && accessCode?.length === globals.ACCESS_CODE_LENGTH;
|
||||
}
|
||||
|
||||
function validateSpectatorFlag (spectatorFlag) {
|
||||
|
||||
Reference in New Issue
Block a user