From 62f30a0492476020ed9f56ba399f1d878c3f16c7 Mon Sep 17 00:00:00 2001 From: Kitzunu <24550914+Kitzunu@users.noreply.github.com> Date: Thu, 23 Jan 2025 21:50:07 +0100 Subject: [PATCH] more cleanup --- src/server/game/Motd/MotdMgr.cpp | 38 +++++++++++++++----------------- src/server/game/Motd/MotdMgr.h | 6 ++--- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/server/game/Motd/MotdMgr.cpp b/src/server/game/Motd/MotdMgr.cpp index 8435c035765460..8c85222d27169c 100644 --- a/src/server/game/Motd/MotdMgr.cpp +++ b/src/server/game/Motd/MotdMgr.cpp @@ -48,13 +48,6 @@ void MotdMgr::SetMotd(std::string motd, LocaleConstant locale) MotdPackets[locale] = CreateWorldPacket(motd); } -void MotdMgr::CreateWorldPackages() -{ - for (auto const& [locale, motd] : MotdMap) - // Store the constructed packet in MotdPackets with the locale as the key - MotdPackets[locale] = CreateWorldPacket(motd); -} - void MotdMgr::LoadMotd() { uint32 oldMSTime = getMSTime(); @@ -67,15 +60,11 @@ void MotdMgr::LoadMotd() if (result) { Field* fields = result->Fetch(); - std::string motd = fields[0].Get(); // Return the main motd if found - - MotdMap[LOCALE_enUS] = motd; // Assign the loaded motd to enUS + std::string motd = fields[0].Get(); - // Load localized texts if available - LoadMotdLocale(realmId); + SetMotd(motd, LOCALE_enUS); - // Create all world packages after loading motd and localized texts - CreateWorldPackages(); + LoadMotdLocale(); } else { @@ -88,10 +77,13 @@ void MotdMgr::LoadMotd() LOG_INFO("server.loading", " "); } -void MotdMgr::LoadMotdLocale(uint32 realmId) +void MotdMgr::LoadMotdLocale() { uint32 oldMSTime = getMSTime(); + uint32 count = 0; + LOG_INFO("server.loading", "Loading Motd locale..."); + uint32 realmId = sConfigMgr->GetOption("RealmID", 0); LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_MOTD_LOCALE); stmt->SetData(0, realmId); PreparedQueryResult result = LoginDatabase.Query(stmt); @@ -102,14 +94,21 @@ void MotdMgr::LoadMotdLocale(uint32 realmId) { Field* fields = result->Fetch(); // fields[0] is the locale string and fields[1] is the localized motd text + std::string locale = fields[0].Get(); std::string localizedText = fields[1].Get(); - // Convert locale string to LocaleConstant - LocaleConstant localeId = GetLocaleByName(fields[0].Get()); + if (!IsLocaleValid(locale)) + { + LOG_ERROR("server.loading", "DB table `motd_localized` has invalid locale ({}), skipped.", locale); + continue; + } + + LocaleConstant localeId = GetLocaleByName(locale); if (localeId == LOCALE_enUS) continue; - MotdMap[localeId] = localizedText; + SetMotd(localizedText, localeId); + ++count; } while (result->NextRow()); } else @@ -118,8 +117,7 @@ void MotdMgr::LoadMotdLocale(uint32 realmId) LOG_INFO("server.loading", " "); } - LOG_INFO("server.loading", ">> Loaded motd locale definitions in {} ms", GetMSTimeDiffToNow(oldMSTime)); - LOG_INFO("server.loading", " "); + LOG_INFO("server.loading", ">> Loaded {} motd locale definitions in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); } char const* MotdMgr::GetMotd(LocaleConstant locale) diff --git a/src/server/game/Motd/MotdMgr.h b/src/server/game/Motd/MotdMgr.h index d752a799e3eb00..1f85ba921c20df 100644 --- a/src/server/game/Motd/MotdMgr.h +++ b/src/server/game/Motd/MotdMgr.h @@ -29,9 +29,6 @@ class AC_GAME_API MotdMgr public: static MotdMgr* instance(); - /// Converts the localized string to world packages - void CreateWorldPackages(); - /// Set a new Message of the Day void SetMotd(std::string motd, LocaleConstant locale); @@ -46,7 +43,8 @@ class AC_GAME_API MotdMgr private: // Loads all available localized motd for the realm - void LoadMotdLocale(uint32 realmId); + void LoadMotdLocale(); + // Create a worldpacket for a given motd localization WorldPacket CreateWorldPacket(std::string motd); };