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:
@@ -23,9 +23,14 @@ export const chessPlugin: GamePlugin<ChessState, ChessAction> = {
|
||||
|
||||
createInitialState(players: string[]): ChessState {
|
||||
const game = new Chess();
|
||||
|
||||
if (players[0] === players[1]) {
|
||||
throw new Error("Cannot create chess game with same player for both sides");
|
||||
}
|
||||
|
||||
return {
|
||||
fen: game.fen(),
|
||||
players: { white: players[0], black: players[1] },
|
||||
players: { white: players[0]!, black: players[1]! },
|
||||
moveHistory: [],
|
||||
status: "playing",
|
||||
winner: null,
|
||||
|
||||
Reference in New Issue
Block a user