-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_game.php
70 lines (56 loc) · 2.38 KB
/
start_game.php
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?
include("utils.php");
if(isset($_POST['devID']) )
{
$devID = $_POST['devID'];
$result = mysql_query("select MIN(partID) from partidas where apuesta='1' and
(player2ID = 0 or
player3ID = 0 or
player4ID = 0 )
");
$row = mysql_fetch_row($result);
if( $row[0] != NULL )
{
$partID = $row[0];
#jugadores actuales
$result = mysql_query("select player1ID, player2ID, player3ID, player4ID from partidas where partID=$partID");
if($row = mysql_fetch_row($result) )
{
$player1ID = $row[0];
$player2ID = $row[1];
$player3ID = $row[2];
$player4ID = $row[3];
if($player2ID == 0)
{
mysql_query("update partidas set player2ID=$devID where partID=$partID");
}
else if($player3ID == 0)
{
mysql_query("update partidas set player3ID=$devID where partID=$partID");
}
else if($player4ID == 0)
{
mysql_query("update partidas set player4ID=$devID where partID=$partID");
}
echo json_encode(array("partID"=>$partID, 'player1ID'=>$player1ID,
'player2ID'=>$player2ID,
'player3ID'=>$player3ID,
'player4ID'=>$player4ID ) );
}
else
{
echo "ERROR_SELECCIONANDO_PLAYERS, $partID";
}
}
else
{
//crear nueva partida
mysql_query("insert into partidas(fecha, apuesta, player1ID) values(NOW(), 1, $devID)");
$partID = mysql_insert_id();
echo json_encode(array("partID"=>$partID, 'player1ID'=>$devID,
'player2ID'=>'0',
'player3ID'=>'0',
'player4ID'=>'0' ));
}
}
?>