Get nearby places and players API, improve DB schema, ignore zero-weighted items when picking
This commit is contained in:
parent
af13a70976
commit
f9afcbe5d8
@ -1,97 +0,0 @@
|
||||
<?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"]);
|
||||
|
||||
$radius = 2;
|
||||
if (!empty($VARS["radius"])) {
|
||||
$radius = min(10.0, $VARS["radius"] * 1.0);
|
||||
}
|
||||
$searchbounds = $userlocation->boundingCoordinates($radius, "miles");
|
||||
|
||||
ob_flush();
|
||||
$people = $database->debug()->select("accounts", [
|
||||
"publicid",
|
||||
"name",
|
||||
"username",
|
||||
"verified",
|
||||
"latitude",
|
||||
"longitude"
|
||||
], [
|
||||
"AND" => [
|
||||
'latitude[<>]' => [$searchbounds[0]->getLatitudeInDegrees(), $searchbounds[1]->getLatitudeInDegrees()],
|
||||
'longitude[<>]' => [$searchbounds[0]->getLongitudeInDegrees(), $searchbounds[1]->getLongitudeInDegrees()],
|
||||
"lastgpsfix[>]" => date("Y-m-d H:i:s", strtotime("-1 hour")),
|
||||
"type" => 2
|
||||
],
|
||||
"LIMIT" => 100
|
||||
]
|
||||
);
|
||||
$query = ob_get_contents();
|
||||
ob_clean();
|
||||
$people = $database->query($query)->fetchAll();
|
||||
|
||||
$nearby = [];
|
||||
|
||||
if (!empty($VARS["format"]) && $VARS["format"] == "geojson") {
|
||||
$geojson = [
|
||||
"name" => "Nearby People",
|
||||
"type" => "FeatureCollection",
|
||||
"features" => []
|
||||
];
|
||||
|
||||
foreach ($people as $person) {
|
||||
$geojson["features"][] = [
|
||||
"type" => "Feature",
|
||||
"geometry" => [
|
||||
"type" => "Point",
|
||||
"coordinates" => [
|
||||
$person["longitude"] * 1.0,
|
||||
$person["latitude"] * 1.0
|
||||
]
|
||||
],
|
||||
"properties" => [
|
||||
"id" => $person["publicid"],
|
||||
"name" => utf8_encode(empty($person["name"]) ? $person["username"] : $person["name"]),
|
||||
"username" => $person["username"],
|
||||
"verified" => $person["verified"] == 1
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
exitWithJson($geojson);
|
||||
}
|
||||
|
||||
foreach ($people as $person) {
|
||||
$nearby[] = [
|
||||
"name" => (empty($person["name"]) ? $person["username"] : $person["name"]),
|
||||
"username" => $person["username"],
|
||||
"verified" => $person["verified"] == 1,
|
||||
"publicid" => $person["publicid"],
|
||||
"latitude" => $person["latitude"] * 1.0,
|
||||
"longitude" => $person["longitude"] * 1.0
|
||||
];
|
||||
}
|
||||
|
||||
exitWithJson([
|
||||
"status" => "OK",
|
||||
"radius" => $radius,
|
||||
"bounds" => [
|
||||
0 => [
|
||||
"latitude" => $searchbounds[0]->getLatitudeInDegrees(),
|
||||
"longitude" => $searchbounds[0]->getLongitudeInDegrees()
|
||||
],
|
||||
1 => [
|
||||
"latitude" => $searchbounds[1]->getLatitudeInDegrees(),
|
||||
"longitude" => $searchbounds[1]->getLongitudeInDegrees()
|
||||
],
|
||||
],
|
||||
"nearby" => $nearby
|
||||
]);
|
63
api/actions/nearbyplaces.php
Normal file
63
api/actions/nearbyplaces.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?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/.
|
||||
*/
|
||||
|
||||
$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);
|
72
api/actions/nearbyplayers.php
Normal file
72
api/actions/nearbyplayers.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?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"]);
|
||||
|
||||
$radius = 2;
|
||||
if (!empty($VARS["radius"])) {
|
||||
$radius = min(10.0, $VARS["radius"] * 1.0);
|
||||
}
|
||||
$searchbounds = $userlocation->boundingCoordinates($radius, "miles");
|
||||
|
||||
ob_flush();
|
||||
$people = $database->debug()->select("players", [
|
||||
"accountid",
|
||||
"level",
|
||||
"nickname",
|
||||
"energy",
|
||||
"maxenergy",
|
||||
"latitude",
|
||||
"longitude",
|
||||
"teamid"
|
||||
], [
|
||||
"AND" => [
|
||||
'latitude[<>]' => [$searchbounds[0]->getLatitudeInDegrees(), $searchbounds[1]->getLatitudeInDegrees()],
|
||||
'longitude[<>]' => [$searchbounds[0]->getLongitudeInDegrees(), $searchbounds[1]->getLongitudeInDegrees()],
|
||||
"lastping[>]" => date("Y-m-d H:i:s", strtotime("-1 minute")),
|
||||
"kick" => ""
|
||||
],
|
||||
"LIMIT" => 100
|
||||
]
|
||||
);
|
||||
$query = ob_get_contents();
|
||||
ob_clean();
|
||||
$people = $database->query($query)->fetchAll();
|
||||
|
||||
$nearby = [];
|
||||
|
||||
$geojson = [
|
||||
"status" => "OK",
|
||||
"name" => "Nearby People",
|
||||
"type" => "FeatureCollection",
|
||||
"features" => []
|
||||
];
|
||||
|
||||
foreach ($people as $person) {
|
||||
$geojson["features"][] = [
|
||||
"type" => "Feature",
|
||||
"geometry" => [
|
||||
"type" => "Point",
|
||||
"coordinates" => [
|
||||
$person["longitude"] * 1.0,
|
||||
$person["latitude"] * 1.0
|
||||
]
|
||||
],
|
||||
"properties" => [
|
||||
"id" => $person["accountid"],
|
||||
"name" => $person["nickname"],
|
||||
"latitude" => $person["latitude"],
|
||||
"longitude" => $person["longitude"],
|
||||
"team" => $person["teamid"]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
exitWithJson($geojson);
|
@ -59,7 +59,8 @@ if ($database->has('claimedcodes', ["AND" => ['code' => $VARS["code"], 'accounti
|
||||
}
|
||||
Random::seed($codeint);
|
||||
|
||||
$items = $database->select("items", ["itemid", "weight"]);
|
||||
// Get all items, except ones that have no rarity, which can't be found normally
|
||||
$items = $database->select("items", ["itemid", "weight"], ["weight[>]" => 0]);
|
||||
$weighted = [];
|
||||
|
||||
foreach ($items as $item) {
|
||||
|
@ -39,7 +39,23 @@ $APIS = [
|
||||
"code" => "string",
|
||||
"latitude (optional)" => "/[0-9]{0,3}\.[0-9]{2,10}/",
|
||||
"longitude (optional)" => "/[0-9]{0,3}\.[0-9]{2,10}/",
|
||||
"accuracy (optional)" => "number"
|
||||
"accuracy (optional)" => "numeric"
|
||||
]
|
||||
],
|
||||
"nearbyplayers" => [
|
||||
"load" => "nearbyplayers.php",
|
||||
"vars" => [
|
||||
"latitude" => "/[0-9]{0,3}\.[0-9]{2,10}/",
|
||||
"longitude" => "/[0-9]{0,3}\.[0-9]{2,10}/",
|
||||
"radius (optional)" => "numeric"
|
||||
]
|
||||
],
|
||||
"nearbyplaces" => [
|
||||
"load" => "nearbyplaces.php",
|
||||
"vars" => [
|
||||
"latitude" => "/[0-9]{0,3}\.[0-9]{2,10}/",
|
||||
"longitude" => "/[0-9]{0,3}\.[0-9]{2,10}/",
|
||||
"radius (optional)" => "numeric"
|
||||
]
|
||||
]
|
||||
];
|
BIN
database.mwb
BIN
database.mwb
Binary file not shown.
BIN
database.mwb.bak
BIN
database.mwb.bak
Binary file not shown.
@ -128,9 +128,19 @@ ADD CONSTRAINT `fk_private_messages_players2`
|
||||
ALTER TABLE `terranquest`.`items`
|
||||
ADD COLUMN `weight` INT(3) NOT NULL DEFAULT 1 AFTER `itemcode`;
|
||||
|
||||
ALTER TABLE `terranquest`.`messages`
|
||||
CHANGE COLUMN `message` `message` VARCHAR(500) COLLATE 'utf8mb4_bin' NOT NULL ;
|
||||
|
||||
ALTER TABLE `terranquest`.`artifacts`
|
||||
CHANGE COLUMN `currentlife` `currentlife` DECIMAL(7,2) NOT NULL DEFAULT 100 ,
|
||||
CHANGE COLUMN `maxlife` `maxlife` DECIMAL(7,2) NOT NULL DEFAULT 100 ;
|
||||
CHANGE COLUMN `maxlife` `maxlife` DECIMAL(7,2) NOT NULL DEFAULT 100 ;
|
||||
|
||||
ALTER TABLE `terranquest`.`players`
|
||||
ADD COLUMN `stealth` TINYINT(1) NOT NULL DEFAULT 0 AFTER `kick`;
|
||||
|
||||
ALTER TABLE `terranquest`.`locations`
|
||||
CHANGE COLUMN `osmid` `osmid` VARCHAR(20) NOT NULL ,
|
||||
ADD COLUMN `lastactivity` DATETIME NULL DEFAULT NULL AFTER `data`;
|
||||
|
||||
ALTER TABLE `terranquest`.`messages`
|
||||
CHANGE COLUMN `message` `message` TEXT COLLATE 'utf8mb4_bin' NOT NULL ;
|
||||
|
||||
ALTER TABLE `terranquest`.`private_messages`
|
||||
CHANGE COLUMN `message` `message` TEXT NOT NULL ;
|
@ -36,6 +36,42 @@ $SETTINGS = [
|
||||
// API key
|
||||
"key" => "123"
|
||||
],
|
||||
// Settings for Point of Interest server to get place data from
|
||||
// https://source.netsyms.com/Netsyms/PointsOfInterestAPI
|
||||
"poi" => [
|
||||
"server" => "https://maps.netsyms.net/poi/",
|
||||
// Location categories/types to filter to with argument type=X
|
||||
"categories" => [
|
||||
"AMENITY_LIBRARY",
|
||||
"AMENITY_POLICE",
|
||||
"AMENITY_PLAYGROUND",
|
||||
"AMENITY_PUBLICBUILDING",
|
||||
"AMENITY_TOWNHALL",
|
||||
"EDUCATION_COLLEGE",
|
||||
"EDUCATION_SCHOOL",
|
||||
"EDUCATION_UNIVERSITY",
|
||||
"POW_BAHAI",
|
||||
"POW_BUDDHIST",
|
||||
"POW_CHRISTIAN",
|
||||
"POW_HINDU",
|
||||
"POW_ISLAMIC",
|
||||
"POW_JAIN",
|
||||
"POW_JEWISH",
|
||||
"POW_SHINTO",
|
||||
"POW_SIKH",
|
||||
"POW_UNKOWN",
|
||||
"POI_PEAK1",
|
||||
"POI_PEAK",
|
||||
"POI_TOWERLOOKOUT",
|
||||
"TOURIST_CASTLE",
|
||||
"TOURIST_FOUNTAIN",
|
||||
"TOURIST_MEMORIAL",
|
||||
"TOURIST_MONUMENT",
|
||||
"TOURIST_RUINS",
|
||||
"TOURIST_WINDMILL",
|
||||
"WATER_TOWER"
|
||||
]
|
||||
],
|
||||
// List of required user permissions to access this app.
|
||||
"permissions" => [
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user