From d85c6e2c8920ec0de0af2d20ae0f54abe680767b Mon Sep 17 00:00:00 2001 From: Audiino <121476415+Audiino@users.noreply.github.com> Date: Tue, 1 Jul 2025 17:00:26 +0700 Subject: [PATCH 1/4] interface: Stop sending game pages to players who forfeited --- src/ps/handlers/interface.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ps/handlers/interface.ts b/src/ps/handlers/interface.ts index 61e9f37c..4e37ccd6 100644 --- a/src/ps/handlers/interface.ts +++ b/src/ps/handlers/interface.ts @@ -26,11 +26,12 @@ export function interfaceHandler(message: PSMessage) { if (!game) return; // Don't put any errors here! People should be able to close games that don't exist, like ones that ended const user = message.author.id; - if (game.hasPlayer(user)) { + const player = Object.values(game.players).find(p => p.id === user); + if (game.hasPlayer(user) && player && !player.out) { message.reply(game.$T('GAME.CANNOT_LEAVE', { prefix, game: game.meta.id })); return game.update(user); } - if (game.spectators.includes(user)) { + if (game.spectators.includes(user) || (player && player.out)) { game.spectators.remove(user); message.reply( game.$T('GAME.NO_LONGER_WATCHING', { From bb68582fb0ec930d63c0f4fb07aad1ce2881ed1d Mon Sep 17 00:00:00 2001 From: Audiino <121476415+Audiino@users.noreply.github.com> Date: Tue, 1 Jul 2025 19:06:20 +0700 Subject: [PATCH 2/4] games: Removed players get added to spectator list --- src/ps/games/game.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ps/games/game.ts b/src/ps/games/game.ts index 5be4a2f6..08447716 100644 --- a/src/ps/games/game.ts +++ b/src/ps/games/game.ts @@ -294,6 +294,7 @@ export class BaseGame { const forfeitPlayer = this.onForfeitPlayer?.(player, ctx); if (forfeitPlayer?.success === false) return forfeitPlayer; player.out = true; + this.spectators.push(player.id); this.log.push({ action: staffAction ? 'dq' : 'forfeit', turn: player.turn, time: new Date(), ctx: null }); return { success: true, From 62fa7e367a60f5c2c5a4e83c37007dcc63329602 Mon Sep 17 00:00:00 2001 From: Audiino <121476415+Audiino@users.noreply.github.com> Date: Wed, 2 Jul 2025 17:24:51 +0700 Subject: [PATCH 3/4] remove the line --- src/ps/handlers/interface.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ps/handlers/interface.ts b/src/ps/handlers/interface.ts index 4e37ccd6..20d70abe 100644 --- a/src/ps/handlers/interface.ts +++ b/src/ps/handlers/interface.ts @@ -31,7 +31,7 @@ export function interfaceHandler(message: PSMessage) { message.reply(game.$T('GAME.CANNOT_LEAVE', { prefix, game: game.meta.id })); return game.update(user); } - if (game.spectators.includes(user) || (player && player.out)) { + if (game.spectators.includes(user)) { game.spectators.remove(user); message.reply( game.$T('GAME.NO_LONGER_WATCHING', { From 9b6743eb482c312052df2a10a4de89d8946661f1 Mon Sep 17 00:00:00 2001 From: Audiino <121476415+Audiino@users.noreply.github.com> Date: Sat, 5 Jul 2025 00:15:35 +0700 Subject: [PATCH 4/4] games: Update doesn't send removed players the full render anymore --- src/ps/games/game.ts | 2 +- src/ps/handlers/interface.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ps/games/game.ts b/src/ps/games/game.ts index 08447716..63384bb7 100644 --- a/src/ps/games/game.ts +++ b/src/ps/games/game.ts @@ -410,7 +410,7 @@ export class BaseGame { if (!this.started) return; if (user) { const asPlayer = Object.values(this.players).find(player => player.id === user); - if (asPlayer) return this.sendHTML(asPlayer.id, this.render(asPlayer.turn)); + if (asPlayer && !asPlayer.out) return this.sendHTML(asPlayer.id, this.render(asPlayer.turn)); if (this.spectators.includes(user)) return this.sendHTML(user, this.render(null)); this.throw('GAME.NON_PLAYER_OR_SPEC'); } diff --git a/src/ps/handlers/interface.ts b/src/ps/handlers/interface.ts index 20d70abe..3a19d010 100644 --- a/src/ps/handlers/interface.ts +++ b/src/ps/handlers/interface.ts @@ -26,7 +26,7 @@ export function interfaceHandler(message: PSMessage) { if (!game) return; // Don't put any errors here! People should be able to close games that don't exist, like ones that ended const user = message.author.id; - const player = Object.values(game.players).find(p => p.id === user); + const player = Object.values(game.players).find(player => player.id === user); if (game.hasPlayer(user) && player && !player.out) { message.reply(game.$T('GAME.CANNOT_LEAVE', { prefix, game: game.meta.id })); return game.update(user);