diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/datas.php | 244 | ||||
-rw-r--r-- | includes/mapoftheday.php | 2 | ||||
-rw-r--r-- | includes/maps.php | 13 |
3 files changed, 229 insertions, 30 deletions
diff --git a/includes/datas.php b/includes/datas.php index fa04300..6cc8f07 100644 --- a/includes/datas.php +++ b/includes/datas.php @@ -313,25 +313,25 @@ function getCompletedChallenges($userID, $mapID, $solution, $moves, $paths) { return; } - $firephp->log($mapID, "mapID"); - $firephp->log($userID, "userID"); + //$firephp->log($mapID, "mapID"); + //$firephp->log($userID, "userID"); $challengeResultset = loadChallengesForMap($mapID, $userID); $challengesCompleted = array(); while($challenge = mysql_fetch_array($challengeResultset)) { - $firephp->log("Checking a challenge"); - $firephp->log("Checking challenge number" . $challenge['challengeID']); - $firephp->log($challenge["dateSolved"], "dateCompleted"); + //$firephp->log("Checking a challenge"); + //$firephp->log("Checking challenge number" . $challenge['challengeID']); + //$firephp->log($challenge["dateSolved"], "dateCompleted"); //Skip checking challenges which have already been completed if($challenge["dateSolved"] !== NULL) { - $firephp->log('Challenge was already completed'); + //$firephp->log('Challenge was already completed'); $challengesCompleted[] = $challenge["challengeID"]; } else if(hasChallengeBeenCompleted($challenge, $solution, $moves, $paths)) { - $firephp->log('Challenge was completed!'); + //$firephp->log('Challenge was completed!'); setChallengeCompleted($challenge, $solution, $userID, $moves); $challengesCompleted[] = $challenge["challengeID"]; } @@ -368,7 +368,7 @@ function onCompletedTutorial($userID) { * Checks if the given solution meets the requirements for the given challenge */ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { - $firephp = FirePHP::getInstance(true); + //$firephp = FirePHP::getInstance(true); //Check the maze-length if($challenge['goal'] != 0) { //Er, "greater than" should really be called "greater than or equal to" :\ @@ -376,7 +376,7 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { || ($challenge['inequality'] == "less than" && $moves >= $challenge['goal']) || ($challenge['inequality'] == "equal" && $moves != $challenge['goal'])) { - $firephp->log("Failed at distance"); + //$firephp->log("Failed at distance"); return false; } } @@ -388,7 +388,7 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { $temp = count_chars($solution, 1); //$temp needed due to extreme PHP-stupidity $numWalls = $temp[ord(",")]; if($numWalls > $challenge['restrictWallCount']) { - $firephp->log("Failed at wall-count"); + //$firephp->log("Failed at wall-count"); return false; } } @@ -402,8 +402,8 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { $stringToSearchFor = "." . swapXandYCoordinates($invalidWall) . "."; if(strpos($solution,$stringToSearchFor) !== false) { - $firephp->log("Failed at wall-placement: " . $invalidWall); - $firephp->log("Solution: " . $solution); + //$firephp->log("Failed at wall-placement: " . $invalidWall); + //$firephp->log("Solution: " . $solution); return false; } } @@ -419,7 +419,7 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { if(count($usedTeleports) !== $challenge['restrictTeleportCount'] && ($challenge['restrictTeleportCount'] != 0 || $usedTeleports[0] != "")) { - $firephp->log("Failed at teleport count"); + //$firephp->log("Failed at teleport count"); return false; } } @@ -434,7 +434,7 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { //Check each path to see if it walks over that teleport if(strpos($path['path'], $usedTeleport) !== false) { - $firephp->log("Failed at teleports used"); + //$firephp->log("Failed at teleports used"); return false; } } @@ -454,7 +454,7 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { if(!$usesCorrectStartPoint) { - $firephp->log("Failed at start-point"); + //$firephp->log("Failed at start-point"); return false; } } @@ -471,13 +471,13 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { if(!$usesCorrectEndPoint) { - $firephp->log("Failed at endpoint"); + //$firephp->log("Failed at endpoint"); return false; } } //All of the restrictions were met, meaning the challenge was completed! - $firephp->log("Succeeded!"); + //$firephp->log("Succeeded!"); return true; } @@ -504,6 +504,21 @@ function setChallengeCompleted($challenge, $solution, $userID, $moves) { mysql_query($sql); } + +function isChallengeMap($mapID) { + include_once('./includes/db.inc.php'); + $sql = "SELECT ID + FROM `maps` + WHERE + ID = '$mapID' AND `isChallenge` = true; + "; + $result = mysql_query($sql) or die(mysql_error()); + if (mysql_num_rows($result) == 0) + return false; + else + return true; +} + function applyAchievements($userID, $aType) { $amount = getAchievementCurrency($userID, $aType); @@ -768,11 +783,163 @@ function trackMOTDstats($mapType) { +//Select Members +function getMembers($order, $pageNumber = 1, $pageDivide = 50) { + + $top = $pageNumber * $pageDivide; + $bottom = $top - $pageDivide; + + $limitTop = ($pageNumber - 1) * $pageDivide; + + $sql = "SELECT COUNT(*) as 'count' FROM `users`"; + $result = mysql_query($sql) or die(mysql_error()); + $row = mysql_fetch_assoc($result); + $total = $row['count']; + + $output['pageCount'] = $total / $pageDivide; + + $pageRequest = 'all'; + if ($pageRequest == 'all') { + $pageReqStart = 1; + $pageReqEnd = 1000; + } elseif (is_int($pageRequest)) { + $pageReqStart = $pageRequest; + $pageReqEnd = $pageRequest; + } else { + $tmp = explode($pageRequest, "-"); + $pageReqStart = $tmp[0]; + $pageReqEnd = $tmp[1]; + } + + $sql = " + SELECT + users.ID as ID, + users.displayName as display, + IfNull( + (SELECT SUM(moves) FROM solutions + WHERE solutions.userID = users.ID AND + solutions.dateModified < CURRENT_DATE) + , 0) AS totalMoves, + IfNull( + (SELECT SUM(moves) FROM solutions + WHERE solutions.userID = users.ID AND + solutions.dateModified BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY) AND CURRENT_DATE) + , 0) AS totalMovesThisWeek, + IfNull( + (SELECT COUNT(*) FROM solutions + WHERE solutions.userID = users.ID AND + solutions.dateModified < CURRENT_DATE) + , 0) AS totalMazes, + SUM(CASE WHEN statistics.type IN (32, 33, 34, 35) THEN statistics.value ELSE 0 END) as totalWins, + SUM(CASE WHEN statistics.type IN (1, 2, 3, 4) THEN statistics.value ELSE 0 END) as totalTies, + IfNull(userData.wallColor, '#666666') as wallColor, + IfNull(userData.displayColor, '#cccccc'), + userData.wallEmblem as wallEmblem, + users.datejoined as dateJoined, + users.dateLogin as dateLogin + FROM `users` + LEFT JOIN `userData` ON users.ID = userData.userID + LEFT JOIN `statistics` ON users.ID = statistics.userID + GROUP BY users.ID + $order + LIMIT $limitTop, $pageDivide + "; + + $result = mysql_query($sql); + //$utime = date("g:i A (T)"); + + $output['updateTime'] = date("g:i A (T)"); + + $i = $limitTop; + $foundUser = false; + while ($row = mysql_fetch_assoc($result)) { + $i++; + + $moves = $row['moves']; + + $userID = $row['ID']; + if ($_SESSION['userID'] == $userID) { + $userPosition = $i; + } + // } else { + // if ($i > $top) + // continue; + // if ($i <= $bottom) + // continue; + // } + + if ($wallEmblem == '') + $wallEmblem = 'blank.png'; + + $cdate = $row['cdate']; + $cdate = date("g:i A (T)", strtotime($cdate)); + + $row['dateJoined'] = Date("Y-m-d", strtotime($row['dateJoined'])); + $row['dateLogin'] = Date("Y-m-d", strtotime($row['dateLogin'])); + + $scoredDate = strtotime($row['cdate']); + $secondsSinceScored = strtotime("now") - $scoredDate ; + + //Alternate background colors + $background = '#262631'; + if ($i % 2 == 1) + $background = '#20202a'; + + if ($userPosition == $i) { + $background = '#343c57'; + $foundUser = true; + } + + // if is blind map. + // $row['moves'] = '???'; + + $output['users'][$i] = $row; + $output['users'][$i]['scoredDate'] = $cdate; + $output['users'][$i]['secondsSinceScored'] = $secondsSinceScored; + $output['users'][$i]['background'] = $background; + $output['users'][$i]['medal'] = $medal; + $output['users'][$i]['isUser'] = $userPosition == $i; + //$output['users'][$i]['debug'] = "Bestmoves: $bestMoves moves: $moves"; + } // END WHILE + + //Need to look this up. + //$output['pageCount'] = ceil(($i / $pageDivide)); + //$output['pageCount'] = 5; + if ($prevPage > 0) { + $navi .= " <a href='javascript:scoresShowPage($mapid, 1);'><<</a> "; + $navi .= " <a href='javascript:scoresShowPage($mapid, $prevPage);'><</a> "; + } else { + $navi .= " << "; + $navi .= " <"; + } + for ($x = 1; $x <= $pageCount; $x++) { + if ($x < $pageNumber - 3 OR $x > $pageNumber + 3) + continue; + if ($x == $pageNumber) + $navi .= "<strong> $x </strong>"; + elseif ($userPage == $x) + $navi .= " <a href='javascript:scoresShowPage($mapid, $x)'><i>$x</i></a> "; + else + $navi .= " <a href='javascript:scoresShowPage($mapid, $x)'>$x</a> "; + } + if ($nextPage <= $pageCount) { + $navi .= " <a href='javascript:scoresShowPage($mapid, $nextPage);'>></a> "; + $navi .= " <a href='javascript:scoresShowPage($mapid, $pageCount);'>>></a> "; + } + + return $output; +} + + + //Select Stats/Scores. -function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { +function getScores($mapID, $pageNumber = 1, $pageDivide = 10) { $top = $pageNumber * $pageDivide; $bottom = $top - $pageDivide; + //TODO: !! set to false before uploading. + $isBlindMap = false; + $pageRequest = 'all'; if ($pageRequest == 'all') { @@ -787,6 +954,17 @@ function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { $pageReqEnd = $tmp[1]; } + $userID = $_SESSION['userID']; + $myBestMoves = 0; + if ($isBlindMap) { + $sql = "SELECT `moves` FROM `solutions` WHERE `mapID` = '$mapID' AND `userID` = '$userID'"; + $result = mysql_query($sql) or die(mysql_error()); + $row = mysql_fetch_assoc($result); + $myBestMoves = $row['moves']; + // echo "XX $myBestMoves XX "; + // echo "XX $userID XX "; + } + $sql = " SELECT timediff(solutions.dateModified, TIMESTAMP(CURDATE())) as diff, @@ -803,9 +981,10 @@ function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { ON users.ID = solutions.userID LEFT JOIN `userData` ON users.ID = userData.userID - WHERE solutions.mapID = '$mapid' + WHERE solutions.mapID = '$mapID' ORDER BY solutions.moves DESC, solutions.dateModified ASC, solutions.ID DESC "; + // ORDER BY solutions.moves ASC, solutions.dateModified DESC, solutions.ID ASC $result = mysql_query($sql); //$utime = date("g:i A (T)"); @@ -813,19 +992,22 @@ function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { $i = 0; $foundUser = false; + while ($row = mysql_fetch_assoc($result)) { $i++; $moves = $row['moves']; - $userID = $row['ID']; + + $requestedUserID = $row['ID']; if ($i == 1) { $bestMoves = $moves; $output['bestMoves'] = $bestMoves; $output['bestBy'] = $row['display']; } - if ($_SESSION['userID'] == $userID) { + if ($_SESSION['userID'] == $requestedUserID) { $userPosition = $i; + //$myBestMoves = $moves; } else { if ($i > $top) continue; @@ -857,6 +1039,10 @@ function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { $medal = 'silver'; if ($i == 1) $medal = 'gold'; + + // if is blind map. + if ($isBlindMap AND $myBestMoves < $moves) + $row['moves'] = '???'; $output['users'][$i] = $row; $output['users'][$i]['scoredDate'] = $cdate; @@ -864,7 +1050,7 @@ function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { $output['users'][$i]['background'] = $background; $output['users'][$i]['medal'] = $medal; $output['users'][$i]['isUser'] = $userPosition == $i; - $output['users'][$i]['debug'] = "Bestmoves: $bestMoves moves: $moves"; + //$output['users'][$i]['debug'] = "Bestmoves: $bestMoves moves: $moves"; } // END WHILE if ($foundUser) { @@ -876,8 +1062,8 @@ function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { $output['pageCount'] = ceil(($i / $pageDivide)); if ($prevPage > 0) { - $navi .= " <a href='javascript:scoresShowPage($mapid, 1);'><<</a> "; - $navi .= " <a href='javascript:scoresShowPage($mapid, $prevPage);'><</a> "; + $navi .= " <a href='javascript:scoresShowPage($mapID, 1);'><<</a> "; + $navi .= " <a href='javascript:scoresShowPage($mapID, $prevPage);'><</a> "; } else { $navi .= " << "; $navi .= " <"; @@ -888,13 +1074,13 @@ function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { if ($x == $pageNumber) $navi .= "<strong> $x </strong>"; elseif ($userPage == $x) - $navi .= " <a href='javascript:scoresShowPage($mapid, $x)'><i>$x</i></a> "; + $navi .= " <a href='javascript:scoresShowPage($mapID, $x)'><i>$x</i></a> "; else - $navi .= " <a href='javascript:scoresShowPage($mapid, $x)'>$x</a> "; + $navi .= " <a href='javascript:scoresShowPage($mapID, $x)'>$x</a> "; } if ($nextPage <= $pageCount) { - $navi .= " <a href='javascript:scoresShowPage($mapid, $nextPage);'>></a> "; - $navi .= " <a href='javascript:scoresShowPage($mapid, $pageCount);'>>></a> "; + $navi .= " <a href='javascript:scoresShowPage($mapID, $nextPage);'>></a> "; + $navi .= " <a href='javascript:scoresShowPage($mapID, $pageCount);'>>></a> "; } return $output; @@ -949,7 +1135,7 @@ function loadChallengeListing($userIdUnsanitized) { $userID = mysql_escape_string($userIdUnsanitized); $sql = " - SELECT maps.ID AS mapID, maps.challengeTier, maps.challengeName, challengeSolutions.dateSolved + SELECT maps.ID AS mapID, maps.challengeTier, maps.name, challengeSolutions.dateSolved FROM maps INNER JOIN challenges ON maps.ID = challenges.mapID LEFT JOIN challengeSolutions ON challenges.ID = challengeSolutions.challengeID diff --git a/includes/mapoftheday.php b/includes/mapoftheday.php index 5ae7ebd..d244635 100644 --- a/includes/mapoftheday.php +++ b/includes/mapoftheday.php @@ -1 +1 @@ -<?php
include_once('maps.php');
include_once('db.inc.php');
/**
* Returns the Map Of The Day with the given type (index)
*/
function mapOfTheDay($type = 1) {
ignore_user_abort(true);
if ($type <= 8)
$expire = 2;
if ($type <= 4)
$expire = 1;
$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);
//No map for today?
if (mysql_num_rows($result) != 0) {
$r['code'] = mysql_result($result, 0, 'code');
$r['map'] = GenerateMapByCode($r['code']);
$r['id'] = mysql_result($result, 0, 'ID');
return $r;
}
return generateNewMapOfTheDay($type, $sql);
}
/**
* Generates a new map of the day. DO NOT CALL OUTSIDE OF mapoftheday.php
*/
function generateNewMapOfTheDay($type, $sql)
{
// 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:
// TEST MAP...
$ultraComplex[] = "soooooooooooooooooooooooooooor";
$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[] = "roooooooooooooooooooooooooooof";
$ultraComplex = insertPoint($ultraComplex, 'abcde');
$ultraComplex = insertPoint($ultraComplex, 'tumngh');
$ultraComplex = insertPoint($ultraComplex, 'ppppppppppp');
$myparams['checkpoints'] = 5;
$myparams['teleports'] = 3;
$myparams['rockchance'] = 9;
$myparams['walls'] = 38;
$myparams['name'] = 'Ultra Complex';
$map = GenerateShapedMap($ultraComplex, $myparams);
break;
default:
$map = GenerateMap(rand(13, 18), rand(10, 14), rand(6, 9));
break;
}
$lock = acquireMotdLock();
try
{
//Double check... $sql is already set
$result = mysql_query($sql);
//Are you SURE there's no map?
if (mysql_num_rows($result) != 0)
{
releaseMotdLock($lock);
return mapOfTheDay($type);
}
$code = GenerateMapCode($map);
$sql = "INSERT INTO `maps` (`code`)
VALUES ('$code')";
$result = mysql_query($sql);
if (!$result)
{
releaseMotdLock($lock);
die("Error on inserting map");
}
$mapID = mysql_insert_id();
$r['code'] = $code;
$r['map'] = $map;
$r['id'] = $mapID;
$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");
}
} catch (Exception $exc) { /* Ignore... :| */ }
releaseMotdLock($lock);
// ---------- Track statistics for 'yesterdays' map.
trackMOTDstats($type);
return $r;
}
/**
* 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;
}
?>
\ No newline at end of file +<?php
include_once('maps.php');
include_once('db.inc.php');
/**
* Returns the Map Of The Day with the given type (index)
*/
function mapOfTheDay($type = 1) {
ignore_user_abort(true);
if ($type <= 8)
$expire = 2;
if ($type <= 4)
$expire = 1;
$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);
//No map for today?
if (mysql_num_rows($result) != 0) {
$r['code'] = mysql_result($result, 0, 'code');
$r['map'] = GenerateMapByCode($r['code']);
$r['id'] = mysql_result($result, 0, 'ID');
return $r;
}
return generateNewMapOfTheDay($type, $sql);
}
/**
* Generates a new map of the day. DO NOT CALL OUTSIDE OF mapoftheday.php
*/
function generateNewMapOfTheDay($type, $sql)
{
// 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;
}
$lock = acquireMotdLock();
try
{
//Double check... $sql is already set
$result = mysql_query($sql);
//Are you SURE there's no map?
if (mysql_num_rows($result) != 0)
{
releaseMotdLock($lock);
return mapOfTheDay($type);
}
$code = GenerateMapCode($map);
$sql = "INSERT INTO `maps` (`code`)
VALUES ('$code')";
$result = mysql_query($sql);
if (!$result)
{
releaseMotdLock($lock);
die("Error on inserting map");
}
$mapID = mysql_insert_id();
$r['code'] = $code;
$r['map'] = $map;
$r['id'] = $mapID;
$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");
}
} catch (Exception $exc) { /* Ignore... :| */ }
releaseMotdLock($lock);
// ---------- Track statistics for 'yesterdays' map.
trackMOTDstats($type);
return $r;
}
/**
* 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 diff --git a/includes/maps.php b/includes/maps.php index 431f006..1df258d 100644 --- a/includes/maps.php +++ b/includes/maps.php @@ -726,6 +726,19 @@ function getSolution($userID, $mapID) { }
}
+function getChallengeSolution($userID, $challengeID) {
+ include_once('db.inc.php');
+ $sql = "SELECT `solution`, `moves`
+ FROM `challengeSolutions`
+ WHERE `userID` = '$userID' AND
+ `challengeID` = '$challengeID'
+ ";
+ $result = mysql_query($sql);
+ if (mysql_num_rows($result) > 0) {
+ return mysql_fetch_assoc($result);
+ }
+}
+
function getMapCode($mapID) {
include_once('db.inc.php');
$sql = "SELECT `code`
|