fix(chess): prevent duplicate players and fix move detection
Some checks failed
Deploy to Production / test (push) Failing after 38s
Some checks failed
Deploy to Production / test (push) Failing after 38s
- Prevent same player from joining as both white and black - Add validation to reject duplicate players in RoomManager - Fix spectator status not resetting when joining as player - Use ref to track latest chess state in ChessBoard for accurate move validation
This commit is contained in:
@@ -46,7 +46,8 @@ export class RoomManager {
|
||||
|
||||
const plugin = gameRegistry.get(room.gameSlug)!;
|
||||
if (room.players.length >= plugin.maxPlayers && role !== "admin") return { ok: false, error: "Room is full" };
|
||||
if (room.players.includes(playerId) && role !== "admin") return { ok: true, started: room.status === "playing" };
|
||||
if (room.players.includes(playerId) && role !== "admin") return { ok: true, started: room.status === "waiting" };
|
||||
if (room.players.includes(playerId) && role === "admin") return { ok: false, error: "Already a player in this game" };
|
||||
|
||||
if (!room.players.includes(playerId) || role === "admin") {
|
||||
room.players.push(playerId);
|
||||
|
||||
Reference in New Issue
Block a user