diff --git a/api/actions/nearby.php b/api/actions/nearby.php deleted file mode 100644 index a4fa65a..0000000 --- a/api/actions/nearby.php +++ /dev/null @@ -1,97 +0,0 @@ -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 -]); diff --git a/api/actions/nearbyplaces.php b/api/actions/nearbyplaces.php new file mode 100644 index 0000000..67ced69 --- /dev/null +++ b/api/actions/nearbyplaces.php @@ -0,0 +1,63 @@ + "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); \ No newline at end of file diff --git a/api/actions/nearbyplayers.php b/api/actions/nearbyplayers.php new file mode 100644 index 0000000..70b7b6b --- /dev/null +++ b/api/actions/nearbyplayers.php @@ -0,0 +1,72 @@ +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); \ No newline at end of file diff --git a/api/actions/submitcode.php b/api/actions/submitcode.php index 33e5bcf..1550881 100644 --- a/api/actions/submitcode.php +++ b/api/actions/submitcode.php @@ -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) { diff --git a/api/apisettings.php b/api/apisettings.php index 95c8998..e0375a1 100644 --- a/api/apisettings.php +++ b/api/apisettings.php @@ -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" ] ] ]; \ No newline at end of file diff --git a/database.mwb b/database.mwb index 4cf762e..76381f7 100644 Binary files a/database.mwb and b/database.mwb differ diff --git a/database.mwb.bak b/database.mwb.bak index 3414328..437b760 100644 Binary files a/database.mwb.bak and b/database.mwb.bak differ diff --git a/database/migrate_v1.sql b/database/migrate_v1.sql index 993c226..a609c08 100644 --- a/database/migrate_v1.sql +++ b/database/migrate_v1.sql @@ -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 ; \ No newline at end of file +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 ; \ No newline at end of file diff --git a/settings.template.php b/settings.template.php index 3b25509..ad06f26 100644 --- a/settings.template.php +++ b/settings.template.php @@ -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" => [ ],