From 23b7ddabd4c2c6286a9b3ef0791befbc6f4ef89f Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Mon, 26 Nov 2012 23:18:05 -0800 Subject: Fixes and changes. Commented out firePHP; Added some debug code. --- do.php | 111 ++++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 62 insertions(+), 49 deletions(-) (limited to 'do.php') diff --git a/do.php b/do.php index f55bd61..b58b1d2 100644 --- a/do.php +++ b/do.php @@ -6,9 +6,9 @@ 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); +// require_once('includes/FirePHPCore/FirePHP.class.php'); +// ob_start(); +// $firephp = FirePHP::getInstance(true); //FirePHP stuff - TODO: Delete $note = false; @@ -21,6 +21,9 @@ if (!isset($_SESSION['accepted']) || $_SESSION['accepted'] <> 1) // encode array $json to JSON string +$debug = false; + +//$debug = true; if (isset($_GET['act']) && $_GET['act'] == "getmap") { @@ -69,7 +72,6 @@ if ($_GET['r'] == 'reqScorePage') { die($encoded); } - if ($_GET['r'] == 'getscores') { $mapID = $_GET['mapid'] + 0; if (!is_int($mapID)) @@ -106,7 +108,6 @@ if ($_GET['r'] == 'getsol') { die($encoded); } - // ------------ MAIN; getpath. if ($_GET['r'] == 'getpath') { @@ -123,7 +124,7 @@ if ($_GET['r'] == 'getpath') { //valid mapID? $mapID = $_GET[mapid] + 0; if (!is_int($mapID)) return; - $firephp->log($mapID, "mapID"); + //$firephp->log($mapID, "mapID"); //the first 10 ID's reserved for challenges & tutorial. if ($mapID > 10) @@ -200,32 +201,45 @@ if ($_GET['r'] == 'getpath') { $json['bestby'] = 'no one'; } + // --------- RUSH THE PATH BACK TO THE USER + if (!$debug) { + ignore_user_abort(true); + $encoded = json_encode($json); + header("Connection: close"); + header("Content-Length: " . mb_strlen($encoded)); + echo $encoded; + flush(); + } + + $json['error'][] = "bestMoves, byName, myMoves: $bestMoves, $byName, $myMoves;"; + // --------- CONTINUE EXECUTION - $firephp->log('Got this far'); - $firephp->log($_SESSION['accepted'], '$_SESSION["accepted"]'); + // $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!'); - } + ////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); - header("Connection: close"); - header("Content-Length: " . mb_strlen($encoded)); - echo $encoded; - flush(); + ////--------- RUSH THE PATH BACK TO THE USER + // ignore_user_abort(true); + // $encoded = json_encode($json); + // header("Connection: close"); + // header("Content-Length: " . mb_strlen($encoded)); + // echo $encoded; + // flush(); - //TODO: Clean this up a bit - if ($_GET['isChallenge'] == 'true') - { - return; - } + ////TODO: Clean this up a bit + // if ($_GET['isChallenge'] == 'true') + // { + // return; + //} //x + // --------- USER NOT LOGGED IN? if ($_SESSION['accepted'] !== 1) { if ($moves >= ($_SESSION[$mapID.'moves'] + 0)) { @@ -234,21 +248,29 @@ if ($_GET['r'] == 'getpath') { } return; } - + $json['error'][] = 'user is logged in'; // --------- USER LOGGED IN - $firephp->log('Got even farther'); + + //Challenge/Tutorial? + if ($mapID <= 10 AND $_GET['isChallenge'] = 'true') { + $json['error'][] = 'executed as a challenge'; + //echo "running function".$_GET['challengeID']; + applyChallengeAchievements($userID, $_GET['challengeID'], $mapID, $solution, $moves); + return; + } //Is the map still valid to score on? if (!isCurrentMap($mapID)) return; // --------- UPDATE SCORES + $json['error'][] = 'map is current'; $checkcp = false; $checkcm = false; //Is there an existing record? - if (isset($myMoves)) { + if ($myMoves > 0) { if ($myMoves < $moves) { $sql = "UPDATE `solutions` SET `moves` = '$moves' , @@ -258,6 +280,7 @@ if ($_GET['r'] == 'getpath') { `mapID` = '$mapID'"; mysql_query($sql); $checkcp = true; + $json['error'][] = 'Score was improved'; //Update the solution only, if it's the same score. } elseif ($myMoves == $moves) { $sql = "UPDATE `solutions` @@ -266,6 +289,7 @@ if ($_GET['r'] == 'getpath') { WHERE `userID` = '$userID' AND `mapID` = '$mapID'"; mysql_query($sql); + $json['error'][] = 'Score unchanged, but solution updated'; } //Create a new record. } else { @@ -274,7 +298,10 @@ if ($_GET['r'] == 'getpath') { mysql_query($sql); $checkcm = true; $checkcp = true; + $json['error'][] = 'A new record was created'; } + + $json['error'][] = "Involved data: ('$userID', '$mapID', '$solution', '$moves')"; // --------- APPLY ACHIEVEMENTS @@ -285,14 +312,15 @@ if ($_GET['r'] == 'getpath') { applyAchievements($userID, 3); applyAchievements($userID, 4); } - - // no need w/ rush-sending. - //$encoded = json_encode($json); - //echo $encoded; - + // --------- END } +$json['error'][] = 'Rush-send failed'; + +$encoded = json_encode($json); +die($encoded); + function isCurrentMap($mapID) { // TODO: Broke @@ -321,9 +349,6 @@ function isCurrentMap($mapID) { return true; } - - - //Very simple, confirm that all targets are reachable. function ValidateMap($mygrid) { $start = "0,1."; @@ -340,16 +365,4 @@ function ValidateMap($mygrid) { } - -$json['error'][] = 'Division by 912 trillion!'; -$json['error'][] = 'Cant count that high.'; - -$json['error'][] = "I forgot what I was doing!"; -$json['error'][] = "Lost track of time, and gaveup!"; - -$encoded = json_encode($json); -die($encoded); - - - ?> -- cgit v1.2.3