Commit d2ec1d78 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: add match_type and initial_time_ms to tournament match creation

The matches table requires these NOT NULL columns. Set match_type
to 'tournament' and parse time_control string for clock values.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 107474d6
......@@ -109,17 +109,31 @@ function handleCreateOrJoin($db, string $userId, array $input): void {
$timeControl = $tournament['time_control'] ?? 'rapid_10_0';
$gameKey = $tournament['game_key'] ?? 'chess';
// Parse time control for initial_time_ms and increment
$tcParts = explode('_', $timeControl);
$minutes = intval($tcParts[1] ?? 10);
$increment = intval($tcParts[2] ?? 0);
$initialTimeMs = $minutes * 60 * 1000;
$incrementMs = $increment * 1000;
// Create the match
$matchData = [
'game_key' => $gameKey,
'match_type' => 'tournament',
'white_player_id' => $whiteId,
'black_player_id' => $blackId,
'status' => 'in_progress',
'time_control' => $timeControl,
'initial_time_ms' => $initialTimeMs,
'increment_ms' => $incrementMs,
'white_time_remaining_ms' => $initialTimeMs,
'black_time_remaining_ms' => $initialTimeMs,
'tournament_id' => $tournamentId,
'tournament_round' => $roundNumber,
'starting_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' => '[]',
'started_at' => date('c'),
'metadata' => json_encode([
'mode' => 'tournament',
'round_id' => $roundId,
......
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