diff --git a/common/ruletypes.h b/common/ruletypes.h index 82c4f9ecc..a3ec71a47 100644 --- a/common/ruletypes.h +++ b/common/ruletypes.h @@ -727,6 +727,7 @@ RULE_CATEGORY_END() RULE_CATEGORY(Logging) RULE_BOOL(Logging, PrintFileFunctionAndLine, false, "Ex: [World Server] [net.cpp::main:309] Loading variables...") +RULE_BOOL(Logging, WorldGMSayLogging, true, "Relay worldserver logging to zone processes via GM say output") RULE_CATEGORY_END() RULE_CATEGORY(HotReload) diff --git a/world/main.cpp b/world/main.cpp index 2aaafca16..d36561544 100644 --- a/world/main.cpp +++ b/world/main.cpp @@ -229,6 +229,44 @@ void RegisterLoginservers() } } +static void GMSayHookCallBackProcessWorld(uint16 log_category, std::string message) +{ + // Cut messages down to 4000 max to prevent client crash + if (!message.empty()) { + message = message.substr(0, 4000); + } + + // Replace Occurrences of % or MessageStatus will crash + find_replace(message, std::string("%"), std::string(".")); + + if (message.find('\n') != std::string::npos) { + auto message_split = SplitString(message, '\n'); + + for (size_t iter = 0; iter < message_split.size(); ++iter) { + zoneserver_list.SendEmoteMessage( + nullptr, + 0, + 80, + LogSys.GetGMSayColorFromCategory(log_category), + " %s%s", + (iter == 0 ? " ---" : ""), + message_split[iter].c_str() + ); + } + + return; + } + + zoneserver_list.SendEmoteMessage( + nullptr, + 0, + 80, + LogSys.GetGMSayColorFromCategory(log_category), + "%s", + message.c_str() + ); +} + /** * World process entrypoint * @@ -297,9 +335,15 @@ int main(int argc, char** argv) { guild_mgr.SetDatabase(&database); - LogSys.SetDatabase(&database) - ->LoadLogDatabaseSettings() - ->StartFileLogs(); + // logging system init + auto logging = LogSys.SetDatabase(&database) + ->LoadLogDatabaseSettings(); + + if (RuleB(Logging, WorldGMSayLogging)) { + logging->SetGMSayHandler(&GMSayHookCallBackProcessWorld); + } + + logging->StartFileLogs(); /** * Parse simple CLI passes