summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ajax/challenges.ajax.php2
-rw-r--r--ajax/maps.ajax.php2
-rw-r--r--ajax/misc.ajax.php3
-rw-r--r--includes/datas.php1
-rw-r--r--includes/header.php3
-rw-r--r--includes/mapoftheday.php2
-rw-r--r--includes/maps.php5
-rw-r--r--index.php2
-rw-r--r--pages/login.php9
-rw-r--r--pages/massemail.php3
-rw-r--r--pages/tutorial.php3
11 files changed, 15 insertions, 20 deletions
diff --git a/ajax/challenges.ajax.php b/ajax/challenges.ajax.php
index cac9e75..0caafd1 100644
--- a/ajax/challenges.ajax.php
+++ b/ajax/challenges.ajax.php
@@ -51,8 +51,6 @@ function getChallengeCode($challengeID) {
function getChallengesByTier($tierUnsanitized, $userIdUnsanitized) {
-
- include_once('../includes/sqlEmbedded.php');
$userID = mysql_escape_string($userIdUnsanitized);
$tier = mysql_escape_string($tierUnsanitized);
diff --git a/ajax/maps.ajax.php b/ajax/maps.ajax.php
index 210fd1b..5ee6499 100644
--- a/ajax/maps.ajax.php
+++ b/ajax/maps.ajax.php
@@ -38,8 +38,6 @@ function sendCacheHeaders() {
}
function getMapObjectByID($mapID) {
- include_once('../includes/sqlEmbedded.php');
- include_once('../includes/maps.php');
$sql = "SELECT `code`, `name`, `mapExpireTime`
FROM `maps`
INNER JOIN `mapOfTheDay` ON mapID = maps.ID
diff --git a/ajax/misc.ajax.php b/ajax/misc.ajax.php
index 64eeccc..76a3158 100644
--- a/ajax/misc.ajax.php
+++ b/ajax/misc.ajax.php
@@ -1,6 +1,8 @@
<?
ob_start("ob_gzhandler");
+include_once('../includes/maps.php');
+
if ($_GET[r] == 'solution') {
solutionRespond();
exit;
@@ -10,7 +12,6 @@ function solutionRespond() {
session_start();
session_write_close();
if ($_SESSION['accepted'] != 1) exit;
- include_once('../includes/maps.php');
$userID = $_SESSION['userID'];
$mapID = $_GET['mapid'] * 1;
diff --git a/includes/datas.php b/includes/datas.php
index 8a50cbb..8711c4a 100644
--- a/includes/datas.php
+++ b/includes/datas.php
@@ -1062,7 +1062,6 @@ function loadChallengeMapCode($mapIdUnsanitized)
}
function isCurrentMap($mapID) {
- include_once('sqlEmbedded.php');
$sql = "SELECT mapID
FROM `mapOfTheDay`
WHERE `mapID` = '$mapID'
diff --git a/includes/header.php b/includes/header.php
index 7085aea..368e1c8 100644
--- a/includes/header.php
+++ b/includes/header.php
@@ -1,4 +1,6 @@
<?php
+include_once('includes/datas.php');
+
function htmlHeader($css = array(), $title = 'Pathery', $desc = '', $scripts = array()) {
global $accepted;
$resourceVer = '050513';
@@ -224,7 +226,6 @@ function userDataToJS() {
$r .= '"ID":"-1","accepted":false,"hasInsaneSpeed":false};';
} else {
$userID = $_SESSION['userID'];
- include_once('includes/datas.php');
$hasInsaneSpeed = hasExtrasUnlock($userID, UNLOCK_EXTRAS, MISC_UNLOCK_INSANE_SPEED);
$r = 'hasInsaneSpeed":'.$hasInsaneSpeed.'};'."\n";
$json = array('ID' => 'fat');
diff --git a/includes/mapoftheday.php b/includes/mapoftheday.php
index 83799aa..2e3b5aa 100644
--- a/includes/mapoftheday.php
+++ b/includes/mapoftheday.php
@@ -1 +1 @@
-<?php include_once('maps.php'); include_once('sqlEmbedded.php'); include_once('playerStats.php'); include_once('constants.php'); /** * Returns the Map Of The Day with the given type (index). Generates new maps if necessary. */ function mapOfTheDay($type = MapType::Simple) { //TODO del comments //echo "[Seeking maptype $type]"; $map = getMapOfTheDayInternal($type); if($map == null) { //Map doesn't exist, so we generate the maps and try again generateNewMapsOfTheDay(); $map = getMapOfTheDayInternal($type); } //else echo "[Found $type]"; return $map; } /** * Returns the map of the day of the given type, or null if not found. * Do not call outside of mapoftheday.php */ function getMapOfTheDayInternal($type) { //The ORDER BY and LIMIT probably shouldn't be necessary, since there should only be one active map of each //type at a time anyways.. $sql = " SELECT maps.ID, maps.code FROM `mapOfTheDay` INNER JOIN `maps` ON mapOfTheDay.mapID = maps.ID WHERE `mapType` = $type AND mapOfTheDay.mapExpireTime > 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) { include_once('mapclass.php'); 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! include_once('chats.php'); addchat(-1, "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
+<?php include_once('maps.php'); include_once('sqlEmbedded.php'); include_once('playerStats.php'); include_once('constants.php'); include_once('mapclass.php'); include_once('chats.php'); /** * Returns the Map Of The Day with the given type (index). Generates new maps if necessary. */ function mapOfTheDay($type = MapType::Simple) { //TODO del comments //echo "[Seeking maptype $type]"; $map = getMapOfTheDayInternal($type); if($map == null) { //Map doesn't exist, so we generate the maps and try again generateNewMapsOfTheDay(); $map = getMapOfTheDayInternal($type); } //else echo "[Found $type]"; return $map; } /** * Returns the map of the day of the given type, or null if not found. * Do not call outside of mapoftheday.php */ function getMapOfTheDayInternal($type) { //The ORDER BY and LIMIT probably shouldn't be necessary, since there should only be one active map of each //type at a time anyways.. $sql = " SELECT maps.ID, maps.code FROM `mapOfTheDay` INNER JOIN `maps` ON mapOfTheDay.mapID = maps.ID WHERE `mapType` = $type AND mapOfTheDay.mapExpireTime > 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(-1, "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/includes/maps.php b/includes/maps.php
index 1dfb3a6..412068e 100644
--- a/includes/maps.php
+++ b/includes/maps.php
@@ -1,4 +1,6 @@
<?PHP
+include_once('sqlEmbedded.php');
+
//Displays the map
//TODO: SOON TO DEPRECIATE!! YAY!
function DisplayMap($mapMatrix, $idprefix = 1, $style = 'normal', $speed = NULL) {
@@ -774,7 +776,6 @@ function formSolution($solution) {
//Returns the best solution.
function getSolution($userID, $mapID) {
- include_once('sqlEmbedded.php');
$sql = "SELECT `solution`, `moves`
FROM `solutions`
WHERE `userID` = '$userID' AND
@@ -787,7 +788,6 @@ function getSolution($userID, $mapID) {
}
function getChallengeSolution($userID, $challengeID) {
- include_once('sqlEmbedded.php');
$sql = "SELECT `solution`, `moves`
FROM `challengeSolutions`
WHERE `userID` = '$userID' AND
@@ -800,7 +800,6 @@ function getChallengeSolution($userID, $challengeID) {
}
function getMapCode($mapID) {
- include_once('sqlEmbedded.php');
$sql = "SELECT `code`
FROM `maps`
WHERE `ID` = '$mapID'
diff --git a/index.php b/index.php
index 63b23cf..ca81bb1 100644
--- a/index.php
+++ b/index.php
@@ -14,6 +14,7 @@ if ($showUpdatePage AND $_GET['cu'] !== "true") {
//globe will start the session.
include_once("globe.php");
include_once("./includes/header.php");
+include_once ('./includes/sqlEmbedded.php');
$accepted = isset($_SESSION['accepted']) && $_SESSION['accepted'] == 1;
@@ -29,7 +30,6 @@ if (isset($_SESSION['accepted']) AND $_SESSION['accepted'] == 1)
//TODO: We could store this data in the session
if ($accepted) {
$userID = $_SESSION['userID'];
- include_once ('./includes/sqlEmbedded.php');
$sql = "
SELECT
users.wallColor,
diff --git a/pages/login.php b/pages/login.php
index f73ca8c..b7c4317 100644
--- a/pages/login.php
+++ b/pages/login.php
@@ -10,6 +10,11 @@ if ($accepted) {
require 'includes/openid.php';
include_once 'globe.php';
+include_once('./includes/sqlEmbedded.php');
+include_once('./includes/datas.php');
+include_once('includes/chats.php');
+include_once('./includes/emails.php');
+
try {
$openid = new LightOpenID;
@@ -52,7 +57,6 @@ try {
$claimedid = $openid->__get('identity');
//I know just where to put this stuff!
- include_once('./includes/sqlEmbedded.php');
//Unless I already have this information...
//* Modify this to WHERE `email`
//$sql = "SELECT `ID`, `isAdmin`, `openID`, `displayName` FROM `users` WHERE `email` = '$email'";
@@ -125,7 +129,6 @@ try {
//Tutorial done?
if (isset($_SESSION['preCompletedTutorial'])) {
if ($_SESSION['preCompletedTutorial'] == true) {
- include_once('./includes/datas.php');
onCompletedTutorial($userID);
}
}
@@ -136,7 +139,6 @@ try {
throwLoginError($d, "Unknown DB Registration failure");
exit;
}
- include_once('includes/chats.php');
addchat(-1, "New user registered: \"$display\"");
sendNewUserEmail($userID, $email, $display, $dateJoined);
}
@@ -177,7 +179,6 @@ try {
function sendNewUserEmail($userID, $email, $display, $dateJoined) {
global $mydomain;
- include_once('./includes/emails.php');
$emailBody = "Thank you for signing in to Pathery!
Questions or feedback? Please reply to this email!
diff --git a/pages/massemail.php b/pages/massemail.php
index a85451b..d9c97c7 100644
--- a/pages/massemail.php
+++ b/pages/massemail.php
@@ -12,6 +12,7 @@ topbar($Links);
include_once('./includes/datas.php');
include_once('./includes/sqlEmbedded.php');
include_once('./includes/emails.php');
+include_once('./includes/sqlEmbedded.php');
if (!$accepted) exit;
@@ -77,8 +78,6 @@ if (isset($_POST['queueMassEmail']) AND $_POST['queueMassEmail'] == 'true') {
exit;
}
-include_once('./includes/sqlEmbedded.php');
-
$res = mysqli_query($mysqli, "SELECT count(*) as count FROM `emailQueue`");
$row = mysqli_fetch_assoc($res);
$count = $row['count'];
diff --git a/pages/tutorial.php b/pages/tutorial.php
index 41151cd..e407866 100644
--- a/pages/tutorial.php
+++ b/pages/tutorial.php
@@ -14,11 +14,10 @@ topbar($Links);
include_once ('./includes/maps.php');
include_once ('./includes/mapclass.php');
-
+include_once ('./includes/sqlEmbedded.php');
//TODO: Turn this into a function?
if ($accepted) {
- include_once ('./includes/sqlEmbedded.php');
$userID = $_SESSION['userID'];
$sql = "