From d9a554beb3eeee51bee0e4b618c1b76aa1899fb7 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Wed, 30 Mar 2022 00:51:30 -0700 Subject: [PATCH] add chat filter proxy option --- src/ProxyServer.cc | 3 ++- src/ProxyServer.hh | 1 + src/ServerShell.cc | 23 ++++++++++++++++++++--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/ProxyServer.cc b/src/ProxyServer.cc index f6f591c5..15ee512e 100644 --- a/src/ProxyServer.cc +++ b/src/ProxyServer.cc @@ -301,6 +301,7 @@ ProxyServer::LinkedSession::LinkedSession( guild_card_number(0), newserv_client_config(newserv_client_config), suppress_newserv_commands(true), + enable_chat_filter(true), lobby_players(12), lobby_client_id(0) { memset(this->remote_client_config_data, 0, 0x20); @@ -484,7 +485,7 @@ void ProxyServer::LinkedSession::on_client_input() { log(WARNING, "[ProxyServer/%08" PRIX32 "] Chat message appears to be a server command; dropping it", this->license->serial_number); should_forward = false; - } else { + } else if (this->enable_chat_filter) { // Turn all $ into \t and all # into \n add_color_inplace(data.data() + 8, data.size() - 8); } diff --git a/src/ProxyServer.hh b/src/ProxyServer.hh index 2f04a6d0..9664cc96 100644 --- a/src/ProxyServer.hh +++ b/src/ProxyServer.hh @@ -49,6 +49,7 @@ public: uint8_t remote_client_config_data[0x20]; ClientConfig newserv_client_config; bool suppress_newserv_commands; + bool enable_chat_filter; struct LobbyPlayer { uint32_t guild_card_number; diff --git a/src/ServerShell.cc b/src/ServerShell.cc index 0272b35d..abe8871f 100644 --- a/src/ServerShell.cc +++ b/src/ServerShell.cc @@ -97,15 +97,21 @@ Proxy commands (these will only work when exactly one client is connected):\n\ Send a lobby event update to yourself.\n\ warp \n\ Send yourself to a specific area.\n\ + set-chat-filter \n\ + Enable or disable chat filtering (enabled by default). Chat filtering\n\ + applies newserv\'s standard character replacements to chat messages (for\n\ + example, $ becomes a tab character and # becomes a newline).\n\ set-chat-safety \n\ Enable or disable chat safety (enabled by default). When chat safety is on,\n\ all chat messages that begin with a $ are not sent to the remote server.\n\ This can prevent embarrassing situations if the remote server isn\'t a\n\ newserv instance and you have newserv commands in your chat shortcuts.\n\ set-save-files \n\ - Enable or disable saving of game files. When this is on, any file that the\n\ - remote server sends to the client will be saved to the current directory.\n\ - This includes data like quests, Episode 3 card definitions, and GBA games.\n\ + Enable or disable saving of game files (disabled by default). When this is\n\ + on, any file that the remote server sends to the client will be saved to\n\ + the current directory. This includes data like quests, Episode 3 card\n\ + definitions, and GBA games. Unlike other proxy commands, this command\n\ + affects all proxy sessions.\n\ "); @@ -317,6 +323,17 @@ Proxy commands (these will only work when exactly one client is connected):\n\ session->send_to_end(data, true); + } else if (command_name == "set-chat-filter") { + auto session = this->get_proxy_session(); + + if (command_args == "on") { + session->enable_chat_filter = true; + } else if (command_args == "off") { + session->enable_chat_filter = false; + } else { + throw invalid_argument("argument must be \"on\" or \"off\""); + } + } else if (command_name == "set-chat-safety") { auto session = this->get_proxy_session();