mirror of
https://github.com/randyjc/Rahoot.git
synced 2026-03-13 20:15:35 +01:00
fix rejoining the game for some clients
This commit is contained in:
@@ -281,18 +281,6 @@ io.on("connection", (socket) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!game.started) {
|
|
||||||
game.players = game.players.filter((p) => p.id !== socket.id)
|
|
||||||
|
|
||||||
io.to(game.manager.id).emit("manager:removePlayer", player.id)
|
|
||||||
io.to(game.manager.id).emit("manager:players", game.players)
|
|
||||||
io.to(game.gameId).emit("game:totalPlayers", game.players.length)
|
|
||||||
|
|
||||||
console.log(`Removed player ${player.username} from game ${game.gameId}`)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
player.connected = false
|
player.connected = false
|
||||||
io.to(game.gameId).emit("game:totalPlayers", game.players.length)
|
io.to(game.gameId).emit("game:totalPlayers", game.players.length)
|
||||||
io.to(game.manager.id).emit("manager:players", game.players)
|
io.to(game.manager.id).emit("manager:players", game.players)
|
||||||
|
|||||||
@@ -213,13 +213,18 @@ class Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
join(socket: Socket, username: string) {
|
join(socket: Socket, username: string) {
|
||||||
const isAlreadyConnected = this.players.find(
|
const existing = this.players.find(
|
||||||
(p) => p.clientId === socket.handshake.auth.clientId
|
(p) => p.clientId === socket.handshake.auth.clientId
|
||||||
)
|
)
|
||||||
|
|
||||||
if (isAlreadyConnected) {
|
if (existing) {
|
||||||
socket.emit("game:errorMessage", "Player already connected")
|
// Reconnect existing player (even before game start)
|
||||||
|
existing.id = socket.id
|
||||||
|
existing.connected = true
|
||||||
|
if (username) existing.username = username
|
||||||
|
socket.join(this.gameId)
|
||||||
|
this.io.to(this.manager.id).emit("manager:players", this.players)
|
||||||
|
socket.emit("game:successJoin", this.gameId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user