AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
MotdMgr Class Reference

#include "MotdMgr.h"

Public Member Functions

void CreateWorldPackages ()
 Converts the localized string to world packages. More...
 
void SetMotd (std::string motd, LocaleConstant locale)
 Set a new Message of the Day. More...
 
void LoadMotd ()
 Load Message of the Day. More...
 
char const * GetMotd (LocaleConstant locale)
 Get the current Message of the Day. More...
 
WorldPacket const * GetMotdPacket (LocaleConstant locale)
 Returns the current motd packet for the given locale. More...
 
bool IsValidLocale (std::string const &locale)
 

Static Public Member Functions

static MotdMgrinstance ()
 

Private Member Functions

std::string LoadDefaultMotd (uint32 realmId)
 
void LoadLocalizedMotds (uint32 realmId)
 
void SetDefaultMotd ()
 
WorldPacket CreateWorldPacket (std::string const &motd)
 

Detailed Description

Member Function Documentation

◆ CreateWorldPackages()

void MotdMgr::CreateWorldPackages ( )

Converts the localized string to world packages.

57{
58 for (auto const& [locale, motd] : MotdMap)
59 // Store the constructed packet in MotdPackets with the locale as the key
60 MotdPackets[locale] = CreateWorldPacket(motd);
61}
std::unordered_map< LocaleConstant, WorldPacket > MotdPackets
Definition: MotdMgr.cpp:31
WorldPacket CreateWorldPacket(std::string const &motd)
Definition: MotdMgr.cpp:168

References CreateWorldPacket().

Referenced by LoadMotd().

◆ CreateWorldPacket()

WorldPacket MotdMgr::CreateWorldPacket ( std::string const &  motd)
private
169{
170 // Create a new WorldPacket for this locale
171 WorldPacket data(SMSG_MOTD); // new in 2.0.1
172
173 // Tokenize the motd string by '@'
174 std::vector<std::string_view> motdTokens = Acore::Tokenize(motd, '@', true);
175 data << uint32(motdTokens.size()); // line count
176
177 for (std::string_view token : motdTokens)
178 data << token;
179
180 return data;
181}
std::uint32_t uint32
Definition: Define.h:107
@ SMSG_MOTD
Definition: Opcodes.h:859
std::vector< std::string_view > Tokenize(std::string_view str, char sep, bool keepEmpty)
Definition: Tokenize.cpp:20
Definition: WorldPacket.h:26

References SMSG_MOTD, and Acore::Tokenize().

Referenced by CreateWorldPackages(), and SetMotd().

◆ GetMotd()

char const * MotdMgr::GetMotd ( LocaleConstant  locale)

Get the current Message of the Day.

84{
85 // Return localized motd if available, otherwise fallback to enUS
86 auto it = MotdMap.find(locale);
87 if (it != MotdMap.end())
88 return it->second.c_str();
89
90 return MotdMap[DEFAULT_LOCALE].c_str(); // Fallback to enUS if locale is not found
91}
#define DEFAULT_LOCALE
Definition: Common.h:79
std::unordered_map< LocaleConstant, std::string > MotdMap
Definition: MotdMgr.cpp:33

References DEFAULT_LOCALE.

◆ GetMotdPacket()

WorldPacket const * MotdMgr::GetMotdPacket ( LocaleConstant  locale)

Returns the current motd packet for the given locale.

94{
95 // Return localized packet if available, otherwise fallback to enUS
96 auto it = MotdPackets.find(locale);
97 if (it != MotdPackets.end())
98 return &it->second;
99
100 return &MotdPackets[DEFAULT_LOCALE]; // Fallback to enUS if locale is not found
101}

References DEFAULT_LOCALE.

◆ instance()

MotdMgr * MotdMgr::instance ( )
static
37{
38 static MotdMgr instance;
39 return &instance;
40}
Definition: MotdMgr.h:28
static MotdMgr * instance()
Definition: MotdMgr.cpp:36

References instance().

Referenced by instance().

◆ IsValidLocale()

bool MotdMgr::IsValidLocale ( std::string const &  locale)
42 {
43 // Use std::find to search for the locale in the array
44 return std::find(std::begin(localeNames), std::end(localeNames), locale) != std::end(localeNames);
45}
char const * localeNames[TOTAL_LOCALES]
Definition: Common.cpp:20

References localeNames.

◆ LoadDefaultMotd()

std::string MotdMgr::LoadDefaultMotd ( uint32  realmId)
private
104{
105 LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_MOTD);
106 stmt->SetData(0, realmId);
107 PreparedQueryResult result = LoginDatabase.Query(stmt);
108
109 if (result)
110 {
111 Field* fields = result->Fetch();
112 return fields[0].Get<std::string>(); // Return the main motd if found
113 }
114
115 return ""; // Return empty string if no motd found
116}
@ LOGIN_SEL_MOTD
Definition: LoginDatabase.h:100
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: DatabaseEnvFwd.h:45
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
Definition: PreparedStatement.h:157
Class used to access individual fields of database query result.
Definition: Field.h:98
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:112
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:77

References Field::Get(), LOGIN_SEL_MOTD, LoginDatabase, and PreparedStatementBase::SetData().

Referenced by LoadMotd().

◆ LoadLocalizedMotds()

void MotdMgr::LoadLocalizedMotds ( uint32  realmId)
private
134 {
135 // First, check if base MOTD exists
136 LoginDatabasePreparedStatement* baseStmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_MOTD);
137 baseStmt->SetData(0, realmId);
138 PreparedQueryResult baseResult = LoginDatabase.Query(baseStmt);
139
140 if (!baseResult)
141 {
142 LOG_ERROR("server.loading", "No base MOTD found for realm %u. Localized MOTDs will not be loaded.", realmId);
143 return;
144 }
145
146 // Now load localized versions
148 stmt->SetData(0, realmId);
149 PreparedQueryResult result = LoginDatabase.Query(stmt);
150
151 if (result)
152 {
153 do {
154 Field* fields = result->Fetch();
155 // fields[0] is the locale string and fields[1] is the localized motd text
156 std::string localizedText = fields[1].Get<std::string>();
157 // Convert locale string to LocaleConstant
158 LocaleConstant localeId = GetLocaleByName(fields[0].Get<std::string>());
159
160 if (localeId == DEFAULT_LOCALE)
161 continue;
162
163 MotdMap[localeId] = localizedText;
164 } while (result->NextRow());
165 }
166}
LocaleConstant
Definition: Common.h:65
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
LocaleConstant GetLocaleByName(const std::string &name)
Definition: Common.cpp:33
@ LOGIN_SEL_MOTD_LOCALE
Definition: LoginDatabase.h:101

References DEFAULT_LOCALE, Field::Get(), GetLocaleByName(), LOG_ERROR, LOGIN_SEL_MOTD, LOGIN_SEL_MOTD_LOCALE, LoginDatabase, and PreparedStatementBase::SetData().

Referenced by LoadMotd().

◆ LoadMotd()

void MotdMgr::LoadMotd ( )

Load Message of the Day.

64{
65 uint32 realmId = sConfigMgr->GetOption<int32>("RealmID", 0);
66
67 // Load the main motd for the realm and assign it to enUS if available
68 std::string motd = LoadDefaultMotd(realmId);
69
70 // Check if motd was loaded; if not, set default only for enUS
71 if (motd.empty())
72 SetDefaultMotd(); // Only sets enUS default if motd is empty
73 else
74 MotdMap[DEFAULT_LOCALE] = motd; // Assign the loaded motd to enUS
75
76 // Load localized texts if available
77 LoadLocalizedMotds(realmId);
78
79 // Create all world packages after loading motd and localized texts
81}
#define sConfigMgr
Definition: Config.h:74
std::int32_t int32
Definition: Define.h:103
void LoadLocalizedMotds(uint32 realmId)
Definition: MotdMgr.cpp:134
void CreateWorldPackages()
Converts the localized string to world packages.
Definition: MotdMgr.cpp:56
std::string LoadDefaultMotd(uint32 realmId)
Definition: MotdMgr.cpp:103
void SetDefaultMotd()
Definition: MotdMgr.cpp:118

References CreateWorldPackages(), DEFAULT_LOCALE, LoadDefaultMotd(), LoadLocalizedMotds(), sConfigMgr, and SetDefaultMotd().

◆ SetDefaultMotd()

void MotdMgr::SetDefaultMotd ( )
private
119{
120 std::string motd = /* fctlsup << //0x338// "63"+"cx""d2"+"1e""dd"+"cx""ds"+"ce""dd"+"ce""7D"+ << */
121 /*"d3"+"ce"*/ std::string("@|") + "cf" +/*"as"+"k4"*/"fF" + "F4" +/*"d5"+"f3"*/"A2" + "DT"/*"F4"+"Az"*/ + "hi" + "s "
122 /*"fd"+"hy"*/ + "se" + "rv" +/*"nh"+"k3"*/"er" + " r" +/*"x1"+"A2"*/"un" + "s "/*"F2"+"Ay"*/ + "on" + " Az"
123 /*"xs"+"5n"*/ + "er" + "ot" +/*"xs"+"A2"*/"hC" + "or" +/*"a4"+"f3"*/"e|" + "r "/*"f2"+"A2"*/ + "|c" + "ff"
124 /*"5g"+"A2"*/ + "3C" + "E7" +/*"k5"+"AX"*/"FF" + "ww" +/*"sx"+"Gj"*/"w." + "az"/*"a1"+"vf"*/ + "er" + "ot"
125 /*"ds"+"sx"*/ + "hc" + "or" +/*"F4"+"k5"*/"e." + "or" +/*"po"+"xs"*/"g|r"/*"F4"+"p2"+"o4"+"A2"+"i2"*/;
126
127 MotdMap[DEFAULT_LOCALE] = motd;
128
129 // Log that no motd was found and a default is being used for enUS
130 LOG_WARN("server.loading", ">> Loaded 0 motd definitions. DB table `motd` is empty for this realm!");
131 LOG_INFO("server.loading", " ");
132}
#define LOG_INFO(filterType__,...)
Definition: Log.h:165
#define LOG_WARN(filterType__,...)
Definition: Log.h:161

References DEFAULT_LOCALE, LOG_INFO, and LOG_WARN.

Referenced by LoadMotd().

◆ SetMotd()

void MotdMgr::SetMotd ( std::string  motd,
LocaleConstant  locale 
)

Set a new Message of the Day.

48{
49 // scripts may change motd
50 sScriptMgr->OnMotdChange(motd, locale);
51
52 MotdMap[locale] = motd;
53 MotdPackets[locale] = CreateWorldPacket(motd);
54}
#define sScriptMgr
Definition: ScriptMgr.h:709

References CreateWorldPacket(), and sScriptMgr.