From 4cb0104124c447253d9035a01e443d93098626ab Mon Sep 17 00:00:00 2001 From: Maieul BOYER Date: Sat, 17 Jan 2026 10:42:51 +0100 Subject: [PATCH] yes --- frontend/src/pages/pong/pong.ts | 12 +++++++++--- src/pong/src/state.ts | 30 +++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/frontend/src/pages/pong/pong.ts b/frontend/src/pages/pong/pong.ts index 3dd40ed..d8c09e3 100644 --- a/frontend/src/pages/pong/pong.ts +++ b/frontend/src/pages/pong/pong.ts @@ -107,7 +107,9 @@ function tourinfoButtons(tourInfo : HTMLButtonElement, tourScoreScreen : HTMLDiv }); } -function gameJoinButtons(socket : CSocket, inTournament : boolean, currentGame : currentGameInfo | null, +let inTournament: boolean = false; + +function gameJoinButtons(socket : CSocket, currentGame : currentGameInfo | null, tournament : HTMLButtonElement, queue : HTMLButtonElement, localGame : HTMLButtonElement, ready : HTMLButtonElement) { tournament.addEventListener("click", () => { @@ -150,6 +152,10 @@ function gameJoinButtons(socket : CSocket, inTournament : boolean, currentGame : } }); localGame.addEventListener("click", () => { + if (inTournament) { + showError("You can't queue up currently !"); + return; + } if ( queue.innerText !== QueueState.Iddle || currentGame !== null || @@ -274,7 +280,7 @@ function pongClient( setTitle("Pong Game"); const urlParams = new URLSearchParams(window.location.search); let game_req_join = urlParams.get("game"); - let inTournament = false; + inTournament = false; return { html: authHtml, @@ -548,7 +554,7 @@ function pongClient( setInterval(() => {keys_listen_setup(currentGame, socket, keys, playHow, playHow_b, tourScoreScreen, queue)}, 1000 / 60); - gameJoinButtons(socket, inTournament, currentGame, tournament, queue, localGame, ready); + gameJoinButtons(socket, currentGame, tournament, queue, localGame, ready); playhowButtons(playHow_b, playHow); tourinfoButtons(tourInfo, tourScoreScreen); diff --git a/src/pong/src/state.ts b/src/pong/src/state.ts index fd77adc..e0bd729 100644 --- a/src/pong/src/state.ts +++ b/src/pong/src/state.ts @@ -160,8 +160,20 @@ class StateI { }); return; } - - this.dequeueUser(user.socket); + if (user.currentGame !== null) { + sock.emit('tournamentRegister', { + kind: 'failure', + msg: 'You are in game', + }); + return; + } + if (this.queue.has(user.id)) { + sock.emit('tournamentRegister', { + kind: 'failure', + msg: 'You are in queue', + }); + return; + } this.tournament.addUser(user.id, name ?? udb.name); sock.emit('tournamentRegister', { kind: 'success', @@ -281,7 +293,9 @@ class StateI { this.games.set(gameId, g); setTimeout(() => { if (!g.ready_checks[0] && !g.ready_checks[1]) { - this.fastify.log.info(`paused game ${gameId} has been canceled`); + this.fastify.log.info( + `paused game ${gameId} has been canceled`, + ); this.cleanupGame(gameId, g); } }, 1000 * 60); @@ -444,13 +458,19 @@ class StateI { ) { this.fastify.log.warn( 'user trying to connect to a game he\'s not part of: gameId:' + - g_id + ' userId:' + sock.authUser.id); + g_id + + ' userId:' + + sock.authUser.id, + ); return JoinRes.no; } if (game.userOnPage[0] === true && game.userOnPage[1] === true) { this.fastify.log.warn( 'user trying to connect to a game he\'s already joined: gameId:' + - g_id + ' userId:' + sock.authUser.id); + g_id + + ' userId:' + + sock.authUser.id, + ); return JoinRes.no; } game.userOnPage[game.userLeft === sock.authUser.id ? 0 : 1] = true;