0) { list($json['solution'], $json['mapid']) = mysql_fetch_row($result); $encoded = json_encode($json); die($encoded); } } if ($_GET['r'] == 'getpath') { //Stage 1; Get the path. //Generate the map based on the code. $mapcode = $_GET['mapcode']; //$tmp = GenerateMapByCode($_GET['mapcode']); //Seperate any existing solution from map (?depreciated?) //$tmp = seperateMapSolution($tmp); //!!!! //Join the partial-solution from the map, and the solution sent (?Again, depreciated?) //$solution = formSolution($_GET['solution'].$tmp); $solution = $_GET['solution']; //valid mapID? $mapID = $_GET[mapid] + 0; if (!is_int($mapID)) return; if ($mapID > 10) { $mapcode = getMapCode($mapID); } //mygrid will be the map, with the solution applied. $map = GenerateMapByCode($mapcode); $mygrid = MergeMapSolution($map, $solution); //Route the path $json = routePath($mygrid, $start); $moves = $json['moves']; $json['mapid'] = $mapID; //What could go wrong? if ($json['blocked']) { //$json['error'][] = "blocked"; $encoded = json_encode($json); die($encoded); } if ($mygrid == -1) { $json['error'][] = "INVALID WALL POSITIONS"; $encoded = json_encode($json); die($encoded); } if ($mygrid[0][4] < 0) { $used = $mygrid[0][4] - $map[0][4]; $json['error'][] = "Too many walls used. ".$used." of ".$map[0][4]." walls used."; $encoded = json_encode($json); die($encoded); } //Get current score data. - to see if a pertinent score was beat. $userID = $_SESSION['userID']; $sql = "SELECT `moves` as bestmoves, `displayName`, IFNULL(q1.mymoves, 0) FROM `solutions`, `users` LEFT JOIN ( SELECT `moves` as mymoves FROM `solutions` WHERE `userID` = '$userID' AND `mapID` = '$mapID' ) as q1 ON 1 WHERE `mapID` = '$mapID' AND `userID` = users.ID ORDER BY `moves` DESC, `dateModified` ASC LIMIT 1"; $result = mysql_query($sql); if (mysql_num_rows($result) > 0) { list($bestMoves, $byName, $myMoves) = mysql_fetch_row($result); $json['best'] = $bestMoves; $json['bestby'] = $byName; $json['mybest'] = $myMoves; } else { $json['best'] = 0; $json['bestby'] = 'no one'; } // --------- 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(); // --------- CONTINUE EXECUTION // --------- USER NOT LOGGED IN if ($_SESSION['accepted'] !== 1) { if ($moves >= ($_SESSION[$mapID.'moves'] + 0)) { $_SESSION[$mapID.'moves'] = $moves; $_SESSION[$mapID.'sol'] = $solution; } return; } // --------- USER LOGGED IN //Challenge/Tutorial? //echo "pre"; if ($mapID <= 10 AND $_GET['isChallenge'] = 'true') { //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 $checkcp = false; $checkcm = false; //Is there an existing record? if ($myMoves > 0) { if ($myMoves < $moves) { $sql = "UPDATE `solutions` SET `moves` = '$moves' , `dateModified` = NOW() , `solution` = '$solution' WHERE `userID` = '$userID' AND `mapID` = '$mapID'"; mysql_query($sql); $checkcp = true; //Update the solution only, if it's the same score. } elseif ($myMoves == $moves) { $sql = "UPDATE `solutions` SET `moves` = '$moves' , `solution` = '$solution' WHERE `userID` = '$userID' AND `mapID` = '$mapID'"; mysql_query($sql); } //Create a new record. } else { $sql = "INSERT INTO `solutions` (`userID`, `mapID`, `solution`, `moves`) VALUES ('$userID', '$mapID', '$solution', '$moves')"; mysql_query($sql); $checkcm = true; } // --------- APPLY ACHIEVEMENTS //while(applyCareerAchievement($userID)) { // usleep(200); //} //if ($checkcm) applyCareerMazesAchievements($userID); //if ($checkcp) applyCareerPathAchievements($userID); //!! no need w/ rush-sending. $encoded = json_encode($json); echo $encoded; // --------- END } function isCurrentMap($mapID) { include_once('./includes/db.inc.php'); $sql = "SELECT `ID` FROM `mapOfTheDay` WHERE `mapDate` = CURDATE() AND `mapID` = '$mapID' "; $result = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($result) == 0) return false; else return true; } //Very simple, confirm that all targets are reachable. function ValidateMap($mygrid) { $start = "0,1."; $target[] = 'a'; $target[] = 'b'; $target[] = 'c'; $target[] = 'f'; $blocked = false; foreach($target as $t) { $p = Findpath ($mygrid, $start, $t); if ($p['blocked']) return false; } return true; } $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); ?>