Add chat API, move "items" to "inventory", add color+icon fields to items
This commit is contained in:
parent
f9afcbe5d8
commit
718bde141d
55
api/actions/getchat.php
Normal file
55
api/actions/getchat.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?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");
|
||||
|
||||
$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]);
|
@ -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]);
|
||||
exitWithJson(["status" => "OK", "items" => $items]);
|
22
api/actions/sendchat.php
Normal file
22
api/actions/sendchat.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?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/.
|
||||
*/
|
||||
|
||||
$message = strip_tags($VARS['message']);
|
||||
if (empty($message)) {
|
||||
sendJsonResp($Strings->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();
|
@ -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"
|
||||
]
|
||||
],
|
||||
];
|
@ -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": [
|
||||
|
58
composer.lock
generated
58
composer.lock
generated
@ -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": [],
|
||||
|
BIN
database.mwb
BIN
database.mwb
Binary file not shown.
@ -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 ;
|
||||
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`;
|
Loading…
x
Reference in New Issue
Block a user