AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
autobroadcast_commandscript Class Reference
Inheritance diagram for autobroadcast_commandscript:
CommandScript ScriptObject

Public Member Functions

 autobroadcast_commandscript ()
 
ChatCommandTable GetCommands () const override
 
- Public Member Functions inherited from ScriptObject
virtual bool IsDatabaseBound () const
 
virtual bool isAfterLoadScript () const
 
virtual void checkValidity ()
 
std::string const & GetName () const
 
uint16 GetTotalAvailableHooks ()
 

Static Public Member Functions

static bool HandleAutobroadcastListCommand (ChatHandler *handler)
 
static bool HandleAutobroadcastAddCommand (ChatHandler *handler, uint8 weight, Tail text)
 
static bool HandleAutobroadcastLocaleCommand (ChatHandler *handler, uint32 id, std::string locale, Tail text)
 
static bool HandleAutobroadcastRemoveCommand (ChatHandler *handler, uint32 id)
 

Additional Inherited Members

- Protected Member Functions inherited from CommandScript
 CommandScript (char const *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (char const *name, uint16 totalAvailableHooks=0)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ autobroadcast_commandscript()

autobroadcast_commandscript::autobroadcast_commandscript ( )
inline
30: CommandScript("autobroadcast_commandscript") { }
Definition CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable autobroadcast_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

33 {
34 static ChatCommandTable autobroadcastCommandTable =
35 {
40 };
41
42 static ChatCommandTable commandTable =
43 {
44 { "autobroadcast", autobroadcastCommandTable }
45 };
46
47 return commandTable;
48 }
static bool HandleAutobroadcastListCommand(ChatHandler *handler)
Definition cs_autobroadcast.cpp:50
static bool HandleAutobroadcastAddCommand(ChatHandler *handler, uint8 weight, Tail text)
Definition cs_autobroadcast.cpp:102
static bool HandleAutobroadcastLocaleCommand(ChatHandler *handler, uint32 id, std::string locale, Tail text)
Definition cs_autobroadcast.cpp:131
static bool HandleAutobroadcastRemoveCommand(ChatHandler *handler, uint32 id)
Definition cs_autobroadcast.cpp:170
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:46
@ RBAC_PERM_COMMAND_AUTOBROADCAST_REMOVE
Definition RBAC.h:693
@ RBAC_PERM_COMMAND_AUTOBROADCAST_LOCALE
Definition RBAC.h:692
@ RBAC_PERM_COMMAND_AUTOBROADCAST_LIST
Definition RBAC.h:690
@ RBAC_PERM_COMMAND_AUTOBROADCAST_ADD
Definition RBAC.h:691

References HandleAutobroadcastAddCommand(), HandleAutobroadcastListCommand(), HandleAutobroadcastLocaleCommand(), HandleAutobroadcastRemoveCommand(), rbac::RBAC_PERM_COMMAND_AUTOBROADCAST_ADD, rbac::RBAC_PERM_COMMAND_AUTOBROADCAST_LIST, rbac::RBAC_PERM_COMMAND_AUTOBROADCAST_LOCALE, and rbac::RBAC_PERM_COMMAND_AUTOBROADCAST_REMOVE.

◆ HandleAutobroadcastAddCommand()

static bool autobroadcast_commandscript::HandleAutobroadcastAddCommand ( ChatHandler handler,
uint8  weight,
Tail  text 
)
inlinestatic
103 {
104 if (text.empty())
105 return false;
106
107 uint32 realmId = sConfigMgr->GetOption<int32>("RealmID", 0);
108
110 stmt->SetData(0, realmId);
111 stmt->SetData(1, weight);
112 stmt->SetData(2, std::string(text));
113 LoginDatabase.DirectExecute(stmt);
114
115 // Retrieve the newly inserted ID
116 stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_AUTOBROADCAST_MAX_ID);
117 stmt->SetData(0, realmId);
118 PreparedQueryResult result = LoginDatabase.Query(stmt);
119
120 uint32 newId = 0;
121 if (result)
122 newId = result->Fetch()[0].Get<uint32>();
123
124 sAutobroadcastMgr->LoadAutobroadcasts();
125 sAutobroadcastMgr->LoadAutobroadcastsLocalized();
126
128 return true;
129 }
#define sAutobroadcastMgr
Definition AutobroadcastMgr.h:54
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
std::uint32_t uint32
Definition Define.h:107
@ LANG_AUTOBROADCAST_ADD_SUCCESS
Definition Language.h:1214
@ LOGIN_INS_AUTOBROADCAST
Definition LoginDatabase.h:105
@ LOGIN_SEL_AUTOBROADCAST_MAX_ID
Definition LoginDatabase.h:111
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:219
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition PreparedStatement.h:77
Definition PreparedStatement.h:157
#define sConfigMgr
Definition Config.h:93

References LANG_AUTOBROADCAST_ADD_SUCCESS, LOGIN_INS_AUTOBROADCAST, LOGIN_SEL_AUTOBROADCAST_MAX_ID, LoginDatabase, ChatHandler::PSendSysMessage(), sAutobroadcastMgr, sConfigMgr, and PreparedStatementBase::SetData().

Referenced by GetCommands().

◆ HandleAutobroadcastListCommand()

static bool autobroadcast_commandscript::HandleAutobroadcastListCommand ( ChatHandler handler)
inlinestatic
51 {
52 uint32 realmId = sConfigMgr->GetOption<int32>("RealmID", 0);
53
55 stmt->SetData(0, realmId);
56 PreparedQueryResult result = LoginDatabase.Query(stmt);
57
58 if (!result)
59 {
61 return true;
62 }
63
64 // Prefetch all locales and group by id
66 localeStmt->SetData(0, realmId);
67 PreparedQueryResult localeResult = LoginDatabase.Query(localeStmt);
68
69 std::unordered_map<uint32, std::vector<std::pair<std::string, std::string>>> localeMap;
70 if (localeResult)
71 {
72 do
73 {
74 Field* localeFields = localeResult->Fetch();
75 uint32 localeId = localeFields[0].Get<uint32>();
76 std::string locale = localeFields[1].Get<std::string>();
77 std::string localeText = localeFields[2].Get<std::string>();
78 localeMap[localeId].emplace_back(std::move(locale), std::move(localeText));
79 } while (localeResult->NextRow());
80 }
81
83
84 do
85 {
86 Field* fields = result->Fetch();
87 uint32 id = fields[0].Get<uint32>();
88 uint8 weight = fields[1].Get<uint8>();
89 std::string text = fields[2].Get<std::string>();
90
91 handler->PSendSysMessage(LANG_AUTOBROADCAST_LIST_ENTRY, id, weight, text);
92
93 auto itr = localeMap.find(id);
94 if (itr != localeMap.end())
95 for (auto const& [locale, localeText] : itr->second)
96 handler->PSendSysMessage(LANG_AUTOBROADCAST_LOCALE_ENTRY, locale, localeText);
97 } while (result->NextRow());
98
99 return true;
100 }
std::uint8_t uint8
Definition Define.h:109
@ LANG_AUTOBROADCAST_LIST_ENTRY
Definition Language.h:1212
@ LANG_AUTOBROADCAST_LIST_EMPTY
Definition Language.h:1213
@ LANG_AUTOBROADCAST_LIST_HEADER
Definition Language.h:1211
@ LANG_AUTOBROADCAST_LOCALE_ENTRY
Definition Language.h:1218
@ LOGIN_SEL_AUTOBROADCAST_LOCALIZED
Definition LoginDatabase.h:104
@ LOGIN_SEL_AUTOBROADCAST
Definition LoginDatabase.h:103
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:168
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

References Field::Get(), LANG_AUTOBROADCAST_LIST_EMPTY, LANG_AUTOBROADCAST_LIST_ENTRY, LANG_AUTOBROADCAST_LIST_HEADER, LANG_AUTOBROADCAST_LOCALE_ENTRY, LOGIN_SEL_AUTOBROADCAST, LOGIN_SEL_AUTOBROADCAST_LOCALIZED, LoginDatabase, ChatHandler::PSendSysMessage(), sConfigMgr, ChatHandler::SendSysMessage(), and PreparedStatementBase::SetData().

Referenced by GetCommands().

◆ HandleAutobroadcastLocaleCommand()

static bool autobroadcast_commandscript::HandleAutobroadcastLocaleCommand ( ChatHandler handler,
uint32  id,
std::string  locale,
Tail  text 
)
inlinestatic
132 {
133 if (text.empty())
134 return false;
135
136 if (!IsLocaleValid(locale))
137 {
139 return true;
140 }
141
142 uint32 realmId = sConfigMgr->GetOption<int32>("RealmID", 0);
143
144 // Verify the autobroadcast entry exists
146 stmt->SetData(0, id);
147 stmt->SetData(1, realmId);
148 PreparedQueryResult result = LoginDatabase.Query(stmt);
149
150 if (!result)
151 {
153 return true;
154 }
155
156 stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_AUTOBROADCAST_LOCALE);
157 stmt->SetData(0, realmId);
158 stmt->SetData(1, id);
159 stmt->SetData(2, locale);
160 stmt->SetData(3, std::string(text));
161 LoginDatabase.DirectExecute(stmt);
162
163 sAutobroadcastMgr->LoadAutobroadcasts();
164 sAutobroadcastMgr->LoadAutobroadcastsLocalized();
165
167 return true;
168 }
bool IsLocaleValid(std::string const &locale)
Definition Common.cpp:69
@ LANG_AUTOBROADCAST_INVALID_LOCALE
Definition Language.h:1219
@ LANG_AUTOBROADCAST_LOCALE_SUCCESS
Definition Language.h:1217
@ LANG_AUTOBROADCAST_NOT_FOUND
Definition Language.h:1216
@ LOGIN_SEL_AUTOBROADCAST_BY_ID
Definition LoginDatabase.h:109
@ LOGIN_INS_AUTOBROADCAST_LOCALE
Definition LoginDatabase.h:107
void SendErrorMessage(uint32 entry)
Definition Chat.cpp:224

References IsLocaleValid(), LANG_AUTOBROADCAST_INVALID_LOCALE, LANG_AUTOBROADCAST_LOCALE_SUCCESS, LANG_AUTOBROADCAST_NOT_FOUND, LOGIN_INS_AUTOBROADCAST_LOCALE, LOGIN_SEL_AUTOBROADCAST_BY_ID, LoginDatabase, ChatHandler::PSendSysMessage(), sAutobroadcastMgr, sConfigMgr, ChatHandler::SendErrorMessage(), and PreparedStatementBase::SetData().

Referenced by GetCommands().

◆ HandleAutobroadcastRemoveCommand()

static bool autobroadcast_commandscript::HandleAutobroadcastRemoveCommand ( ChatHandler handler,
uint32  id 
)
inlinestatic
171 {
172 uint32 realmId = sConfigMgr->GetOption<int32>("RealmID", 0);
173
174 // Verify the autobroadcast entry exists
176 stmt->SetData(0, id);
177 stmt->SetData(1, realmId);
178 PreparedQueryResult result = LoginDatabase.Query(stmt);
179
180 if (!result)
181 {
183 return true;
184 }
185
186 // Delete the autobroadcast entry
187 stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_AUTOBROADCAST);
188 stmt->SetData(0, id);
189 stmt->SetData(1, realmId);
190 LoginDatabase.DirectExecute(stmt);
191
192 // Delete associated locale entries
193 stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_AUTOBROADCAST_LOCALE);
194 stmt->SetData(0, id);
195 stmt->SetData(1, realmId);
196 LoginDatabase.DirectExecute(stmt);
197
198 sAutobroadcastMgr->LoadAutobroadcasts();
199 sAutobroadcastMgr->LoadAutobroadcastsLocalized();
200
202 return true;
203 }
@ LANG_AUTOBROADCAST_REMOVE_SUCCESS
Definition Language.h:1215
@ LOGIN_DEL_AUTOBROADCAST
Definition LoginDatabase.h:106
@ LOGIN_DEL_AUTOBROADCAST_LOCALE
Definition LoginDatabase.h:108

References LANG_AUTOBROADCAST_NOT_FOUND, LANG_AUTOBROADCAST_REMOVE_SUCCESS, LOGIN_DEL_AUTOBROADCAST, LOGIN_DEL_AUTOBROADCAST_LOCALE, LOGIN_SEL_AUTOBROADCAST_BY_ID, LoginDatabase, ChatHandler::PSendSysMessage(), sAutobroadcastMgr, sConfigMgr, ChatHandler::SendErrorMessage(), and PreparedStatementBase::SetData().

Referenced by GetCommands().


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