diff options
-rw-r--r-- | do.php | 38 | ||||
-rw-r--r-- | includes/datas.php | 57 | ||||
-rw-r--r-- | pages/challenge.php | 9 |
3 files changed, 85 insertions, 19 deletions
@@ -5,6 +5,12 @@ include "includes/maps.php"; include "includes/db.inc.php";
include "includes/datas.php";
+//FirePHP stuff - TODO: Delete
+require_once('includes/FirePHPCore/FirePHP.class.php');
+ob_start();
+$firephp = FirePHP::getInstance(true);
+//FirePHP stuff - TODO: Delete
+
$note = false;
//Auto login;
@@ -117,6 +123,7 @@ if ($_GET['r'] == 'getpath') { //valid mapID?
$mapID = $_GET[mapid] + 0;
if (!is_int($mapID)) return;
+ $firephp->log($mapID, "mapID");
//the first 10 ID's reserved for challenges & tutorial.
if ($mapID > 10)
@@ -193,6 +200,18 @@ if ($_GET['r'] == 'getpath') { $json['bestby'] = 'no one';
}
+ // --------- CONTINUE EXECUTION
+
+ $firephp->log('Got this far');
+ $firephp->log($_SESSION['accepted'], '$_SESSION["accepted"]');
+
+ //Challenge/Tutorial?
+ if ($_GET['isChallenge'] == 'true') {
+ $firephp->log('Calling challenges');
+ $json['completedChallenges'] = getCompletedChallenges($userID, $mapID, $solution, $moves, $json['path']);
+ $firephp->log('Challenges called!');
+ }
+
// --------- RUSH THE PATH BACK TO THE USER
ignore_user_abort(true);
$encoded = json_encode($json);
@@ -200,10 +219,13 @@ if ($_GET['r'] == 'getpath') { header("Content-Length: " . mb_strlen($encoded));
echo $encoded;
flush();
-
- // --------- CONTINUE EXECUTION
-
-
+
+ //TODO: Clean this up a bit
+ if ($_GET['isChallenge'] == 'true')
+ {
+ return;
+ }
+
// --------- USER NOT LOGGED IN?
if ($_SESSION['accepted'] !== 1) {
if ($moves >= ($_SESSION[$mapID.'moves'] + 0)) {
@@ -212,13 +234,9 @@ if ($_GET['r'] == 'getpath') { }
return;
}
+
// --------- USER LOGGED IN
-
- //Challenge/Tutorial?
- if ($_GET['isChallenge'] == 'true') {
- checkForCompletedChallenges($userID, $mapID, $solution, $moves, $json['path']);
- return;
- }
+ $firephp->log('Got even farther');
//Is the map still valid to score on?
if (!isCurrentMap($mapID))
diff --git a/includes/datas.php b/includes/datas.php index 676e68b..d1e2618 100644 --- a/includes/datas.php +++ b/includes/datas.php @@ -4,6 +4,10 @@ include_once('db.inc.php'); +//FirePHP stuff - TODO: Delete +require_once('includes/FirePHPCore/FirePHP.class.php'); +//FirePHP stuff - TODO: Delete + //Select Stats/Scores. function topScores($mapid, $top = 5, $bottom = 0) { $sql = " @@ -298,8 +302,10 @@ function applyCareerMazesAchievements($userID) { * @param type $moves The total number of moves in the solution, for all paths * @param type $paths An array of path-objects, each as returned by routePath(). */ -function checkForCompletedChallenges($userID, $mapID, $solution, $moves, $paths) { +function getCompletedChallenges($userID, $mapID, $solution, $moves, $paths) { //mapID 5 is the tutorial, and is treated specially + $firephp = FirePHP::getInstance(true); + $firephp->log("In challenges"); if($mapID == 5) { if ($moves == 75) { onCompletedTutorial($userID); @@ -307,15 +313,31 @@ function checkForCompletedChallenges($userID, $mapID, $solution, $moves, $paths) return; } + $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"); //Skip checking challenges which have already been completed - if($challenge["dateCompleted"] !== NULL) - continue; + if($challenge["dateSolved"] !== NULL) + { + $firephp->log('Challenge was already completed'); + $challengesCompleted[] = $challenge["challengeID"]; + } else if(hasChallengeBeenCompleted($challenge, $solution, $moves, $paths)) + { + $firephp->log('Challenge was completed!'); setChallengeCompleted($challenge, $solution, $userID, $moves); + $challengesCompleted[] = $challenge["challengeID"]; + } } + + return $challengesCompleted; } /** @@ -346,6 +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); //Check the maze-length if($challenge['goal'] != 0) { //Er, "greater than" should really be called "greater than or equal to" :\ @@ -353,6 +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"); return false; } } @@ -364,6 +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"); return false; } } @@ -374,8 +399,11 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { $invalidWalls = explode(".", $challenge['restrictWallPlacement']); foreach($invalidWalls as $invalidWall) { - if(strpos($solution,$invalidWall) !== false) + $stringToSearchFor = "." . swapXandYCoordinates($invalidWall) . "."; + if(strpos($solution,$stringToSearchFor) !== false) { + $firephp->log("Failed at wall-placement: " . $invalidWall); + $firephp->log("Solution: " . $solution); return false; } } @@ -385,12 +413,13 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { if($challenge['restrictTeleportCount'] !== NULL || $challenge['restrictTeleportsUsed'] !== NULL) { //Check teleport count - $usedTeleports = explode(".", getUsedTeleports($paths)); + $usedTeleports = explode(".", getUsedTeleports($paths)); //TODO: Implement if($challenge['restrictTeleportCount'] !== NULL) { if(count($usedTeleports) !== $challenge['restrictTeleportCount'] && ($challenge['restrictTeleportCount'] != 0 || $usedTeleports[0] != "")) { + $firephp->log("Failed at teleport count"); return false; } } @@ -405,6 +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"); return false; } } @@ -423,7 +453,10 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { } if(!$usesCorrectStartPoint) + { + $firephp->log("Failed at start-point"); return false; + } } //Check end points @@ -437,14 +470,27 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { } if(!$usesCorrectEndPoint) + { + $firephp->log("Failed at endpoint"); return false; + } } //All of the restrictions were met, meaning the challenge was completed! + $firephp->log("Succeeded!"); return true; } /** + * Hack, due to positions being stored as x,y in some places and y,x in others + */ +function swapXandYCoordinates($position) +{ + $coords = explode(",", $position); + return $coords[1] . "," . $coords[0]; +} + +/** * Sets the given challenge as completed by the user in the database */ function setChallengeCompleted($challenge, $solution, $userID, $moves) { @@ -884,6 +930,7 @@ function loadChallengesForMap($mapIdUnsanitized, $userIdUnsanitized) FROM challenges LEFT JOIN challengeSolutions ON challenges.ID = challengeSolutions.challengeID AND challengeSolutions.userID = '$userID' WHERE challenges.mapID = '$mapID' AND challenges.enabled = 1 + ORDER BY challenges.ordering "; $result = mysql_query($sql); diff --git a/pages/challenge.php b/pages/challenge.php index 6990644..24218c7 100644 --- a/pages/challenge.php +++ b/pages/challenge.php @@ -89,7 +89,7 @@ if($mapCode === NULL) return;
}
-$mapContent = displayMap(GenerateMapByCode($mapCode), 1);
+$mapContent = displayMap(GenerateMapByCode($mapCode), $_GET["mapID"]);
$challengeResultset = loadChallengesForMap($_GET["mapID"], $userID);
if($challengeResultset === NULL)
{
@@ -126,16 +126,17 @@ htmlFooter(); function displayChallenges($challengeResultset)
{
echo '<div id="challenges">';
- echo '<div id="challenges_title">Challenges</div>';
+ echo '<div id="challenges_title">Challenges9</div>'; //TODO: remove number
echo '<div id="challenges_listing"><ol>';
while($challenge = mysql_fetch_array($challengeResultset))
{
+ $challengeId = $challenge["challengeID"];
echo "<li>";
- if($challenge["dateCompleted"] !== NULL)
+ if($challenge["dateSolved"] !== NULL)
$cssClass = "challenge_complete";
else
$cssClass = "challenge_incomplete";
- echo "<span class='$cssClass'>" . getChallengeDisplayString($challenge) . "</span>";
+ echo "<span class='$cssClass' id='challenge_id_$challengeId'>" . getChallengeDisplayString($challenge) . "</span>";
echo "</li>";
}
echo "</ol></div></div>";
|