Add private messaging (closes #8), add more formatting options to chat

names, add multi-server list for clients to choose from
master
Skylar Ittner 7 years ago
parent 88175dbe9d
commit 89fb2fc69b

@ -69,8 +69,10 @@ if (is_empty($VARS['msg'])) {
$msgs[$key]['uuid'] = "0"; $msgs[$key]['uuid'] = "0";
$msgs[$key]['nickname'] = "SERVER MESSAGE"; $msgs[$key]['nickname'] = "SERVER MESSAGE";
$msgs[$key]['color'] = CHAT_ADMIN_COLOR; $msgs[$key]['color'] = CHAT_ADMIN_COLOR;
$msgs[$key]['css'] = CHAT_ADMIN_CSS;
} else if (in_array($msg['nickname'], CHAT_ADMINS)) { } else if (in_array($msg['nickname'], CHAT_ADMINS)) {
$msgs[$key]['color'] = CHAT_ADMIN_COLOR; $msgs[$key]['color'] = CHAT_ADMIN_COLOR;
$msgs[$key]['css'] = CHAT_ADMIN_CSS;
} }
} }
@ -85,6 +87,18 @@ if (is_empty($VARS['msg'])) {
$msg = strip_tags($VARS['msg']); $msg = strip_tags($VARS['msg']);
preg_match_all("/\@\w+/", $msg, $search, PREG_PATTERN_ORDER);
$privmsgto = $search[0];
foreach ($privmsgto as $to) {
$name = str_replace("@", "", $to); // Remove leading @
if ($database->has('players', ['nickname' => $name])) {
echo $name;
$touuid = $database->select('players', ['uuid'], ['nickname' => $name])[0]['uuid'];
echo $touuid;
$database->insert('private_messages', ['#time' => 'NOW()', 'message' => $msg, 'from_uuid' => $_SESSION['uuid'], 'to_uuid' => $touuid]);
}
}
$database->insert('messages', ['#time' => 'NOW()', 'uuid' => $_SESSION['uuid'], 'message' => $msg, 'lat' => $VARS['lat'], 'long' => $VARS['long']]); $database->insert('messages', ['#time' => 'NOW()', 'uuid' => $_SESSION['uuid'], 'message' => $msg, 'lat' => $VARS['lat'], 'long' => $VARS['long']]);
sendOK(); sendOK();

@ -0,0 +1,20 @@
<?php
/*
* Send the client a list of servers that share the database. The client should
* pick one at random and use it for the entire session.
*/
require 'required.php';
$servers = [];
if (is_empty(SERVER_URLS) || SERVER_URLS == []) {
$servers[] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
} else {
foreach (SERVER_URLS as $server) {
$servers[] = $server;
}
}
die(json_encode($servers));

18
composer.lock generated

@ -9,16 +9,16 @@
"packages": [ "packages": [
{ {
"name": "anthonymartin/geo-location", "name": "anthonymartin/geo-location",
"version": "v1.0.0", "version": "v1.0.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/anthonymartin/GeoLocation.php.git", "url": "https://github.com/anthonymartin/GeoLocation.php.git",
"reference": "a54a562dfe8ae3eef9a5863552401d26bc80e921" "reference": "50bf026f069296dfae11aa195d987854b2e75855"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/anthonymartin/GeoLocation.php/zipball/a54a562dfe8ae3eef9a5863552401d26bc80e921", "url": "https://api.github.com/repos/anthonymartin/GeoLocation.php/zipball/50bf026f069296dfae11aa195d987854b2e75855",
"reference": "a54a562dfe8ae3eef9a5863552401d26bc80e921", "reference": "50bf026f069296dfae11aa195d987854b2e75855",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -50,7 +50,7 @@
"geocoding", "geocoding",
"geolocation" "geolocation"
], ],
"time": "2013-10-25 21:13:03" "time": "2016-09-17 18:05:14"
}, },
{ {
"name": "catfan/medoo", "name": "catfan/medoo",
@ -58,12 +58,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/catfan/Medoo.git", "url": "https://github.com/catfan/Medoo.git",
"reference": "342e2d6a3bcf4adcac58e67593d63547139ab1ac" "reference": "2601ffd53971866695c544c955d580d3d36b3848"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/catfan/Medoo/zipball/342e2d6a3bcf4adcac58e67593d63547139ab1ac", "url": "https://api.github.com/repos/catfan/Medoo/zipball/2601ffd53971866695c544c955d580d3d36b3848",
"reference": "342e2d6a3bcf4adcac58e67593d63547139ab1ac", "reference": "2601ffd53971866695c544c955d580d3d36b3848",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -105,7 +105,7 @@
"sql", "sql",
"sqlite" "sqlite"
], ],
"time": "2016-02-14 16:03:42" "time": "2016-09-05 07:18:35"
} }
], ],
"packages-dev": [], "packages-dev": [],

Binary file not shown.

@ -1,7 +1,7 @@
include.path=${php.global.include.path} include.path=${php.global.include.path}
php.version=PHP_54 php.version=PHP_70
source.encoding=UTF-8 source.encoding=UTF-8
src.dir=. src.dir=.
tags.asp=false tags.asp=false
tags.short=false tags.short=false
web.root=. web.root=.

@ -0,0 +1,50 @@
<?php
require 'required.php';
require 'onlyloggedin.php';
if (!is_empty($VARS['markread'])) {
if (preg_match("/[0-9]+/", $VARS['markread'])) {
$database->update('private_messages', ['msg_read' => 1], [
'AND' => [
"id" => $VARS['markread'],
"to_uuid" => $_SESSION['uuid']
]]);
sendOK();
} else {
sendError("Malformed input.", true);
}
} else if (!is_empty($VARS['delete'])) {
if (preg_match("/[0-9]+/", $VARS['delete'])) {
$database->delete('private_messages', [
'AND' => [
"id" => $VARS['delete'],
"to_uuid" => $_SESSION['uuid']
]]);
sendOK();
} else {
sendError("Malformed input.", true);
}
} else {
$where = [
"private_messages.to_uuid" => $_SESSION['uuid']
];
if ($VARS['filter'] == 'read') {
$where["msg_read"] = 1;
} else if ($VARS['filter'] == 'unread') {
$where["msg_read"] = 0;
}
$out = ["status" => "OK", "msgs" => []];
$out['msgs'] = $database->select('private_messages', [
"[>]players" => [
"from_uuid" => "uuid"
]
], [
'private_messages.id', 'private_messages.message', 'private_messages.time', 'players.nickname', 'private_messages.msg_read'
], [
'AND' => $where,
"ORDER" => "private_messages.time DESC"]
);
echo json_encode($out);
}

@ -3,6 +3,10 @@
define("DEBUG", false); define("DEBUG", false);
define("BETA_MODE", false); define("BETA_MODE", false);
// A list of server addresses that can be used by the client.
// See cluster.php for details.
define("SERVER_URLS", []);
define("DB_TYPE", "mysql"); define("DB_TYPE", "mysql");
define("DB_NAME", ""); define("DB_NAME", "");
define("DB_SERVER", ""); define("DB_SERVER", "");
@ -31,6 +35,8 @@ define("DARKSKY_APIKEY", "");
define("CHAT_ADMINS", ["admin"]); define("CHAT_ADMINS", ["admin"]);
// Color for chat admin names. Accepts any HTML named color or hexcode (#ff0000) // Color for chat admin names. Accepts any HTML named color or hexcode (#ff0000)
define("CHAT_ADMIN_COLOR", "red"); define("CHAT_ADMIN_COLOR", "red");
// CSS styles for chat admin username. Default is "font-weight: bold;".
define("CHAT_ADMIN_CSS", "");
// Admin control panel login // Admin control panel login
define("ADMIN_USER", ""); define("ADMIN_USER", "");