[a-z.0-9]+)\/(?P(\-?)[0-9]+)_(?P(\-?)[0-9]+)\.json$/', $_GET['q'], $matches)) { printf("%s
\n", $_GET['q']); printf("Invalid request reg
\n"); exit(0); } else { $server = $matches['server']; $x = (int)$matches['x']; $y = (int)$matches['y']; } } //printf("Server: %s (%d,%d)
\n", $server, $x, $y); // Find table for server $table = null; foreach ($Servers as $s) { if (preg_match('/^http:\/\/(?P[a-z.0-9]+)/', $s['dumpfile'], $matches)) { if ($matches['server'] == $server) { $table = $s['name']; break; } } } if ($table == null) { printf("Unable to find table for server, probably not indexed"); exit(0); } $cacheName = sprintf("%s-%s-(%d,%d)", 'travmap', $server, $x, $y); if ($data = fromCache($cacheName)) { header("Expires: " . gmdate( "D, d M Y H:i:s", time()+60*60*1) . "GMT" ); header("Content-type: application/json"); echo json_encode($data); exit(0); } // Fix the query $sx = floor($x*$multiplier); $sy = floor($y*$multiplier); $k = $x+1; $j = $y+1; $ex = ceil($k*$multiplier); $ey = ceil($j*$multiplier); $query = sprintf("SELECT * FROM %s WHERE x>=%d AND x<=%d AND y>=%d and y<=%d", $table, $sx, $ex, $sy, $ey); //printf("query: %s
\n", $query); $db = new mysqli($DB['host'], $DB['user'], $DB['pass'], 'travian'); if (!$result = $db->query($query)) { die("Query failed:".$db->error); } //printf("numrows: %d
", $result->num_rows); //header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" ); //header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" ); //header("Cache-Control: no-cache, must-revalidate" ); //header("Pragma: no-cache" ); header("Expires: " . gmdate( "D, d M Y H:i:s", time()+$cacheTime) . "GMT" ); header("Last-Modified: " . gmdate( "D, d M Y H:i:s", time()+$cacheTime) . "GMT" ); header("Content-type: application/json"); $r = array(); while ($obj = $result->fetch_object()) { $r[] = array( 'x' => $obj->x, 'y' => $obj->y, 'village' => utf8_encode($obj->village), 'player' => utf8_encode($obj->player), 'alliance' => utf8_encode($obj->alliance), 'population' => $obj->population, 'aid' => $obj->aid ); } toCache($cacheName, $r); echo json_encode($r); ?>