• Mahmoud Aglan's avatar
    fix: realtime chess multiplayer — RLS bypass + live polling + opponent move sync · c37f0571
    Mahmoud Aglan authored
    ROOT CAUSE: Supabase RLS on matchmaking_queue only allowed players to
    see their OWN rows. Player A couldn't find Player B in the queue.
    
    FIX: All matchmaking operations now use service_role key (bypasses RLS):
    - handleQueue: searches ALL waiting players, not just own
    - handleStatus: reads match details with service key
    - handleDequeue: cleans up with service key
    - Random color assignment (50/50 white/black)
    
    Chess game live mode:
    - NEW: sendLiveMove() — sends current FEN + move_count to server after player moves
    - NEW: startLivePolling() — polls match row every 2s for opponent's move
    - NEW: When opponent's move_count increases, loads new FEN and updates board
    - NEW: Detects opponent resign/completion via status field
    - If playing as black in live mode, waits for white's first move
    - stopLivePolling() on game end
    
    Flow:
    1. Player A queues → inserted as 'waiting'
    2. Player B queues → finds Player A, creates match, marks A as 'matched'
    3. Player B gets match_id immediately (they're white or black randomly)
    4. Player A polls status → finds 'matched' → gets match_id + color
    5. Both enter chess-game with mode:'live' + matchId
    6. Each player's moves update the match row
    7. Opponent detects new move_count via polling
    Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
    c37f0571
Name
Last commit
Last update
..
home-redesigned.png Loading commit data...