mirror of
https://github.com/AlecM33/Werewolf.git
synced 2025-12-26 15:57:50 +01:00
gcloud, crude killing players functionality
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const debugMode = Array.from(process.argv.map((arg) => arg.trim().toLowerCase())).includes('debug');
|
||||
const logger = require('../modules/logger')(debugMode);
|
||||
const logger = require('../modules/Logger')(debugMode);
|
||||
const GameManager = require('../modules/GameManager.js');
|
||||
|
||||
const gameManager = new GameManager().getInstance();
|
||||
|
||||
@@ -8,7 +8,8 @@ const globals = {
|
||||
START_GAME: 'startGame',
|
||||
PAUSE_TIMER: 'pauseTimer',
|
||||
RESUME_TIMER: 'resumeTimer',
|
||||
GET_TIME_REMAINING: 'getTimeRemaining'
|
||||
GET_TIME_REMAINING: 'getTimeRemaining',
|
||||
KILL_PLAYER: 'killPlayer'
|
||||
},
|
||||
STATUS: {
|
||||
LOBBY: "lobby",
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// noinspection DuplicatedCode
|
||||
class Person {
|
||||
constructor(id, name, userType, gameRole=null, gameRoleDescription=null, alignment=null, assigned=false) {
|
||||
constructor(id, cookie, name, userType, gameRole=null, gameRoleDescription=null, alignment=null, assigned=false) {
|
||||
this.id = id;
|
||||
this.cookie = cookie
|
||||
this.socketId = null;
|
||||
this.name = name;
|
||||
this.userType = userType;
|
||||
|
||||
@@ -91,6 +91,18 @@ class GameManager {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socket.on(globals.CLIENT_COMMANDS.KILL_PLAYER, (accessCode, personId) => {
|
||||
let game = this.activeGameRunner.activeGames[accessCode];
|
||||
if (game) {
|
||||
let person = game.people.find((person) => person.id === personId)
|
||||
if (person) {
|
||||
this.logger.debug('game ' + accessCode + ': killing player ' + person.name);
|
||||
person.out = true;
|
||||
namespace.in(accessCode).emit(globals.CLIENT_COMMANDS.KILL_PLAYER, )
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -154,7 +166,7 @@ function initializeModerator(name, hasDedicatedModerator) {
|
||||
const userType = hasDedicatedModerator
|
||||
? globals.USER_TYPES.MODERATOR
|
||||
: globals.USER_TYPES.TEMPORARY_MODERATOR;
|
||||
return new Person(createRandomUserId(), name, userType)
|
||||
return new Person(createRandomId(), createRandomId(), name, userType)
|
||||
}
|
||||
|
||||
function initializePeopleForGame(uniqueCards, moderator) {
|
||||
@@ -180,7 +192,7 @@ function initializePeopleForGame(uniqueCards, moderator) {
|
||||
}
|
||||
|
||||
while (j < numberOfRoles) {
|
||||
people.push(new Person(createRandomUserId(), UsernameGenerator.generate(), globals.USER_TYPES.PLAYER, cards[j].role, cards[j].description, cards[j].team))
|
||||
people.push(new Person(createRandomId(), createRandomId(), UsernameGenerator.generate(), globals.USER_TYPES.PLAYER, cards[j].role, cards[j].description, cards[j].team))
|
||||
j ++;
|
||||
}
|
||||
|
||||
@@ -197,7 +209,7 @@ function shuffleArray (array) {
|
||||
return array;
|
||||
}
|
||||
|
||||
function createRandomUserId () {
|
||||
function createRandomId () {
|
||||
let id = '';
|
||||
for (let i = 0; i < globals.USER_SIGNATURE_LENGTH; i++) {
|
||||
id += globals.ACCESS_CODE_CHAR_POOL[Math.floor(Math.random() * globals.ACCESS_CODE_CHAR_POOL.length)];
|
||||
@@ -226,11 +238,11 @@ class Singleton {
|
||||
cookie. Though if a client wants to clear their cookie and reset their connection, there's not much we can do.
|
||||
The best thing in my opinion is to make it hard for clients to _accidentally_ break their experience.
|
||||
*/
|
||||
function handleRequestForGameState(namespace, logger, gameRunner, accessCode, personId, ackFn, socket) {
|
||||
function handleRequestForGameState(namespace, logger, gameRunner, accessCode, personCookie, ackFn, socket) {
|
||||
const game = gameRunner.activeGames[accessCode];
|
||||
if (game) {
|
||||
let matchingPerson = game.people.find((person) => person.id === personId);
|
||||
if (!matchingPerson && game.moderator.id === personId) {
|
||||
let matchingPerson = game.people.find((person) => person.cookie === personCookie);
|
||||
if (!matchingPerson && game.moderator.cookie === personCookie) {
|
||||
matchingPerson = game.moderator;
|
||||
}
|
||||
if (matchingPerson) {
|
||||
|
||||
@@ -8,10 +8,10 @@ const GameStateCurator = {
|
||||
|
||||
function getGameStateBasedOnPermissions(game, person, gameRunner) {
|
||||
let client = game.status === globals.STATUS.LOBBY // people won't be able to know their role until past the lobby stage.
|
||||
? { name: person.name, id: person.id, userType: person.userType }
|
||||
? { name: person.name, cookie: person.cookie, userType: person.userType }
|
||||
: {
|
||||
name: person.name,
|
||||
id: person.id,
|
||||
cookie: person.cookie,
|
||||
userType: person.userType,
|
||||
gameRole: person.gameRole,
|
||||
gameRoleDescription: person.gameRoleDescription,
|
||||
@@ -27,7 +27,7 @@ function getGameStateBasedOnPermissions(game, person, gameRunner) {
|
||||
deck: game.deck,
|
||||
people: game.people
|
||||
.filter((person) => {
|
||||
return person.assigned === true && person.id !== client.id
|
||||
return person.assigned === true && person.cookie !== client.cookie
|
||||
&& (person.userType !== globals.USER_TYPES.MODERATOR && person.userType !== globals.USER_TYPES.TEMPORARY_MODERATOR)
|
||||
})
|
||||
.map((filteredPerson) => ({ name: filteredPerson.name, userType: filteredPerson.userType })),
|
||||
@@ -64,10 +64,11 @@ function getGameStateBasedOnPermissions(game, person, gameRunner) {
|
||||
function mapPeopleForModerator(people, client) {
|
||||
return people
|
||||
.filter((person) => {
|
||||
return person.assigned === true && person.id !== client.id
|
||||
return person.assigned === true && person.cookie !== client.cookie
|
||||
})
|
||||
.map((person) => ({
|
||||
name: person.name,
|
||||
id: person.id,
|
||||
userType: person.userType,
|
||||
gameRole: person.gameRole,
|
||||
gameRoleDescription: person.gameRoleDescription,
|
||||
@@ -79,10 +80,11 @@ function mapPeopleForModerator(people, client) {
|
||||
function mapPeopleForTempModerator(people, client) {
|
||||
return people
|
||||
.filter((person) => {
|
||||
return person.assigned === true && person.id !== client.id
|
||||
return person.assigned === true && person.cookie !== client.cookie
|
||||
})
|
||||
.map((person) => ({
|
||||
name: person.name,
|
||||
id: person.id,
|
||||
userType: person.userType,
|
||||
out: person.out
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user