diff --git a/api/actions/getchat.php b/api/actions/getchat.php new file mode 100644 index 0000000..59bec22 --- /dev/null +++ b/api/actions/getchat.php @@ -0,0 +1,55 @@ +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" + ], $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]); diff --git a/api/actions/items.php b/api/actions/inventory.php similarity index 77% rename from api/actions/items.php rename to api/actions/inventory.php index 0bdab1e..cb6768a 100644 --- a/api/actions/items.php +++ b/api/actions/inventory.php @@ -17,11 +17,13 @@ $items = $database->select( 'items.itemname (name)', 'items.itemdesc (description)', 'items.itemcode (code)', + 'items.icon', + 'items.color', 'itemclasses.classid (classid)', - 'itemclasses.classname (classname' + 'itemclasses.classname (classname)' ], [ - "playeruuid" => getRequestUser()->getUID() + "inventory.accountid" => getRequestUser()->getUID() ] ); -exitWithJson(["status" => "OK", "items" => $items]); \ No newline at end of file +exitWithJson(["status" => "OK", "items" => $items]); diff --git a/api/actions/sendchat.php b/api/actions/sendchat.php new file mode 100644 index 0000000..8980a82 --- /dev/null +++ b/api/actions/sendchat.php @@ -0,0 +1,22 @@ +get("Message cannot be empty.", false), "ERROR"); +} + +$database->insert('messages', [ + 'time' => date("Y-m-d H:i:s"), + 'message' => $message, + 'lat' => $VARS['latitude'], + 'long' => $VARS['longitude'], + 'accountid' => getRequestUser()->getUID() +]); + +sendJsonResp(); diff --git a/api/apisettings.php b/api/apisettings.php index e0375a1..0e932a9 100644 --- a/api/apisettings.php +++ b/api/apisettings.php @@ -12,8 +12,8 @@ $APIS = [ "vars" => [ ] ], - "items" => [ - "load" => "items.php" + "inventory" => [ + "load" => "inventory.php" ], "createplayer" => [ "load" => "createplayer.php", @@ -57,5 +57,21 @@ $APIS = [ "longitude" => "/[0-9]{0,3}\.[0-9]{2,10}/", "radius (optional)" => "numeric" ] - ] + ], + "getchat" => [ + "load" => "getchat.php", + "vars" => [ + "latitude (optional)" => "/[0-9]{0,3}\.[0-9]{2,10}/", + "longitude (optional)" => "/[0-9]{0,3}\.[0-9]{2,10}/", + "radius (optional)" => "numeric" + ] + ], + "sendchat" => [ + "load" => "sendchat.php", + "vars" => [ + "latitude" => "/[0-9]{0,3}\.[0-9]{2,10}/", + "longitude" => "/[0-9]{0,3}\.[0-9]{2,10}/", + "message" => "string" + ] + ], ]; \ No newline at end of file diff --git a/composer.json b/composer.json index fb37c32..c81c0af 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,8 @@ "type": "project", "require": { "catfan/medoo": "^1.5", - "guzzlehttp/guzzle": "^6.2" + "guzzlehttp/guzzle": "^6.2", + "anthonymartin/geo-location": "^1.0" }, "license": "MPL-2.0", "authors": [ diff --git a/composer.lock b/composer.lock index 8d36028..09d9030 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,53 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "5c7439c6e041764f2f6b0270a95ab3ae", - "content-hash": "e4e700119f47d2f68b0ed82abaf8c5c6", + "content-hash": "a4330dce069db4d0d962b670496ca8ef", "packages": [ + { + "name": "anthonymartin/geo-location", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/anthonymartin/GeoLocation.php.git", + "reference": "50bf026f069296dfae11aa195d987854b2e75855" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/anthonymartin/GeoLocation.php/zipball/50bf026f069296dfae11aa195d987854b2e75855", + "reference": "50bf026f069296dfae11aa195d987854b2e75855", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "class", + "autoload": { + "psr-0": { + "AnthonyMartin": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "CC 3.0" + ], + "authors": [ + { + "name": "Anthony Martin", + "email": "anthony@replaycreative.com", + "homepage": "http://replaycreative.com", + "role": "Developer" + } + ], + "description": "Retrieve bounding coordinates, distances, longitude and latitude with GeoLocation.class.php", + "homepage": "https://github.com/anthonymartin/GeoLocation.php", + "keywords": [ + "bounding coordinates", + "distances", + "geocoding", + "geolocation" + ], + "time": "2016-09-17T18:05:14+00:00" + }, { "name": "catfan/medoo", "version": "v1.5.7", @@ -64,7 +108,7 @@ "sql", "sqlite" ], - "time": "2018-06-14 18:59:08" + "time": "2018-06-14T18:59:08+00:00" }, { "name": "guzzlehttp/guzzle", @@ -129,7 +173,7 @@ "rest", "web service" ], - "time": "2018-04-22 15:46:56" + "time": "2018-04-22T15:46:56+00:00" }, { "name": "guzzlehttp/promises", @@ -180,7 +224,7 @@ "keywords": [ "promise" ], - "time": "2016-12-20 10:07:11" + "time": "2016-12-20T10:07:11+00:00" }, { "name": "guzzlehttp/psr7", @@ -245,7 +289,7 @@ "uri", "url" ], - "time": "2017-03-20 17:10:46" + "time": "2017-03-20T17:10:46+00:00" }, { "name": "psr/http-message", @@ -295,7 +339,7 @@ "request", "response" ], - "time": "2016-08-06 14:39:51" + "time": "2016-08-06T14:39:51+00:00" } ], "packages-dev": [], diff --git a/database.mwb b/database.mwb index 76381f7..0751eb3 100644 Binary files a/database.mwb and b/database.mwb differ diff --git a/database/migrate_v1.sql b/database/migrate_v1.sql index a609c08..3dadfed 100644 --- a/database/migrate_v1.sql +++ b/database/migrate_v1.sql @@ -143,4 +143,8 @@ 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 +CHANGE COLUMN `message` `message` TEXT NOT NULL ; + +ALTER TABLE `terranquest`.`items` +ADD COLUMN `icon` VARCHAR(100) NULL DEFAULT NULL AFTER `weight`, +ADD COLUMN `color` VARCHAR(45) NULL DEFAULT NULL AFTER `icon`; \ No newline at end of file