From 9c20000fb8871437dafb41ec830afbf56a746a57 Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 9 Jun 2013 01:03:03 -0500 Subject: Attempting to remove the multiple calls to getChat(); however, I seem to have broken chat... --- ajax/chat.ajax.php | 35 +++++++++++------------------------ includes/chats.php | 16 ++++++++-------- 2 files changed, 19 insertions(+), 32 deletions(-) diff --git a/ajax/chat.ajax.php b/ajax/chat.ajax.php index 02a11c6..f9370aa 100644 --- a/ajax/chat.ajax.php +++ b/ajax/chat.ajax.php @@ -111,35 +111,22 @@ if (isset($_REQUEST['messages'])) { if ($_REQUEST['getChatFromID']) { $getChatID = $_REQUEST['getChatFromID']; if ($sent) { - //Wait .2 seconds - usleep(200000); - //echo "yesSent"; - for( $i = 1; $i < 3; $i++) { - //echo "loop"; - $data = getChat($getChatID); - if ($data !== false) { - //$data['debug'][] = "Count times: $i"; - //$data['debug'][] = "Count value:".count($data); - echo prepareChatData($data); - exit; - } - //Wait .1 seconds - usleep(100000); - } + $data = getChat($getChatID); + echo prepareChatData($data); + exit; } - $json = prepareChatData(getChat($getChatID)); - echo $json; } exit; function prepareChatData($data) { - if ($data) { - foreach($data as &$user) { - //$user['message'] = $user['message'].'write-append'; - $user['secondsSince'] = strtotime($user['dateSent']) - strtotime("now"); - } - return json_encode($data); + if (!$data) + { + return false; + } + foreach($data as &$user) { + //$user['message'] = $user['message'].'write-append'; + $user['secondsSince'] = strtotime($user['dateSent']) - strtotime("now"); } - return $data; + return json_encode($data); } ?> \ No newline at end of file diff --git a/includes/chats.php b/includes/chats.php index 7db4c58..f55ce35 100644 --- a/includes/chats.php +++ b/includes/chats.php @@ -44,12 +44,17 @@ function addChat($userID, $message) { $ID = $stmt->insert_id; $stmt->close(); + + //Turnicate messages. + $deleteFromID = $ID - CHAT_ROWS_TO_KEEP; + $mysqli->query("DELETE FROM `chat` WHERE `ID` < $deleteFromID"); + $mysqli->close(); + return $ID; } function getChat($startID = 0) { global $mysqli; - $array = array(); if (!is_numeric($startID)) return false; @@ -68,7 +73,7 @@ function getChat($startID = 0) { LEFT JOIN `users` ON chat.userID = users.ID WHERE chat.ID > '$startID' - ORDER BY chat.ID ASC + ORDER BY chat.dateSent ASC, chat.ID ASC "); $array = array(); if ($res->num_rows == 0) { @@ -77,16 +82,11 @@ function getChat($startID = 0) { } while ($response = $res->fetch_assoc()) { $array[] = $response; - $lastID = $response['ID']; } $res->close(); + $mysqli->close(); if (count($array) < 1) return false; - - //Turnicate messages. - $deleteFromID = $lastID - CHAT_ROWS_TO_KEEP; - $mysqli->query("DELETE FROM `chat` WHERE `ID` < $deleteFromID"); - $mysqli->close(); return $array; } -- cgit v1.2.3 From 07e94c2eb5f36fd295204f4e4e81ce813c1f2150 Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Wed, 12 Jun 2013 13:45:38 -0700 Subject: removed some includes. --- index.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/index.php b/index.php index 0fa0b8a..fce390a 100644 --- a/index.php +++ b/index.php @@ -37,12 +37,6 @@ if ($showUpdatePage AND $_GET['cu'] !== "true") { exit; } -include_once("globe.php"); -include_once("./includes/header.php"); -include_once ('./includes/sqlEmbedded.php'); - -$accepted = isset($_SESSION['accepted']) && $_SESSION['accepted'] == 1; - //Not logged in? if (!$accepted) { if (isset($_COOKIE['doLogin']) && $_COOKIE['doLogin'] == 'yes') { -- cgit v1.2.3 From e5d7098e7901ee80bc8e98c642d8d8b16d0b50af Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Mon, 13 Jan 2014 23:37:38 -0800 Subject: Minor fiddlings of nothingness --- pages/challengelist.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pages/challengelist.php b/pages/challengelist.php index a3b5ca7..8b60bd7 100644 --- a/pages/challengelist.php +++ b/pages/challengelist.php @@ -287,19 +287,21 @@ function showChallengeTiers() {
-

Challenges - I'z working on this stuff.

+

Challenges

Greetings tester of test-needed things.
+ +
-
-

Easy

+
+

Challenges

-
-

Normal

+ -
- Hard +
+

Coming Soon

-- cgit v1.2.3 From 3bbab1ac012426818ecf463fbe6749d0e66666ff Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Tue, 14 Jan 2014 02:53:58 -0800 Subject: Fixed the chat - Re-added the longpolling - with opt boolean. --- ajax/chat.ajax.php | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/ajax/chat.ajax.php b/ajax/chat.ajax.php index f9370aa..8302c33 100644 --- a/ajax/chat.ajax.php +++ b/ajax/chat.ajax.php @@ -6,6 +6,12 @@ session_start(); // exit; // } + +ini_set('display_errors',1); +ini_set('display_startup_errors',1); +error_reporting(-1); + + if (isset($_SESSION['chatLastReset'])) $chatLastReset = $_SESSION['chatLastReset']; else $chatLastReset = 0; @@ -31,6 +37,8 @@ session_write_close(); $userID = $_SESSION['userID']; $chatLockDown = false; +$use_psuedo_longpoll = true; + // STOP CHAT? //$chatLockDown = true; @@ -42,6 +50,7 @@ $chatLockDown = false; require_once('../includes/chats.php'); + $sent = false; if (isset($_REQUEST['messages'])) { @@ -110,13 +119,23 @@ if (isset($_REQUEST['messages'])) { if ($_REQUEST['getChatFromID']) { $getChatID = $_REQUEST['getChatFromID']; - if ($sent) { - $data = getChat($getChatID); - echo prepareChatData($data); - exit; + 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; } -exit; function prepareChatData($data) { if (!$data) -- cgit v1.2.3 From 1b40945878f33ab4b8af8089ea6c5be02b9d0761 Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Tue, 14 Jan 2014 02:59:16 -0800 Subject: Channellist preperations. - Fixes with regards to close() which apparently means DESTROY or something retarded. --- includes/chats.php | 77 ++++++++++++++++++++++++++++++++++++++++++++++-- includes/mapoftheday.php | 2 +- update notes.txt | 19 ++++++++++++ 3 files changed, 94 insertions(+), 4 deletions(-) diff --git a/includes/chats.php b/includes/chats.php index f55ce35..0e48ecf 100644 --- a/includes/chats.php +++ b/includes/chats.php @@ -32,6 +32,8 @@ function muteUser($userID, $numMinutes) { return; } + + function addChat($userID, $message) { global $mysqli; if ($message == '') return; @@ -48,7 +50,6 @@ function addChat($userID, $message) { //Turnicate messages. $deleteFromID = $ID - CHAT_ROWS_TO_KEEP; $mysqli->query("DELETE FROM `chat` WHERE `ID` < $deleteFromID"); - $mysqli->close(); return $ID; } @@ -61,7 +62,7 @@ function getChat($startID = 0) { //Not sure why this happens; but just return nothing.. if (!is_object($mysqli)) die("mysqli is not an object"); - $res = $mysqli->query(" + if ($res = $mysqli->query(" SELECT chat.ID, chat.userID, chat.message, chat.dateSent, users.displayName, @@ -74,6 +75,76 @@ function getChat($startID = 0) { ON chat.userID = users.ID WHERE chat.ID > '$startID' ORDER BY chat.dateSent ASC, chat.ID ASC + ")) { + $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; + } + +} + + + +//Enters a user into a channel +function enterChannel($userID, $channel = 1) { + global $mysqli; + $stmt = $mysqli->prepare("INSERT INTO `chatUsers` + (`userID`, `channel`, `dateEntered`, `isHere`) + VALUES (?, ?, NOW(), true) + + ON DUPLICATE KEY UPDATE `isHere` = true + "); + $stmt->bind_param('ii', $userID, $channel); + $stmt->execute(); + $stmt->close(); + return; +} + +//User leaves the channel +function exitChannel($userID, $channel = 1) { + global $mysqli; + $stmt = $mysqli->prepare("UPDATE `chatUsers` + SET `isHere` = false + WHERE `userID` = ? AND `channel` = ?"); + $stmt->bind_param('ii', $userID, $channel); + $stmt->execute(); + return; +} + +//Get a list of users in channel +function getChannelList($channel = 1) { + global $mysqli; + + if (!is_numeric($channel)) return false; + + $res = $mysqli->query(" + SELECT + chatUsers.userID, + chatUsers.dateEntered, + chatUsers.dateLastActive, + chatUsers.isAdmin, + chatUsers.isMod, + + users.displayName, + users.displayColor, + users.wallColor, + users.wallEmblem, + users.wallOrientation + FROM `chatUsers` + LEFT JOIN `users` + ON chatUsers.userID = users.ID + ORDER BY chatUsers.isMod DESC, chatUsers.dateEntered DESC "); $array = array(); if ($res->num_rows == 0) { @@ -87,10 +158,10 @@ function getChat($startID = 0) { $mysqli->close(); if (count($array) < 1) return false; - return $array; } + function filterStringForBadLanguage($chat) { //cuss words $chat = str_ireplace("fuck you", "i am moron", $chat); diff --git a/includes/mapoftheday.php b/includes/mapoftheday.php index 669abb9..02d64f4 100644 --- a/includes/mapoftheday.php +++ b/includes/mapoftheday.php @@ -1 +1 @@ - NOW() ORDER BY mapOfTheDay.mapDate DESC LIMIT 1 "; $result = mysql_query($sql); if (mysql_num_rows($result) == 0) { return null; } //A map was found, so return it $r['code'] = mysql_result($result, 0, 'code'); $r['map'] = GenerateMapByCode($r['code']); $r['id'] = mysql_result($result, 0, 'ID'); return $r; } /** * Generates all the new maps for the day. Includes a critical section so maps aren't generated more * than once per day. */ function generateNewMapsOfTheDay() { ignore_user_abort(true); set_time_limit(0); $lock = acquireMotdLock(); try { //Double check that we still need to generate a new map for today. Since that was done outside of the lock, it's possible //two threads could reach this point at the same time. $latestSpecialMap = getMapOfTheDayInternal(MapType::Special); $latestWeeklyMap = getMapOfTheDayInternal(MapType::Weekly); if($latestSpecialMap != null && $latestWeeklyMap != null) { releaseMotdLock($lock); return; } //The rest of the code in the try{} can be assumed to only be run once a day //Generate the maps $mapCode = array(); if($latestSpecialMap == null) { $mapCode[MapType::Simple] = generateNewMapCode(MapType::Simple); $mapCode[MapType::Normal] = generateNewMapCode(MapType::Normal); $mapCode[MapType::Complex] = generateNewMapCode(MapType::Complex); $mapCode[MapType::Special] = generateNewMapCode(MapType::Special); } //The weekly maps might not need to be generated tonight. Check if it does first if($latestWeeklyMap == null) { $mapCode[MapType::Weekly] = generateNewMapCode(MapType::Weekly); } //Add the actual maps to the DB addNewMapsToDB($mapCode); //Update the player-statistics if($latestSpecialMap == null) { //Add points for yesterday's maps if we just created the daily maps addStatsForYesterdaysMaps(); } if($latestWeeklyMap == null) { //Add points for the weekly map, which is created at noon rather than midnight addStatsForMiddayMaps(); //Note that there could potentially be an issue adding points twice if server goes from noon on Saturday //(or whenever we generate the new weekly map) to midnight the next morning without anyone visiting the site. //That's probably not going to be an issue on the production site, however... } } catch (Exception $exc) { /* Ignore... :| */ } //try/catch above is necessary to make sure an exception doesn't prevent us from releasing the lock! releaseMotdLock($lock); } /** * Generates a single map of the given type, and returns its "map code" */ function generateNewMapCode($type) { // If you want to modify the maps created! This is the line //GenerateMap($rows, $cols, $rockchance, $numBlocks = -1, $cp = -1, $tp = -1) switch ($type) { case MapType::Simple: $map = GenerateMap(13, 7, 12, rand(7, 10), rand(0, 1), 0, 'Simple'); break; case MapType::Normal: $map = GenerateMap(15, 9, 7, rand(11, 13), rand(1, 3) + rand(0, 1), 0, 'Normal'); break; case MapType::Complex: $map = getRandomComplexMap(); break; case MapType::Special: $map = getRandomSpecialMap(); break; case MapType::Weekly: $map = getRandomWeeklyMap(); break; default: $map = GenerateMap(rand(13, 18), rand(10, 14), rand(6, 9)); break; } return GenerateMapCode($map); } function addNewMapsToDB($mapCode) { foreach($mapCode as $code) { $map = new map($code); $codeSafe = mysql_escape_string($code); $nameSafe = mysql_escape_string($map->name); $codeValuesAry[] = " ('$codeSafe', '$nameSafe')"; } $codeValues = implode(",", $codeValuesAry); //Insert all the maps at once. $sql = "INSERT INTO `maps` (`code`, `name`) VALUES $codeValues"; //Did we succeed? $result = mysql_query($sql); if (!$result) { releaseMotdLock($lock); die("Error on inserting maps, offending SQL: $sql"); } //Get the ID of the first insert. $mapIDI = mysql_insert_id(); foreach ($mapCode as $type => $code) { if($type == MapType::Weekly) { //Weekly map lasts MAP_EXPIRE_TIME_WEEKLY days. We also want to offset by 12 hours $numHours = 24*MAP_EXPIRE_TIME_WEEKLY + 12; $expireTime = "ADDDATE(CURDATE(), INTERVAL $numHours HOUR)"; } else { //All other maps are assumed to last one day $expireTime = 'ADDDATE(CURDATE(), INTERVAL 1 DAY)'; } $mapOfTheDayAry[] = "('$mapIDI', '$type', CURDATE(), $expireTime)"; $mapIDI++; } $mapOfTheDayValues = implode(",", $mapOfTheDayAry); $sql = "INSERT INTO `mapOfTheDay` (`mapID`, `mapType`, `mapDate`, `mapExpireTime`) VALUES $mapOfTheDayValues "; $result = mysql_query($sql); if (!$result) { releaseMotdLock($lock); die("Error on insert into mapOfTheDay SQL: $sql"); } else { //Post it in the chat! addchat(null, "New maps added!"); } } /** * The file locked in order to create serialize map-creations, since our DB doesn't support transactions... */ define('FILE_MOTD_LOCK', './motdLockFile'); /** * Obtains the mutex used for creating the Map Of The Day, so that race-conditions cannot occur (like two threads * creating and inserting the maps into the database at the same time, which has happened */ function acquireMotdLock() { $fileHandle = fopen(FILE_MOTD_LOCK, 'a+'); flock($fileHandle, LOCK_EX); return $fileHandle; } /** * Releases the lock acquired from acquireMotdLock */ function releaseMotdLock($fileHandle) { if($fileHandle) flock($fileHandle, LOCK_UN); } function getRandomComplexMap() { $random = weight(0, 0, 0, 0, 0, 0, 0, 1); switch ($random) { case 0: $map = GenerateMap(19, 9, rand(7, 9), rand(14, 16), rand(2, 5), rand(1, 2), 'Complex'); break; case 1: $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath = insertPoint($reversePath, 'abc'); $reversePath = insertPoint($reversePath, 'tu'); $myparams['checkpoints'] = 3; $myparams['teleports'] = 0; $myparams['rockchance'] = 7; $myparams['walls'] = 12; $myparams['name'] = 'Reverse Order'; $map = GenerateShapedMap($reversePath, $myparams); break; } return $map; } function getRandomSpecialMap() { //This can be used to add additional weight to certain maps that we like. $random = weight(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); //FORCE: //$random = 11; $shape = array(); $params = array(); switch ($random) { //===================================== case 0: //Thirty $map = GenerateMap( 18, 14, 20, //width, height, rocks weight(30), //Walls weight(1), //Checkpoints weight(1), //Teleports 'Thirty' ); break; //===================================== case 1: //Finite $map = GenerateMap( 18, 9, 7, //width, height, rocks weight(15, 16, 17), //Walls weight(0), //Checkpoints weight(0), //Teleports 'Finite' ); break; //===================================== case 2: //ABC's $map = GenerateMap( 19, 11, 12, //width, height, rocks weight(20, 21, 22, 22, 23), //Walls weight(3), //Checkpoints weight(0), //Teleports "ABC's " ); break; //===================================== case 3: //Tele Madness $map = GenerateMap( 17, 12, 10, //width, height, rocks weight(17, 18), //Walls weight(1), //Checkpoints weight(5), //Teleports 'Teleport Madness' ); break; //===================================== case 4: //Rocky Maze $map = GenerateMap( 19, 15, 5, //width, height, rocks weight(16, 17, 18), //Walls weight(1, 2, 2, 2, 3, 3), //Checkpoints weight(0), //Teleports 'Rocky Maze' ); break; //===================================== case 5: //Side to Side $map = GenerateMap( 26, 6, 12, //width, height, rocks weight(17, 18, 19), //Walls weight(2, 2, 2, 3, 3), //Checkpoints weight(3, 3, 3, 4), //Teleports 'Side to Side' ); break; //===================================== case 6: //Ultimate's Random map: //Create shape $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; //Insert points $shape = insertPoint($shape, "sfabcr", $target = '?'); $shape = insertPoint($shape, weight("tu", "d", "tu", "", ""), $target = '?'); //Set params $params['rockchance'] = 10; $params['walls'] = weight(21, 20, 22, 20, 21); $params['name'] = 'Ultimate Random'; //Put it all together. $map = GenerateShapedMap($shape, $params); break; //===================================== //===================================== case 7: //Dual map $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "oqqqqqqqqqqqqqqqqqqqo"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapa = insertPoint($dualmapa, 'abc'); $dualmapb = insertPoint($dualmapb, 'abc'); $dualmap = array_merge($dualmapa, $dualmapb); $dualmap = insertPoint($dualmap, 'tu'); $myparams['checkpoints'] = 3; $myparams['teleports'] = 1; $myparams['rockchance'] = 9; $myparams['walls'] = weight(20, 20, 21, 21, 22, 23); $myparams['name'] = 'Seeing Double'; $map = GenerateShapedMap($dualmap, $myparams); break; //===================================== //===================================== case 8: //Centralized $myshape[] = "ooooooooooooooooooo"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o???????fos???????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "ooooooooooooooooooo"; $myshape = insertPoint($myshape, "abc", $target = '?'); $myshape = insertPoint($myshape, weight("tu", "d", "tud", ""), $target = '?'); $myparams['rockchance'] = 7; $myparams['walls'] = weight(17, 18, 19, 18, 17); $myparams['name'] = 'Centralized'; $map = GenerateShapedMap($myshape, $myparams); break; //===================================== //===================================== case 9: //Dualing paths $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'Xo??????????????ox'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths = insertPoint($dualingPaths, 'abc'); $dualingPaths = insertPoint($dualingPaths, weight('xx', 'xxx', 'xxxx').weight('XX', 'XXX', 'XXXX')); $myparams['checkpoints'] = 3; $myparams['teleports'] = 0; $myparams['rockchance'] = 9; $myparams['walls'] = 13; $myparams['name'] = 'Dualing paths'; $map = GenerateShapedMap($dualingPaths, $myparams); break; //===================================== //===================================== case 10: //Unlimited $unlimited[] = 'so?o?o?o?o?o?o?of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?o?o?o?o?o?o?of'; $unlimited = insertPoint($unlimited, 'abc'); $unlimited = insertPoint($unlimited, weight('tu', 'dtu')); $myparams['checkpoints'] = 3; $myparams['teleports'] = 1; $myparams['rockchance'] = 9; $myparams['walls'] = 999; $myparams['name'] = 'Unlimited'; $map = GenerateShapedMap($unlimited, $myparams); break; //===================================== //===================================== case 11: //Thirty Too $thirtyTooShape[] = 's??????????????????Xf'; $thirtyTooShape[] = '????????????????????X'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = 'x????????????????????'; $thirtyTooShape[] = 'fx??????????????????S'; $thirtyTooShape = insertPoint($thirtyTooShape, 'atupppp'); $myparams['checkpoints'] = 2; $myparams['teleports'] = 1; $myparams['rockchance'] = 20; $myparams['walls'] = 32; $myparams['name'] = 'Thirty Too'; $map = GenerateShapedMap($thirtyTooShape, $myparams); break; //===================================== } return $map; } function getRandomWeeklyMap() { //This can be used to add additional weight to certain maps that we like. $random = weight(0); //FORCE: //$random = 1; $shape = array(); $params = array(); switch ($random) { case 0: $ultraComplex[] = "sooooooooooooooooooooooor"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "sooooooooooooooooooooooor"; $ultraComplex = insertPoint($ultraComplex, 'abcde'); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e')); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e', 'u', 'n', 'j', 'h', 'n')); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e', 'u', 'n', 'j', 'h', 'n')); $ultraComplex = insertPoint($ultraComplex, 'tumnghij'); $myparams['checkpoints'] = 5; $myparams['teleports'] = 3; $myparams['rockchance'] = 12; $myparams['walls'] = 50; $myparams['name'] = 'Ultra Complex'; $map = GenerateShapedMap($ultraComplex, $myparams); break; case 1: $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage = insertPoint($mirrorImage, 'abcdetnglrrrrr'); $mirrorImageB = $mirrorImage; foreach ($mirrorImageB as &$value) { $value = str_replace("t", "u", $value); $value = str_replace("n", "m", $value); $value = str_replace("g", "h", $value); $value = str_replace("l", "k", $value); $value = str_replace("f", "s", $value); $value = str_replace("S", "f", $value); } $mirrorImage[] = "qqqqqqqqqqqqqqqqqqqqqqqqq"; $mirrorImage = array_merge($mirrorImage, $mirrorImageB); $myparams['checkpoints'] = 5; $myparams['teleports'] = 3; $myparams['rockchance'] = 400; $myparams['walls'] = 999; $myparams['name'] = 'Mirror Image'; $map = GenerateShapedMap($mirrorImage, $myparams); break; } return $map; } ?> \ No newline at end of file + NOW() ORDER BY mapOfTheDay.mapDate DESC LIMIT 1 "; $result = mysql_query($sql); if (mysql_num_rows($result) == 0) { return null; } //A map was found, so return it $r['code'] = mysql_result($result, 0, 'code'); $r['map'] = GenerateMapByCode($r['code']); $r['id'] = mysql_result($result, 0, 'ID'); return $r; } /** * Generates all the new maps for the day. Includes a critical section so maps aren't generated more * than once per day. */ function generateNewMapsOfTheDay() { ignore_user_abort(true); set_time_limit(0); $lock = acquireMotdLock(); try { //Double check that we still need to generate a new map for today. Since that was done outside of the lock, it's possible //two threads could reach this point at the same time. $latestSpecialMap = getMapOfTheDayInternal(MapType::Special); $latestWeeklyMap = getMapOfTheDayInternal(MapType::Weekly); if($latestSpecialMap != null && $latestWeeklyMap != null) { releaseMotdLock($lock); return; } //The rest of the code in the try{} can be assumed to only be run once a day //Generate the maps $mapCode = array(); if($latestSpecialMap == null) { $mapCode[MapType::Simple] = generateNewMapCode(MapType::Simple); $mapCode[MapType::Normal] = generateNewMapCode(MapType::Normal); $mapCode[MapType::Complex] = generateNewMapCode(MapType::Complex); $mapCode[MapType::Special] = generateNewMapCode(MapType::Special); } //The weekly maps might not need to be generated tonight. Check if it does first if($latestWeeklyMap == null) { $mapCode[MapType::Weekly] = generateNewMapCode(MapType::Weekly); } //Add the actual maps to the DB addNewMapsToDB($mapCode); //Update the player-statistics if($latestSpecialMap == null) { //Add points for yesterday's maps if we just created the daily maps addStatsForYesterdaysMaps(); } if($latestWeeklyMap == null) { //Add points for the weekly map, which is created at noon rather than midnight addStatsForMiddayMaps(); //Note that there could potentially be an issue adding points twice if server goes from noon on Saturday //(or whenever we generate the new weekly map) to midnight the next morning without anyone visiting the site. //That's probably not going to be an issue on the production site, however... } } catch (Exception $exc) { /* Ignore... :| */ } //try/catch above is necessary to make sure an exception doesn't prevent us from releasing the lock! releaseMotdLock($lock); } /** * Generates a single map of the given type, and returns its "map code" */ function generateNewMapCode($type) { // If you want to modify the maps created! This is the line //GenerateMap($rows, $cols, $rockchance, $numBlocks = -1, $cp = -1, $tp = -1) switch ($type) { case MapType::Simple: $map = GenerateMap(13, 7, 12, rand(7, 10), rand(0, 1), 0, 'Simple'); break; case MapType::Normal: $map = GenerateMap(15, 9, 7, rand(11, 13), rand(1, 3) + rand(0, 1), 0, 'Normal'); break; case MapType::Complex: $map = getRandomComplexMap(); break; case MapType::Special: $map = getRandomSpecialMap(); break; case MapType::Weekly: $map = getRandomWeeklyMap(); break; default: $map = GenerateMap(rand(13, 18), rand(10, 14), rand(6, 9)); break; } return GenerateMapCode($map); } function addNewMapsToDB($mapCode) { foreach($mapCode as $code) { $map = new map($code); $codeSafe = mysql_escape_string($code); $nameSafe = mysql_escape_string($map->name); $codeValuesAry[] = " ('$codeSafe', '$nameSafe')"; } $codeValues = implode(",", $codeValuesAry); //Insert all the maps at once. $sql = "INSERT INTO `maps` (`code`, `name`) VALUES $codeValues"; //Did we succeed? $result = mysql_query($sql); if (!$result) { releaseMotdLock($lock); die("Error on inserting maps, offending SQL: $sql"); } //Get the ID of the first insert. $mapIDI = mysql_insert_id(); foreach ($mapCode as $type => $code) { if($type == MapType::Weekly) { //Weekly map lasts MAP_EXPIRE_TIME_WEEKLY days. We also want to offset by 12 hours $numHours = 24*MAP_EXPIRE_TIME_WEEKLY + 12; $expireTime = "ADDDATE(CURDATE(), INTERVAL $numHours HOUR)"; } else { //All other maps are assumed to last one day $expireTime = 'ADDDATE(CURDATE(), INTERVAL 1 DAY)'; } $mapOfTheDayAry[] = "('$mapIDI', '$type', CURDATE(), $expireTime)"; $mapIDI++; } $mapOfTheDayValues = implode(",", $mapOfTheDayAry); $sql = "INSERT INTO `mapOfTheDay` (`mapID`, `mapType`, `mapDate`, `mapExpireTime`) VALUES $mapOfTheDayValues "; $result = mysql_query($sql); if (!$result) { releaseMotdLock($lock); die("Error on insert into mapOfTheDay SQL: $sql"); } else { //Post it in the chat! addchat(null, "New maps added!"); } } /** * The file locked in order to create serialize map-creations, since our DB doesn't support transactions... */ define('FILE_MOTD_LOCK', './motdLockFile'); /** * Obtains the mutex used for creating the Map Of The Day, so that race-conditions cannot occur (like two threads * creating and inserting the maps into the database at the same time, which has happened */ function acquireMotdLock() { $fileHandle = fopen(FILE_MOTD_LOCK, 'a+'); flock($fileHandle, LOCK_EX); return $fileHandle; } /** * Releases the lock acquired from acquireMotdLock */ function releaseMotdLock($fileHandle) { if($fileHandle) flock($fileHandle, LOCK_UN); } function getRandomComplexMap() { $random = weight(0, 0, 0, 0, 0, 0, 0, 1); switch ($random) { case 0: $map = GenerateMap(19, 9, rand(7, 9), rand(14, 16), rand(2, 5), rand(1, 2), 'Complex'); break; case 1: $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath = insertPoint($reversePath, 'abc'); $reversePath = insertPoint($reversePath, 'tu'); $myparams['checkpoints'] = 3; $myparams['teleports'] = 0; $myparams['rockchance'] = 7; $myparams['walls'] = 12; $myparams['name'] = 'Reverse Order'; $map = GenerateShapedMap($reversePath, $myparams); break; } return $map; } function getRandomSpecialMap() { //This can be used to add additional weight to certain maps that we like. $random = weight(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); //FORCE: //$random = 11; $shape = array(); $params = array(); switch ($random) { //===================================== case 0: //Thirty $map = GenerateMap( 18, 14, 20, //width, height, rocks weight(30), //Walls weight(1), //Checkpoints weight(1), //Teleports 'Thirty' ); break; //===================================== case 1: //Finite $map = GenerateMap( 18, 9, 7, //width, height, rocks weight(15, 16, 17), //Walls weight(0), //Checkpoints weight(0), //Teleports 'Finite' ); break; //===================================== case 2: //ABC's $map = GenerateMap( 19, 11, 12, //width, height, rocks weight(20, 21, 22, 22, 23), //Walls weight(3), //Checkpoints weight(0), //Teleports "ABC's " ); break; //===================================== case 3: //Tele Madness $map = GenerateMap( 17, 12, 10, //width, height, rocks weight(17, 18), //Walls weight(1), //Checkpoints weight(5), //Teleports 'Teleport Madness' ); break; //===================================== case 4: //Rocky Maze $map = GenerateMap( 19, 15, 5, //width, height, rocks weight(16, 17, 18), //Walls weight(1, 2, 2, 2, 3, 3), //Checkpoints weight(0), //Teleports 'Rocky Maze' ); break; //===================================== case 5: //Side to Side $map = GenerateMap( 26, 6, 12, //width, height, rocks weight(17, 18, 19), //Walls weight(2, 2, 2, 3, 3), //Checkpoints weight(3, 3, 3, 4), //Teleports 'Side to Side' ); break; //===================================== case 6: //Ultimate's Random map: //Create shape $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; //Insert points $shape = insertPoint($shape, "sfabcr", $target = '?'); $shape = insertPoint($shape, weight("tu", "d", "tu", "", ""), $target = '?'); //Set params $params['rockchance'] = 10; $params['walls'] = weight(21, 20, 22, 20, 21); $params['name'] = 'Ultimate Random'; //Put it all together. $map = GenerateShapedMap($shape, $params); break; //===================================== //===================================== case 7: //Dual map $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "oqqqqqqqqqqqqqqqqqqqo"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapa = insertPoint($dualmapa, 'abc'); $dualmapb = insertPoint($dualmapb, 'abc'); $dualmap = array_merge($dualmapa, $dualmapb); $dualmap = insertPoint($dualmap, 'tu'); $myparams['checkpoints'] = 3; $myparams['teleports'] = 1; $myparams['rockchance'] = 9; $myparams['walls'] = weight(20, 20, 21, 21, 22, 23); $myparams['name'] = 'Seeing Double'; $map = GenerateShapedMap($dualmap, $myparams); break; //===================================== //===================================== case 8: //Centralized $myshape[] = "ooooooooooooooooooo"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o???????fos???????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "ooooooooooooooooooo"; $myshape = insertPoint($myshape, "abc", $target = '?'); $myshape = insertPoint($myshape, weight("tu", "d", "tud", ""), $target = '?'); $myparams['rockchance'] = 7; $myparams['walls'] = weight(17, 18, 19, 18, 17); $myparams['name'] = 'Centralized'; $map = GenerateShapedMap($myshape, $myparams); break; //===================================== //===================================== case 9: //Dualing paths $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'Xo??????????????ox'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths = insertPoint($dualingPaths, 'abc'); $dualingPaths = insertPoint($dualingPaths, weight('xx', 'xxx', 'xxxx').weight('XX', 'XXX', 'XXXX')); $myparams['checkpoints'] = 3; $myparams['teleports'] = 0; $myparams['rockchance'] = 9; $myparams['walls'] = 13; $myparams['name'] = 'Dualing paths'; $map = GenerateShapedMap($dualingPaths, $myparams); break; //===================================== //===================================== case 10: //Unlimited $unlimited[] = 'so?o?o?o?o?o?o?of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?o?o?o?o?o?o?of'; $unlimited = insertPoint($unlimited, 'abc'); $unlimited = insertPoint($unlimited, weight('tu', 'dtu')); $myparams['checkpoints'] = 3; $myparams['teleports'] = 1; $myparams['rockchance'] = 9; $myparams['walls'] = 999; $myparams['name'] = 'Unlimited'; $map = GenerateShapedMap($unlimited, $myparams); break; //===================================== //===================================== case 11: //Thirty Too $thirtyTooShape[] = 's??????????????????Xf'; $thirtyTooShape[] = '????????????????????X'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = 'x????????????????????'; $thirtyTooShape[] = 'fx??????????????????S'; $thirtyTooShape = insertPoint($thirtyTooShape, 'atupppp'); $myparams['checkpoints'] = 2; $myparams['teleports'] = 1; $myparams['rockchance'] = 20; $myparams['walls'] = 32; $myparams['name'] = 'Thirty Too'; $map = GenerateShapedMap($thirtyTooShape, $myparams); break; //===================================== } return $map; } function getRandomWeeklyMap() { //This can be used to add additional weight to certain maps that we like. $random = weight(0); //FORCE: $random = 1; $shape = array(); $params = array(); switch ($random) { case 0: $ultraComplex[] = "sooooooooooooooooooooooor"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "sooooooooooooooooooooooor"; $ultraComplex = insertPoint($ultraComplex, 'abcde'); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e')); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e', 'u', 'n', 'j', 'h', 'n')); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e', 'u', 'n', 'j', 'h', 'n')); $ultraComplex = insertPoint($ultraComplex, 'tumnghij'); $myparams['checkpoints'] = 5; $myparams['teleports'] = 3; $myparams['rockchance'] = 12; $myparams['walls'] = 50; $myparams['name'] = 'Ultra Complex'; $map = GenerateShapedMap($ultraComplex, $myparams); break; case 1: $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage = insertPoint($mirrorImage, 'abcdetnglrrrrr'); $mirrorImageB = $mirrorImage; foreach ($mirrorImageB as &$value) { $value = str_replace("t", "u", $value); $value = str_replace("n", "m", $value); $value = str_replace("g", "h", $value); $value = str_replace("l", "k", $value); $value = str_replace("f", "s", $value); $value = str_replace("S", "f", $value); } $mirrorImage[] = "qqqqqqqqqqqqqqqqqqqqqqqqq"; $mirrorImage = array_merge($mirrorImage, $mirrorImageB); $myparams['checkpoints'] = 5; $myparams['teleports'] = 3; $myparams['rockchance'] = 400; $myparams['walls'] = 999; $myparams['name'] = 'Mirror Image'; $map = GenerateShapedMap($mirrorImage, $myparams); break; } return $map; } ?> \ No newline at end of file diff --git a/update notes.txt b/update notes.txt index 1ff219c..df95be1 100644 --- a/update notes.txt +++ b/update notes.txt @@ -1,3 +1,22 @@ + +Add Table: + +CREATE TABLE IF NOT EXISTS `chatUsers` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `userID` int(11) NOT NULL, + `channel` int(11) NOT NULL, + `client` varchar(16) NOT NULL, + `dateEntered` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `dateLastActive` timestamp NULL DEFAULT NULL, + `isHere` tinyint(1) NOT NULL, + `isAdmin` tinyint(1) NOT NULL, + `isMod` tinyint(1) NOT NULL, + PRIMARY KEY (`ID`), + KEY `userID` (`userID`,`channel`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; + + + -- Did we do everything below? I think we did.. Jan 13 2014? For next update: - Move the new columns from BlueRaja's database over to your other databases (see also: db updates.sql. Most, but not all, are in there. I don't think Snap added his stuff there). Make sure to get not only the type, but nullable/default as well. -- cgit v1.2.3 From 640816989a99e069397ed18f3fa703d1ec12d596 Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Wed, 15 Jan 2014 01:39:04 -0800 Subject: More work on channel list. --- ajax/chat.ajax.php | 13 ++++++-- css/chat.css | 4 +-- includes/chats.php | 30 ++++++++++++++--- pages/chat.php | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 125 insertions(+), 16 deletions(-) diff --git a/ajax/chat.ajax.php b/ajax/chat.ajax.php index 8302c33..91c5b95 100644 --- a/ajax/chat.ajax.php +++ b/ajax/chat.ajax.php @@ -7,10 +7,15 @@ session_start(); // } -ini_set('display_errors',1); -ini_set('display_startup_errors',1); -error_reporting(-1); +//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; @@ -50,7 +55,9 @@ $use_psuedo_longpoll = true; require_once('../includes/chats.php'); +//exit; +enterChannel($userID); $sent = false; if (isset($_REQUEST['messages'])) { diff --git a/css/chat.css b/css/chat.css index 5973b4d..d0bccab 100644 --- a/css/chat.css +++ b/css/chat.css @@ -89,7 +89,7 @@ font-family: 'Trebuchet MS1', 'Trebuchet MS', sans-serif; font-size: 16px; display: inline-block; - width: 525px; + width: 335px; padding: 5px 5px 5px 5px; white-space: pre-wrap; /* CSS3 */ white-space: -moz-pre-wrap; /* Firefox */ @@ -122,7 +122,7 @@ } .chatMessage { - width:780px; + width:590px; min-height:35px; margin:1px; display:block; diff --git a/includes/chats.php b/includes/chats.php index 0e48ecf..c4a43dc 100644 --- a/includes/chats.php +++ b/includes/chats.php @@ -103,7 +103,7 @@ function enterChannel($userID, $channel = 1) { (`userID`, `channel`, `dateEntered`, `isHere`) VALUES (?, ?, NOW(), true) - ON DUPLICATE KEY UPDATE `isHere` = true + ON DUPLICATE KEY UPDATE `isHere` = true, dateLastActive = NOW() "); $stmt->bind_param('ii', $userID, $channel); $stmt->execute(); @@ -122,6 +122,23 @@ function exitChannel($userID, $channel = 1) { return; } + +function channelListUpdated($timeStamp) { + global $mysqli; + + $stmt = $mysqli->prepare("SELECT `value` FROM `settings` + WHERE `name` = 'Channel_Last_Update' AND + `value` < '?'" + ); + $stmt->bind_param( "i", $timeStamp); + $stmt->execute(); + + $stmt->bind_result($value); + + return $value; +} + + //Get a list of users in channel function getChannelList($channel = 1) { global $mysqli; @@ -130,13 +147,15 @@ function getChannelList($channel = 1) { $res = $mysqli->query(" SELECT - chatUsers.userID, + chatUsers.userID as 'ID', chatUsers.dateEntered, - chatUsers.dateLastActive, + + TIME_TO_SEC(TIMEDIFF(NOW(), chatUsers.dateLastActive)) as dateLastActive, + chatUsers.isAdmin, chatUsers.isMod, - users.displayName, + users.displayName as 'display', users.displayColor, users.wallColor, users.wallEmblem, @@ -144,6 +163,7 @@ function getChannelList($channel = 1) { FROM `chatUsers` LEFT JOIN `users` ON chatUsers.userID = users.ID + WHERE chatUsers.dateLastActive > NOW() - INTERVAL 5 MINUTE ORDER BY chatUsers.isMod DESC, chatUsers.dateEntered DESC "); $array = array(); @@ -152,7 +172,7 @@ function getChannelList($channel = 1) { return false; } while ($response = $res->fetch_assoc()) { - $array[] = $response; + $array['users'][] = $response; } $res->close(); $mysqli->close(); diff --git a/pages/chat.php b/pages/chat.php index f55476f..992d600 100644 --- a/pages/chat.php +++ b/pages/chat.php @@ -20,10 +20,13 @@ if (!$accepted) {

Pathery Chat - BETA

-
-
+ +
Loading...
+ +
+ +
+
@@ -386,6 +466,8 @@ function setChatMute() {
+ +
Date: Tue, 18 Mar 2014 21:53:45 -0700 Subject: More memberlist edits --- ajax/chat.ajax.php | 14 ++++++++++++++ css/chat.css | 4 ++-- includes/chats.php | 5 +++-- includes/mapoftheday.php | 2 +- pages/chat.php | 30 +++++++++++++++++++++++------- 5 files changed, 43 insertions(+), 12 deletions(-) diff --git a/ajax/chat.ajax.php b/ajax/chat.ajax.php index 91c5b95..1574bde 100644 --- a/ajax/chat.ajax.php +++ b/ajax/chat.ajax.php @@ -24,6 +24,20 @@ 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) { diff --git a/css/chat.css b/css/chat.css index d0bccab..105dfaf 100644 --- a/css/chat.css +++ b/css/chat.css @@ -89,7 +89,7 @@ font-family: 'Trebuchet MS1', 'Trebuchet MS', sans-serif; font-size: 16px; display: inline-block; - width: 335px; + width: 315px; padding: 5px 5px 5px 5px; white-space: pre-wrap; /* CSS3 */ white-space: -moz-pre-wrap; /* Firefox */ @@ -122,7 +122,7 @@ } .chatMessage { - width:590px; + width:570px; min-height:35px; margin:1px; display:block; diff --git a/includes/chats.php b/includes/chats.php index c4a43dc..47ecd39 100644 --- a/includes/chats.php +++ b/includes/chats.php @@ -163,8 +163,8 @@ function getChannelList($channel = 1) { FROM `chatUsers` LEFT JOIN `users` ON chatUsers.userID = users.ID - WHERE chatUsers.dateLastActive > NOW() - INTERVAL 5 MINUTE - ORDER BY chatUsers.isMod DESC, chatUsers.dateEntered DESC + + ORDER BY chatUsers.isMod DESC, chatUsers.dateEntered ASC "); $array = array(); if ($res->num_rows == 0) { @@ -173,6 +173,7 @@ function getChannelList($channel = 1) { } while ($response = $res->fetch_assoc()) { $array['users'][] = $response; + } $res->close(); $mysqli->close(); diff --git a/includes/mapoftheday.php b/includes/mapoftheday.php index 02d64f4..b5d469d 100644 --- a/includes/mapoftheday.php +++ b/includes/mapoftheday.php @@ -1 +1 @@ - NOW() ORDER BY mapOfTheDay.mapDate DESC LIMIT 1 "; $result = mysql_query($sql); if (mysql_num_rows($result) == 0) { return null; } //A map was found, so return it $r['code'] = mysql_result($result, 0, 'code'); $r['map'] = GenerateMapByCode($r['code']); $r['id'] = mysql_result($result, 0, 'ID'); return $r; } /** * Generates all the new maps for the day. Includes a critical section so maps aren't generated more * than once per day. */ function generateNewMapsOfTheDay() { ignore_user_abort(true); set_time_limit(0); $lock = acquireMotdLock(); try { //Double check that we still need to generate a new map for today. Since that was done outside of the lock, it's possible //two threads could reach this point at the same time. $latestSpecialMap = getMapOfTheDayInternal(MapType::Special); $latestWeeklyMap = getMapOfTheDayInternal(MapType::Weekly); if($latestSpecialMap != null && $latestWeeklyMap != null) { releaseMotdLock($lock); return; } //The rest of the code in the try{} can be assumed to only be run once a day //Generate the maps $mapCode = array(); if($latestSpecialMap == null) { $mapCode[MapType::Simple] = generateNewMapCode(MapType::Simple); $mapCode[MapType::Normal] = generateNewMapCode(MapType::Normal); $mapCode[MapType::Complex] = generateNewMapCode(MapType::Complex); $mapCode[MapType::Special] = generateNewMapCode(MapType::Special); } //The weekly maps might not need to be generated tonight. Check if it does first if($latestWeeklyMap == null) { $mapCode[MapType::Weekly] = generateNewMapCode(MapType::Weekly); } //Add the actual maps to the DB addNewMapsToDB($mapCode); //Update the player-statistics if($latestSpecialMap == null) { //Add points for yesterday's maps if we just created the daily maps addStatsForYesterdaysMaps(); } if($latestWeeklyMap == null) { //Add points for the weekly map, which is created at noon rather than midnight addStatsForMiddayMaps(); //Note that there could potentially be an issue adding points twice if server goes from noon on Saturday //(or whenever we generate the new weekly map) to midnight the next morning without anyone visiting the site. //That's probably not going to be an issue on the production site, however... } } catch (Exception $exc) { /* Ignore... :| */ } //try/catch above is necessary to make sure an exception doesn't prevent us from releasing the lock! releaseMotdLock($lock); } /** * Generates a single map of the given type, and returns its "map code" */ function generateNewMapCode($type) { // If you want to modify the maps created! This is the line //GenerateMap($rows, $cols, $rockchance, $numBlocks = -1, $cp = -1, $tp = -1) switch ($type) { case MapType::Simple: $map = GenerateMap(13, 7, 12, rand(7, 10), rand(0, 1), 0, 'Simple'); break; case MapType::Normal: $map = GenerateMap(15, 9, 7, rand(11, 13), rand(1, 3) + rand(0, 1), 0, 'Normal'); break; case MapType::Complex: $map = getRandomComplexMap(); break; case MapType::Special: $map = getRandomSpecialMap(); break; case MapType::Weekly: $map = getRandomWeeklyMap(); break; default: $map = GenerateMap(rand(13, 18), rand(10, 14), rand(6, 9)); break; } return GenerateMapCode($map); } function addNewMapsToDB($mapCode) { foreach($mapCode as $code) { $map = new map($code); $codeSafe = mysql_escape_string($code); $nameSafe = mysql_escape_string($map->name); $codeValuesAry[] = " ('$codeSafe', '$nameSafe')"; } $codeValues = implode(",", $codeValuesAry); //Insert all the maps at once. $sql = "INSERT INTO `maps` (`code`, `name`) VALUES $codeValues"; //Did we succeed? $result = mysql_query($sql); if (!$result) { releaseMotdLock($lock); die("Error on inserting maps, offending SQL: $sql"); } //Get the ID of the first insert. $mapIDI = mysql_insert_id(); foreach ($mapCode as $type => $code) { if($type == MapType::Weekly) { //Weekly map lasts MAP_EXPIRE_TIME_WEEKLY days. We also want to offset by 12 hours $numHours = 24*MAP_EXPIRE_TIME_WEEKLY + 12; $expireTime = "ADDDATE(CURDATE(), INTERVAL $numHours HOUR)"; } else { //All other maps are assumed to last one day $expireTime = 'ADDDATE(CURDATE(), INTERVAL 1 DAY)'; } $mapOfTheDayAry[] = "('$mapIDI', '$type', CURDATE(), $expireTime)"; $mapIDI++; } $mapOfTheDayValues = implode(",", $mapOfTheDayAry); $sql = "INSERT INTO `mapOfTheDay` (`mapID`, `mapType`, `mapDate`, `mapExpireTime`) VALUES $mapOfTheDayValues "; $result = mysql_query($sql); if (!$result) { releaseMotdLock($lock); die("Error on insert into mapOfTheDay SQL: $sql"); } else { //Post it in the chat! addchat(null, "New maps added!"); } } /** * The file locked in order to create serialize map-creations, since our DB doesn't support transactions... */ define('FILE_MOTD_LOCK', './motdLockFile'); /** * Obtains the mutex used for creating the Map Of The Day, so that race-conditions cannot occur (like two threads * creating and inserting the maps into the database at the same time, which has happened */ function acquireMotdLock() { $fileHandle = fopen(FILE_MOTD_LOCK, 'a+'); flock($fileHandle, LOCK_EX); return $fileHandle; } /** * Releases the lock acquired from acquireMotdLock */ function releaseMotdLock($fileHandle) { if($fileHandle) flock($fileHandle, LOCK_UN); } function getRandomComplexMap() { $random = weight(0, 0, 0, 0, 0, 0, 0, 1); switch ($random) { case 0: $map = GenerateMap(19, 9, rand(7, 9), rand(14, 16), rand(2, 5), rand(1, 2), 'Complex'); break; case 1: $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath = insertPoint($reversePath, 'abc'); $reversePath = insertPoint($reversePath, 'tu'); $myparams['checkpoints'] = 3; $myparams['teleports'] = 0; $myparams['rockchance'] = 7; $myparams['walls'] = 12; $myparams['name'] = 'Reverse Order'; $map = GenerateShapedMap($reversePath, $myparams); break; } return $map; } function getRandomSpecialMap() { //This can be used to add additional weight to certain maps that we like. $random = weight(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); //FORCE: //$random = 11; $shape = array(); $params = array(); switch ($random) { //===================================== case 0: //Thirty $map = GenerateMap( 18, 14, 20, //width, height, rocks weight(30), //Walls weight(1), //Checkpoints weight(1), //Teleports 'Thirty' ); break; //===================================== case 1: //Finite $map = GenerateMap( 18, 9, 7, //width, height, rocks weight(15, 16, 17), //Walls weight(0), //Checkpoints weight(0), //Teleports 'Finite' ); break; //===================================== case 2: //ABC's $map = GenerateMap( 19, 11, 12, //width, height, rocks weight(20, 21, 22, 22, 23), //Walls weight(3), //Checkpoints weight(0), //Teleports "ABC's " ); break; //===================================== case 3: //Tele Madness $map = GenerateMap( 17, 12, 10, //width, height, rocks weight(17, 18), //Walls weight(1), //Checkpoints weight(5), //Teleports 'Teleport Madness' ); break; //===================================== case 4: //Rocky Maze $map = GenerateMap( 19, 15, 5, //width, height, rocks weight(16, 17, 18), //Walls weight(1, 2, 2, 2, 3, 3), //Checkpoints weight(0), //Teleports 'Rocky Maze' ); break; //===================================== case 5: //Side to Side $map = GenerateMap( 26, 6, 12, //width, height, rocks weight(17, 18, 19), //Walls weight(2, 2, 2, 3, 3), //Checkpoints weight(3, 3, 3, 4), //Teleports 'Side to Side' ); break; //===================================== case 6: //Ultimate's Random map: //Create shape $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; //Insert points $shape = insertPoint($shape, "sfabcr", $target = '?'); $shape = insertPoint($shape, weight("tu", "d", "tu", "", ""), $target = '?'); //Set params $params['rockchance'] = 10; $params['walls'] = weight(21, 20, 22, 20, 21); $params['name'] = 'Ultimate Random'; //Put it all together. $map = GenerateShapedMap($shape, $params); break; //===================================== //===================================== case 7: //Dual map $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "oqqqqqqqqqqqqqqqqqqqo"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapa = insertPoint($dualmapa, 'abc'); $dualmapb = insertPoint($dualmapb, 'abc'); $dualmap = array_merge($dualmapa, $dualmapb); $dualmap = insertPoint($dualmap, 'tu'); $myparams['checkpoints'] = 3; $myparams['teleports'] = 1; $myparams['rockchance'] = 9; $myparams['walls'] = weight(20, 20, 21, 21, 22, 23); $myparams['name'] = 'Seeing Double'; $map = GenerateShapedMap($dualmap, $myparams); break; //===================================== //===================================== case 8: //Centralized $myshape[] = "ooooooooooooooooooo"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o???????fos???????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "ooooooooooooooooooo"; $myshape = insertPoint($myshape, "abc", $target = '?'); $myshape = insertPoint($myshape, weight("tu", "d", "tud", ""), $target = '?'); $myparams['rockchance'] = 7; $myparams['walls'] = weight(17, 18, 19, 18, 17); $myparams['name'] = 'Centralized'; $map = GenerateShapedMap($myshape, $myparams); break; //===================================== //===================================== case 9: //Dualing paths $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'Xo??????????????ox'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths = insertPoint($dualingPaths, 'abc'); $dualingPaths = insertPoint($dualingPaths, weight('xx', 'xxx', 'xxxx').weight('XX', 'XXX', 'XXXX')); $myparams['checkpoints'] = 3; $myparams['teleports'] = 0; $myparams['rockchance'] = 9; $myparams['walls'] = 13; $myparams['name'] = 'Dualing paths'; $map = GenerateShapedMap($dualingPaths, $myparams); break; //===================================== //===================================== case 10: //Unlimited $unlimited[] = 'so?o?o?o?o?o?o?of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?o?o?o?o?o?o?of'; $unlimited = insertPoint($unlimited, 'abc'); $unlimited = insertPoint($unlimited, weight('tu', 'dtu')); $myparams['checkpoints'] = 3; $myparams['teleports'] = 1; $myparams['rockchance'] = 9; $myparams['walls'] = 999; $myparams['name'] = 'Unlimited'; $map = GenerateShapedMap($unlimited, $myparams); break; //===================================== //===================================== case 11: //Thirty Too $thirtyTooShape[] = 's??????????????????Xf'; $thirtyTooShape[] = '????????????????????X'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = 'x????????????????????'; $thirtyTooShape[] = 'fx??????????????????S'; $thirtyTooShape = insertPoint($thirtyTooShape, 'atupppp'); $myparams['checkpoints'] = 2; $myparams['teleports'] = 1; $myparams['rockchance'] = 20; $myparams['walls'] = 32; $myparams['name'] = 'Thirty Too'; $map = GenerateShapedMap($thirtyTooShape, $myparams); break; //===================================== } return $map; } function getRandomWeeklyMap() { //This can be used to add additional weight to certain maps that we like. $random = weight(0); //FORCE: $random = 1; $shape = array(); $params = array(); switch ($random) { case 0: $ultraComplex[] = "sooooooooooooooooooooooor"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "sooooooooooooooooooooooor"; $ultraComplex = insertPoint($ultraComplex, 'abcde'); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e')); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e', 'u', 'n', 'j', 'h', 'n')); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e', 'u', 'n', 'j', 'h', 'n')); $ultraComplex = insertPoint($ultraComplex, 'tumnghij'); $myparams['checkpoints'] = 5; $myparams['teleports'] = 3; $myparams['rockchance'] = 12; $myparams['walls'] = 50; $myparams['name'] = 'Ultra Complex'; $map = GenerateShapedMap($ultraComplex, $myparams); break; case 1: $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage = insertPoint($mirrorImage, 'abcdetnglrrrrr'); $mirrorImageB = $mirrorImage; foreach ($mirrorImageB as &$value) { $value = str_replace("t", "u", $value); $value = str_replace("n", "m", $value); $value = str_replace("g", "h", $value); $value = str_replace("l", "k", $value); $value = str_replace("f", "s", $value); $value = str_replace("S", "f", $value); } $mirrorImage[] = "qqqqqqqqqqqqqqqqqqqqqqqqq"; $mirrorImage = array_merge($mirrorImage, $mirrorImageB); $myparams['checkpoints'] = 5; $myparams['teleports'] = 3; $myparams['rockchance'] = 400; $myparams['walls'] = 999; $myparams['name'] = 'Mirror Image'; $map = GenerateShapedMap($mirrorImage, $myparams); break; } return $map; } ?> \ No newline at end of file + NOW() ORDER BY mapOfTheDay.mapDate DESC LIMIT 1 "; $result = mysql_query($sql); if (mysql_num_rows($result) == 0) { return null; } //A map was found, so return it $r['code'] = mysql_result($result, 0, 'code'); $r['map'] = GenerateMapByCode($r['code']); $r['id'] = mysql_result($result, 0, 'ID'); return $r; } /** * Generates all the new maps for the day. Includes a critical section so maps aren't generated more * than once per day. */ function generateNewMapsOfTheDay() { ignore_user_abort(true); set_time_limit(0); $lock = acquireMotdLock(); try { //Double check that we still need to generate a new map for today. Since that was done outside of the lock, it's possible //two threads could reach this point at the same time. $latestSpecialMap = getMapOfTheDayInternal(MapType::Special); $latestWeeklyMap = getMapOfTheDayInternal(MapType::Weekly); if($latestSpecialMap != null && $latestWeeklyMap != null) { releaseMotdLock($lock); return; } //The rest of the code in the try{} can be assumed to only be run once a day //Generate the maps $mapCode = array(); if($latestSpecialMap == null) { $mapCode[MapType::Simple] = generateNewMapCode(MapType::Simple); $mapCode[MapType::Normal] = generateNewMapCode(MapType::Normal); $mapCode[MapType::Complex] = generateNewMapCode(MapType::Complex); $mapCode[MapType::Special] = generateNewMapCode(MapType::Special); } //The weekly maps might not need to be generated tonight. Check if it does first if($latestWeeklyMap == null) { $mapCode[MapType::Weekly] = generateNewMapCode(MapType::Weekly); } //Add the actual maps to the DB addNewMapsToDB($mapCode); //Update the player-statistics if($latestSpecialMap == null) { //Add points for yesterday's maps if we just created the daily maps addStatsForYesterdaysMaps(); } if($latestWeeklyMap == null) { //Add points for the weekly map, which is created at noon rather than midnight addStatsForMiddayMaps(); //Note that there could potentially be an issue adding points twice if server goes from noon on Saturday //(or whenever we generate the new weekly map) to midnight the next morning without anyone visiting the site. //That's probably not going to be an issue on the production site, however... } } catch (Exception $exc) { /* Ignore... :| */ } //try/catch above is necessary to make sure an exception doesn't prevent us from releasing the lock! releaseMotdLock($lock); } /** * Generates a single map of the given type, and returns its "map code" */ function generateNewMapCode($type) { // If you want to modify the maps created! This is the line //GenerateMap($rows, $cols, $rockchance, $numBlocks = -1, $cp = -1, $tp = -1) switch ($type) { case MapType::Simple: $map = GenerateMap(13, 7, 12, rand(7, 10), rand(0, 1), 0, 'Simple'); break; case MapType::Normal: $map = GenerateMap(15, 9, 7, rand(11, 13), rand(1, 3) + rand(0, 1), 0, 'Normal'); break; case MapType::Complex: $map = getRandomComplexMap(); break; case MapType::Special: $map = getRandomSpecialMap(); break; case MapType::Weekly: $map = getRandomWeeklyMap(); break; default: $map = GenerateMap(rand(13, 18), rand(10, 14), rand(6, 9)); break; } return GenerateMapCode($map); } function addNewMapsToDB($mapCode) { foreach($mapCode as $code) { $map = new map($code); $codeSafe = mysql_escape_string($code); $nameSafe = mysql_escape_string($map->name); $codeValuesAry[] = " ('$codeSafe', '$nameSafe')"; } $codeValues = implode(",", $codeValuesAry); //Insert all the maps at once. $sql = "INSERT INTO `maps` (`code`, `name`) VALUES $codeValues"; //Did we succeed? $result = mysql_query($sql); if (!$result) { releaseMotdLock($lock); die("Error on inserting maps, offending SQL: $sql"); } //Get the ID of the first insert. $mapIDI = mysql_insert_id(); foreach ($mapCode as $type => $code) { if($type == MapType::Weekly) { //Weekly map lasts MAP_EXPIRE_TIME_WEEKLY days. We also want to offset by 12 hours $numHours = 24*MAP_EXPIRE_TIME_WEEKLY + 12; $expireTime = "ADDDATE(CURDATE(), INTERVAL $numHours HOUR)"; } else { //All other maps are assumed to last one day $expireTime = 'ADDDATE(CURDATE(), INTERVAL 1 DAY)'; } $mapOfTheDayAry[] = "('$mapIDI', '$type', CURDATE(), $expireTime)"; $mapIDI++; } $mapOfTheDayValues = implode(",", $mapOfTheDayAry); $sql = "INSERT INTO `mapOfTheDay` (`mapID`, `mapType`, `mapDate`, `mapExpireTime`) VALUES $mapOfTheDayValues "; $result = mysql_query($sql); if (!$result) { releaseMotdLock($lock); die("Error on insert into mapOfTheDay SQL: $sql"); } else { //Post it in the chat! addchat(null, "New maps added!"); } } /** * The file locked in order to create serialize map-creations, since our DB doesn't support transactions... */ define('FILE_MOTD_LOCK', './motdLockFile'); /** * Obtains the mutex used for creating the Map Of The Day, so that race-conditions cannot occur (like two threads * creating and inserting the maps into the database at the same time, which has happened */ function acquireMotdLock() { $fileHandle = fopen(FILE_MOTD_LOCK, 'a+'); flock($fileHandle, LOCK_EX); return $fileHandle; } /** * Releases the lock acquired from acquireMotdLock */ function releaseMotdLock($fileHandle) { if($fileHandle) flock($fileHandle, LOCK_UN); } function getRandomComplexMap() { $random = weight(0, 0, 0, 0, 0, 0, 0, 1); switch ($random) { case 0: $map = GenerateMap(19, 9, rand(7, 9), rand(14, 16), rand(2, 5), rand(1, 2), 'Complex'); break; case 1: $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath = insertPoint($reversePath, 'abc'); $reversePath = insertPoint($reversePath, 'tu'); $myparams['checkpoints'] = 3; $myparams['teleports'] = 0; $myparams['rockchance'] = 7; $myparams['walls'] = 12; $myparams['name'] = 'Reverse Order'; $map = GenerateShapedMap($reversePath, $myparams); break; } return $map; } function getRandomSpecialMap() { //This can be used to add additional weight to certain maps that we like. $random = weight(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); //FORCE: //$random = 11; $shape = array(); $params = array(); switch ($random) { //===================================== case 0: //Thirty $map = GenerateMap( 18, 14, 20, //width, height, rocks weight(30), //Walls weight(1), //Checkpoints weight(1), //Teleports 'Thirty' ); break; //===================================== case 1: //Finite $map = GenerateMap( 18, 9, 7, //width, height, rocks weight(15, 16, 17), //Walls weight(0), //Checkpoints weight(0), //Teleports 'Finite' ); break; //===================================== case 2: //ABC's $map = GenerateMap( 19, 11, 12, //width, height, rocks weight(20, 21, 22, 22, 23), //Walls weight(3), //Checkpoints weight(0), //Teleports "ABC's " ); break; //===================================== case 3: //Tele Madness $map = GenerateMap( 17, 12, 10, //width, height, rocks weight(17, 18), //Walls weight(1), //Checkpoints weight(5), //Teleports 'Teleport Madness' ); break; //===================================== case 4: //Rocky Maze $map = GenerateMap( 19, 15, 5, //width, height, rocks weight(16, 17, 18), //Walls weight(1, 2, 2, 2, 3, 3), //Checkpoints weight(0), //Teleports 'Rocky Maze' ); break; //===================================== case 5: //Side to Side $map = GenerateMap( 26, 6, 12, //width, height, rocks weight(17, 18, 19), //Walls weight(2, 2, 2, 3, 3), //Checkpoints weight(3, 3, 3, 4), //Teleports 'Side to Side' ); break; //===================================== case 6: //Ultimate's Random map: //Create shape $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; //Insert points $shape = insertPoint($shape, "sfabcr", $target = '?'); $shape = insertPoint($shape, weight("tu", "d", "tu", "", ""), $target = '?'); //Set params $params['rockchance'] = 10; $params['walls'] = weight(21, 20, 22, 20, 21); $params['name'] = 'Ultimate Random'; //Put it all together. $map = GenerateShapedMap($shape, $params); break; //===================================== //===================================== case 7: //Dual map $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "oqqqqqqqqqqqqqqqqqqqo"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapa = insertPoint($dualmapa, 'abc'); $dualmapb = insertPoint($dualmapb, 'abc'); $dualmap = array_merge($dualmapa, $dualmapb); $dualmap = insertPoint($dualmap, 'tu'); $myparams['checkpoints'] = 3; $myparams['teleports'] = 1; $myparams['rockchance'] = 9; $myparams['walls'] = weight(20, 20, 21, 21, 22, 23); $myparams['name'] = 'Seeing Double'; $map = GenerateShapedMap($dualmap, $myparams); break; //===================================== //===================================== case 8: //Centralized $myshape[] = "ooooooooooooooooooo"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o???????fos???????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "ooooooooooooooooooo"; $myshape = insertPoint($myshape, "abc", $target = '?'); $myshape = insertPoint($myshape, weight("tu", "d", "tud", ""), $target = '?'); $myparams['rockchance'] = 7; $myparams['walls'] = weight(17, 18, 19, 18, 17); $myparams['name'] = 'Centralized'; $map = GenerateShapedMap($myshape, $myparams); break; //===================================== //===================================== case 9: //Dualing paths $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'Xo??????????????ox'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths = insertPoint($dualingPaths, 'abc'); $dualingPaths = insertPoint($dualingPaths, weight('xx', 'xxx', 'xxxx').weight('XX', 'XXX', 'XXXX')); $myparams['checkpoints'] = 3; $myparams['teleports'] = 0; $myparams['rockchance'] = 9; $myparams['walls'] = 13; $myparams['name'] = 'Dualing paths'; $map = GenerateShapedMap($dualingPaths, $myparams); break; //===================================== //===================================== case 10: //Unlimited $unlimited[] = 'so?o?o?o?o?o?o?of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?o?o?o?o?o?o?of'; $unlimited = insertPoint($unlimited, 'abc'); $unlimited = insertPoint($unlimited, weight('tu', 'dtu')); $myparams['checkpoints'] = 3; $myparams['teleports'] = 1; $myparams['rockchance'] = 9; $myparams['walls'] = 999; $myparams['name'] = 'Unlimited'; $map = GenerateShapedMap($unlimited, $myparams); break; //===================================== //===================================== case 11: //Thirty Too $thirtyTooShape[] = 's??????????????????Xf'; $thirtyTooShape[] = '????????????????????X'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = 'x????????????????????'; $thirtyTooShape[] = 'fx??????????????????S'; $thirtyTooShape = insertPoint($thirtyTooShape, 'atupppp'); $myparams['checkpoints'] = 2; $myparams['teleports'] = 1; $myparams['rockchance'] = 20; $myparams['walls'] = 32; $myparams['name'] = 'Thirty Too'; $map = GenerateShapedMap($thirtyTooShape, $myparams); break; //===================================== } return $map; } function getRandomWeeklyMap() { //This can be used to add additional weight to certain maps that we like. $random = weight(0); //FORCE: $random = 0; $shape = array(); $params = array(); switch ($random) { case 0: $ultraComplex[] = "sooooooooooooooooooooooor"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "sooooooooooooooooooooooor"; $ultraComplex = insertPoint($ultraComplex, 'abcde'); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e')); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e', 'u', 'n', 'j', 'h', 'n')); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e', 'u', 'n', 'j', 'h', 'n')); $ultraComplex = insertPoint($ultraComplex, 'tumnghij'); $myparams['checkpoints'] = 5; $myparams['teleports'] = 3; $myparams['rockchance'] = 12; $myparams['walls'] = 50; $myparams['name'] = 'Ultra Complex'; $map = GenerateShapedMap($ultraComplex, $myparams); break; case 1: $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage = insertPoint($mirrorImage, 'abcdetnglrrrrr'); $mirrorImageB = $mirrorImage; foreach ($mirrorImageB as &$value) { $value = str_replace("t", "u", $value); $value = str_replace("n", "m", $value); $value = str_replace("g", "h", $value); $value = str_replace("l", "k", $value); $value = str_replace("f", "s", $value); $value = str_replace("S", "f", $value); } $mirrorImage[] = "qqqqqqqqqqqqqqqqqqqqqqqqq"; $mirrorImage = array_merge($mirrorImage, $mirrorImageB); $myparams['checkpoints'] = 5; $myparams['teleports'] = 3; $myparams['rockchance'] = 400; $myparams['walls'] = 999; $myparams['name'] = 'Mirror Image'; $map = GenerateShapedMap($mirrorImage, $myparams); break; } return $map; } ?> \ No newline at end of file diff --git a/pages/chat.php b/pages/chat.php index 992d600..a1870a6 100644 --- a/pages/chat.php +++ b/pages/chat.php @@ -77,6 +77,11 @@ function getChatDone(data) { chat.displayName = 'SERVER' } + if (chat.isJoinLeave == 'true') { + console.log('IsJoin Leave!') + //return true; + } + //Message is legitmently new or a server message? if (chat.ID > lastID || typeof(chat.ID) == 'undefined') { addChatMessage(chat.displayName, chat.message, postDate, isSelf, isServer, chat.wallColor, chat.wallEmblem, @@ -283,12 +288,11 @@ function pollChannelListDone(data) { function channelListShow(JO) { console.log("Formating channelList"); - var p = ""; + var p = "
"; console.log('beginloop'); var previousI = 0; - for (var i in JO.users) { console.log('loop') var u = JO.users[i]; @@ -308,11 +312,9 @@ function channelListShow(JO) { p = p+ "
"; p = p+ "
"; p = p+ " "; - p = p+ " "+u.display+""; + p = p+ " "+u.display+""; p = p+ ""; - //p = p+ ""; - //p = p+ ""; previousI = i; } p = p+"
"+u.championPoints+"
"; @@ -443,11 +445,25 @@ pollChannelList();

Pathery Chat - BETA

+ +
-
Loading...
+
Loading...
-
+
-- cgit v1.2.3 From 598c2a0195fd95cda53d9067e6d6973048446a27 Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Tue, 18 Mar 2014 21:55:41 -0700 Subject: Updated charm.mp3 from AKI <3 --- sounds/charm.mp3 | Bin 10368 -> 11540 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/sounds/charm.mp3 b/sounds/charm.mp3 index 951c8d1..f2a72ef 100644 Binary files a/sounds/charm.mp3 and b/sounds/charm.mp3 differ -- cgit v1.2.3