From 2c03f6cd34fac7fe6be0e3c747efdd3fb6a8baa8 Mon Sep 17 00:00:00 2001 From: dot-Comfey <84290266+dot-Comfey@users.noreply.github.com> Date: Sat, 14 Dec 2024 03:03:48 -0800 Subject: [PATCH 1/2] Trivia: Fix crash and Number mode game cap Discussed with Trivia auth. Fixes an issue in Number mode where the game fails to end after a specified amount of questions, and fixes a crash caused by ending a game with no participation --- server/chat-plugins/trivia/trivia.ts | 34 ++++++++++++++++------------ 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/server/chat-plugins/trivia/trivia.ts b/server/chat-plugins/trivia/trivia.ts index b158344bdf37..cb04983946eb 100644 --- a/server/chat-plugins/trivia/trivia.ts +++ b/server/chat-plugins/trivia/trivia.ts @@ -826,6 +826,7 @@ export class Trivia extends Rooms.RoomGame { const prizes = this.getPrizes(); const [p1, p2, p3] = winners; + if (!p1) return `No winners this game!`; let initialPart = this.room.tr`${Utils.escapeHTML(p1.name)} won the game with a final score of ${p1.player.points}`; if (!this.game.givesPoints) { return `${initialPart}.`; @@ -847,18 +848,25 @@ export class Trivia extends Rooms.RoomGame { getStaffEndMessage(winners: TopPlayer[], mapper: (k: TopPlayer) => string) { let message = ""; - const winnerParts: ((k: TopPlayer) => string)[] = [ - winner => this.room.tr`User ${mapper(winner)} won the game of ` + + if (winners.length) { + const winnerParts: ((k: TopPlayer) => string)[] = [ + winner => this.room.tr`User ${mapper(winner)} won the game of ` + + (this.game.givesPoints ? this.room.tr`ranked ` : this.room.tr`unranked `) + + this.room.tr`${this.game.mode} mode trivia under the ${this.game.category} category with ` + + this.room.tr`a cap of ${this.getDisplayableCap()} ` + + this.room.tr`with ${winner.player.points} points and ` + + this.room.tr`${winner.player.correctAnswers} correct answers`, + winner => this.room.tr` Second place: ${mapper(winner)} (${winner.player.points} points)`, + winner => this.room.tr`, third place: ${mapper(winner)} (${winner.player.points} points)`, + ]; + for (let i = 0; i < winners.length; i++) { + message += winnerParts[i](winners[i]); + } + } else { + message = `No participants in the game of ` + (this.game.givesPoints ? this.room.tr`ranked ` : this.room.tr`unranked `) + this.room.tr`${this.game.mode} mode trivia under the ${this.game.category} category with ` + - this.room.tr`a cap of ${this.getDisplayableCap()} ` + - this.room.tr`with ${winner.player.points} points and ` + - this.room.tr`${winner.player.correctAnswers} correct answers`, - winner => this.room.tr` Second place: ${mapper(winner)} (${winner.player.points} points)`, - winner => this.room.tr`, third place: ${mapper(winner)} (${winner.player.points} points)`, - ]; - for (let i = 0; i < winners.length; i++) { - message += winnerParts[i](winners[i]); + this.room.tr`a cap of ${this.getDisplayableCap()}`; } return `${message}`; } @@ -1088,11 +1096,9 @@ export class NumberModeTrivia extends Trivia { ); const points = this.calculatePoints(innerBuffer.length); - let winner = false; + const cap = this.getCap(); + let winner = cap.questions && this.questionNumber >= cap.questions; if (points) { - const cap = this.getCap(); - // We add 1 questionNumber because it starts at 0 - winner = !!cap.questions && this.questionNumber >= cap.questions; for (const userid in this.playerTable) { const player = this.playerTable[userid]; if (player.isCorrect) player.incrementPoints(points, this.questionNumber); From 0b4be5beb34b8b31ac2f8dce5d2006cef2961473 Mon Sep 17 00:00:00 2001 From: dot-Comfey <84290266+dot-Comfey@users.noreply.github.com> Date: Sat, 14 Dec 2024 16:08:28 -0800 Subject: [PATCH 2/2] Update server/chat-plugins/trivia/trivia.ts Co-authored-by: Kris Johnson <11083252+KrisXV@users.noreply.github.com> --- server/chat-plugins/trivia/trivia.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/chat-plugins/trivia/trivia.ts b/server/chat-plugins/trivia/trivia.ts index cb04983946eb..5f613c5db3ef 100644 --- a/server/chat-plugins/trivia/trivia.ts +++ b/server/chat-plugins/trivia/trivia.ts @@ -859,8 +859,8 @@ export class Trivia extends Rooms.RoomGame { winner => this.room.tr` Second place: ${mapper(winner)} (${winner.player.points} points)`, winner => this.room.tr`, third place: ${mapper(winner)} (${winner.player.points} points)`, ]; - for (let i = 0; i < winners.length; i++) { - message += winnerParts[i](winners[i]); + for (const [i, winner] of winners.entries()) { + message += winnerParts[i](winner); } } else { message = `No participants in the game of ` +