This repository was archived by the owner on Jul 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_requests.php
66 lines (64 loc) · 2.36 KB
/
server_requests.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
<?php
// All variable used in database access are stored in secret.php are listed below:
// $server: The server on which the database exists
// $user: the username credentials to access the database
// $password: Password associated with username
// $db: The name of the database within the server
require 'secret.php';
require 'server_functions.php';
$con = mysqli_connect($server, $user, $password, $db);
$func = $_GET['FUNCTION'];
$retObj = (object) [
'ERROR' => null,
'DATA' => null,
];
switch($func) {
case 'CREATE_USER':
$name = $_GET['USERNAME'];
$pass = $_GET['PASSWORD'];
createUser($con, $name, $pass, $retObj);
break;
case 'AUTHENTICATE_USER':
$name = $_GET['USERNAME'];
$pass = $_GET['PASSWORD'];
authenticateUser($con, $name, $pass, $retObj);
break;
case 'CREATE_GAME':
$creatorID = $_GET['CREATOR_ID'];
$challengedName = $_GET['CHALLENGED_NAME'];
if($retObj->ERROR == null) {
createGame($con, $creatorID, $challengedName, $retObj);
}
break;
case 'LOAD_GAME':
$gameID = $_GET['GAME_ID'];
loadGame($con, $gameID, $retObj);
break;
case 'FETCH_GAMES':
$userID = $_GET['USER_ID'];
fetchGames($con, $userID, $retObj);
break;
case 'TAKE_TURN':
$nextTurnNumber = $_GET['NEXT_TURN'];
$cellID = $_GET['CELL_ID'];
$squareID = $_GET['SQUARE_ID'];
$gameID = $_GET['GAME_ID'];
$nextSquare = $_GET['NEXT_SQUARE'];
$playerID = $_GET['PLAYER_ID'];
$opponentID = $_GET['OPPONENT_ID'];
$tookSquare = $_GET['TOOK_SQUARE'] == "true";
$wonGame = $_GET['WON_GAME'] == "true";
takeTurn($con, $nextTurnNumber, $cellID, $squareID, $gameID, $nextSquare, $playerID, $opponentID, $tookSquare, $wonGame, $retObj);
break;
case 'POLL_TURN':
$gameID = $_GET['GAME_ID'];
$userID = $_GET['USER_ID'];
pollTurn($con, $gameID, $userID, $retObj);
break;
default:
$retObj->ERROR = "COMMAND UNKNOWN";
}
mysqli_close($con);
echo json_encode($retObj);
exit();
?>