Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions client/src/modules/front_end_components/HTMLFragments.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,6 @@ export const HTMLFragments = {
<option value="no" selected>No</option>
<option value="yes">Yes</option>
</select>
</div>
<div>
<label for="all-kill-permission">
Give all players kill/reveal permission?
<span id="kill-permission-help" class="help-icon" title="If evil players need to kill on the very first night (AKA &quot;Night 0&quot;), and there is no dedicated moderator, enable this to give all players the ability to kill and reveal players.">?</span>
</label>
<select id="all-kill-permission">
<option value="no" selected>No</option>
<option value="yes">Yes</option>
</select>
</div>`,
START_GAME_PROMPT:
`<button id='edit-roles-button'>Edit Roles</button>
Expand Down
13 changes: 4 additions & 9 deletions client/src/modules/game_creation/GameCreationStepManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@
"<label for='mod-name'>Your name:</label>" +
"<div id='mod-name' class='review-option'></div>" +
'</div>' +
'<div>' +
"<label for='test-game'>Populate game with bots?</label>" +
"<div id='test-game' class='review-option'></div>" +
'</div>' +
'<div>' +
"<label for='mod-option'>Moderation:</label>" +
"<div id='mod-option' class='review-option'></div>" +
Expand All @@ -434,14 +438,6 @@
"<label for='timer-option'>Timer:</label>" +
"<div id='timer-option' class='review-option'></div>" +
'</div>' +
'<div>' +
"<label for='test-game'>Populate game with bots?</label>" +
"<div id='test-game' class='review-option'></div>" +
'</div>' +
'<div>' +
"<label for='kill-permission-option'>All players can kill/reveal?</label>" +
"<div id='kill-permission-option' class='review-option'></div>" +
'</div>' +
'<div>' +
"<label id='roles-option-label' for='roles-option'>Game Deck:</label>" +
"<div id='roles-option' class='review-option'>No cards selected.</div>" +
Expand All @@ -453,8 +449,7 @@
? "Dedicated Moderator - don't deal me a card."
: 'Temporary Moderator - deal me into the game.';

div.querySelector('#kill-permission-option').innerText = game.hasAllKillPermission ? 'Yes' : 'No';

Check failure on line 452 in client/src/modules/game_creation/GameCreationStepManager.js

View workflow job for this annotation

GitHub Actions / build (20.x)

More than 1 blank line not allowed
if (game.hasTimer) {
const formattedHours = game.timerParams.hours !== null
? game.timerParams.hours + ' Hours'
Expand Down
10 changes: 1 addition & 9 deletions client/src/modules/game_state/states/InProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,15 +390,7 @@ export class InProgress {
} else if (!player.out && moderatorType) {
killPlayerHandlers[player.id] = () => {
Confirmation('Kill \'' + player.name + '\'?', () => {
const gameState = this.stateBucket.currentGameState;
const hasTempMod = gameState.people.some(
p => p.id === gameState.currentModeratorId
&& !p.out
&& (p.userType === USER_TYPES.TEMPORARY_MODERATOR || p.userType === USER_TYPES.PLAYER)
);
const noOneKilledYet = !gameState.people.some(p => p.killed);
if (gameState.client.userType === USER_TYPES.TEMPORARY_MODERATOR
|| (gameState.hasAllKillPermission && hasTempMod && noOneKilledYet)) {
if (this.stateBucket.currentGameState.client.userType === USER_TYPES.TEMPORARY_MODERATOR) {
socket.emit(SOCKET_EVENTS.IN_GAME_MESSAGE, EVENT_IDS.ASSIGN_DEDICATED_MOD, accessCode, { personId: player.id });
} else {
socket.emit(SOCKET_EVENTS.IN_GAME_MESSAGE, EVENT_IDS.KILL_PLAYER, accessCode, { personId: player.id });
Expand Down
39 changes: 1 addition & 38 deletions client/src/styles/create.css
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ option {
margin-top: 25px;
}

#step-4 label[for="test-game"], #step-4 label[for="all-kill-permission"] {
#step-4 label[for="test-game"] {
display: block;
margin-bottom: 10px;
}
Expand Down Expand Up @@ -673,43 +673,6 @@ input[type="number"] {
align-self: flex-start;
}

.help-icon {
display: inline-flex;
align-items: center;
justify-content: center;
width: 18px;
height: 18px;
border-radius: 50%;
background-color: #555;
color: #fff;
font-size: 12px;
font-weight: bold;
cursor: pointer;
margin-left: 5px;
vertical-align: middle;
user-select: none;
position: relative;
}

.help-icon:hover::after {
content: attr(title);
position: absolute;
bottom: 130%;
right: 0;
transform: none;
background-color: #333;
color: #fff;
padding: 8px 12px;
border-radius: 6px;
font-size: 13px;
font-weight: normal;
white-space: normal;
width: 250px;
max-width: 80vw;
text-align: center;
z-index: 100;
box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

@keyframes fade-in {
from {
Expand Down
2 changes: 1 addition & 1 deletion client/src/styles/game.css
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ canvas {
width: 18px;
}

#game-player-list > .game-player.killed:not(:has(.player-action-buttons))::after {
#game-player-list > .game-player.killed::after {
content: '\01F480';
font-size: 24px;
margin-left: 1em;
Expand Down
4 changes: 1 addition & 3 deletions server/model/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ class Game {
hasDedicatedModerator,
originalModeratorId,
createTime,
timerParams = null,
hasAllKillPermission = false
timerParams = null
) {
this.accessCode = accessCode;
this.status = status;
Expand All @@ -28,7 +27,6 @@ class Game {
this.createTime = createTime;
this.timerParams = timerParams;
this.timeRemaining = null;
this.hasAllKillPermission = hasAllKillPermission;
}
}

Expand Down
7 changes: 2 additions & 5 deletions server/model/GameCreationRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ class GameCreationRequest {
timerParams,
moderatorName,
hasDedicatedModerator,
isTestGame,
hasAllKillPermission
isTestGame
) {
this.deck = deck;
this.hasTimer = hasTimer;
this.timerParams = timerParams;
this.moderatorName = moderatorName;
this.hasDedicatedModerator = hasDedicatedModerator;
this.isTestGame = isTestGame;
this.hasAllKillPermission = hasAllKillPermission;
}

static validate = (gameParams) => {
const expectedKeys = ['deck', 'hasTimer', 'timerParams', 'moderatorName', 'hasDedicatedModerator', 'isTestGame', 'hasAllKillPermission'];
const expectedKeys = ['deck', 'hasTimer', 'timerParams', 'moderatorName', 'hasDedicatedModerator', 'isTestGame'];
if (gameParams === null
|| typeof gameParams !== 'object'
|| expectedKeys.some((key) => !Object.keys(gameParams).includes(key))
Expand Down Expand Up @@ -80,7 +78,6 @@ function valid (gameParams) {
return typeof gameParams.hasTimer === 'boolean'
&& typeof gameParams.isTestGame === 'boolean'
&& typeof gameParams.hasDedicatedModerator === 'boolean'
&& typeof gameParams.hasAllKillPermission === 'boolean'
&& typeof gameParams.moderatorName === 'string'
&& gameParams.moderatorName.length > 0
&& gameParams.moderatorName.length <= 30
Expand Down
2 changes: 1 addition & 1 deletion server/modules/Events.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ const Events = [
},
{
id: EVENT_IDS.ASSIGN_DEDICATED_MOD,
authorize: (person, game) => isModeratorOrTempMod(person) || (game.hasAllKillPermission && isPlayerOrMod(person)),
authorize: (person) => isModeratorOrTempMod(person),
stateChange: async (game, socketArgs, vars) => {
const currentModerator = vars.gameManager.findPersonByField(game, 'id', game.currentModeratorId);
const toTransferTo = vars.gameManager.findPersonByField(game, 'id', socketArgs.personId);
Expand Down
3 changes: 1 addition & 2 deletions server/modules/GameStateCurator.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ function getGameStateBasedOnPermissions (game, person) {
})
.map((filteredPerson) => GameStateCurator.mapPerson(filteredPerson)),
timerParams: game.timerParams,
isStartable: game.isStartable,
hasAllKillPermission: game.hasAllKillPermission
isStartable: game.isStartable
};
default:
break;
Expand Down
3 changes: 1 addition & 2 deletions server/modules/singletons/GameManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ class GameManager {
req.hasDedicatedModerator,
moderator.id,
new Date().toJSON(),
req.timerParams,
req.hasAllKillPermission
req.timerParams
);
newGame.people = initializePeopleForGame(req.deck, moderator, this.shuffle, req.isTestGame, newGame.gameSize);
newGame.isStartable = newGame.people.filter(person => person.userType === USER_TYPES.PLAYER
Expand Down
30 changes: 0 additions & 30 deletions spec/unit/server/model/GameCreationRequest_Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,34 +101,4 @@ describe('GameCreationRequest', () => {
expect(GameCreationRequest.deckIsValid(deck)).toBe(false);
});
});

describe('#validate', () => {
const validParams = {
deck: [{ role: 'Villager', team: ALIGNMENT.GOOD, description: 'A villager', custom: false, quantity: 1 }],
hasTimer: false,
timerParams: null,
moderatorName: 'TestMod',
hasDedicatedModerator: true,
isTestGame: false,
hasAllKillPermission: false
};

it('should accept valid game params with hasAllKillPermission set to false', async () => {
await expectAsync(GameCreationRequest.validate(validParams)).toBeResolved();
});

it('should accept valid game params with hasAllKillPermission set to true', async () => {
await expectAsync(GameCreationRequest.validate({ ...validParams, hasAllKillPermission: true })).toBeResolved();
});

it('should reject game params when hasAllKillPermission is missing', async () => {
const params = { ...validParams };
delete params.hasAllKillPermission;
await expectAsync(GameCreationRequest.validate(params)).toBeRejected();
});

it('should reject game params when hasAllKillPermission is not a boolean', async () => {
await expectAsync(GameCreationRequest.validate({ ...validParams, hasAllKillPermission: 'yes' })).toBeRejected();
});
});
});
9 changes: 1 addition & 8 deletions spec/unit/server/modules/Events_Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,18 +503,11 @@ describe('Events', () => {
const result = Events.find((e) => e.id === EVENT_IDS.ASSIGN_DEDICATED_MOD).authorize(person, game);
expect(result).toBeTrue();
});
it('should not allow a regular player when hasAllKillPermission is false', () => {
game.hasAllKillPermission = false;
it('should not allow a regular player to assign a dedicated mod', () => {
const person = { userType: USER_TYPES.PLAYER };
const result = Events.find((e) => e.id === EVENT_IDS.ASSIGN_DEDICATED_MOD).authorize(person, game);
expect(result).toBeFalse();
});
it('should allow a regular player when hasAllKillPermission is true', () => {
game.hasAllKillPermission = true;
const person = { userType: USER_TYPES.PLAYER };
const result = Events.find((e) => e.id === EVENT_IDS.ASSIGN_DEDICATED_MOD).authorize(person, game);
expect(result).toBeTrue();
});
});
beforeEach(() => {
game.people = [
Expand Down
19 changes: 3 additions & 16 deletions spec/unit/server/modules/singletons/EventManager_Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ describe('EventManager', () => {
});

describe('#handleEventById - authorization', () => {
it('should block a regular player from killing when hasAllKillPermission is false', async () => {
game.hasAllKillPermission = false;
it('should block a regular player from killing', async () => {
await eventManager.handleEventById(
EVENT_IDS.KILL_PLAYER, null, game, 'socket-b', game.accessCode, { personId: 'b' }, null, false
);
Expand All @@ -60,18 +59,7 @@ describe('EventManager', () => {
expect(person.killed).toBeFalse();
});

it('should allow a regular player to kill when hasAllKillPermission is true', async () => {
game.hasAllKillPermission = true;
await eventManager.handleEventById(
EVENT_IDS.KILL_PLAYER, null, game, 'socket-b', game.accessCode, { personId: 'b' }, null, false
);
const person = game.people.find(p => p.id === 'b');
expect(person.out).toBeTrue();
expect(person.killed).toBeTrue();
});

it('should allow a moderator to kill regardless of hasAllKillPermission', async () => {
game.hasAllKillPermission = false;
it('should allow a moderator to kill regardless', async () => {
await eventManager.handleEventById(
EVENT_IDS.KILL_PLAYER, null, game, 'socket-a', game.accessCode, { personId: 'b' }, null, false
);
Expand All @@ -80,8 +68,7 @@ describe('EventManager', () => {
expect(person.killed).toBeTrue();
});

it('should block a spectator from killing even when hasAllKillPermission is true', async () => {
game.hasAllKillPermission = true;
it('should block a spectator from killing', async () => {
game.people.find(p => p.id === 'c').out = false;
await eventManager.handleEventById(
EVENT_IDS.KILL_PLAYER, null, game, 'socket-c', game.accessCode, { personId: 'b' }, null, false
Expand Down
Loading