summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ajax/match.ajax.php226
-rw-r--r--pages/creategame.php (renamed from pages/gamecreate.php)21
-rw-r--r--pages/games.php142
3 files changed, 385 insertions, 4 deletions
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 @@
+<?
+session_start();
+//For testing purposes send a fake 404.
+// if (rand(1,3) == 2) {
+ // header("HTTP/1.0 404 Not Found");
+ // exit;
+// }
+
+header_remove();
+
+
+// Client sends isReady
+
+ // Return true
+
+
+// Client sends StartGame
+
+ // Can he start the game?
+
+ // Generate map
+
+ // Set map expires
+
+ // Return true
+
+
+
+// Client sends updateRequest
+
+ //Return data on match
+ $r['gameStarted'] = true;
+ $r['gameStarted'] = true;
+ $r['secondsTillGameStarts'] = 8.6342;
+ $r['mapID'] = 534;
+ $r['mapID'] = false;
+ $r['players'][0]['username'] = 'Bob!';
+ $r['players'][0]['isCreator'] = true;
+
+ echo json_encode($r);
+ exit;
+
+
+
+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;
+}
+
+if (isset($_SESSION['chatLastReset'])) $chatLastReset = $_SESSION['chatLastReset'];
+else $chatLastReset = 0;
+
+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;
+}
+
+
+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/gamecreate.php b/pages/creategame.php
index 44fe2d1..ee8af67 100644
--- a/pages/gamecreate.php
+++ b/pages/creategame.php
@@ -1,14 +1,28 @@
<?php
+//If thar be a game to be creatin
+if (isset($_POST['playerCount'])) {
+
+ //Confirm yarn data and fill them be databases. Hah har!
+
+
+
+ $gameID = 22;
+
+ //Return tiz be the gameID and change yarn header location! to games?id=ID
+ header("Location: $mydomain"."games?ID=" . $gameID);
+}
+
+htmlHeader(array(), 'Create Game', 'Create a game');
topbar($headerLinks);
-
?>
<div class="wrapper" style="width:600px;">
<h2>Create Game</h2>
-<h3>Send us a line!</h3>
<p>
+
+Doesn't matter what you do - you'll go to games?ID=22 ! (Testing still; sorry)
</p>
<form action="createGame" method="post" name="gameOptions">
@@ -18,11 +32,10 @@ topbar($headerLinks);
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
- <option value='6'>6</option>
+
</select>
<br /><br />
-<textarea name='body' rows="10" cols="30"></textarea><br />
<input type="checkbox" name="smartTime" value="yes" /> Use Smart-Time? *
<br /><br />
<input type="submit" value="Create Game" />
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 @@
+<?php
+htmlHeader(
+ array('stats'), 'Game Lobby',
+ 'Match',
+ array('scores', 'dateformat')
+);
+
+htmlHeader(array(), 'Game Lobby', 'Game Lobby');
+echo soundManager2();
+topbar($headerLinks);
+
+?>
+
+
+<script>
+
+mapID = 222;
+pointerPage = 1;
+
+displayMap(mapID, "mapDisplay", 600);
+scoresShowPage(pointerPage, mapID);
+
+
+var matchUpdateTimerDelay = 6000;
+
+
+var playerIsReady = false;
+var matchMapReceived = false;
+var matchCountdownStarted = false;
+var matchStarted = false;
+
+matchUpdateTimer();
+function matchUpdateTimer() {
+ setTimeout("matchUpdateTimer()", matchUpdateTimerDelay);
+
+}
+
+
+
+function pollMatchStatus() {
+ var dataString = 'requestUpdate=1';
+ dataString = '&playerIsReady='+playerIsReady;
+
+ $.ajax({
+ //type: "POST",
+ url: "ajax/match.ajax.php?" + dataString,
+ error: function() {
+ console.log('Error: Failed pollMatchStatus');
+ },
+ success: function(data) {
+ console.log("Data recieved", data);
+ pollMatchStatusDone(data);
+ }
+ });
+}
+
+function pollMatchStatusDone(data) {
+
+ console.log('data recieved:', data);
+ if (data.length < 3 || data == 'false') return;
+ json = jQuery.parseJSON(data);
+
+ if (json.gameStarted == true) {
+ // Show the game if it's ready
+ if (isInt(json.mapID) && matchMapReceived == false) {
+ displayMap(json.mapID, "mapDisplay", 600);
+ matchMapReceived = true;
+ }
+
+ //This will be a negative number if the game is going.
+ if (json.secondsTillGameStarts > 0 && matchCountdownStarted == false) {
+ displayCountDownToGame(json.secondsTillGameStarts);
+
+ //Make sure we're making a call when the map is ready.
+ setTimeout("pollMatchStatus()", ((json.secondsTillGameStarts) * 1000) - 10);
+ matchCountdownStarted = true;
+ }
+
+ // json.secondsTillGameStarts
+ // var gameStartsDate = new Date();
+ //gameStartsDate.setTime(gameStartsDate.getTime() + json.secondsTillGameStarts * 1000);
+ }
+
+}
+
+function isInt(n) {
+ return n % 1 === 0;
+}
+
+
+function displayCountDownToGame(seconds) {
+ decSeconds = Math.round(seconds * 10);
+ var x = 0;
+ for (var i = decSeconds; i > 0; i--) {
+ x++;
+ setTimeout("setDisplay(" + i / 10 + ")", x * 100);
+ }
+}
+function setDisplay(newContent) {
+ $("#countDown").html(newContent);
+}
+
+function setReady() {
+ playerIsReady = true;
+ pollMatchStatus();
+}
+
+</script>
+
+
+<div class="wrapper">
+
+<br />
+<br /><h2>Game Lobby</h2>
+<br /><h2 id='countDown'>X</h2>
+<br />
+ <div>
+ <div class='scoreCol' id='scoreDisplay'></div>
+ <div class="mapCol" id='mapDisplay' style='display:none; float:left;'></div>
+ </div>
+
+ <div style='clear:both'></div>
+</div>
+
+
+<div class="wrapper">
+ <form id='markReady' onsubmit="return false">
+ <input type="hidden" name="stuff" value="1724">
+
+ <?
+ echo "
+ <a title='TmpBtn?' class='readyButton_unready unselectable' href='javascript:setReady()' id='readyButton'/>BTN!</a>";
+ ?>
+ </form>
+</div>
+
+
+
+
+<?php
+htmlFooter();
+?> \ No newline at end of file