-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogress.php
More file actions
50 lines (41 loc) · 1.12 KB
/
progress.php
File metadata and controls
50 lines (41 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
include 'App/Quiuq.php';
use App\Quiuq;
function error($msg) {
header('Content-type: application/json');
echo json_encode(['success' => false, 'msg' => $msg]);
return;
}
if (!isset($_POST['room_id'])) {
error("O número da sala é obrigatório.");
return;
}
if (!isset($_POST['index'])) {
error("O index é obrigatório.");
return;
}
$filename = "rooms/".$_POST['room_id'].".json";
if (!is_writable($filename)) {
error("O número da sala não existe.");
return;
}
$scheme = file_get_contents($filename);
$obj = json_decode($scheme, true);
if ($obj['end_game'] == 1) {
$wplayer = '';
foreach ($obj['players'] as $player) {
if ($player['winner'])
$wplayer = $player['name'];
}
error("O vencedor foi: ". $wplayer);
return;
}
header('Content-type: application/json');
echo json_encode([
'success' => true,
'room_id' => $_POST['room_id'],
'my_turn' => $obj['players'][$_POST['index']]['my_turn'],
'mnmb' => $obj['players'][$_POST['index']]['nmb'],
'guess' => $obj['players'][$_POST['index']]['guess'],
'console' => $obj['console']
]);