diff options
author | BlueRaja <BlueRaja.admin@gmail.com> | 2013-01-24 03:04:26 -0600 |
---|---|---|
committer | BlueRaja <BlueRaja.admin@gmail.com> | 2013-01-24 03:04:26 -0600 |
commit | b6dc90e3f658a8201424aafec8e304c74d981022 (patch) | |
tree | 08440455657f7d657c6659ae41614bafbd8e0cbc | |
parent | 1e4045408872ac9bc83417f9c58ca740e54fff3d (diff) | |
download | pathery-b6dc90e3f658a8201424aafec8e304c74d981022.tar.xz |
Added a 'mapExpireTime' column to mapOfTheDay table, to simply a lot of SQL
-rw-r--r-- | db updates.sql | 19 | ||||
-rw-r--r-- | do.php | 26 | ||||
-rw-r--r-- | includes/mapoftheday.php | 2 | ||||
-rw-r--r-- | pages/gallery.php | 4 | ||||
-rw-r--r-- | pages/home.php | 52 |
5 files changed, 50 insertions, 53 deletions
diff --git a/db updates.sql b/db updates.sql index b8b63a2..440f473 100644 --- a/db updates.sql +++ b/db updates.sql @@ -1,4 +1,4 @@ -ALTER TABLE `db428221563`.`mapOfTheDay` DROP INDEX `UniqueTypeDate` , +ALTER TABLE `mapOfTheDay` DROP INDEX `UniqueTypeDate` , ADD UNIQUE `UniqueTypeDate` ( `mapDate` , `mapType` ); ALTER TABLE `mapOfTheDay` ADD `championPointsWorth` INT NOT NULL DEFAULT '0'; @@ -6,4 +6,19 @@ ALTER TABLE `mapOfTheDay` ADD `championPointsWorth` INT NOT NULL DEFAULT '0'; ALTER TABLE `users` ADD `totalMazes` INT NOT NULL DEFAULT '0', ADD `totalMoves` INT NOT NULL DEFAULT '0'; -ALTER TABLE `solutions` ADD `isTiedForHighScore` BOOLEAN NOT NULL DEFAULT '0';
\ No newline at end of file +ALTER TABLE `solutions` ADD `isTiedForHighScore` BOOLEAN NOT NULL DEFAULT '0'; + +-- Add the 'mapExpireTime' column +ALTER TABLE `mapOfTheDay` ADD `mapExpireTime` DATETIME NULL DEFAULT NULL AFTER `mapDate`; + +UPDATE mapOfTheDay +SET mapExpireTime = DATE_ADD(mapDate, INTERVAL 1 DAY) +WHERE mapType <> 5; + +UPDATE mapOfTheDay +SET mapExpireTime = DATE_ADD(mapDate, INTERVAL 2 DAY) +WHERE mapType = 5; + +ALTER TABLE `mapOfTheDay` CHANGE `mapExpireTime` `mapExpireTime` DATETIME NOT NULL; + +ALTER TABLE `mapOfTheDay` ADD INDEX ( `mapExpireTime` , `mapType` );
\ No newline at end of file @@ -372,30 +372,16 @@ die(json_encode($json)); function isCurrentMap($mapID) {
- // TODO: change methodology
include_once('./includes/sqlEmbedded.php');
- $sql = "SELECT maps.ID
+ $sql = "SELECT mapID
FROM `mapOfTheDay`
- LEFT JOIN `maps` ON maps.ID = `mapID`
- WHERE
- `mapID` = '$mapID' AND
- (
- (
- DATEDIFF(CURDATE(), mapOfTheDay.mapDate) < 1 AND
- `mapType` IN (1, 2, 3, 4)
- )
- OR
- (
- DATEDIFF(CURDATE(), mapOfTheDay.mapDate) < 2 AND
- `mapType` IN (5)
- )
- )
+ WHERE `mapID` = '$mapID'
+ AND mapExpireTime > NOW()
+ LIMIT 1
";
+
$result = mysql_query($sql) or die(mysql_error());
- if (mysql_num_rows($result) == 0)
- return false;
- else
- return true;
+ return (mysql_num_rows($result) != 0);
}
//Very simple, confirm that all targets are reachable.
diff --git a/includes/mapoftheday.php b/includes/mapoftheday.php index b858fd4..4e14312 100644 --- a/includes/mapoftheday.php +++ b/includes/mapoftheday.php @@ -1 +1 @@ -<?php
include_once('maps.php');
include_once('sqlEmbedded.php');
include_once('playerStats.php');
define('MAP_EXPIRE_TIME_NORMAL', 1); //Days that non-weekly maps should last. Changing this won't
//really work without changes to generateNewMapsOfTheDay()..
define('MAP_EXPIRE_TIME_WEEKLY', 2); //Days that a weekly map should last
/**
* Returns the Map Of The Day with the given type (index). Generates new maps if necessary.
*/
function mapOfTheDay($type = 1)
{
$map = getMapOfTheDayInternal($type);
if($map == null)
{
//Map doesn't exist, so we generate the maps and try again
generateNewMapsOfTheDay();
$map = getMapOfTheDayInternal($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)
{
if ($type <= 4)
$expire = MAP_EXPIRE_TIME_NORMAL;
else if ($type <= 8)
$expire = MAP_EXPIRE_TIME_WEEKLY;
$sql = "
SELECT maps.ID, maps.code
FROM `mapOfTheDay`, `maps`
WHERE `mapType` = $type
AND DATEDIFF(CURDATE(), mapOfTheDay.mapDate) < $expire
AND mapID = maps.ID
";
$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);
$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(4);
$latestWeeklyMap = getMapOfTheDayInternal(5);
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[1] = generateNewMapCode(1);
$mapCode[2] = generateNewMapCode(2);
$mapCode[3] = generateNewMapCode(3);
$mapCode[4] = generateNewMapCode(4);
}
//The weekly maps might not need to be generated tonight. Check if it does first
if($latestWeeklyMap == null)
{
$mapCode[5] = generateNewMapCode(5);
}
//Add the actual maps to the DB
foreach($mapCode as $type => $code)
{
addNewMapToDB($code, $type, $lock);
}
//Update the player-statistics
//TODO: Since we could now be calling this more than once a day, we probably need to update this... sigh.
addStatsForYesterdaysMaps();
} 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 1: //Easy
$map = GenerateMap(13, 7, 12, rand(7, 10), rand(0, 1), 0);
break;
case 2: //Normal
$map = GenerateMap(15, 9, 7, rand(11, 13), rand(1, 3) + rand(0, 1), 0);
break;
case 3: //Hard
$map = getRandomComplexMap();
break;
case 4: //Full random map
$map = getRandomSpecialMap();
break;
case 5:
$map = getRandomWeeklyMap();
break;
default:
$map = GenerateMap(rand(13, 18), rand(10, 14), rand(6, 9));
break;
}
return GenerateMapCode($map);
}
/**
* Adds the given map to the database as today's map of the day
*/
function addNewMapToDB($code, $type, $lock)
{
$sql = "INSERT INTO `maps` (`code`)
VALUES ('$code')";
$result = mysql_query($sql);
if (!$result)
{
releaseMotdLock($lock);
die("Error on inserting map");
}
$mapID = mysql_insert_id();
$sql = "INSERT INTO `mapOfTheDay` (`mapID`, `mapType`, `mapDate`)
VALUES ('$mapID', '$type', CURDATE()) ";
$result = mysql_query($sql);
if (!$result)
{
releaseMotdLock($lock);
die("Error on insert into mapOfTheDay");
}
}
/**
* 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);
}
//Select from yesterday
function getYesterdaysMap() {
$sql = "
select `ID`, `code` from `maps`
WHERE (
DAY(dateCreated) = DAY(NOW()) - 1
AND
MONTH(dateCreated) = MONTH(NOW())
AND
YEAR(dateCreated) = YEAR(NOW())
)
";
$result = mysql_query($sql);
//No map for today?
if (mysql_num_rows($result) == 0) {
return -1;
}
$r['code'] = mysql_result($result, 0, 'code');
$r['id'] = mysql_result($result, 0, 'ID');
return $r;
}
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));
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);
$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:
//Simple
$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: //Thursday
//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: //Friday
//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:
$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[] = '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;
//=====================================
}
return $map;
}
function getRandomWeeklyMap() {
// TEST MAP...
$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);
return $map;
}
?>
\ No newline at end of file +<?php
include_once('maps.php');
include_once('sqlEmbedded.php');
include_once('playerStats.php');
define('MAP_EXPIRE_TIME_WEEKLY', 7); //Days that a weekly map should last
class MapType
{
const Simple = 1;
const Normal = 2;
const Complex = 3;
const Special = 4;
const Weekly = 5;
}
/**
* Returns the Map Of The Day with the given type (index). Generates new maps if necessary.
*/
function mapOfTheDay($type = MapType::Simple)
{
$map = getMapOfTheDayInternal($type);
if($map == null)
{
//Map doesn't exist, so we generate the maps and try again
generateNewMapsOfTheDay();
$map = getMapOfTheDayInternal($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);
$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
foreach($mapCode as $type => $code)
{
addNewMapToDB($code, $type, $lock);
}
//Update the player-statistics
//TODO: Since we could now be calling this more than once a day, we probably need to update this... sigh.
addStatsForYesterdaysMaps();
} 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);
break;
case MapType::Normal:
$map = GenerateMap(15, 9, 7, rand(11, 13), rand(1, 3) + rand(0, 1), 0);
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);
}
/**
* Adds the given map to the database as today's map of the day
*/
function addNewMapToDB($code, $type, $lock)
{
$sql = "INSERT INTO `maps` (`code`)
VALUES ('$code')";
$result = mysql_query($sql);
if (!$result)
{
releaseMotdLock($lock);
die("Error on inserting map");
}
$mapID = mysql_insert_id();
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 HOURS";
}
else
{
//All other maps are assumed to last one day
$expireTime = 'ADDDATE(CURDATE(), INTERVAL 1 DAY)';
}
$sql = "INSERT INTO `mapOfTheDay` (`mapID`, `mapType`, `mapDate`, `mapExpireTime`)
VALUES ('$mapID', '$type', CURDATE(), $expireTime) ";
$result = mysql_query($sql);
if (!$result)
{
releaseMotdLock($lock);
die("Error on insert into mapOfTheDay");
}
}
/**
* 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));
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);
$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:
//Simple
$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;
//=====================================
}
return $map;
}
function getRandomWeeklyMap() {
$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);
return $map;
}
?>
\ No newline at end of file diff --git a/pages/gallery.php b/pages/gallery.php index 525c73a..fce6256 100644 --- a/pages/gallery.php +++ b/pages/gallery.php @@ -360,10 +360,6 @@ ini_set('display_errors',1); echo ini_get('max_execution_time'); echo ":"; - -//$motd = MapOfTheDay(3); -//$map = $motd['map']; - if (isset($_GET['walls'])) { $map[0][4] = ($_GET['walls'] * 1); } diff --git a/pages/home.php b/pages/home.php index d5ba45f..156014c 100644 --- a/pages/home.php +++ b/pages/home.php @@ -134,43 +134,43 @@ if ($accepted) { }
// 3 Main maps
-$motd = MapOfTheDay(1);
-$jmid[1] = $motd['id'];
-$mapContent = displayMaze($motd, 1);
-$mapNames[1] = 'Simple';
+$motd = MapOfTheDay(MapType::Simple);
+$jmid[MapType::Simple] = $motd['id'];
+$mapContent = displayMaze($motd, MapType::Simple);
+$mapNames[MapType::Simple] = 'Simple';
-$motd = MapOfTheDay(2);
-$jmid[2] = $motd['id'];
-$mapContent .= displayMaze($motd, 2);
-$mapNames[2] = 'Normal';
+$motd = MapOfTheDay(MapType::Normal);
+$jmid[MapType::Normal] = $motd['id'];
+$mapContent .= displayMaze($motd, MapType::Normal);
+$mapNames[MapType::Normal] = 'Normal';
// Complex Map
-$motd = MapOfTheDay(3);
-$jmid[3] = $motd['id'];
-$mapContent .= displayMaze($motd, 3);
-$mapNames[3] = $motd['map'][0][6];
-if ($mapNames[3] == '') {
- $mapNames[3] = 'Complex';
+$motd = MapOfTheDay(MapType::Complex);
+$jmid[MapType::Complex] = $motd['id'];
+$mapContent .= displayMaze($motd, MapType::Complex);
+$mapNames[MapType::Complex] = $motd['map'][0][6];
+if ($mapNames[MapType::Complex] == '') {
+ $mapNames[MapType::Complex] = 'Complex';
}
// Additional or special maps:
-$motd = MapOfTheDay(4);
-$jmid[4] = $motd['id'];
-$mapContent .= displayMaze($motd, 4);
+$motd = MapOfTheDay(MapType::Special);
+$jmid[MapType::Special] = $motd['id'];
+$mapContent .= displayMaze($motd, MapType::Special);
-$mapNames[4] = $motd['map'][0][6];
-if ($mapNames[4] == '') {
- $mapNames[4] = 'Special';
+$mapNames[MapType::Special] = $motd['map'][0][6];
+if ($mapNames[MapType::Special] == '') {
+ $mapNames[MapType::Special] = 'Special';
}
-$motd = MapOfTheDay(5);
-$jmid[5] = $motd['id'];
-$mapContent .= displayMaze($motd, 5);
-$mapNames[5] = $motd['map'][0][6];
-if ($mapNames[5] == '') {
- $mapNames[5] = 'Special';
+$motd = MapOfTheDay(MapType::Weekly);
+$jmid[MapType::Weekly] = $motd['id'];
+$mapContent .= displayMaze($motd, MapType::Weekly);
+$mapNames[MapType::Weekly] = $motd['map'][0][6];
+if ($mapNames[MapType::Weekly] == '') {
+ $mapNames[MapType::Weekly] = 'Ultra Complex';
}
echo ' <div id="difficulties">';
|