From 35e1a863f6404d5630c3000b720f6ba99bf8548e Mon Sep 17 00:00:00 2001 From: Snap Date: Sun, 3 May 2015 23:00:34 -0700 Subject: Login fixes and matches progress --- ajax/match.ajax.php | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) (limited to 'ajax/match.ajax.php') diff --git a/ajax/match.ajax.php b/ajax/match.ajax.php index 391c69e..3a4bfae 100644 --- a/ajax/match.ajax.php +++ b/ajax/match.ajax.php @@ -8,11 +8,19 @@ session_start(); //header_remove(); - require_once('../includes/sqlEmbedded.php'); +//Prep response $r = ''; +//Gamelist request? +if (isset($_REQUEST['getGameList'])) { + $r['matches'] = getMatchList(); + echo json_encode($r); + exit; +} + + if (is_int($_GET['matchID'])) { $matchID = $_GET['matchID']; } @@ -129,6 +137,59 @@ function getPlayersForMatch($matchID) { return $array; } +function getMatchList() { + global $mysqli; + + if (!is_object($mysqli)) die("mysqli is not an object"); + + if ($res = $mysqli->query(" + SELECT + matches.ID, + matches.creatorUserID, + matches.mapID, + matches.isComplete, + matches.isStarted, + + TIME_TO_SEC(TIMEDIFF(NOW(), matches.dateCreated)) as secondsSinceCreated, + + matches.dateExpires, + matches.dateStarted, + matches.requiredPlayers, + + COUNT(matchUsers.matchID) as currentPlayers, + + matches.secondsGiven, + matches.useSmartTime, + + users.displayName, + users.displayColor, + users.wallColor, + users.wallEmblem, + users.wallOrientation + FROM `matches` + JOIN `matchUsers` + ON matchUsers.matchID = matches.ID + JOIN `users` + ON matches.creatorUserID = users.ID + GROUP BY matches.ID + ")) { + $array = array(); + if ($res->num_rows == 0) { + $res->close(); + return false; + } + while ($response = $res->fetch_assoc()) { + $array[] = $response; + } + $res->close(); + if (count($array) < 1) return false; + return $array; + } else { + printf("DB Error: %s\n", $mysqli->error); + return false; + } +} + function getMatchStatus($matchID) { global $mysqli; -- cgit v1.2.3