From bcd69bab898d3b6cab7651b732db3927724ef569 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Tue, 29 Mar 2022 23:46:17 -0700 Subject: [PATCH] add option for suppressing commands --- src/ProxyServer.cc | 6 ++++-- src/ProxyServer.hh | 1 + src/ServerShell.cc | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/ProxyServer.cc b/src/ProxyServer.cc index 608f19da..f6f591c5 100644 --- a/src/ProxyServer.cc +++ b/src/ProxyServer.cc @@ -300,6 +300,7 @@ ProxyServer::LinkedSession::LinkedSession( sub_version(0), // This is set during resume() guild_card_number(0), newserv_client_config(newserv_client_config), + suppress_newserv_commands(true), lobby_players(12), lobby_client_id(0) { memset(this->remote_client_config_data, 0, 0x20); @@ -477,8 +478,9 @@ void ProxyServer::LinkedSession::on_client_input() { if (data.size() < 12) { break; } - // If this chat message looks like a chat command, suppress it - if (data[8] == '$' || (data[8] == '\t' && data[9] != 'C' && data[10] == '$')) { + // If this chat message looks like a newserv chat command, suppress it + if (this->suppress_newserv_commands && + (data[8] == '$' || (data[8] == '\t' && data[9] != 'C' && data[10] == '$'))) { log(WARNING, "[ProxyServer/%08" PRIX32 "] Chat message appears to be a server command; dropping it", this->license->serial_number); should_forward = false; diff --git a/src/ProxyServer.hh b/src/ProxyServer.hh index 52fa40fd..2f04a6d0 100644 --- a/src/ProxyServer.hh +++ b/src/ProxyServer.hh @@ -48,6 +48,7 @@ public: uint32_t guild_card_number; uint8_t remote_client_config_data[0x20]; ClientConfig newserv_client_config; + bool suppress_newserv_commands; struct LobbyPlayer { uint32_t guild_card_number; diff --git a/src/ServerShell.cc b/src/ServerShell.cc index ba0a7210..0272b35d 100644 --- a/src/ServerShell.cc +++ b/src/ServerShell.cc @@ -97,6 +97,11 @@ 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-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\ @@ -312,6 +317,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-safety") { + auto session = this->get_proxy_session(); + + if (command_args == "on") { + session->suppress_newserv_commands = true; + } else if (command_args == "off") { + session->suppress_newserv_commands = false; + } else { + throw invalid_argument("argument must be \"on\" or \"off\""); + } + } else if (command_name == "set-save-files") { if (this->state->proxy_server.get()) { if (command_args == "on") { @@ -321,6 +337,7 @@ Proxy commands (these will only work when exactly one client is connected):\n\ } else { throw invalid_argument("argument must be \"on\" or \"off\""); } + } else { throw invalid_argument("proxy server is not available"); }