diff --git a/client/src/views/DemoGame.vue b/client/src/views/DemoGame.vue index 9e713f7..8ec2533 100644 --- a/client/src/views/DemoGame.vue +++ b/client/src/views/DemoGame.vue @@ -329,9 +329,39 @@ function onP2Action(action: 'accept'|'reject'|'snatch') { colyseusService.p2Acti function onReport(val: boolean) { colyseusService.report(val); } function onAssignShame(val: boolean) { colyseusService.assignShame(val); } -function leaveGame() { - console.log('[DemoGame] User manually leaving game'); - colyseusService.leaveGame(); +async function leaveGame() { + // Ask for confirmation before closing the room for both players + if (!confirm('¿Cerrar la sala para ambos jugadores? Esto terminará el juego inmediatamente.')) { + return; + } + + console.log('[DemoGame] User closing room for both players'); + + try { + // Close the room for both players using the admin API + const response = await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3000/api'}/rooms/${roomId.value}/close`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' } + }); + + if (!response.ok) { + console.error('Failed to close room via API'); + // Fallback to normal leave if API fails + colyseusService.leaveGame(); + } else { + console.log(`Room ${roomId.value} closed successfully for both players`); + // Just leave locally, the server will handle disconnecting both players + if (colyseusService.gameRoom.value) { + colyseusService.gameRoom.value.leave(); + } + } + } catch (error) { + console.error('Error closing room:', error); + // Fallback to normal leave if error occurs + colyseusService.leaveGame(); + } + + // Navigate back to lobby router.push(`/${routeUuid.value}`); } diff --git a/client/src/views/Lobby.vue b/client/src/views/Lobby.vue index 54be0ff..93b1bb5 100644 --- a/client/src/views/Lobby.vue +++ b/client/src/views/Lobby.vue @@ -95,6 +95,11 @@ const previewPlayer = computed(() => ({ color: colorInput.value || playerColor.value })); +// Define missing reactive variables +const availableRooms = ref([]); +const totalPlayers = ref(0); +const onlinePlayers = ref([]); + onMounted(async () => { try { const room = await colyseusService.joinLobby();