Commit 57d5b88d authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: matchmaking — add match_type, initial_time_ms, started_at to match creation

ROOT CAUSE: matches table has NOT NULL constraint on 'match_type' column.
Insert was failing silently, falling through to 'queued: true'.

FIX: Added required fields:
- match_type: 'rated'
- initial_time_ms: calculated from time_control
- white/black_time_remaining_ms: set to initial
- is_rated: true
- started_at: current timestamp

Removed debug output.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 9c2f1f1d
...@@ -93,22 +93,30 @@ function handleQueue($db, string $userId, array $input): void { ...@@ -93,22 +93,30 @@ function handleQueue($db, string $userId, array $input): void {
$blackId = $isWhite ? $opponent['player_id'] : $userId; $blackId = $isWhite ? $opponent['player_id'] : $userId;
// Create match // Create match
$initialTime = 600000; // default 10 min
if (strpos($timeControl, 'bullet') !== false) $initialTime = 60000;
elseif (strpos($timeControl, 'blitz') !== false) $initialTime = 300000;
elseif (strpos($timeControl, 'classical') !== false) $initialTime = 3600000;
$matchData = [ $matchData = [
'game_key' => $gameKey, 'game_key' => $gameKey,
'match_type' => 'rated',
'white_player_id' => $whiteId, 'white_player_id' => $whiteId,
'black_player_id' => $blackId, 'black_player_id' => $blackId,
'status' => 'in_progress', 'status' => 'in_progress',
'time_control' => $timeControl, 'time_control' => $timeControl,
'initial_time_ms' => $initialTime,
'white_time_remaining_ms' => $initialTime,
'black_time_remaining_ms' => $initialTime,
'current_fen' => 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1', 'current_fen' => 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1',
'moves' => '[]', 'moves' => '[]',
'move_count' => 0, 'move_count' => 0,
'game_state' => '{}' 'game_state' => '{}',
'is_rated' => true,
'started_at' => date('c')
]; ];
$match = $sdb->insert('matches', $matchData); $match = $sdb->insert('matches', $matchData);
if (isset($match['error'])) {
jsonResponse(['queued' => true, 'debug_match_error' => $match['error'], 'debug_data' => $matchData]);
}
$matchId = $match[0]['id'] ?? $match['id'] ?? null; $matchId = $match[0]['id'] ?? $match['id'] ?? null;
if ($matchId) { if ($matchId) {
...@@ -130,9 +138,7 @@ function handleQueue($db, string $userId, array $input): void { ...@@ -130,9 +138,7 @@ function handleQueue($db, string $userId, array $input): void {
} }
} }
// Debug: return what the search found jsonResponse(['queued' => true]);
$debugOpponents = is_array($opponents) ? count($opponents) : 'not_array';
jsonResponse(['queued' => true, 'debug_found' => $debugOpponents, 'debug_user' => $userId, 'debug_url' => $searchUrl ?? 'none']);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment