-
Notifications
You must be signed in to change notification settings - Fork 0
/
password.game.php
74 lines (68 loc) · 2.51 KB
/
password.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
71
72
73
74
<?PHP
define('CONFIG',true);
include 'config.php';
header("Content-Type: text/json");
$return = array(
"auth" => array(
"code" => "",
"id" => 0,
"spectate" => 0
),
"return" => "none"
);
$admin = $my_code;
if(!$admin){
$return = array(
"auth" => array(
"code" => "",
"id" => 0,
"spectate" => 0
),
"return" => "user"
);
die(json_encode($return));
}
$spectate = false;
if($_POST['spectate']=='1') $spectate = true;
$return['auth']['spectate'] = $spectate?'1':'0';
if(strlen($_POST['code'])<=40 && !preg_match('/[^a-z_\-0-9]/i',$_POST['code'])){
$player_count = 2;
$spectator_limit = 1;
if($game = $link->query("SELECT * FROM `totd_games` WHERE `game_id` = '".$_POST['game']."'")){
$game = $game->fetch_array();
if($auth = $link->query("SELECT * FROM `totd_auth` WHERE `user` = '".$admin."' && `game` = '".$game['game_id']."'")){
$auth = $auth->fetch_array();
if($auth['id'] && (($auth['spectate'] && !$spectate) || (!$auth['spectate'] && $spectate))){
$link->query("DELETE FROM `totd_auth` WHERE `id` = ".$auth['id']);
$auth['id'] = false;
}
if($auth['id']){
$return = array(
"auth" => array(
"code" => $auth['code'],
"id" => $game['game_id'],
"spectate" => $spectate?'1':'0'
),
"return" => "success"
);
}
}
if($return['auth']['id']) $return=$return;
else if(!$game['id']) $return['return']='none';
else if($game['ended']) $return['return']='ended';
else if($game['admin']==$admin) $return['return']='success';
else if($game['protected']) $return['return']='password';
else if($game['player_limit']<=$player_count && !$spectate) $return['return']='full';
else if($game['spectator_limit']<=$spectator_limit && $spectate) $return['return']='full';
else $return['return']='success';
}
if($return['return']=='success' && !$return['auth']['id']){
$link->query("INSERT INTO `ids` (`id`) VALUES (NULL)");
$auth_code = randomString(36) . $link->insert_id . randomString(36);
$link->query("INSERT INTO `totd_auth` (`id`,`user`,`game`,`code`,`spectate`,`active`) VALUES (NULL,'".$admin."','".$game['game_id']."','".$auth_code."',".($spectate?'"1"':'NULL').",".time().");");
$return['auth']['code'] = $auth_code;
$return['auth']['id'] = $game['game_id'];
}
}
die(json_encode($return));
?>