summaryrefslogtreecommitdiffstats
path: root/api/app.php
diff options
context:
space:
mode:
authorPatrick Davison <snapwilliam@gmail.com>2013-01-30 01:09:38 -0800
committerPatrick Davison <snapwilliam@gmail.com>2013-01-30 01:09:38 -0800
commitf18df1575490d83293fddb79d389ef170bbb5a2c (patch)
treee3a737d275871637cd61c05270a0cb5a1aa0c4c8 /api/app.php
parent286833cb153aa3555a789cd6b0a052b7c5fbdd09 (diff)
downloadpathery-f18df1575490d83293fddb79d389ef170bbb5a2c.tar.xz
More deletion of old code.
Diffstat (limited to 'api/app.php')
-rw-r--r--api/app.php567
1 files changed, 1 insertions, 566 deletions
diff --git a/api/app.php b/api/app.php
index 8ad5115..3b91681 100644
--- a/api/app.php
+++ b/api/app.php
@@ -1,4 +1,5 @@
<?PHP
+ob_start("ob_gzhandler");
include "../includes/maps.php";
include "../includes/db.inc.php";
@@ -77,570 +78,4 @@ function getMapsPlayed($daysAgo) {
}
-
-exit;
-
-
-
-echo json_encode($myNewMap);
-
-//By Wrikken
-function getJsonData($obj){
- $var = get_object_vars($obj);
- foreach($var as &$value) {
- if(is_object($value) && method_exists($value,'getJsonData')) {
- $value = $value->getJsonData();
- }
- }
- return $var;
-}
-
-
-exit;
-
-//Conditions for effectiveness.
-
-//Yes:
-echo ((20 & 4) == 4);
-echo "<br>";
-//Yes:
-echo ((4 & 20) == 4);
-echo "<br>";
-//No:
-echo ((4 & 20) == 20);
-echo "<br>";
-//No:
-echo ((16 & 4) == 4);
-echo "<br>";
-//Yes:
-echo ((37 & 4) == 4);
-echo "<br>";
-
-
-
-
-
-$format = '(%1$2d = %1$04b) = (%2$2d = %2$04b)'
- . ' %3$s (%4$2d = %4$04b)' . "\n";
-
-echo <<<EOH
- --------- --------- -- ---------
- result value op test
- --------- --------- -- ---------
-EOH;
-
-
-/*
- * Here are the examples.
- */
-
-$values = array(0, 1, 2, 4, 8);
-$test = 1 + 4;
-
-echo "\n Bitwise AND \n";
-foreach ($values as $value) {
- $result = $value & $test;
- printf($format, $result, $value, '&', $test);
-}
-
-echo "\n Bitwise Inclusive OR \n";
-foreach ($values as $value) {
- $result = $value | $test;
- printf($format, $result, $value, '|', $test);
-}
-
-echo "\n Bitwise Exclusive OR (XOR) \n";
-foreach ($values as $value) {
- $result = $value ^ $test;
- printf($format, $result, $value, '^', $test);
-}
-
-
-
-exit;
-
-
-
-
-
-//Select Stats/Scores.
-function getScoresB($mapID, $pageNumber = 1, $pageDivide = 10) {
- $top = $pageNumber * $pageDivide;
- $bottom = $top - $pageDivide;
-
- //TODO: !! set to false before uploading.
- $isBlindMap = true;
-
- $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];
- }
-
- $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,
- users.displayName as display,
- solutions.moves as moves,
- users.ID as ID,
- users.displayColor,
- users.wallColor,
- users.wallEmblem,
- solutions.dateModified as cdate
- FROM
- `users`
- JOIN `solutions`
- ON users.ID = solutions.userID
- 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)");
-
- $output['updateTime'] = date("g:i A (T)");
-
- $i = -1;
- $foundUser = false;
-
- while ($row = mysql_fetch_assoc($result)) {
- $i++;
-
- $moves = $row['moves'];
-
- $requestedUserID = $row['ID'];
- if ($i == 1) {
- $bestMoves = $moves;
- $output['bestMoves'] = $bestMoves;
- $output['bestBy'] = $row['display'];
- }
-
- if ($_SESSION['userID'] == $requestedUserID) {
- $userPosition = $i;
- //$myBestMoves = $moves;
- } 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));
-
- $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;
- }
-
- $medal = 'none';
- if ($moves == $bestMoves)
- $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]['rank'] = $i;
- $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
-
- if ($foundUser) {
- $userPage = ceil(($userPosition / $pageDivide));
- $output['userPage'] = $userPage;
- $output['userPosition'] = $userPosition;
- }
-
- $output['pageCount'] = ceil(($i / $pageDivide));
-
- if ($prevPage > 0) {
- $navi .= " <a href='javascript:scoresShowPage($mapID, 1);'>&lt;&lt;</a> ";
- $navi .= " <a href='javascript:scoresShowPage($mapID, $prevPage);'>&lt;</a> ";
- } else {
- $navi .= " &lt;&lt; ";
- $navi .= " &lt;";
- }
- 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);'>&gt;</a> ";
- $navi .= " <a href='javascript:scoresShowPage($mapID, $pageCount);'>&gt;&gt;</a> ";
- }
-
- $output['users'] = array_values($output['users']);
-
- return $output;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-$prep['name'] = 'Active';
-for($i = 1; $i <= 4; $i++) {
-
- $map = MapOfTheDay($i);
- $mapid = $map['id'];
-
- $data['name'] = $map['map'][0][6];
- $data['id'] = $map['id'];
- $data['tiles'] = convertMapTiles($map['map']);
- $prep['levels'][] = $data;
-}
-
-// $past['name'] = 'Past Maps';
-// for($i = 2; $i <= 4; $i++) {
-
- //$map = MapOfTheDay($i);
-
- // $pastMap = pastMap(1, $i);
- // $mapid = $pastMap;
- // $mapcode = getMapCode($mapID);
- // $map = GenerateMapByCode($mapcode);
-
- // $mapid = $map['id'];
-
- // $data['name'] = $map['map'][0][6];
- // $data['id'] = $map['id'];
- // $data['tiles'] = convertMapTiles($map['map']);
- // $past['levels'][] = $data;
-// }
-
-
-$json['action'] = 'getLevelSets';
-$json['response'] = 'ok';
-$json['data']['levelSetsResponse']['sets'][] = $prep;
-$json['data']['levelSetsResponse']['sets'][] = $past;
-
-
-$encoded = json_encode($json);
-die($encoded);
-
-
-function convertMapTiles($map) {
- $r = '';
- for($i = 1; $i < count($map); $i++) {
- if ($i !== 1)
- $r .= ',';
- for($j = 0; $j < count($map[$i]); $j++) {
- switch($map[$i][$j]) {
- case 'o': $r .= '00'; break;
- case 's': $r .= '02'; break;
- //Multipath:
- case 'S': $r .= '99'; break;
- //Path 1 and Path 2 allow-only rocks.
- case 'X':
- break;
- case 'x':
- break;
-
- case 'f': $r .= '03';break;
- case 't': $r .= '50';break;
- case 'u': $r .= '60';break;
- case 'm': $r .= '51';break;
- case 'n': $r .= '61';break;
- case 'g': $r .= '52';break;
- case 'h': $r .= '63';break;
- case 'i': $r .= '54';break;
- case 'j': $r .= '64';break;
- case 'k': $r .= '55';break;
- case 'l': $r .= '65';break;
-
- case 'a': $r .= '40';break;
- case 'b': $r .= '41';break;
- case 'c': $r .= '42';break;
- case 'd': $r .= '43';break;
- case 'e': $r .= '44';break;
- case 'r': $r .= '00';break;
- //Visually distinct rocks:
- case 'R': $r .= '00';break;
- case 'q': $r .= '00';break;
-
- //Technically shouldn't ever be used to display a wall...
- case 'w': $r .= '01';break;
- }
- }
- }
- return $r;
-}
-
-
-function translatemap($mapMatrix, $mapID) {
-
-
- $mapdata['height'] = $mapMatrix[0][0];
- $mapdata['width'] = $mapMatrix[0][1];
- $waypoints = $mapMatrix[0][2];
- $mapdata['rocks'] = $mapMatrix[0][3];
- $walls = $mapMatrix[0][4];
- $mapdata['teleports'] = $mapMatrix[0][5];
-
- $r .= "<level>";
- $r .= "\n <properties>";
- $r .= "\n <mapID>$mapID</mapID>";
- $r .= "\n <availableCost>$walls</availableCost>";
- $r .= "\n <waypoints>$waypoints</waypoints>";
- $r .= "\n </properties>";
-
-
- $r .= "\n <tiles>";
- $r .= "\n <rows>";
- for ($i = 1; $i < count($mapMatrix); $i++) {
-
- $r .= "\n <row>";
- for ($j = 0; $j < count($mapMatrix[$i]); $j++) {
-
- switch($mapMatrix[$i][$j]) {
- case 's': $r .= "02 "; break;
- case 'f': $r .= "03 "; break;
-
- case 't': $r .= "50 "; break;
- case 'u': $r .= "61 "; break;
- //TP2
- case 'm': $r .= "51 "; break;
- case 'n': $r .= "62 "; break;
- //TP3
- case 'g': $r .= "52 "; break;
- case 'h': $r .= "63 "; break;
- //TP4
- case 'i': $r .= "53 "; break;
- case 'j': $r .= "64 "; break;
- //TP5
- case 'k': $r .= "54 "; break;
- case 'l': $r .= "65 "; break;
-
- case 'a': $r .= "40 "; break;
- case 'b': $r .= "41 "; break;
- case 'c': $r .= "42 "; break;
- case 'd': $r .= "43 "; break;
- case 'e': $r .= "44 "; break;
-
- case 'r': $r .= "00 "; break; //rock
- case 'w': $r .= "01 "; break; //wall
- //default: $r .= "<td class='grid_td' id='$handle' onClick='grid_click(this)' >".$index."</td>";
- default: $r .= "10 ";
- //default: $r .= "<td class='grid_td' id='$handle' onClick='grid_click(this)' >".$mapMatrix[$i][$j]."</td>";
- }
- }
- $r .= "</row>";
- }
- $r .= "\n </rows>";
- $r .= "\n </tiles>";
- $r .= "\n</level>";
- return $r;
-}
-
-
-
-
-
-
-
-
-
-// encode array $json to JSON string
-
-//echo "working...";
-
-if ($_GET['act'] == "test") {
-
-//header('Content-Type: text/xml');
-header("Content-Type: text/plain");
-
-if ($_POST['XMLRequest']) {
- $string = $_POST['XMLRequest'];
-} else {
- $string = '<!-- request -->
-<BrainMazeAPI version="0.1">
- <APIRequest>
- <SubmitScore>
- <MapID>5</MapID>
- <Username>FiftyToo</Username>
- <Score>50</Score>
- </SubmitScore>
- </APIRequest>
-</BrainMazeAPI>';
-}
-
-$xml = simplexml_load_string($string);
-
-//echo $xml->APIRequest->SubmitScore->MapID;
-//print_r ($xml);
-
-
-
-
-$score = $xml->APIRequest[0]->SubmitScore[0]->Score;
-$username = $xml->APIRequest[0]->SubmitScore[0]->Username;
-
-//echo $xml->getName() . "<br />";
-// foreach($xml->children() as $child) {
-// echo $child->getName() . ": " . $child . "<br />";
-// }
-
-
-//$score = 50;
-$previousScore = 49;
-$rank = 1;
-
-//Begin XML Response
-$w = new XMLWriter();
-$w->openMemory();
-$w->startDocument('1.0','UTF-8');
-$w->startElement("BrainMazeAPI");
- $w->writeAttribute("version", "0.1");
- $w->startElement("APIResponse");
- $w->startElement("SubmitScore");
- $w->writeAttribute("result", "SUCCESS");
-
- $w->startElement("rank");
- $w->text($rank);
- $w->endElement();
-
- $w->startElement("update");
- $w->text('true');
- $w->endElement();
-
- $w->startElement("UsernameUsed");
- $w->text($username);
- $w->endElement();
-
- $w->startElement("SubmittedScore");
- $w->text($score);
- $w->endElement();
-
- $w->startElement("PreviousHighScore");
- $w->text($previousScore);
- $w->endElement();
-
- $w->endElement();
- $w->endElement();
-$w->endElement();
-echo $w->outputMemory(true);
-
-}
-
-
-
-if ($_GET['act'] == "submit") {
-header('Content-Type: text/xml');
-echo '<!-- response -->
-<BrainMazeAPI version="0.1">
- <APIResponse>
- <SubmitScore result="SUCCESS">
- <Rank>5</Rank>
- <SubmittedScore>50</SubmittedScore>
- <PreviousHighScore>49</PreviousHighScore>
- </SubmitScore>
- </APIResponse>
-</BrainMazeAPI>';
-
-}
-
-
-$xml = '<!-- request -->
-<BrainMazeAPI version="0.1">
- <APIRequest>
- <SubmitScore>
- <MapID>5</MapID>
- <Username>FiftyToo</Username>
- <Score>50</Score>
- </SubmitScore>
- </APIRequest>
-</BrainMazeAPI>
-
-
-<!-- response -->
-<BrainMazeAPI version="0.1">
- <APIResponse>
- <SubmitScore result="SUCCESS">
- <Rank>5</Rank>
- <SubmittedScore>50</SubmittedScore>
- <PreviousHighScore>49</PreviousHighScore>
- </SubmitScore>
- </APIResponse>
-</BrainMazeAPI>';
-
-
-
-
-if ($_GET['act'] == "getmap") {
-
- $maptype = $_GET['maptype'] + 0;
- if (!is_int($maptype))
- return;
- if ($maptype > 4)
- return;
- if ($maptype < 1)
- return;
-
- $motd = MapOfTheDay($maptype);
- $map = $motd['map'];
- $mapID = $motd['id'];
-
- //print_r($map);
-
- echo translatemap($map, $mapID);
-
-}
-
?>