diff --git a/chat.php b/chat.php index 63412a4..47c6fb7 100644 --- a/chat.php +++ b/chat.php @@ -69,8 +69,10 @@ if (is_empty($VARS['msg'])) { $msgs[$key]['uuid'] = "0"; $msgs[$key]['nickname'] = "SERVER MESSAGE"; $msgs[$key]['color'] = CHAT_ADMIN_COLOR; + $msgs[$key]['css'] = CHAT_ADMIN_CSS; } else if (in_array($msg['nickname'], CHAT_ADMINS)) { $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']); + 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']]); sendOK(); diff --git a/cluster.php b/cluster.php new file mode 100644 index 0000000..6da338c --- /dev/null +++ b/cluster.php @@ -0,0 +1,20 @@ +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); +} \ No newline at end of file diff --git a/settings.template.php b/settings.template.php index 596c14b..2eb6ee7 100644 --- a/settings.template.php +++ b/settings.template.php @@ -3,6 +3,10 @@ define("DEBUG", 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_NAME", ""); define("DB_SERVER", ""); @@ -31,6 +35,8 @@ define("DARKSKY_APIKEY", ""); define("CHAT_ADMINS", ["admin"]); // Color for chat admin names. Accepts any HTML named color or hexcode (#ff0000) define("CHAT_ADMIN_COLOR", "red"); +// CSS styles for chat admin username. Default is "font-weight: bold;". +define("CHAT_ADMIN_CSS", ""); // Admin control panel login define("ADMIN_USER", "");