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.
66 lines
1.7 KiB
PHP
66 lines
1.7 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/.
|
|
*/
|
|
|
|
use AnthonyMartin\GeoLocation\GeoLocation as GeoLocation;
|
|
|
|
$userlocation = GeoLocation::fromDegrees($VARS["latitude"], $VARS["longitude"]);
|
|
|
|
// 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 = 2;
|
|
if (!empty($VARS["radius"])) {
|
|
$radius = min(10.0, $VARS["radius"] * 1.0);
|
|
}
|
|
$searchbounds = $userlocation->boundingCoordinates($radius, "miles");
|
|
|
|
$where = [
|
|
"LIMIT" => 100,
|
|
"ORDER" => "time"
|
|
];
|
|
|
|
if (!empty($VARS["latitude"]) && !empty($VARS["longitude"])) {
|
|
$where["AND"] = [
|
|
'lat[<>]' => [$searchbounds[0]->getLatitudeInDegrees(), $searchbounds[1]->getLatitudeInDegrees()],
|
|
'long[<>]' => [$searchbounds[0]->getLongitudeInDegrees(), $searchbounds[1]->getLongitudeInDegrees()],
|
|
];
|
|
}
|
|
|
|
ob_flush();
|
|
$database->debug()->select("messages", [
|
|
"[>]players" => "accountid"
|
|
], [
|
|
"id",
|
|
"time",
|
|
"message",
|
|
"messages.accountid",
|
|
"players.nickname",
|
|
"players.teamid"
|
|
], $where
|
|
);
|
|
$query = ob_get_contents();
|
|
ob_clean();
|
|
$messages = $database->query($query)->fetchAll();
|
|
|
|
$myid = getRequestUser()->getUID();
|
|
for ($i = 0; $i < count($messages); $i++) {
|
|
if ($messages[$i]["accountid"] == $myid) {
|
|
$messages[$i]["me"] = true;
|
|
} else {
|
|
$messages[$i]["me"] = false;
|
|
}
|
|
}
|
|
|
|
exitWithJson(["status" => "OK", "count" => count($messages), "messages" => $messages]);
|