Skip to content
Merged
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
15 changes: 10 additions & 5 deletions client/play/mp/MultiplayerTossupBonusClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,17 @@ export const MultiplayerClientMixin = (ClientClass) => class extends ClientClass
}
}

leave ({ userId, username }) {
leave ({ userId, username, remove }) {
this.logEventConditionally(username, 'left the game');
this.room.players[userId].online = false;
document.getElementById(`list-group-${userId}`).classList.add('offline');
document.getElementById(`points-${userId}`).classList.remove('bg-success');
document.getElementById(`points-${userId}`).classList.add('bg-secondary');
if (remove) {
delete this.room.players[userId];
document.getElementById(`list-group-${userId}`)?.remove();
} else {
this.room.players[userId].online = false;
document.getElementById(`list-group-${userId}`).classList.add('offline');
document.getElementById(`points-${userId}`).classList.remove('bg-success');
document.getElementById(`points-${userId}`).classList.add('bg-secondary');
}
}

/**
Expand Down
10 changes: 10 additions & 0 deletions quizbowl/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Player {

this.teamId = undefined;
this.username = '';
this.buzzes = 0;
this.powers = 0;
this.tens = 0;
this.zeroes = 0;
Expand All @@ -24,6 +25,7 @@ class Player {
}

clearStats () {
this.buzzes = 0;
this.powers = 0;
this.tens = 0;
this.zeroes = 0;
Expand Down Expand Up @@ -63,6 +65,14 @@ class Player {
}
}

/**
* Returns true if the player has recorded any stats or buzzes.
* @returns {boolean}
*/
hasActivity () {
return this.tuh > 0 || this.buzzes > 0 || this.powers > 0 || this.tens > 0 || this.zeroes > 0 || this.negs > 0;
}

/**
* Safely update the player's username, and return the new username.
* @param {string} username
Expand Down
15 changes: 11 additions & 4 deletions quizbowl/Room.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,18 @@ export default class Room {
}

leave (userId) {
// this.deletePlayer(userId);
this.players[userId].online = false;
if (!this.players[userId]) { return; }
const player = this.players[userId];
const username = player.username;
delete this.sockets[userId];
const username = this.players[userId].username;
this.emitMessage({ type: 'leave', userId, username });
if (!player.hasActivity()) {
delete this.players[userId];
delete this.teams[userId];
this.emitMessage({ type: 'leave', userId, username, remove: true });
} else {
player.online = false;
this.emitMessage({ type: 'leave', userId, username });
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions quizbowl/TossupRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const TossupRoomMixin = (QuestionRoomClass) => class extends QuestionRoom
clearTimeout(this.timeoutID);
this.buzzedIn = userId;
this.buzzes.push(userId);
this.players[userId].buzzes++;
this.buzzpointIndices.push(this.questionSplit.slice(0, this.wordIndex).join(' ').length);
this.paused = false;

Expand Down