From b4ed31d4fb0b15cf36bc7b21eee1b2ac0af79ad2 Mon Sep 17 00:00:00 2001 From: Gent Semaj Date: Thu, 2 Jan 2025 17:18:53 -0500 Subject: [PATCH] Dedicated bcast monitor event --- src/Chat.cpp | 10 +++++++--- src/Chat.hpp | 1 + src/servers/Monitor.cpp | 9 +++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Chat.cpp b/src/Chat.cpp index 51d4222..eea03d1 100644 --- a/src/Chat.cpp +++ b/src/Chat.cpp @@ -9,6 +9,7 @@ #include std::vector Chat::dump; +std::vector Chat::bcasts; using namespace Chat; @@ -120,9 +121,12 @@ static void announcementHandler(CNSocket* sock, CNPacketData* data) { break; } - std::string logLine = "[Bcast " + std::to_string(announcement->iAreaType) + "] " + PlayerManager::getPlayerName(plr, false) + ": " + AUTOU16TOU8(msg.szAnnounceMsg); - std::cout << logLine << std::endl; - dump.push_back("**" + logLine + "**"); + std::string logLine = std::to_string(announcement->iAreaType) + " " + + std::to_string(announcement->iAnnounceType) + " " + + std::to_string(announcement->iDuringTime) + " " + + PlayerManager::getPlayerName(plr, false) + ": " + AUTOU16TOU8(msg.szAnnounceMsg); + std::cout << "Broadcast " << logLine << std::endl; + bcasts.push_back(logLine); } // Buddy freechatting diff --git a/src/Chat.hpp b/src/Chat.hpp index 26b4236..0dff714 100644 --- a/src/Chat.hpp +++ b/src/Chat.hpp @@ -9,6 +9,7 @@ namespace Chat { extern std::vector dump; + extern std::vector bcasts; void init(); void sendServerMessage(CNSocket* sock, std::string msg); // uses MOTD diff --git a/src/servers/Monitor.cpp b/src/servers/Monitor.cpp index 687eab1..092ffc5 100644 --- a/src/servers/Monitor.cpp +++ b/src/servers/Monitor.cpp @@ -106,6 +106,14 @@ outer: goto outer; } + // announcements + for (auto& str : Chat::bcasts) { + n = std::snprintf(buff, sizeof(buff), "bcast %s\n", str.c_str()); + + if (!transmit(it, buff, n)) + goto outer; + } + // emails for (auto& str : Email::dump) { n = process_email(buff, str); @@ -124,6 +132,7 @@ outer: } Chat::dump.clear(); + Chat::bcasts.clear(); Email::dump.clear(); }