• 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
..
achievements.php Loading commit data...
activity.php Loading commit data...
analysis.php Loading commit data...
auth.php Loading commit data...
battlepass.php Loading commit data...
bots.php Loading commit data...
challenges.php Loading commit data...
config.php Loading commit data...
daily-reward.php Loading commit data...
domino.php Loading commit data...
friends.php Loading commit data...
game.php Loading commit data...
leaderboard.php Loading commit data...
ludo.php Loading commit data...
matchmaking.php Loading commit data...
multiplayer.php Loading commit data...
notifications.php Loading commit data...
orgs.php Loading commit data...
profile.php Loading commit data...
puzzles.php Loading commit data...
ratings.php Loading commit data...
shop.php Loading commit data...
swiss.php Loading commit data...
theme.php Loading commit data...
tournaments.php Loading commit data...