summaryrefslogtreecommitdiffstats
path: root/ajax/match.ajax.php
diff options
context:
space:
mode:
Diffstat (limited to 'ajax/match.ajax.php')
-rw-r--r--ajax/match.ajax.php63
1 files changed, 62 insertions, 1 deletions
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;