From d03c4f109f56b89eb2a56e741d9b81c442478892 Mon Sep 17 00:00:00 2001 From: Gent S Date: Tue, 15 Dec 2020 09:58:11 -0500 Subject: [PATCH] Add chat dump to monitor --- src/ChatManager.cpp | 4 ++++ src/ChatManager.hpp | 1 + src/Monitor.cpp | 12 ++++++++++++ 3 files changed, 17 insertions(+) diff --git a/src/ChatManager.cpp b/src/ChatManager.cpp index 6bd104e..108d2fe 100644 --- a/src/ChatManager.cpp +++ b/src/ChatManager.cpp @@ -14,6 +14,7 @@ #include std::map ChatManager::commands; +std::vector ChatManager::dump; std::vector parseArgs(std::string full) { std::stringstream ss(full); @@ -815,6 +816,7 @@ void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) { std::string fullChat = sanitizeText(U16toU8(chat->szFreeChat)); std::cout << "[FreeChat] " << PlayerManager::getPlayerName(plr, false) << ": " << fullChat << std::endl; + dump.push_back(PlayerManager::getPlayerName(plr, true) + ": " + fullChat); if (fullChat.length() > 1 && fullChat[0] == CMD_PREFIX) { // PREFIX runCmd(fullChat, sock); @@ -844,6 +846,7 @@ void ChatManager::menuChatHandler(CNSocket* sock, CNPacketData* data) { std::string fullChat = sanitizeText(U16toU8(chat->szFreeChat)); std::cout << "[MenuChat] " << PlayerManager::getPlayerName(plr, false) << ": " << fullChat << std::endl; + dump.push_back(PlayerManager::getPlayerName(plr, true) + ": " + fullChat); // send to client INITSTRUCT(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, resp); @@ -921,6 +924,7 @@ void ChatManager::announcementHandler(CNSocket* sock, CNPacketData* data) { } std::cout << "[Bcast " << announcement->iAreaType << "] " << PlayerManager::getPlayerName(plr, false) << ": " << U16toU8(msg.szAnnounceMsg) << std::endl; + dump.push_back("**" + PlayerManager::getPlayerName(plr, true) + ": " + U16toU8(msg.szAnnounceMsg) + "**"); } // we only allow plain ascii, at least for now diff --git a/src/ChatManager.hpp b/src/ChatManager.hpp index b8d06ee..d6c825c 100644 --- a/src/ChatManager.hpp +++ b/src/ChatManager.hpp @@ -18,6 +18,7 @@ struct ChatCommand { namespace ChatManager { extern std::map commands; + extern std::vector dump; void init(); void registerCommand(std::string cmd, int requiredLevel, CommandHandler handlr, std::string help = ""); diff --git a/src/Monitor.cpp b/src/Monitor.cpp index bc0b333..fe99182 100644 --- a/src/Monitor.cpp +++ b/src/Monitor.cpp @@ -1,5 +1,6 @@ #include "CNShardServer.hpp" #include "PlayerManager.hpp" +#include "ChatManager.hpp" #include "CNStructs.hpp" #include "Monitor.hpp" #include "settings.hpp" @@ -102,6 +103,7 @@ outer: if (!transmit(it, (char*)"begin\n", 6)) continue; + // player for (auto& pair : PlayerManager::players) { if (pair.second->hidden) continue; @@ -114,11 +116,21 @@ outer: goto outer; } + // chat + for (auto& str : ChatManager::dump) { + n = std::snprintf(buff, sizeof(buff), "chat %s\n", str.c_str()); + + if (!transmit(it, buff, n)) + goto outer; + } + if (!transmit(it, (char*)"end\n", 4)) continue; it++; } + + ChatManager::dump.clear(); } bool Monitor::acceptConnection(SOCKET fd, uint16_t revents) {