summaryrefslogtreecommitdiffstats
path: root/do.php
diff options
context:
space:
mode:
Diffstat (limited to 'do.php')
-rw-r--r--do.php83
1 files changed, 41 insertions, 42 deletions
diff --git a/do.php b/do.php
index a2f25d7..2bf6bb9 100644
--- a/do.php
+++ b/do.php
@@ -7,19 +7,19 @@ include "includes/datas.php";
//Auto login;
include_once("globe.php");
-if ($_SESSION['accepted'] <> 1)
- if ($_COOKIE['doLogin'] == 'yes')
+if (!isset($_SESSION['accepted']) || $_SESSION['accepted'] <> 1)
+ if (isset($_COOKIE['doLogin']) && $_COOKIE['doLogin'] == 'yes')
CookieLogin();
// encode array $json to JSON string
-
-if ($_GET['act'] == "getmap") {
+
+if (isset($_GET['act']) && $_GET['act'] == "getmap") {
$map = GenerateMapByCode($_GET['mapcode']);
-
+
$solution = formSolution($_GET['solution']);
-
+
$solvedmap = MergeMapSolution($map, $solution);
if ($solvedmap == -1) {
$json['error'][] = "INVALID WALL POSITIONS";
@@ -29,21 +29,21 @@ if ($_GET['act'] == "getmap") {
}
}
-if ($_GET['checkachieve'] == 'true' AND $_SESSION['accepted'] == 1) {
+if (isset($_GET['checkachieve']) && $_GET['checkachieve'] == 'true' && $_SESSION['accepted'] == 1) {
$json['notification'] = true;
-
+
$userID = $_SESSION['userID'];
-
+
//Located in includes/datas.php
$note = getNotified($userID);
-
+
if ($note !== false)
$json['notificationtext'] = $note;
}
if ($_GET['r'] == 'getscores') {
$mapID = $_GET['mapid'] + 0;
- if (!is_int($mapID))
+ if (!is_int($mapID))
return;
$topscores = topScores($mapID, 30);
$json['scores'] = $topscores;
@@ -58,7 +58,7 @@ if ($_GET['r'] == 'getsol') {
if (!is_int($mapID)) return;
$userID = $_SESSION['userID'];
-
+
if ($_SESSION['accepted'] == 1)
$json = getSolution($userID, $mapID);
if (isset($_SESSION[$mapID.'sol']) AND $mysolution == '') {
@@ -66,7 +66,7 @@ if ($_GET['r'] == 'getsol') {
$json['moves'] = $_SESSION[$mapID.'moves'];
}
$json['mapid'] = $mapID;
-
+
$encoded = json_encode($json);
die($encoded);
}
@@ -76,36 +76,36 @@ if ($_GET['r'] == 'getsol') {
if ($_GET['r'] == 'getpath') {
//Join the partial-solution from the map, and the solution sent.
- //Could be used to validate maps in for challenges where
+ //Could be used to validate maps in for challenges where
// getting the map code from the database is not an option
//$tmp = GenerateMapByCode($_GET['mapcode']);
//$tmp = seperateMapSolution($tmp);
//$solution = formSolution($_GET['solution'].$tmp);
-
+
// Enables the ability to discover an exact duplicate solution.
$solution = formSolution($_GET['solution']);
- //valid mapID?
+ //valid mapID?
$mapID = $_GET[mapid] + 0;
if (!is_int($mapID)) return;
-
+
//the first 10 ID's reserved for challenges & tutorial.
if ($mapID > 10)
$mapcode = getMapCode($mapID);
- else
+ else
$mapcode = $_GET['mapcode'];
-
+
//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";
@@ -133,10 +133,10 @@ if ($_GET['r'] == 'getpath') {
FROM `solutions`
WHERE `userID` = '$userID' AND
`mapID` = '$mapID'
- ) as q1
+ ) as q1
ON 1
WHERE
- `mapID` = '$mapID' AND
+ `mapID` = '$mapID' AND
`userID` = users.ID
ORDER BY `moves` DESC, `dateModified` ASC
LIMIT 1";
@@ -150,18 +150,18 @@ if ($_GET['r'] == 'getpath') {
$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));
+ 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)) {
@@ -171,27 +171,27 @@ if ($_GET['r'] == 'getpath') {
return;
}
// --------- USER LOGGED IN
-
+
//Challenge/Tutorial?
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`
+ $sql = "UPDATE `solutions`
SET `moves` = '$moves' ,
`dateModified` = NOW() ,
`solution` = '$solution'
@@ -201,13 +201,12 @@ if ($_GET['r'] == 'getpath') {
$checkcp = true;
//Update the solution only, if it's the same score.
} elseif ($myMoves == $moves) {
- $sql = "UPDATE `solutions`
+ $sql = "UPDATE `solutions`
SET `moves` = '$moves' ,
`solution` = '$solution'
WHERE `userID` = '$userID' AND
`mapID` = '$mapID'";
mysql_query($sql);
-
}
//Create a new record.
} else {
@@ -217,7 +216,7 @@ if ($_GET['r'] == 'getpath') {
$checkcm = true;
$checkcp = true;
}
-
+
// --------- APPLY ACHIEVEMENTS
if ($checkcp)
@@ -231,7 +230,7 @@ if ($_GET['r'] == 'getpath') {
// no need w/ rush-sending.
//$encoded = json_encode($json);
//echo $encoded;
-
+
// --------- END
}
@@ -243,9 +242,9 @@ function isCurrentMap($mapID) {
`mapID` = '$mapID'
";
$result = mysql_query($sql) or die(mysql_error());
- if (mysql_num_rows($result) == 0)
+ if (mysql_num_rows($result) == 0)
return false;
- else
+ else
return true;
}
@@ -271,7 +270,7 @@ 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!";
@@ -280,4 +279,4 @@ die($encoded);
-?> \ No newline at end of file
+?>