add sender's name to $ann message; closes #547

This commit is contained in:
Martin Michelsen
2024-10-21 22:58:41 -07:00
parent a9a15600b2
commit e5afc1d937
4 changed files with 43 additions and 10 deletions
+2 -2
View File
@@ -618,8 +618,8 @@ Some commands only work on the game server and not on the proxy server. The chat
* `$song <song-id>` (Episode 3 only): Play a specific song in the current lobby.
* Administration commands (game server only)
* `$ann <message>`: Send an announcement message. The message is sent as temporary on-screen text to all players in all games and lobbies.
* `$ann! <message>`: Send an announcement message. The message is sent as a Simple Mail message to all players in all games and lobbies.
* `$ann <message>`: 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 <message>`: Send a message to the server's terminal. This cannot be used to run server shell commands; it only prints text to stderr.
* `$silence <identifier>`: 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 <identifier>`: Disconnect a player. The identifier may be the player's name or Guild Card number.
+32 -8
View File
@@ -270,16 +270,37 @@ static void server_command_ax(shared_ptr<Client> c, const std::string& args) {
ax_messages_log.info("%s", args.c_str());
}
static void server_command_announce(shared_ptr<Client> c, const std::string& args) {
static void server_command_announce_inner(shared_ptr<Client> 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<Client> 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<Client> c, const std::string& args) {
server_command_announce_inner(c, args, false, false);
}
static void server_command_announce_anonymous(shared_ptr<Client> c, const std::string& args) {
server_command_announce_inner(c, args, false, true);
}
static void server_command_announce_mail_named(shared_ptr<Client> c, const std::string& args) {
server_command_announce_inner(c, args, true, false);
}
static void server_command_announce_mail_anonymous(shared_ptr<Client> c, const std::string& args) {
server_command_announce_inner(c, args, true, true);
}
static void server_command_arrow(shared_ptr<Client> c, const std::string& args) {
@@ -2585,8 +2606,11 @@ struct ChatCommandDefinition {
static const unordered_map<string, ChatCommandDefinition> 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}},
+8
View File
@@ -953,6 +953,14 @@ void send_text_or_scrolling_message(
}
}
void send_text_or_scrolling_message(shared_ptr<ServerState> 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,
+1
View File
@@ -214,6 +214,7 @@ void send_scrolling_message_bb(std::shared_ptr<Client> c, const std::string& tex
void send_text_or_scrolling_message(std::shared_ptr<Client> c, const std::string& text, const std::string& scrolling);
void send_text_or_scrolling_message(
std::shared_ptr<Lobby> l, std::shared_ptr<Client> exclude_c, const std::string& text, const std::string& scrolling);
void send_text_or_scrolling_message(std::shared_ptr<ServerState> s, const std::string& text, const std::string& scrolling);
std::string prepare_chat_data(
Version version,