Add geocache search, add placeholder files, rearrange settings

master
Skylar Ittner 8 years ago
parent d0cc2b6fc1
commit 9decd046ec

@ -1,9 +1,10 @@
<?php
$database = new medoo([
'database_type' => 'mysql',
'database_name' => 'c0terranquest',
'server' => 'localhost',
'username' => 'c0terranquest',
'password' => 'qinkifTQ!OMY2',
'charset' => 'utf8'
]);
'database_type' => 'mysql',
'database_name' => 'c0terranquest',
'server' => 'localhost',
'username' => 'c0terranquest',
'password' => 'qinkifTQ!OMY2',
'charset' => 'latin1'
]);

@ -0,0 +1,39 @@
<?php
require 'required.php';
$okapi = "http://opencaching.us/okapi/";
if (is_empty($VARS['lat']) || is_empty($VARS['long'])) {
sendError("Missing information.", true);
}
if (!preg_match('/-?[0-9]{1,3}\.[0-9]{3,}/', $VARS['lat'])) {
sendError("Latitude (lat) is in the wrong format.", true);
}
if (!preg_match('/-?[0-9]{1,3}\.[0-9]{3,}/', $VARS['long'])) {
sendError("Longitude (long) is in the wrong format.", true);
}
$lat = $VARS['lat'];
$long = $VARS['long'];
$limit = 25;
if (!is_empty($VARS['limit']) && is_numeric($VARS['limit'])) {
$limit = intval($VARS['limit']);
}
$json = file_get_contents($okapi . "services/caches/search/nearest?center=" . $lat . "|" . $long . "&limit=" . $limit . "&consumer_key=" . GEOCACHE_KEY);
if (!$json)
sendError("Something went wrong, try again later.", true);
$caches = json_decode($json)->results;
$list = "";
foreach ($caches as $val) {
$list .= $val . "|";
}
echo file_get_contents($okapi . "services/caches/geocaches?consumer_key=" . GEOCACHE_KEY . "&cache_codes=" . rtrim($list, "|"));

@ -0,0 +1,13 @@
<?php
require 'required.php';
if (is_empty($VARS['user'])) {
sendError("Missing data.", true);
}
$inv = $database->select('items', ['[>]inventory' => ['itemid' => 'itemid'], '[>]itemclasses' => ['classid', 'classid']], ['inventory.itemuuid', 'inventory.itemid', 'inventory.itemjson', 'items.itemname', 'items.itemdesc', 'itemclasses.classid', 'itemclasses.classname'], ['inventory.playeruuid' => file_get_contents("https://sso.netsyms.com/api/getguid.php?user=" . $VARS['user'])]);
$out['status'] = 'OK';
$out['items'] = $inv;
echo json_encode($out);

@ -0,0 +1,8 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

@ -1,10 +1,60 @@
<?php
$msgs = $database->select('messages', ['username', 'message', 'time'], ['AND' => [
'lat[>]' => $searchbounds[0]->getLatitudeInDegrees(),
'lat[<]' => $searchbounds[1]->getLatitudeInDegrees(),
'long[>]' => $searchbounds[0]->getLongitudeInDegrees(),
'long[<]' => $searchbounds[1]->getLongitudeInDegrees()],
"ORDER" => "time DESC",
"LIMIT" => 30
]);
/*
Coordinate decimal places to earth resolution
decimal
places degrees distance
------- ------- --------
0 1 111 km
1 0.1 11.1 km
2 0.01 1.11 km
3 0.001 111 m
4 0.0001 11.1 m
5 0.00001 1.11 m
6 0.000001 11.1 cm
7 0.0000001 1.11 cm
8 0.00000001 1.11 mm
*/
require 'required.php';
use AnthonyMartin\GeoLocation\GeoLocation as GeoLocation;
if (is_empty($VARS['lat']) || is_empty($VARS['long'])) {
sendError("Missing information.", true);
}
if (!preg_match('/-?[0-9]{1,3}\.[0-9]{3,}/', $VARS['lat'])) {
sendError("Latitude (lat) is in the wrong format.", true);
}
if (!preg_match('/-?[0-9]{1,3}\.[0-9]{3,}/', $VARS['long'])) {
sendError("Longitude (long) is in the wrong format.", true);
}
$radius = 1;
if (!is_empty($VARS['radius']) && is_numeric($VARS['radius'])) {
$radius = intval($VARS['radius']);
}
$userlocation = GeoLocation::fromDegrees($VARS['lat'], $VARS['long']);
$searchbounds = $userlocation->boundingCoordinates($radius, 'miles');
$people = $database->select('players', ['uuid', 'level', 'latitude', 'longitude', 'lastping'], ['AND' => [
'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(),
'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(),
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees(),
'#lastping[>]' => 'DATE_SUB(NOW(), INTERVAL 5 MINUTE)'],
"LIMIT" => 50
]);
var_dump($database->error());
if (!$people) {
die('[]');
}
for ($i = 0; $i < count($people); $i++) {
$people[$i]['username'] = file_get_contents('https://sso.netsyms.com/api/getname.php?uuid=' . $people[$i]['uuid']);
}
echo json_encode($people);

@ -1,29 +1,40 @@
<?php
/**
* This file contains global settings and things that should be loaded at the
* top of each file.
*/
ob_start();
header("Access-Control-Allow-Origin: *");
if (strtolower($_GET['format']) == 'plain') {
define("JSON", false);
header('Content-Type: text/plain');
} else {
define("JSON", true);
header('Content-Type: application/json');
}
// Composer
require 'vendor/autoload.php';
// API response formatters
require 'response.php';
// Settings file
require 'settings.php';
// Database settings
// Also inits database and stuff
$database;
try {
require 'dbsettings.php';
$database = new medoo([
'database_type' => DB_TYPE,
'database_name' => DB_NAME,
'server' => DB_SERVER,
'username' => DB_USER,
'password' => DB_PASS,
'charset' => DB_CHARSET
]);
} catch (Exception $ex) {
header('HTTP/1.1 500 Internal Server Error');
sendError('Database error. Try again later.', true);
@ -60,4 +71,4 @@ if (GET) {
*/
function is_empty($str) {
return (!isset($str) || $str == '' || $str == null);
}
}

@ -0,0 +1,10 @@
<?php
define("DB_TYPE", "mysql");
define("DB_NAME", "c0terranquest");
define("DB_SERVER", "localhost");
define("DB_USER", "c0terranquest");
define("DB_PASS", "qinkifTQ!OMY2");
define("DB_CHARSET", "latin1");
define("GEOCACHE_KEY", "z6BxjV5ssS7DYrzfF7pw");