From a469b4355e6d272e66ae31a0600cc7ff6d26d172 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Sun, 4 Jan 2026 00:32:46 -0800 Subject: [PATCH] add option to change chat command character --- src/ChatCommands.cc | 6 +++--- src/ProxyCommands.cc | 5 ++++- src/ReceiveCommands.cc | 5 ++++- src/ServerState.cc | 8 ++++++++ src/ServerState.hh | 1 + system/config.example.json | 4 ++++ 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/ChatCommands.cc b/src/ChatCommands.cc index 4857683a..41cfd76d 100644 --- a/src/ChatCommands.cc +++ b/src/ChatCommands.cc @@ -3183,9 +3183,9 @@ struct SplitCommand { asio::awaitable on_chat_command(std::shared_ptr c, const std::string& text, bool check_permissions) { SplitCommand cmd(text); - // This function is only called by on_06 if it looks like a chat command (starts with $, or @ on 11/2000), so we just - // normalize all commands to $ here - if (!cmd.name.empty() && cmd.name[0] == '@') { + // This function is only called by on_06 if it looks like a chat command (starts with $, or @ on 11/2000, or + // s->chat_command_sentinel if overridden), so we just normalize all commands to $ here + if (!cmd.name.empty()) { cmd.name[0] = '$'; } diff --git a/src/ProxyCommands.cc b/src/ProxyCommands.cc index 51aaae56..73b0481d 100644 --- a/src/ProxyCommands.cc +++ b/src/ProxyCommands.cc @@ -1972,7 +1972,10 @@ static asio::awaitable C_06(shared_ptr c, Channel::Messag co_return HandlerResult::FORWARD; } - char command_sentinel = (c->version() == Version::DC_11_2000) ? '@' : '$'; + auto s = c->require_server_state(); + char command_sentinel = s->chat_command_sentinel + ? s->chat_command_sentinel + : ((c->version() == Version::DC_11_2000) ? '@' : '$'); bool is_command = (text[0] == command_sentinel) || (text[0] == '\t' && text[1] != 'C' && text[2] == command_sentinel); if (is_command && c->check_flag(Client::Flag::PROXY_CHAT_COMMANDS_ENABLED)) { diff --git a/src/ReceiveCommands.cc b/src/ReceiveCommands.cc index 94ba8972..339f58fb 100644 --- a/src/ReceiveCommands.cc +++ b/src/ReceiveCommands.cc @@ -3628,7 +3628,10 @@ static asio::awaitable on_06(shared_ptr c, Channel::Message& msg) co_return; } - char command_sentinel = (c->version() == Version::DC_11_2000) ? '@' : '$'; + auto s = c->require_server_state(); + char command_sentinel = s->chat_command_sentinel + ? s->chat_command_sentinel + : ((c->version() == Version::DC_11_2000) ? '@' : '$'); if ((text[0] == command_sentinel) && c->can_use_chat_commands()) { if (text[1] == command_sentinel) { text = text.substr(1); diff --git a/src/ServerState.cc b/src/ServerState.cc index 8d4884c4..c4047633 100644 --- a/src/ServerState.cc +++ b/src/ServerState.cc @@ -1114,6 +1114,14 @@ void ServerState::load_config_early() { } this->enable_chat_commands = this->config_json->get_bool("EnableChatCommands", true); + try { + const auto& s = this->config_json->get_string("ChatCommandSentinel"); + if (s.size() != 1) { + throw std::runtime_error("ChatCommandSentinel must be a string of length 1"); + } + this->chat_command_sentinel = s[0]; + } catch (const std::out_of_range&) { + } this->num_backup_character_slots = this->config_json->get_int("BackupCharacterSlots", 16); this->version_name_colors.reset(); diff --git a/src/ServerState.hh b/src/ServerState.hh index b539e470..3221f15c 100644 --- a/src/ServerState.hh +++ b/src/ServerState.hh @@ -115,6 +115,7 @@ struct ServerState : public std::enable_shared_from_this { bool use_temp_accounts_for_prototypes = true; std::array compatibility_groups = {}; bool enable_chat_commands = true; + char chat_command_sentinel = '\0'; // 0 = default (@ on 11/2000; $ on all other versions) size_t num_backup_character_slots = 16; std::unique_ptr> version_name_colors; uint32_t client_customization_name_color = 0x00000000; diff --git a/system/config.example.json b/system/config.example.json index 998082e6..e9248f2a 100644 --- a/system/config.example.json +++ b/system/config.example.json @@ -279,6 +279,10 @@ // use chat commands. "EnableChatCommands": true, + // Sentinel to use for chat commands. If this is specified, chat commands are + // prefixed by this character instead of $. + // "ChatCommandSentinel": "/", + // Number of backup character slots for each account, accessible with the // $savechar, $loadchar, and $checkchar commands. This can be any value, but // it's recommended to use a small number such as 16.