Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
el3ab-Player
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
el3ab-Player
Commits
a43f91fe
Commit
a43f91fe
authored
May 26, 2026
by
Mahmoud Aglan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: use matches table (not games) + fix analysis API table refs
Co-Authored-By:
Claude Opus 4.6
<
noreply@anthropic.com
>
parent
4f3da099
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
32 deletions
+65
-32
analysis.php
api/analysis.php
+5
-5
game.php
api/game.php
+60
-27
No files found.
api/analysis.php
View file @
a43f91fe
...
...
@@ -21,7 +21,7 @@ if ($method === 'GET') {
exit
;
}
$res
=
supabase_rest
(
'GET'
,
"
games?id=eq.
{
$gameId
}
&select=id,bot_id,player_color,pgn,fen,final_fen,result,reason,time_control,increment,rated,status,started_at,ended_at,game_state,clock_white,clock_black
"
,
[],
$token
);
$res
=
supabase_rest
(
'GET'
,
"
matches?id=eq.
{
$gameId
}
&select=*
"
,
[],
$token
);
if
(
$res
[
'status'
]
>=
200
&&
$res
[
'status'
]
<
300
&&
!
empty
(
$res
[
'data'
]))
{
$game
=
$res
[
'data'
][
0
];
...
...
@@ -83,7 +83,7 @@ switch ($action) {
$response
=
curl_exec
(
$ch
);
$httpCode
=
curl_getinfo
(
$ch
,
CURLINFO_HTTP_CODE
);
curl_close
(
$ch
);
unset
(
$ch
);
if
(
$httpCode
===
200
)
{
$data
=
json_decode
(
$response
,
true
);
...
...
@@ -118,7 +118,7 @@ switch ($action) {
];
// Get existing game_state
$gameRes
=
supabase_rest
(
'GET'
,
"
gam
es?id=eq.
{
$gameId
}
&select=game_state"
,
[],
$token
);
$gameRes
=
supabase_rest
(
'GET'
,
"
match
es?id=eq.
{
$gameId
}
&select=game_state"
,
[],
$token
);
$existingState
=
[];
if
(
!
empty
(
$gameRes
[
'data'
][
0
][
'game_state'
]))
{
$existingState
=
$gameRes
[
'data'
][
0
][
'game_state'
];
...
...
@@ -128,7 +128,7 @@ switch ($action) {
}
$existingState
[
'analysis'
]
=
$analysisData
;
supabase_rest
(
'PATCH'
,
"
gam
es?id=eq.
{
$gameId
}
"
,
[
supabase_rest
(
'PATCH'
,
"
match
es?id=eq.
{
$gameId
}
"
,
[
'game_state'
=>
json_encode
(
$existingState
)
],
$token
);
...
...
@@ -167,7 +167,7 @@ switch ($action) {
$response
=
curl_exec
(
$ch
);
$httpCode
=
curl_getinfo
(
$ch
,
CURLINFO_HTTP_CODE
);
curl_close
(
$ch
);
unset
(
$ch
);
if
(
$httpCode
===
200
)
{
$data
=
json_decode
(
$response
,
true
);
...
...
api/game.php
View file @
a43f91fe
...
...
@@ -16,8 +16,17 @@ $method = $_SERVER['REQUEST_METHOD'];
if
(
$method
===
'GET'
)
{
$action
=
$_GET
[
'action'
]
??
''
;
if
(
$action
===
'recent'
)
{
$res
=
supabase_rest
(
'GET'
,
'
games?select=id,bot_id,result,reason,time_control,created_at&status=eq.completed&order=crea
ted_at.desc&limit=10'
,
[],
$token
);
$res
=
supabase_rest
(
'GET'
,
'
matches?select=id,bot_id,result,time_control,completed_at&status=eq.completed&order=comple
ted_at.desc&limit=10'
,
[],
$token
);
echo
json_encode
([
'games'
=>
$res
[
'data'
]
??
[]]);
}
elseif
(
$action
===
'get'
)
{
$id
=
$_GET
[
'id'
]
??
''
;
$res
=
supabase_rest
(
'GET'
,
"matches?id=eq.
{
$id
}
&select=*"
,
[],
$token
);
if
(
!
empty
(
$res
[
'data'
]))
{
echo
json_encode
([
'game'
=>
$res
[
'data'
][
0
]]);
}
else
{
http_response_code
(
404
);
echo
json_encode
([
'error'
=>
'not found'
]);
}
}
else
{
echo
json_encode
([
'error'
=>
'invalid action'
]);
}
...
...
@@ -35,18 +44,34 @@ switch ($action) {
$increment
=
$input
[
'increment'
]
??
0
;
$rated
=
$input
[
'rated'
]
??
true
;
$gameData
=
[
'player_color'
=>
$color
,
$userRes
=
supabase_auth
(
'user'
,
[],
$token
,
'GET'
);
$userId
=
$userRes
[
'data'
][
'id'
]
??
null
;
$matchData
=
[
'match_type'
=>
'bot'
,
'bot_id'
=>
$botId
,
'time_control'
=>
$timeControl
,
'increment'
=>
$increment
,
'rated'
=>
$rated
,
'status'
=>
'active'
,
'bot_difficulty'
=>
$botId
,
'status'
=>
'in_progress'
,
'time_control'
=>
$timeControl
<=
180
?
'bullet'
:
(
$timeControl
<=
600
?
'blitz'
:
'rapid'
),
'initial_time_ms'
=>
$timeControl
*
1000
,
'increment_ms'
=>
$increment
*
1000
,
'white_time_remaining_ms'
=>
$timeControl
*
1000
,
'black_time_remaining_ms'
=>
$timeControl
*
1000
,
'is_rated'
=>
$rated
,
'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'
,
'move_count'
=>
0
,
'moves'
=>
'[]'
,
'started_at'
=>
date
(
'c'
),
'fen'
=>
'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'
];
$res
=
supabase_rest
(
'POST'
,
'games'
,
$gameData
,
$token
);
if
(
$color
===
'w'
)
{
$matchData
[
'white_player_id'
]
=
$userId
;
}
else
{
$matchData
[
'black_player_id'
]
=
$userId
;
}
$res
=
supabase_rest
(
'POST'
,
'matches'
,
$matchData
,
$token
);
if
(
$res
[
'status'
]
>=
200
&&
$res
[
'status'
]
<
300
&&
!
empty
(
$res
[
'data'
]))
{
echo
json_encode
([
'game_id'
=>
$res
[
'data'
][
0
][
'id'
]
??
null
,
'status'
=>
'started'
]);
...
...
@@ -85,7 +110,7 @@ switch ($action) {
if
(
$httpCode
===
200
)
{
$data
=
json_decode
(
$response
,
true
);
echo
json_encode
([
'move'
=>
$data
[
'best_move'
]
??
null
]);
echo
json_encode
([
'move'
=>
$data
[
'best_move'
]
??
null
,
'eval'
=>
$data
[
'evaluation'
]
??
null
]);
}
else
{
http_response_code
(
502
);
echo
json_encode
([
'error'
=>
'bot_unavailable'
,
'status'
=>
$httpCode
]);
...
...
@@ -96,14 +121,19 @@ switch ($action) {
$gameId
=
$input
[
'game_id'
]
??
''
;
$move
=
$input
[
'move'
]
??
''
;
$fen
=
$input
[
'fen'
]
??
''
;
$moves
=
$input
[
'moves'
]
??
null
;
if
(
$gameId
&&
!
str_starts_with
(
$gameId
,
'game_'
))
{
supabase_rest
(
'PATCH'
,
"games?id=eq.
{
$gameId
}
"
,
[
'fen'
=>
$fen
,
'last_move'
=>
$move
,
'clock_white'
=>
$input
[
'clock_white'
]
??
null
,
'clock_black'
=>
$input
[
'clock_black'
]
??
null
],
$token
);
$update
=
[
'current_fen'
=>
$fen
,
'white_time_remaining_ms'
=>
(
$input
[
'clock_white'
]
??
0
)
*
1000
,
'black_time_remaining_ms'
=>
(
$input
[
'clock_black'
]
??
0
)
*
1000
,
];
if
(
$moves
!==
null
)
{
$update
[
'moves'
]
=
json_encode
(
$moves
);
$update
[
'move_count'
]
=
count
(
$moves
);
}
supabase_rest
(
'PATCH'
,
"matches?id=eq.
{
$gameId
}
"
,
$update
,
$token
);
}
echo
json_encode
([
'ok'
=>
true
]);
break
;
...
...
@@ -114,23 +144,26 @@ switch ($action) {
$reason
=
$input
[
'reason'
]
??
''
;
$pgn
=
$input
[
'pgn'
]
??
''
;
$finalFen
=
$input
[
'final_fen'
]
??
''
;
$moves
=
$input
[
'moves'
]
??
null
;
$resultMap
=
[
'win'
=>
'white_win'
,
'loss'
=>
'black_win'
,
'draw'
=>
'draw'
];
if
(
$gameId
&&
!
str_starts_with
(
$gameId
,
'game_'
))
{
supabase_rest
(
'PATCH'
,
"games?id=eq.
{
$gameId
}
"
,
[
$update
=
[
'status'
=>
'completed'
,
'result'
=>
$result
,
'reason'
=>
$reason
,
'result'
=>
$resultMap
[
$result
]
??
$result
,
'pgn'
=>
$pgn
,
'final_fen'
=>
$finalFen
,
'ended_at'
=>
date
(
'c'
)
],
$token
);
'current_fen'
=>
$finalFen
,
'completed_at'
=>
date
(
'c'
),
];
if
(
$moves
!==
null
)
{
$update
[
'moves'
]
=
json_encode
(
$moves
);
$update
[
'move_count'
]
=
count
(
$moves
);
}
if
(
$result
===
'win'
)
{
supabase_rest
(
'POST'
,
'rpc/add_coins'
,
[
'amount'
=>
50
],
$token
);
supabase_rest
(
'PATCH'
,
"matches?id=eq.
{
$gameId
}
"
,
$update
,
$token
);
}
echo
json_encode
([
'ok'
=>
true
,
'result'
=>
$result
]);
echo
json_encode
([
'ok'
=>
true
,
'result'
=>
$result
,
'game_id'
=>
$gameId
]);
break
;
default
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment