Issue #2: Merge chat code into main game server, add nickname storage.

Also visually reorganized the database EER diagram to make it nicer.
master
Skylar Ittner 8 years ago
parent 4ad058d394
commit e3015f2ade

@ -0,0 +1,71 @@
<?php
/*
* 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';
require 'onlyloggedin.php';
use AnthonyMartin\GeoLocation\GeoLocation as GeoLocation;
if (!preg_match('/-?[0-9]{1,3}\.[0-9]{2,}/', $VARS['lat'])) {
sendError("Latitude (lat) is in the wrong format.", true);
}
if (!preg_match('/-?[0-9]{1,3}\.[0-9]{2,}/', $VARS['long'])) {
sendError("Longitude (long) is in the wrong format.", true);
}
if (GET) {
// Get messages
if (is_empty($VARS['lat']) || is_empty($VARS['long'])) {
sendError("Missing information.", true);
}
$radius = 50;
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');
//echo $searchbounds[0]->getLatitudeInDegrees();
//echo $searchbounds[0]->getLongitudeInDegrees();
//echo $searchbounds[1]->getLatitudeInDegrees();
//echo $searchbounds[1]->getLongitudeInDegrees();
$msgs = $database->select('messages', ["[>]players" => ["uuid" => "uuid"]], ['messages.uuid', 'messages.message', 'messages.time', 'players.nickname'], ['AND' => [
'lat[>]' => $searchbounds[0]->getLatitudeInDegrees(),
'lat[<]' => $searchbounds[1]->getLatitudeInDegrees(),
'long[>]' => $searchbounds[0]->getLongitudeInDegrees(),
'long[<]' => $searchbounds[1]->getLongitudeInDegrees()],
"ORDER" => "messages.time DESC",
"LIMIT" => 30
]);
echo json_encode($msgs);
} else {
// Post message
if (is_empty($VARS['lat']) || is_empty($VARS['long']) || is_empty($VARS['msg'])) {
sendError("Missing information.", true);
}
$msg = strip_tags($VARS['msg']);
$database->insert('messages', ['#time' => 'NOW()', 'uuid' => $_SESSION['uuid'], 'message' => $msg, 'lat' => $VARS['lat'], 'long' => $VARS['long']]);
sendOK();
}

Binary file not shown.

Binary file not shown.

@ -10,8 +10,12 @@ if (is_empty($VARS['pass'])) {
sendError("Missing password.", true);
}
/* Insert code to check login here, it should return "OK" or an error string */
/* ------------------------------- */
$logininfo = file_get_contents("https://sso.netsyms.com/api/simplehashauth.php?get=1&user=" . urlencode($VARS['user']) . "&pass=" . hash('sha1', $VARS['pass']));
/* ------------------------------- */
if ($logininfo != "OK") {
sendError(str_replace("Error: ", "", $logininfo), true);
}
@ -20,14 +24,12 @@ $guid = file_get_contents("https://sso.netsyms.com/api/getguid.php?user=" . urle
if (is_empty($guid)) {
sendError("Account does not exist.", true);
} else {
}
if ($database->has('players', ['uuid' => $guid])) {
sendOK();
} else {
$database->insert('players', ['uuid' => $guid, 'level' => 1.0, 'energy' => 100, 'maxenergy' => 100, '#lastping' => 'NOW()']);
$database->insert('players', ['uuid' => $guid, 'level' => 1.0, 'energy' => 100, 'maxenergy' => 100, '#lastping' => 'NOW()', 'nickname' => $VARS['user']]);
sendOK("Successfully synced Netsyms account to TerranQuest.");
ini_set("sendmail_from", "sso@netsyms.com");

@ -15,7 +15,7 @@ if (is_empty($guid)) {
if ($database->has('players', ['uuid' => $guid])) {
sendOK();
} else {
$database->insert('players', ['uuid' => $guid, 'level' => 1.0, 'energy' => 100, 'maxenergy' => 100, '#lastping' => 'NOW()']);
$database->insert('players', ['uuid' => $guid, 'level' => 1.0, 'energy' => 100, 'maxenergy' => 100, '#lastping' => 'NOW()', 'nickname' => $VARS['user']]);
sendOK("Successfully synced Netsyms account to TerranQuest.");
ini_set("sendmail_from", "sso@netsyms.com");