From 79d3c716e38084beab01d34a5f49a5aee7e72526 Mon Sep 17 00:00:00 2001 From: Snap Date: Sat, 25 Apr 2015 22:30:21 -0700 Subject: Some work on the Chat. Fixed bug where user could chat as "SERVER" --- ajax/chat.ajax.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'ajax') diff --git a/ajax/chat.ajax.php b/ajax/chat.ajax.php index 1574bde..576ab39 100644 --- a/ajax/chat.ajax.php +++ b/ajax/chat.ajax.php @@ -52,6 +52,9 @@ if (isset($_REQUEST['messages'])) { } } //Don't lockout requests by holding the session file open! + +$isLoggedIn = ($_SESSION['accepted'] == 1); + session_write_close(); $userID = $_SESSION['userID']; @@ -74,8 +77,19 @@ require_once('../includes/chats.php'); enterChannel($userID); $sent = false; +//User is sending a message if (isset($_REQUEST['messages'])) { $date = isMuted($userID); + if ($isLoggedIn !== true) { + $r[0]['error'] = 'Logged out'; + $r[0]['serverMessage'] = 'true'; + $r[0]['message'] = "Whoops, your session has timed out. Please sign in again."; + $r[0]['secondsSince'] = 0; + $r[0]['displayName'] = 'SERVER'; + $r[0]['userID'] = null; + echo json_encode($r); + exit; + } if ($date !== false) { $r[0]['error'] = 'Muted'; $r[0]['serverMessage'] = 'true'; -- cgit v1.2.3 From e90a8d192446fce277dc3efe4f2913d5fecca0dc Mon Sep 17 00:00:00 2001 From: Snap Date: Tue, 28 Apr 2015 15:53:05 -0700 Subject: Chat improvements. Fixed "&P" or ";P" bug. Reduced size of chat-request size considerably with use of header_remove(); --- ajax/chat.ajax.php | 1 + includes/chats.php | 1 + pages/chat.php | 18 +++++++++++------- 3 files changed, 13 insertions(+), 7 deletions(-) (limited to 'ajax') diff --git a/ajax/chat.ajax.php b/ajax/chat.ajax.php index 576ab39..2ffa878 100644 --- a/ajax/chat.ajax.php +++ b/ajax/chat.ajax.php @@ -6,6 +6,7 @@ session_start(); // exit; // } +header_remove(); //ini_set('display_errors',1); //ini_set('display_startup_errors',1); diff --git a/includes/chats.php b/includes/chats.php index 5bfd61f..d9616fd 100644 --- a/includes/chats.php +++ b/includes/chats.php @@ -160,6 +160,7 @@ function getChannelList($channel = 1) { chatUsers.dateEntered, TIME_TO_SEC(TIMEDIFF(NOW(), chatUsers.dateLastActive)) as secFromLastActive, + TIME_TO_SEC(TIMEDIFF(NOW(), chatUsers.dateEntered)) as secFromEntered, TIME_TO_SEC(TIMEDIFF(NOW(), users.dateChatGaggedUntil)) as secSinceGagged, chatUsers.isAdmin, diff --git a/pages/chat.php b/pages/chat.php index 4f10a1c..cc8d0eb 100644 --- a/pages/chat.php +++ b/pages/chat.php @@ -46,12 +46,13 @@ function getChatTimer() { //addChatMessage("Debug", "Chat timer called!"); } -pollChannelListTimer(); -function pollChannelListTimer() { - setTimeout("pollChannelListTimer()", channelTimerDelay); - pollChannelList(); -} +var pollChannelListTimer = setInterval(function () {pollChannelList()}, channelTimerDelay); +// pollChannelListTimer(); +// function pollChannelListTimer() { + // setTimeout("pollChannelListTimer()", channelTimerDelay); + // pollChannelList(); +// } var firstGetChat = true; function getChatDone(data) { @@ -212,7 +213,7 @@ function replaceSmileys(chat) { chat = chat.replace(/\:d/gi, ''); chat = chat.replace(/\:o/gi, ''); chat = chat.replace(/\:p/gi, ''); - chat = chat.replace(/;p/gi, ''); + chat = chat.replace(/;p/gi, ''); chat = chat.replace(/\:c/gi, ''); chat = chat.replace(/\:s/gi, ''); chat = chat.replace(/\>_\</g, ''); @@ -314,8 +315,11 @@ function channelListShow(JO) { // u.secFromLastActive could be used in here someplace.. + var dateEntered = new Date(); + dateEntered.setTime(dateEntered.getTime() + u.secFromEntered * 1000); + if (u.wallEmblem == undefined) u.wallEmblem = 'blank.png'; - p = p+ ""; + p = p+ ""; p = p+ ""; p = p+ "
"; -- cgit v1.2.3 From e6b60448bc08df316daf220db8ecfddc58aefe84 Mon Sep 17 00:00:00 2001 From: Snap Date: Fri, 1 May 2015 16:25:28 -0700 Subject: Minor fixes and adjustments. Moved Javascript in chat to: js/chat.js re-ordered script loading so Jquery loads first. Fixed cookie login issue. --- ajax/chat.ajax.php | 4 +- globe.php | 3 +- includes/header.php | 11 +- index.php | 42 +++-- js/chat.js | 430 ++++++++++++++++++++++++++++++++++++++++++++++++++ js/globe.js | 30 ++++ js/mapspecs.js | 28 ---- pages/chat.php | 441 +--------------------------------------------------- 8 files changed, 501 insertions(+), 488 deletions(-) create mode 100644 js/chat.js (limited to 'ajax') diff --git a/ajax/chat.ajax.php b/ajax/chat.ajax.php index 2ffa878..036efad 100644 --- a/ajax/chat.ajax.php +++ b/ajax/chat.ajax.php @@ -72,10 +72,8 @@ $use_psuedo_longpoll = true; // } require_once('../includes/chats.php'); - -//exit; - enterChannel($userID); + $sent = false; //User is sending a message diff --git a/globe.php b/globe.php index fe7123b..5abff5f 100644 --- a/globe.php +++ b/globe.php @@ -98,7 +98,8 @@ function CookieLogin() { $_SESSION['displayName'] = $display; $_SESSION['dateJoined'] = $dateJoined; if ($isAdmin == 1) $_SESSION['isAdmin'] = true; - header("Location: $mydomain"); + // There should be no reason to re-load the page. + //header("Location: $mydomain"); } else { setcookie("doLogin", "lastAttemptFailed"); setcookie("userID", ""); diff --git a/includes/header.php b/includes/header.php index cb34fac..427a57d 100644 --- a/includes/header.php +++ b/includes/header.php @@ -22,18 +22,21 @@ function htmlHeader($css = array(), $title = 'Pathery', $desc = '', $scripts = a -\n"; } - if ($desc !== '') echo " "; - - foreach ($scripts as $s) echo ""; ?> +"; + + foreach ($scripts as $s) echo ""; +?> + - -

Pathery Chat - BETA

-- cgit v1.2.3 From 01cb30b61739780e680b501e7719fb23749ecaeb Mon Sep 17 00:00:00 2001 From: Snap Date: Fri, 1 May 2015 16:26:15 -0700 Subject: Versus Matches - Initial code and testing. --- ajax/match.ajax.php | 226 +++++++++++++++++++++++++++++++++++++++++++++++++++ pages/creategame.php | 50 ++++++++++++ pages/gamecreate.php | 37 --------- pages/games.php | 142 ++++++++++++++++++++++++++++++++ 4 files changed, 418 insertions(+), 37 deletions(-) create mode 100644 ajax/match.ajax.php create mode 100644 pages/creategame.php delete mode 100644 pages/gamecreate.php create mode 100644 pages/games.php (limited to 'ajax') diff --git a/ajax/match.ajax.php b/ajax/match.ajax.php new file mode 100644 index 0000000..7568115 --- /dev/null +++ b/ajax/match.ajax.php @@ -0,0 +1,226 @@ + 6) { + $_SESSION['chatSendCount'] = 0; + $_SESSION['chatLastReset'] = strtotime('now'); +} + +//T: +if (rand(1,4) == 2 || true) { + $r[0]['serverMessage'] = 'true'; + $r[0]['isJoinLeave'] = 'true'; + $r[0]['message'] = "Server Test"; + $r[0]['secondsSince'] = 0; + $r[0]['displayName'] = 'SERVER'; + $r[0]['userID'] = null; + //echo json_encode($r); + //exit; +} + + +if (isset($_REQUEST['messages'])) { + $_SESSION['chatSendCount']++; + if ($_SESSION['chatSendCount'] > 4) { + $r[0]['error'] = 'Spam'; + $r[0]['serverMessage'] = 'true'; + $r[0]['message'] = "You're talking too fast - or your internet is being too slow. *OR ARE YOU SPAMMING ON PURPOSE?! JERK!*"; + $r[0]['secondsSince'] = 0; + $r[0]['displayName'] = 'SERVER'; + $r[0]['userID'] = null; + echo json_encode($r); + exit; + } +} +//Don't lockout requests by holding the session file open! + +$isLoggedIn = ($_SESSION['accepted'] == 1); + +session_write_close(); +$userID = $_SESSION['userID']; + +$chatLockDown = false; +$use_psuedo_longpoll = true; + +// STOP CHAT? +//$chatLockDown = true; + +// if (true) { + // if ($_SESSION['accepted'] !== 1) { + // exit; + // } +// } + +require_once('../includes/chats.php'); + +//exit; + +enterChannel($userID); +$sent = false; + +//User is sending a message +if (isset($_REQUEST['messages'])) { + $date = isMuted($userID); + if ($isLoggedIn !== true) { + $r[0]['error'] = 'Logged out'; + $r[0]['serverMessage'] = 'true'; + $r[0]['message'] = "Whoops, your session has timed out. Please sign in again."; + $r[0]['secondsSince'] = 0; + $r[0]['displayName'] = 'SERVER'; + $r[0]['userID'] = null; + echo json_encode($r); + exit; + } + if ($date !== false) { + $r[0]['error'] = 'Muted'; + $r[0]['serverMessage'] = 'true'; + $r[0]['message'] = 'You have been muted; You are muted until '.$date." (The current time is: ".date("Y-m-d H:i:s").")"; + $r[0]['secondsSince'] = 0; + $r[0]['displayName'] = 'SERVER'; + $r[0]['userID'] = null; + echo json_encode($r); + exit; + } + if ($chatLockDown == true AND $_SESSION['isAdmin'] !== true) { + $r[0]['error'] = 'Lockdown'; + $r[0]['serverMessage'] = 'true'; + $r[0]['message'] = 'Chat Lockdown has been activated. Messages are not being accepted'; + $r[0]['secondsSince'] = 0; + $r[0]['displayName'] = 'SERVER'; + $r[0]['userID'] = null; + echo json_encode($r); + exit; + } + + $messages = $_REQUEST['messages']; + $messages = explode("|:|", $messages); + foreach ($messages as $message) { + $message = filterStringForBadLanguage($message); + if ($message[0] == "/") { + $arguements = explode(" ", substr($message, 1)); + $command = $arguements[0]; + + //Admin only commands + if ($_SESSION['isAdmin'] == true) { + if ($command == 'say') { + $insertID = addchat(null, substr($message, 5)); + } + } + //javascript based commands: + if ($command == 'spoiler' OR $command == 'me') { + $insertID = addchat($userID, $message); + } + if ($command == 'help') { + $r[0]['serverMessage'] = 'true'; + $r[0]['message'] = "Commands: /help /time /spoiler /me. Surround text with ** for bold * for italics and ~~ for strikethrough. Chat by Pathery.com"; + $r[0]['secondsSince'] = 0; + $r[0]['userID'] = null; + echo json_encode($r); + exit; + } + if ($command == 'time') { + $r[0]['serverMessage'] = 'true'; + $r[0]['message'] = "Server Time: ".date('l jS \of F Y h:i:s A'); + $r[0]['secondsSince'] = 0; + $r[0]['userID'] = null; + echo json_encode($r); + exit; + } + } else { + $insertID = addchat($userID, $message); + } + } + $sent = true; +} + +if ($_REQUEST['getChatFromID']) { + $getChatID = $_REQUEST['getChatFromID']; + if ($sent == true AND $use_psuedo_longpoll == true) { + // PSUEDO LONG POLLING: - This loops to try to retrieve + // the message you just sent, back from the server. + + for( $i = 1; $i < 3; $i++) { + $data = getChat($getChatID); + if ($data !== false) { + echo prepareChatData($data); + exit; + } + //Wait .01 seconds per loop + usleep(10000); + } + } + $json = prepareChatData(getChat($getChatID)); + echo $json; +} + +function prepareChatData($data) { + if (!$data) + { + return false; + } + foreach($data as &$user) { + //$user['message'] = $user['message'].'write-append'; + $user['secondsSince'] = strtotime($user['dateSent']) - strtotime("now"); + } + return json_encode($data); +} +?> \ No newline at end of file diff --git a/pages/creategame.php b/pages/creategame.php new file mode 100644 index 0000000..ee8af67 --- /dev/null +++ b/pages/creategame.php @@ -0,0 +1,50 @@ + + + +
+

Create Game

+ +

+ +Doesn't matter what you do - you'll go to games?ID=22 ! (Testing still; sorry) +

+ +
+ + +

+ + Use Smart-Time? * +

+ + +
+ +
+ + + \ No newline at end of file diff --git a/pages/gamecreate.php b/pages/gamecreate.php deleted file mode 100644 index 44fe2d1..0000000 --- a/pages/gamecreate.php +++ /dev/null @@ -1,37 +0,0 @@ - - - -
-

Create Game

-

Send us a line!

- -

-

- -
- - -

- -
- Use Smart-Time? * -

- - -
- -
- - - \ No newline at end of file diff --git a/pages/games.php b/pages/games.php new file mode 100644 index 0000000..bee6cd3 --- /dev/null +++ b/pages/games.php @@ -0,0 +1,142 @@ + + + + + + +
+ +
+

Game Lobby

+

X

+
+
+
+ +
+ +
+
+ + +
+
+ + + BTN!"; + ?> +
+
+ + + + + \ No newline at end of file -- cgit v1.2.3 From c21481d9806ea5e7350b60134e0360fe392fc78d Mon Sep 17 00:00:00 2001 From: Snap Date: Sat, 2 May 2015 20:39:43 -0700 Subject: Progress continues for the Matches! Hoorah --- ajax/match.ajax.php | 322 ++++++++++++++++++++++++---------------------------- pages/games.php | 17 ++- 2 files changed, 162 insertions(+), 177 deletions(-) (limited to 'ajax') diff --git a/ajax/match.ajax.php b/ajax/match.ajax.php index 7568115..391c69e 100644 --- a/ajax/match.ajax.php +++ b/ajax/match.ajax.php @@ -6,16 +6,40 @@ session_start(); // exit; // } -header_remove(); +//header_remove(); + + +require_once('../includes/sqlEmbedded.php'); + +$r = ''; + +if (is_int($_GET['matchID'])) { + $matchID = $_GET['matchID']; +} + + +$matchID = 1; + - // Client sends isReady +if (isset($_REQUEST['isReady'])) { + + if ($_REQUEST['isReady'] == "true") { - // Return true + $r['isReady'] = true; + } else { + $r['isReady'] = false; + } + + setReady($userID, $matchID, $r['isReady']); +} +//echo "2"; -// Client sends StartGame +// Client sends StartGame +if (isset($_REQUEST['startGame'])) { + // Can he start the game? // Generate map @@ -23,204 +47,156 @@ header_remove(); // Set map expires // Return true + $r['startGameSuccess'] = true; +} - +//echo "3"; // Client sends updateRequest +if (isset($_REQUEST['requestUpdate'])) { //Return data on match $r['gameStarted'] = true; $r['gameStarted'] = true; $r['secondsTillGameStarts'] = 8.6342; + $r['secondsTillGameExpires'] = 122.6342; $r['mapID'] = 534; - $r['mapID'] = false; - $r['players'][0]['username'] = 'Bob!'; - $r['players'][0]['isCreator'] = true; - - echo json_encode($r); - exit; - - + $r['mapReady'] = true; + $r['players'] = getPlayersForMatch($matchID); -exit; -//The below is just temporary reference material. -////////////////////////////////////////////////////////////////////////// - -//ini_set('display_errors',1); -//ini_set('display_startup_errors',1); -//error_reporting(-1); - -if (isset($_REQUEST['pollChannelList'])) { - require_once('../includes/chats.php'); - echo json_encode(getChannelList()); - exit; + echo json_encode($r); } -if (isset($_SESSION['chatLastReset'])) $chatLastReset = $_SESSION['chatLastReset']; -else $chatLastReset = 0; +//echo "4"; -if (strtotime('now') - $chatLastReset > 6) { - $_SESSION['chatSendCount'] = 0; - $_SESSION['chatLastReset'] = strtotime('now'); -} - -//T: -if (rand(1,4) == 2 || true) { - $r[0]['serverMessage'] = 'true'; - $r[0]['isJoinLeave'] = 'true'; - $r[0]['message'] = "Server Test"; - $r[0]['secondsSince'] = 0; - $r[0]['displayName'] = 'SERVER'; - $r[0]['userID'] = null; - //echo json_encode($r); - //exit; -} +// Functions -if (isset($_REQUEST['messages'])) { - $_SESSION['chatSendCount']++; - if ($_SESSION['chatSendCount'] > 4) { - $r[0]['error'] = 'Spam'; - $r[0]['serverMessage'] = 'true'; - $r[0]['message'] = "You're talking too fast - or your internet is being too slow. *OR ARE YOU SPAMMING ON PURPOSE?! JERK!*"; - $r[0]['secondsSince'] = 0; - $r[0]['displayName'] = 'SERVER'; - $r[0]['userID'] = null; - echo json_encode($r); - exit; - } +function setReady($userID, $matchID, $readyStatus) { + global $mysqli; + + //Turn this to 0 to fill the bit + $intReadyStatus = intval($readyStatus); + + $stmt = $mysqli->prepare("UPDATE `matchUsers` + SET `isReady` = ? + WHERE `userID` = ? + AND `matchID` = ?"); + $stmt->bind_param('iii', $intReadyStatus, $userID, $matchID); + $stmt->execute(); + return; } -//Don't lockout requests by holding the session file open! - -$isLoggedIn = ($_SESSION['accepted'] == 1); - -session_write_close(); -$userID = $_SESSION['userID']; -$chatLockDown = false; -$use_psuedo_longpoll = true; +// !! +function getPlayersForMatch($matchID) { + global $mysqli; -// STOP CHAT? -//$chatLockDown = true; - -// if (true) { - // if ($_SESSION['accepted'] !== 1) { - // exit; - // } -// } - -require_once('../includes/chats.php'); - -//exit; - -enterChannel($userID); -$sent = false; - -//User is sending a message -if (isset($_REQUEST['messages'])) { - $date = isMuted($userID); - if ($isLoggedIn !== true) { - $r[0]['error'] = 'Logged out'; - $r[0]['serverMessage'] = 'true'; - $r[0]['message'] = "Whoops, your session has timed out. Please sign in again."; - $r[0]['secondsSince'] = 0; - $r[0]['displayName'] = 'SERVER'; - $r[0]['userID'] = null; - echo json_encode($r); - exit; + if (!is_numeric($matchID)) { + return false; } - if ($date !== false) { - $r[0]['error'] = 'Muted'; - $r[0]['serverMessage'] = 'true'; - $r[0]['message'] = 'You have been muted; You are muted until '.$date." (The current time is: ".date("Y-m-d H:i:s").")"; - $r[0]['secondsSince'] = 0; - $r[0]['displayName'] = 'SERVER'; - $r[0]['userID'] = null; - echo json_encode($r); - exit; + $res = $mysqli->query(" + SELECT + matchUsers.userID, + TIME_TO_SEC(TIMEDIFF(NOW(), matchUsers.dateLastChecked)) as secFromLastChecked, + matchUsers.isReady, + + users.displayName as 'display', + users.displayColor, + users.wallColor, + users.wallEmblem, + users.wallOrientation, + (matches.creatorUserID = users.ID) as `isCreator` + + FROM `matches` + LEFT JOIN `matchUsers` + ON matchUsers.matchID = matches.ID + LEFT JOIN `users` + ON matchUsers.userID = users.ID + "); + $array = array(); + if ($res->num_rows == 0) { + $res->close(); + return false; } - if ($chatLockDown == true AND $_SESSION['isAdmin'] !== true) { - $r[0]['error'] = 'Lockdown'; - $r[0]['serverMessage'] = 'true'; - $r[0]['message'] = 'Chat Lockdown has been activated. Messages are not being accepted'; - $r[0]['secondsSince'] = 0; - $r[0]['displayName'] = 'SERVER'; - $r[0]['userID'] = null; - echo json_encode($r); - exit; + while ($response = $res->fetch_assoc()) { + $array['users'][] = $response; } + $res->close(); + $mysqli->close(); - $messages = $_REQUEST['messages']; - $messages = explode("|:|", $messages); - foreach ($messages as $message) { - $message = filterStringForBadLanguage($message); - if ($message[0] == "/") { - $arguements = explode(" ", substr($message, 1)); - $command = $arguements[0]; - - //Admin only commands - if ($_SESSION['isAdmin'] == true) { - if ($command == 'say') { - $insertID = addchat(null, substr($message, 5)); - } - } - //javascript based commands: - if ($command == 'spoiler' OR $command == 'me') { - $insertID = addchat($userID, $message); - } - if ($command == 'help') { - $r[0]['serverMessage'] = 'true'; - $r[0]['message'] = "Commands: /help /time /spoiler /me. Surround text with ** for bold * for italics and ~~ for strikethrough. Chat by Pathery.com"; - $r[0]['secondsSince'] = 0; - $r[0]['userID'] = null; - echo json_encode($r); - exit; - } - if ($command == 'time') { - $r[0]['serverMessage'] = 'true'; - $r[0]['message'] = "Server Time: ".date('l jS \of F Y h:i:s A'); - $r[0]['secondsSince'] = 0; - $r[0]['userID'] = null; - echo json_encode($r); - exit; - } - } else { - $insertID = addchat($userID, $message); - } - } - $sent = true; + if (count($array) < 1) return false; + return $array; } -if ($_REQUEST['getChatFromID']) { - $getChatID = $_REQUEST['getChatFromID']; - if ($sent == true AND $use_psuedo_longpoll == true) { - // PSUEDO LONG POLLING: - This loops to try to retrieve - // the message you just sent, back from the server. + +function getMatchStatus($matchID) { + global $mysqli; + + if (!is_numeric($matchID)) return false; + + //Not sure why this happens; but just return nothing.. + if (!is_object($mysqli)) die("mysqli is not an object"); + + if ($res = $mysqli->query(" + SELECT + matches.creatorUserID, + matches.mapID, + matches.isComplete, + matches.isStarted, + matches.dateCreated, + matches.dateExpires, + matches.dateStarted, + matches.requiredPlayers, + matches.secondsGiven, + matches.useSmartTime, - for( $i = 1; $i < 3; $i++) { - $data = getChat($getChatID); - if ($data !== false) { - echo prepareChatData($data); - exit; - } - //Wait .01 seconds per loop - usleep(10000); + users.displayName, + users.displayColor, + users.wallColor, + users.wallEmblem, + users.wallOrientation + FROM `matches` + LEFT JOIN `users` + ON matches.userID = users.ID + WHERE matches.ID = '$matchID' + ")) { + $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("DError: %s\n", $mysqli->error); + return false; } - $json = prepareChatData(getChat($getChatID)); - echo $json; } -function prepareChatData($data) { - if (!$data) - { - return false; - } - foreach($data as &$user) { - //$user['message'] = $user['message'].'write-append'; - $user['secondsSince'] = strtotime($user['dateSent']) - strtotime("now"); - } - return json_encode($data); + +//Returns the matchID +function createMatch($creatorID, $requiredPlayers, $secondsGiven, $useSmartTime = false) { + global $mysqli; + + $useSmartTime = intval($useSmartTime); + + $stmt = $mysqli->prepare("INSERT INTO `matches` + (`creatorUserID`, `requiredPlayers`, `secondsGiven`, `useSmartTime`) + VALUES (?, ?)"); + $stmt->bind_param('iiii', $creatorID, $requiredPlayers, $secondsGiven, $useSmartTime); + $stmt->execute(); + + $ID = $stmt->insert_id; + $stmt->close(); + + return $ID; } + + + ?> \ No newline at end of file diff --git a/pages/games.php b/pages/games.php index bee6cd3..b68a530 100644 --- a/pages/games.php +++ b/pages/games.php @@ -9,6 +9,12 @@ htmlHeader(array(), 'Game Lobby', 'Game Lobby'); echo soundManager2(); topbar($headerLinks); + +if (is_int($_GET['ID'])) { + $matchID = $_GET['ID']; +} + + ?> @@ -35,11 +41,10 @@ function matchUpdateTimer() { } - - function pollMatchStatus() { var dataString = 'requestUpdate=1'; - dataString = '&playerIsReady='+playerIsReady; + dataString += '&matchID='; + dataString += '&playerIsReady='+playerIsReady; $.ajax({ //type: "POST", @@ -62,9 +67,13 @@ function pollMatchStatusDone(data) { if (json.gameStarted == true) { // Show the game if it's ready - if (isInt(json.mapID) && matchMapReceived == false) { + if (json.mapReady == true && matchMapReceived == false) { + console.log("match countdown start!"); displayMap(json.mapID, "mapDisplay", 600); matchMapReceived = true; + + displayCountDownToGame(json.secondsTillGameExpires); + } //This will be a negative number if the game is going. -- cgit v1.2.3 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 ++++++++++++++++++++++- pages/login.php | 20 +++----- pages/matches.php | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 209 insertions(+), 14 deletions(-) create mode 100644 pages/matches.php (limited to 'ajax') 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; diff --git a/pages/login.php b/pages/login.php index d698527..b0caf07 100644 --- a/pages/login.php +++ b/pages/login.php @@ -19,13 +19,14 @@ include_once('./includes/HybridAuth/Auth.php'); $hybrid_config_file = 'includes/HybridAuth/HybridAuthConfig.php'; +//TODO: SQL needs to be updated to sqli instead. + try { + //OpenID 2.0 Method - if (!$_GET['op'] || $_GET['op'] == 'steam' || $_GET['op'] == 'yahoo') { $openid = new LightOpenID; - //Require Email, and first name. $openid->required = array('namePerson/first', 'contact/email'); @@ -68,26 +69,19 @@ try { DoRedirect("Login failed. Back to the home page with you!"); } - //Google's OpenID Connect method + //Google's OpenID Connect method } else if ($_GET['op'] == 'google') { - - echo "ello..."; - include_once('./includes/google-api-php-client-master/src/Google/autoload.php'); $redirect_uri = $mydomain . "login?op=google"; - //echo "$redirect_uri $google_client_id $google_client_secret "; - $client = new Google_Client(); $client->setClientId($google_client_id); $client->setClientSecret($google_client_secret); $client->setRedirectUri($redirect_uri); $client->setScopes('email'); - //echo 'Tests running'; - if (isset($_GET['code'])) { //echo 'code recpt'; $client->authenticate($_GET['code']); @@ -174,7 +168,7 @@ function createNewUser($claimedid, $display, $email, $oldID = NULL) $sql = "SELECT `ID`, `isAdmin`, `openID`, `displayName`, `dateJoined` FROM `users` WHERE `openID` = '$claimedid' OR `email` = '$email'"; if (isset($oldID)) { - $sql = $sql." OR `openID` = '$oldID'"; + $sql = $sql." OR `openID` = '" . $oldID . "'"; } $result = mysql_query($sql); @@ -237,7 +231,7 @@ function createNewUser($claimedid, $display, $email, $oldID = NULL) if ($result) { $userID = mysql_insert_id(); $dateJoined = date(DateTime::ISO8601); - + //Tutorial done? if (isset($_SESSION['preCompletedTutorial'])) { if ($_SESSION['preCompletedTutorial'] == true) { @@ -280,7 +274,7 @@ function createNewUser($claimedid, $display, $email, $oldID = NULL) $refTo = $_GET['ref']; //DoRedirect("Thank you $display.", $_GET['ref']); DoRedirect("", $refTo, 0); - exit; + return true; } function sendNewUserEmail($userID, $email, $display, $dateJoined) { diff --git a/pages/matches.php b/pages/matches.php new file mode 100644 index 0000000..7fd8559 --- /dev/null +++ b/pages/matches.php @@ -0,0 +1,140 @@ + + + + + + +
+

Available Matches

+ +
+ +
+
+
+
+ -- cgit v1.2.3