allow moderators to kick players and spectators

This commit is contained in:
AlecM33
2023-08-02 23:23:01 -04:00
parent d00f3d630a
commit 0d82227824
14 changed files with 195 additions and 38 deletions

View File

@@ -103,8 +103,6 @@ router.patch('/:code/restart', async function (req, res) {
const game = await gameManager.getActiveGame(req.body.accessCode);
if (game) {
gameManager.restartGame(game, gameManager.namespace, req.query.status).then((data) => {
console.log(req.query.status);
console.log(req.query.toLobby);
res.status(200).send();
}).catch((code) => {
res.status(code).send();

View File

@@ -55,7 +55,8 @@ const globals = {
SYNC_GAME_STATE: 'syncGameState',
UPDATE_SOCKET: 'updateSocket',
ASSIGN_DEDICATED_MOD: 'assignDedicatedMod',
TIMER_EVENT: 'timerEvent'
TIMER_EVENT: 'timerEvent',
KICK_PERSON: 'kickPerson'
},
SYNCABLE_EVENTS: function () {
return [
@@ -74,7 +75,8 @@ const globals = {
this.EVENT_IDS.ASSIGN_DEDICATED_MOD,
this.EVENT_IDS.RESUME_TIMER,
this.EVENT_IDS.PAUSE_TIMER,
this.EVENT_IDS.END_TIMER
this.EVENT_IDS.END_TIMER,
this.EVENT_IDS.KICK_PERSON
];
},
TIMER_EVENTS: function () {

View File

@@ -1,5 +1,6 @@
const globals = require('../config/globals');
const GameStateCurator = require('./GameStateCurator');
const UsernameGenerator = require('./UsernameGenerator');
const EVENT_IDS = globals.EVENT_IDS;
const Events = [
@@ -22,6 +23,40 @@ const Events = [
);
}
},
{
id: EVENT_IDS.KICK_PERSON,
stateChange: async (game, socketArgs, vars) => {
const toBeClearedIndex = game.people.findIndex(
(person) => person.id === socketArgs.personId && person.assigned === true
);
if (toBeClearedIndex >= 0) {
const toBeCleared = game.people[toBeClearedIndex];
if (toBeCleared.userType === globals.USER_TYPES.SPECTATOR) {
game.people.splice(toBeClearedIndex, 1);
} else {
toBeCleared.assigned = false;
toBeCleared.socketId = null;
toBeCleared.cookie = (() => {
let id = '';
for (let i = 0; i < globals.INSTANCE_ID_LENGTH; i ++) {
id += globals.INSTANCE_ID_CHAR_POOL[Math.floor(Math.random() * globals.INSTANCE_ID_CHAR_POOL.length)];
}
return id;
})();
toBeCleared.hasEnteredName = false;
toBeCleared.name = UsernameGenerator.generate();
game.isFull = vars.gameManager.isGameFull(game);
}
}
},
communicate: async (game, socketArgs, vars) => {
vars.gameManager.namespace.in(game.accessCode).emit(
EVENT_IDS.KICK_PERSON,
socketArgs.personId,
game.isFull
);
}
},
{
id: EVENT_IDS.ADD_SPECTATOR,
stateChange: async (game, socketArgs, vars) => {

View File

@@ -272,7 +272,6 @@ class GameManager {
game.status = globals.STATUS.LOBBY;
}
await this.refreshGame(game);
await this.eventManager.publisher?.publish(
globals.REDIS_CHANNELS.ACTIVE_GAME_STREAM,