From d816b6846d9bcf2be2bc2e7c855d18edc02fcab0 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Mon, 3 Oct 2016 17:57:01 -0600 Subject: [PATCH] Add nearby players list --- nearby.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/nearby.php b/nearby.php index 8568d4a..960e0c9 100644 --- a/nearby.php +++ b/nearby.php @@ -32,7 +32,7 @@ if (!preg_match('/-?[0-9]{1,3}\.[0-9]{3,}/', $VARS['long'])) { sendError("Longitude (long) is in the wrong format.", true); } -$radius = 1; +$radius = .25; if (!is_empty($VARS['radius']) && is_numeric($VARS['radius'])) { $radius = intval($VARS['radius']); } @@ -41,20 +41,18 @@ $userlocation = GeoLocation::fromDegrees($VARS['lat'], $VARS['long']); $searchbounds = $userlocation->boundingCoordinates($radius, 'miles'); -$people = $database->select('players', ['uuid', 'level', 'latitude', 'longitude', 'lastping'], ['AND' => [ +$people = $database->select('players', ['uuid', 'level', 'nickname', 'teamid', 'energy', 'maxenergy'], ['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 + 'lastping[>]' => date('Y-m-d H:i:s', strtotime('-1 minute'))], + "LIMIT" => 20 ]); -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']); + +$out = ["status" => "OK", "people" => []]; +foreach ($people as $person) { + $out['people'][] = ["uuid" => $person["uuid"], "name" => $person["nickname"], "team" => $person["teamid"]]; } -echo json_encode($people); +echo json_encode($out);