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

#include "MotdMgr.h"

Public Member Functions

void SetMotd (std::string motd, LocaleConstant locale)
 Set a new Message of the Day.
 
void LoadMotd ()
 Load Message of the Day.
 
char const * GetMotd (LocaleConstant locale)
 Get the current Message of the Day.
 
WorldPacket const * GetMotdPacket (LocaleConstant locale)
 Returns the current motd packet for the given locale.
 

Static Public Member Functions

static MotdMgrinstance ()
 

Private Member Functions

void LoadMotdLocale ()
 
WorldPacket CreateWorldPacket (std::string motd)
 

Detailed Description

Member Function Documentation

◆ CreateWorldPacket()

WorldPacket MotdMgr::CreateWorldPacket ( std::string  motd)
private
144{
145 // Create a new WorldPacket for this locale
146 WorldPacket data(SMSG_MOTD); // new in 2.0.1
147
148 motd = /* fctlsup << //0x338// "63"+"cx""d2"+"1e""dd"+"cx""ds"+"ce""dd"+"ce""7D"+ << */ motd
149 /*"d3"+"ce"*/ + "@|" + "cf" +/*"as"+"k4"*/"fF" + "F4" +/*"d5"+"f3"*/"A2" + "DT"/*"F4"+"Az"*/ + "hi" + "s "
150 /*"fd"+"hy"*/ + "se" + "rv" +/*"nh"+"k3"*/"er" + " r" +/*"x1"+"A2"*/"un" + "s "/*"F2"+"Ay"*/ + "on" + " Az"
151 /*"xs"+"5n"*/ + "er" + "ot" +/*"xs"+"A2"*/"hC" + "or" +/*"a4"+"f3"*/"e|" + "r "/*"f2"+"A2"*/ + "|c" + "ff"
152 /*"5g"+"A2"*/ + "3C" + "E7" +/*"k5"+"AX"*/"FF" + "ww" +/*"sx"+"Gj"*/"w." + "az"/*"a1"+"vf"*/ + "er" + "ot"
153 /*"ds"+"sx"*/ + "hc" + "or" +/*"F4"+"k5"*/"e." + "or" +/*"po"+"xs"*/"g|r"/*"F4"+"p2"+"o4"+"A2"+"i2"*/;
154
155 // Tokenize the motd string by '@'
156 std::vector<std::string_view> motdTokens = Acore::Tokenize(motd, '@', true);
157 data << uint32(motdTokens.size()); // line count
158
159 for (std::string_view token : motdTokens)
160 data << token;
161
162 return data;
163}
std::uint32_t uint32
Definition Define.h:107
Definition WorldPacket.h:26
@ SMSG_MOTD
Definition Opcodes.h:859
std::vector< std::string_view > Tokenize(std::string_view str, char sep, bool keepEmpty)
Definition Tokenize.cpp:20

References SMSG_MOTD, and Acore::Tokenize().

Referenced by SetMotd().

◆ GetMotd()

char const * MotdMgr::GetMotd ( LocaleConstant  locale)

Get the current Message of the Day.

124{
125 // Return localized motd if available, otherwise fallback to enUS
126 auto it = MotdMap.find(locale);
127 if (it != MotdMap.end())
128 return it->second.c_str();
129
130 return MotdMap[LOCALE_enUS].c_str(); // Fallback to enUS if locale is not found
131}
@ LOCALE_enUS
Definition Common.h:66

References LOCALE_enUS.

◆ GetMotdPacket()

WorldPacket const * MotdMgr::GetMotdPacket ( LocaleConstant  locale)

Returns the current motd packet for the given locale.

134{
135 // Return localized packet if available, otherwise fallback to enUS
136 auto it = MotdPackets.find(locale);
137 if (it != MotdPackets.end())
138 return &it->second;
139
140 return &MotdPackets[LOCALE_enUS]; // Fallback to enUS if locale is not found
141}

References LOCALE_enUS.

◆ 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().

◆ LoadMotd()

void MotdMgr::LoadMotd ( )

Load Message of the Day.

52{
53 uint32 oldMSTime = getMSTime();
54
55 uint32 realmId = sConfigMgr->GetOption<int32>("RealmID", 0);
57 stmt->SetData(0, realmId);
58 PreparedQueryResult result = LoginDatabase.Query(stmt);
59
60 if (result)
61 {
62 Field* fields = result->Fetch();
63 std::string motd = fields[0].Get<std::string>();
64
65 SetMotd(motd, LOCALE_enUS);
66
68 }
69 else
70 {
71 LOG_INFO("server.loading", ">> Loaded 0 motd definitions. DB table `motd` is empty for this realm!");
72 LOG_INFO("server.loading", ">> Loaded 0 motd locale definitions. DB table `motd` needs an entry to be able to load DB table `motd_locale`!");
73 LOG_INFO("server.loading", " ");
74 }
75
76 LOG_INFO("server.loading", ">> Loaded motd definitions in {} ms", GetMSTimeDiffToNow(oldMSTime));
77 LOG_INFO("server.loading", " ");
78}
#define sConfigMgr
Definition Config.h:74
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition DatabaseEnvFwd.h:45
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
Definition DatabaseEnv.cpp:22
std::int32_t int32
Definition Define.h:103
#define LOG_INFO(filterType__,...)
Definition Log.h:165
@ LOGIN_SEL_MOTD
Definition LoginDatabase.h:101
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition Timer.h:131
uint32 getMSTime()
Definition Timer.h:103
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
void LoadMotdLocale()
Definition MotdMgr.cpp:80
void SetMotd(std::string motd, LocaleConstant locale)
Set a new Message of the Day.
Definition MotdMgr.cpp:42
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition PreparedStatement.h:77
Definition PreparedStatement.h:157

References Field::Get(), getMSTime(), GetMSTimeDiffToNow(), LoadMotdLocale(), LOCALE_enUS, LOG_INFO, LOGIN_SEL_MOTD, LoginDatabase, sConfigMgr, PreparedStatementBase::SetData(), and SetMotd().

◆ LoadMotdLocale()

void MotdMgr::LoadMotdLocale ( )
private
81{
82 uint32 oldMSTime = getMSTime();
83 uint32 count = 0;
84 LOG_INFO("server.loading", "Loading Motd locale...");
85
86 uint32 realmId = sConfigMgr->GetOption<int32>("RealmID", 0);
88 stmt->SetData(0, realmId);
89 PreparedQueryResult result = LoginDatabase.Query(stmt);
90
91 if (result)
92 {
93 do
94 {
95 Field* fields = result->Fetch();
96 // fields[0] is the locale string and fields[1] is the localized motd text
97 std::string locale = fields[0].Get<std::string>();
98 std::string localizedText = fields[1].Get<std::string>();
99
100 if (!IsLocaleValid(locale))
101 {
102 LOG_ERROR("server.loading", "DB table `motd_localized` has invalid locale ({}), skipped.", locale);
103 continue;
104 }
105
106 LocaleConstant localeId = GetLocaleByName(locale);
107 if (localeId == LOCALE_enUS)
108 continue;
109
110 SetMotd(localizedText, localeId);
111 ++count;
112 } while (result->NextRow());
113 }
114 else
115 {
116 LOG_INFO("server.loading", ">> Loaded 0 motd locale definitions. DB table `motd_localized` is empty for this realm!");
117 LOG_INFO("server.loading", " ");
118 }
119
120 LOG_INFO("server.loading", ">> Loaded {} motd locale definitions in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
121}
LocaleConstant GetLocaleByName(const std::string &name)
Definition Common.cpp:42
bool IsLocaleValid(std::string const &locale)
Definition Common.cpp:33
LocaleConstant
Definition Common.h:65
#define LOG_ERROR(filterType__,...)
Definition Log.h:157
@ LOGIN_SEL_MOTD_LOCALE
Definition LoginDatabase.h:102

References Field::Get(), GetLocaleByName(), getMSTime(), GetMSTimeDiffToNow(), IsLocaleValid(), LOCALE_enUS, LOG_ERROR, LOG_INFO, LOGIN_SEL_MOTD_LOCALE, LoginDatabase, sConfigMgr, PreparedStatementBase::SetData(), and SetMotd().

Referenced by LoadMotd().

◆ SetMotd()

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

Set a new Message of the Day.

43{
44 // scripts may change motd
45 sScriptMgr->OnMotdChange(motd, locale);
46
47 MotdMap[locale] = motd;
48 MotdPackets[locale] = CreateWorldPacket(motd);
49}
#define sScriptMgr
Definition ScriptMgr.h:727
WorldPacket CreateWorldPacket(std::string motd)
Definition MotdMgr.cpp:143

References CreateWorldPacket(), and sScriptMgr.

Referenced by LoadMotd(), and LoadMotdLocale().


The documentation for this class was generated from the following files: