add option for suppressing commands

This commit is contained in:
Martin Michelsen
2022-03-29 23:46:17 -07:00
parent 5848beb6c2
commit bcd69bab89
3 changed files with 22 additions and 2 deletions
+4 -2
View File
@@ -300,6 +300,7 @@ ProxyServer::LinkedSession::LinkedSession(
sub_version(0), // This is set during resume() sub_version(0), // This is set during resume()
guild_card_number(0), guild_card_number(0),
newserv_client_config(newserv_client_config), newserv_client_config(newserv_client_config),
suppress_newserv_commands(true),
lobby_players(12), lobby_players(12),
lobby_client_id(0) { lobby_client_id(0) {
memset(this->remote_client_config_data, 0, 0x20); memset(this->remote_client_config_data, 0, 0x20);
@@ -477,8 +478,9 @@ void ProxyServer::LinkedSession::on_client_input() {
if (data.size() < 12) { if (data.size() < 12) {
break; break;
} }
// If this chat message looks like a chat command, suppress it // If this chat message looks like a newserv chat command, suppress it
if (data[8] == '$' || (data[8] == '\t' && data[9] != 'C' && data[10] == '$')) { 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", log(WARNING, "[ProxyServer/%08" PRIX32 "] Chat message appears to be a server command; dropping it",
this->license->serial_number); this->license->serial_number);
should_forward = false; should_forward = false;
+1
View File
@@ -48,6 +48,7 @@ public:
uint32_t guild_card_number; uint32_t guild_card_number;
uint8_t remote_client_config_data[0x20]; uint8_t remote_client_config_data[0x20];
ClientConfig newserv_client_config; ClientConfig newserv_client_config;
bool suppress_newserv_commands;
struct LobbyPlayer { struct LobbyPlayer {
uint32_t guild_card_number; uint32_t guild_card_number;
+17
View File
@@ -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\ Send a lobby event update to yourself.\n\
warp <area-id>\n\ warp <area-id>\n\
Send yourself to a specific area.\n\ Send yourself to a specific area.\n\
set-chat-safety <on|off>\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 <on|off>\n\ set-save-files <on|off>\n\
Enable or disable saving of game files. When this is on, any file that the\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\ 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); 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") { } else if (command_name == "set-save-files") {
if (this->state->proxy_server.get()) { if (this->state->proxy_server.get()) {
if (command_args == "on") { if (command_args == "on") {
@@ -321,6 +337,7 @@ Proxy commands (these will only work when exactly one client is connected):\n\
} else { } else {
throw invalid_argument("argument must be \"on\" or \"off\""); throw invalid_argument("argument must be \"on\" or \"off\"");
} }
} else { } else {
throw invalid_argument("proxy server is not available"); throw invalid_argument("proxy server is not available");
} }