From e5afc1d9378a28bf218d200527c7a457f6febc35 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Mon, 21 Oct 2024 22:58:41 -0700 Subject: [PATCH] add sender's name to $ann message; closes #547 --- README.md | 4 ++-- src/ChatCommands.cc | 40 ++++++++++++++++++++++++++++++++-------- src/SendCommands.cc | 8 ++++++++ src/SendCommands.hh | 1 + 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index bf3e1448..2def0139 100644 --- a/README.md +++ b/README.md @@ -618,8 +618,8 @@ Some commands only work on the game server and not on the proxy server. The chat * `$song ` (Episode 3 only): Play a specific song in the current lobby. * Administration commands (game server only) - * `$ann `: Send an announcement message. The message is sent as temporary on-screen text to all players in all games and lobbies. - * `$ann! `: Send an announcement message. The message is sent as a Simple Mail message to all players in all games and lobbies. + * `$ann `: Send an announcement message. The message is sent as temporary on-screen text to all players in all games and lobbies. On BB, the message appears in the scrolling top bar. + * `$ann!`, `$ann?`, `$ann?!`: Same as `$ann`, but with `?`, omits the sender's name, and with `!`, sends the message as a Simple Mail message instead of on-screen text. * `$ax `: Send a message to the server's terminal. This cannot be used to run server shell commands; it only prints text to stderr. * `$silence `: Silence a player (remove their ability to chat) or unsilence a player. The identifier may be the player's name or Guild Card number. * `$kick `: Disconnect a player. The identifier may be the player's name or Guild Card number. diff --git a/src/ChatCommands.cc b/src/ChatCommands.cc index 8e4265d5..a3f0b79f 100644 --- a/src/ChatCommands.cc +++ b/src/ChatCommands.cc @@ -270,16 +270,37 @@ static void server_command_ax(shared_ptr c, const std::string& args) { ax_messages_log.info("%s", args.c_str()); } -static void server_command_announce(shared_ptr c, const std::string& args) { +static void server_command_announce_inner(shared_ptr c, const std::string& args, bool mail, bool anonymous) { auto s = c->require_server_state(); check_account_flag(c, Account::Flag::ANNOUNCE); - send_text_message(s, args); + if (anonymous) { + if (mail) { + send_simple_mail(s, 0, s->name, args); + } else { + send_text_or_scrolling_message(s, args, args); + } + } else { + auto from_name = c->character()->disp.name.decode(c->language()); + if (mail) { + send_simple_mail(s, 0, from_name, args); + } else { + auto message = from_name + ": " + args; + send_text_or_scrolling_message(s, message, message); + } + } } -static void server_command_announce_mail(shared_ptr c, const std::string& args) { - auto s = c->require_server_state(); - check_account_flag(c, Account::Flag::ANNOUNCE); - send_simple_mail(s, 0, s->name, args); +static void server_command_announce_named(shared_ptr c, const std::string& args) { + server_command_announce_inner(c, args, false, false); +} +static void server_command_announce_anonymous(shared_ptr c, const std::string& args) { + server_command_announce_inner(c, args, false, true); +} +static void server_command_announce_mail_named(shared_ptr c, const std::string& args) { + server_command_announce_inner(c, args, true, false); +} +static void server_command_announce_mail_anonymous(shared_ptr c, const std::string& args) { + server_command_announce_inner(c, args, true, true); } static void server_command_arrow(shared_ptr c, const std::string& args) { @@ -2585,8 +2606,11 @@ struct ChatCommandDefinition { static const unordered_map chat_commands({ {"$allevent", {server_command_lobby_event_all, nullptr}}, - {"$ann", {server_command_announce, nullptr}}, - {"$ann!", {server_command_announce_mail, nullptr}}, + {"$ann", {server_command_announce_named, nullptr}}, + {"$ann?", {server_command_announce_anonymous, nullptr}}, + {"$ann!", {server_command_announce_mail_named, nullptr}}, + {"$ann?!", {server_command_announce_mail_anonymous, nullptr}}, + {"$ann!?", {server_command_announce_mail_anonymous, nullptr}}, {"$announcerares", {server_command_toggle_rare_announce, nullptr}}, {"$arrow", {server_command_arrow, proxy_command_arrow}}, {"$auction", {server_command_auction, proxy_command_auction}}, diff --git a/src/SendCommands.cc b/src/SendCommands.cc index 88e94d23..276d0fac 100644 --- a/src/SendCommands.cc +++ b/src/SendCommands.cc @@ -953,6 +953,14 @@ void send_text_or_scrolling_message( } } +void send_text_or_scrolling_message(shared_ptr s, const std::string& text, const std::string& scrolling) { + for (const auto& it : s->channel_to_client) { + if (it.second->login && !is_patch(it.second->version())) { + send_text_or_scrolling_message(it.second, text, scrolling); + } + } +} + string prepare_chat_data( Version version, uint8_t language, diff --git a/src/SendCommands.hh b/src/SendCommands.hh index 2b46503f..8865ec06 100644 --- a/src/SendCommands.hh +++ b/src/SendCommands.hh @@ -214,6 +214,7 @@ void send_scrolling_message_bb(std::shared_ptr c, const std::string& tex void send_text_or_scrolling_message(std::shared_ptr c, const std::string& text, const std::string& scrolling); void send_text_or_scrolling_message( std::shared_ptr l, std::shared_ptr exclude_c, const std::string& text, const std::string& scrolling); +void send_text_or_scrolling_message(std::shared_ptr s, const std::string& text, const std::string& scrolling); std::string prepare_chat_data( Version version,