fix: ghost players on back - leaveRoom, store.reset, dynamic lobby slots

This commit is contained in:
kevin.lhereec committed 2026-08-17 14:18:27 +02:00
1 parent 6e384d5985
commit c7672b1793
5 files changed
+86 -20

No files matched your search

+13
View File
@@ -119,6 +119,19 @@ io.on('connection', (socket) => {
}
})
// ─── Quitter une salle explicitement (bouton retour) ────────────────────────
socket.on('leave-room', ({ roomId }) => {
const room = rooms.get(roomId)
if (room) {
room.removePlayer(socket.id)
socket.leave(roomId)
io.to(roomId).emit('room-update', { players: room.getPlayersInfo() })
if (room.playerCount === 0) rooms.delete(roomId)
console.log(`[${roomId}] ${socket.data.playerName ?? socket.id} a quitté`)
}
socket.data.roomId = null
})
// ─── Déconnexion ─────────────────────────────────────────────────────────────
socket.on('disconnect', () => {
const roomId = socket.data.roomId