From f09e14f99ac26bd4cd6cf33e4d7901bbf10f0e14 Mon Sep 17 00:00:00 2001 From: Resistencia Dev Date: Mon, 8 Dec 2025 20:51:46 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=AA=20Finalizar=20partida=20expulsa=20?= =?UTF-8?q?a=20todos=20al=20lobby=20-=20El=20host=20puede=20terminar=20la?= =?UTF-8?q?=20partida,=20elimin=C3=A1ndola=20del=20listado=20y=20enviando?= =?UTF-8?q?=20a=20todos=20los=20jugadores=20al=20lobby?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/hooks/useSocket.ts | 6 ++++++ server/src/index.ts | 18 ++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/client/src/hooks/useSocket.ts b/client/src/hooks/useSocket.ts index c1292c5..3dc1775 100644 --- a/client/src/hooks/useSocket.ts +++ b/client/src/hooks/useSocket.ts @@ -44,6 +44,12 @@ export const useSocket = () => { alert(msg); // Simple error handling for now }); + // Manejar finalización de partida por el host + socketInstance.on('game_finalized', () => { + console.log('La partida ha sido finalizada por el host'); + setGameState(null); // Resetear estado para volver al lobby + }); + setSocket(socketInstance); return () => { diff --git a/server/src/index.ts b/server/src/index.ts index f77df69..0b4044f 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -287,15 +287,17 @@ io.on('connection', (socket) => { socket.on('finalize_game', ({ roomId }) => { const game = games[roomId]; if (game && game.hostId === socket.id) { - game.finalizeGame(); - io.to(roomId).emit('game_state', game.state); + // Notificar a todos los jugadores que la partida ha sido finalizada + io.to(roomId).emit('game_finalized'); - // Esperar 5 segundos y luego eliminar la partida - setTimeout(() => { - delete games[roomId]; - // Desconectar a todos los jugadores de la sala - io.in(roomId).socketsLeave(roomId); - }, 5000); + // Eliminar la partida inmediatamente del registro + delete games[roomId]; + + // Actualizar lista de salas para todos los clientes + io.emit('rooms_list', getRoomsList()); + + // Desconectar a todos los jugadores de la sala + io.in(roomId).socketsLeave(roomId); } });