You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.9 KiB
PHP

<?php
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// Update player ping/location
$database->update("players", [
"latitude" => $VARS["latitude"],
"longitude" => $VARS["longitude"],
"lastping" => date("Y-m-d H:i:s")
], [
"accountid" => getRequestUser()->getUID()
]);
$radius = 0.5;
if (!empty($VARS["radius"])) {
$radius = $VARS["radius"];
}
$poiurl = $SETTINGS["poi"]["server"] . "?latitude=" . $VARS["latitude"] . "&longitude=" . $VARS["longitude"] . "&radius_mi=" . $radius;
foreach ($SETTINGS["poi"]["categories"] as $cat) {
$poiurl .= "&type[]=$cat";
}
$nearby = json_decode(file_get_contents($poiurl), true)["features"];
$geojson = [
"status" => "OK",
"name" => "Nearby Places",
"type" => "FeatureCollection",
"features" => []
];
if ($SETTINGS["debug"]) {
$geojson["url"] = $poiurl;
}
foreach ($nearby as $n) {
$properties = [
"id" => $n["properties"]["osmid"],
"name" => $n["properties"]["name"],
"currentlife" => 0,
"maxlife" => 0,
"teamid" => null,
"ownerid" => null
];
// Update properties with game data
if ($database->has("locations", ["osmid" => $properties["id"]])) {
$gameprops = $database->get("locations", ["teamid", "ownerid", "currentlife", "maxlife"], ["osmid" => $properties["id"]]);
foreach ($gameprops as $key => $value) {
$properties[$key] = $value;
}
}
$geojson["features"][] = [
"type" => "Feature",
"geometry" => [
"type" => "Point",
"coordinates" => [
$n["geometry"]["coordinates"][0],
$n["geometry"]["coordinates"][1],
]
],
"properties" => $properties
];
}
exitWithJson($geojson);