From 9decd046ec2956b46427f5c2426b1755fbe943f5 Mon Sep 17 00:00:00 2001 From: Skylar Date: Sun, 3 Apr 2016 16:12:59 -0600 Subject: [PATCH] Add geocache search, add placeholder files, rearrange settings --- dbsettings.php | 15 ++++++------ geocaches.php | 39 +++++++++++++++++++++++++++++ inventory.php | 13 ++++++++++ places.php | 8 ++++++ proximity.php | 66 ++++++++++++++++++++++++++++++++++++++++++++------ required.php | 17 ++++++++++--- settings.php | 10 ++++++++ 7 files changed, 150 insertions(+), 18 deletions(-) create mode 100644 geocaches.php create mode 100644 inventory.php create mode 100644 places.php create mode 100644 settings.php diff --git a/dbsettings.php b/dbsettings.php index 8e29eb9..baf6e6d 100644 --- a/dbsettings.php +++ b/dbsettings.php @@ -1,9 +1,10 @@ 'mysql', -'database_name' => 'c0terranquest', -'server' => 'localhost', -'username' => 'c0terranquest', -'password' => 'qinkifTQ!OMY2', -'charset' => 'utf8' -]); \ No newline at end of file + 'database_type' => 'mysql', + 'database_name' => 'c0terranquest', + 'server' => 'localhost', + 'username' => 'c0terranquest', + 'password' => 'qinkifTQ!OMY2', + 'charset' => 'latin1' + ]); diff --git a/geocaches.php b/geocaches.php new file mode 100644 index 0000000..b1cbb42 --- /dev/null +++ b/geocaches.php @@ -0,0 +1,39 @@ +results; + +$list = ""; +foreach ($caches as $val) { + $list .= $val . "|"; +} +echo file_get_contents($okapi . "services/caches/geocaches?consumer_key=" . GEOCACHE_KEY . "&cache_codes=" . rtrim($list, "|")); + diff --git a/inventory.php b/inventory.php new file mode 100644 index 0000000..49528ad --- /dev/null +++ b/inventory.php @@ -0,0 +1,13 @@ +select('items', ['[>]inventory' => ['itemid' => 'itemid'], '[>]itemclasses' => ['classid', 'classid']], ['inventory.itemuuid', 'inventory.itemid', 'inventory.itemjson', 'items.itemname', 'items.itemdesc', 'itemclasses.classid', 'itemclasses.classname'], ['inventory.playeruuid' => file_get_contents("https://sso.netsyms.com/api/getguid.php?user=" . $VARS['user'])]); + +$out['status'] = 'OK'; +$out['items'] = $inv; +echo json_encode($out); \ No newline at end of file diff --git a/places.php b/places.php new file mode 100644 index 0000000..3ac00fa --- /dev/null +++ b/places.php @@ -0,0 +1,8 @@ +select('messages', ['username', 'message', 'time'], ['AND' => [ - 'lat[>]' => $searchbounds[0]->getLatitudeInDegrees(), - 'lat[<]' => $searchbounds[1]->getLatitudeInDegrees(), - 'long[>]' => $searchbounds[0]->getLongitudeInDegrees(), - 'long[<]' => $searchbounds[1]->getLongitudeInDegrees()], - "ORDER" => "time DESC", - "LIMIT" => 30 - ]); \ No newline at end of file +/* + Coordinate decimal places to earth resolution + decimal + places degrees distance + ------- ------- -------- + 0 1 111 km + 1 0.1 11.1 km + 2 0.01 1.11 km + 3 0.001 111 m + 4 0.0001 11.1 m + 5 0.00001 1.11 m + 6 0.000001 11.1 cm + 7 0.0000001 1.11 cm + 8 0.00000001 1.11 mm + */ + +require 'required.php'; + +use AnthonyMartin\GeoLocation\GeoLocation as GeoLocation; + +if (is_empty($VARS['lat']) || is_empty($VARS['long'])) { + sendError("Missing information.", true); +} + +if (!preg_match('/-?[0-9]{1,3}\.[0-9]{3,}/', $VARS['lat'])) { + sendError("Latitude (lat) is in the wrong format.", true); +} + +if (!preg_match('/-?[0-9]{1,3}\.[0-9]{3,}/', $VARS['long'])) { + sendError("Longitude (long) is in the wrong format.", true); +} + +$radius = 1; +if (!is_empty($VARS['radius']) && is_numeric($VARS['radius'])) { + $radius = intval($VARS['radius']); +} + +$userlocation = GeoLocation::fromDegrees($VARS['lat'], $VARS['long']); +$searchbounds = $userlocation->boundingCoordinates($radius, 'miles'); + + +$people = $database->select('players', ['uuid', 'level', 'latitude', 'longitude', 'lastping'], ['AND' => [ + 'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(), + 'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(), + 'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(), + 'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees(), + '#lastping[>]' => 'DATE_SUB(NOW(), INTERVAL 5 MINUTE)'], + "LIMIT" => 50 + ]); +var_dump($database->error()); +if (!$people) { + die('[]'); +} +for ($i = 0; $i < count($people); $i++) { + $people[$i]['username'] = file_get_contents('https://sso.netsyms.com/api/getname.php?uuid=' . $people[$i]['uuid']); +} + +echo json_encode($people); diff --git a/required.php b/required.php index d82b967..058653b 100644 --- a/required.php +++ b/required.php @@ -1,29 +1,40 @@ DB_TYPE, + 'database_name' => DB_NAME, + 'server' => DB_SERVER, + 'username' => DB_USER, + 'password' => DB_PASS, + 'charset' => DB_CHARSET + ]); } catch (Exception $ex) { header('HTTP/1.1 500 Internal Server Error'); sendError('Database error. Try again later.', true); @@ -60,4 +71,4 @@ if (GET) { */ function is_empty($str) { return (!isset($str) || $str == '' || $str == null); -} \ No newline at end of file +} diff --git a/settings.php b/settings.php new file mode 100644 index 0000000..8252388 --- /dev/null +++ b/settings.php @@ -0,0 +1,10 @@ +