From acbebaeb70ebabe2964cf0516c15af84953532e2 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Sun, 31 Mar 2024 09:56:30 -0700 Subject: [PATCH] use scrolling message for rare and max level announcements on BB --- src/ReceiveSubcommands.cc | 9 ++++++--- src/SendCommands.cc | 25 +++++++++++++++++++++++++ src/SendCommands.hh | 4 ++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/ReceiveSubcommands.cc b/src/ReceiveSubcommands.cc index 91cc9ae4..f646a15c 100644 --- a/src/ReceiveSubcommands.cc +++ b/src/ReceiveSubcommands.cc @@ -2005,17 +2005,18 @@ static void on_pick_up_item_generic( string p_name = p->disp.name.decode(); string desc = s->describe_item(c->version(), fi->data, true); string message = string_printf("$C6%s$C7 found\n%s", p_name.c_str(), desc.c_str()); + string bb_message = string_printf("$C6%s$C7 has found %s", p_name.c_str(), desc.c_str()); if (should_send_global_notif) { for (auto& it : s->channel_to_client) { if (it.second->license && !is_patch(it.second->version()) && !is_ep3(it.second->version()) && it.second->lobby.lock()) { - send_text_message(it.second, message); + send_text_or_scrolling_message(it.second, message, bb_message); } } } else { - send_text_message(l, message); + send_text_or_scrolling_message(l, nullptr, message, bb_message); } } } @@ -3150,9 +3151,11 @@ static void send_max_level_notification_if_needed(shared_ptr c) { size_t level_for_str = max_level + 1; string message = string_printf("$CG%s$C6\nGC: %" PRIu32 "\nhas reached Level $CG%zu", name.c_str(), c->license->serial_number, level_for_str); + string bb_message = string_printf("$CG%s$C6 (GC: %" PRIu32 ") has reached Level $CG%zu", + name.c_str(), c->license->serial_number, level_for_str); for (auto& it : s->channel_to_client) { if ((it.second != c) && it.second->license && !is_patch(it.second->version()) && it.second->lobby.lock()) { - send_text_message(it.second, message); + send_text_or_scrolling_message(it.second, message, bb_message); } } } diff --git a/src/SendCommands.cc b/src/SendCommands.cc index 70ca9b23..0afca9f2 100644 --- a/src/SendCommands.cc +++ b/src/SendCommands.cc @@ -884,6 +884,31 @@ __attribute__((format(printf, 2, 3))) void send_ep3_text_message_printf(shared_p } } +void send_scrolling_message_bb(shared_ptr c, const string& text) { + if (c->version() != Version::BB_V4) { + throw logic_error("cannot send scrolling message to non-BB player"); + } + send_header_text(c->channel, 0x00EE, 0, text, ColorMode::ADD); +} + +void send_text_or_scrolling_message(shared_ptr c, const string& text, const string& scrolling) { + if (is_v4(c->version())) { + send_scrolling_message_bb(c, scrolling); + } else { + send_text_message(c, text); + } +} + +void send_text_or_scrolling_message( + std::shared_ptr l, std::shared_ptr exclude_c, const std::string& text, const std::string& scrolling) { + for (const auto& lc : l->clients) { + if (!lc || (lc == exclude_c)) { + continue; + } + send_text_or_scrolling_message(lc, text, scrolling); + } +} + string prepare_chat_data( Version version, uint8_t language, diff --git a/src/SendCommands.hh b/src/SendCommands.hh index c22a8896..73ad33f3 100644 --- a/src/SendCommands.hh +++ b/src/SendCommands.hh @@ -191,6 +191,10 @@ void send_text_message(Channel& ch, const std::string& text); void send_text_message(std::shared_ptr c, const std::string& text); void send_text_message(std::shared_ptr l, const std::string& text); void send_text_message(std::shared_ptr s, const std::string& text); +void send_scrolling_message_bb(std::shared_ptr c, const std::string& text); +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); std::string prepare_chat_data( Version version,