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 ()
 
const std::string & 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 (const char *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name, uint16 totalAvailableHooks=0)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ autobroadcast_commandscript()

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

Member Function Documentation

◆ GetCommands()

ChatCommandTable autobroadcast_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

32 {
33 static ChatCommandTable autobroadcastCommandTable =
34 {
35 { "list", HandleAutobroadcastListCommand, SEC_GAMEMASTER, Console::Yes },
36 { "add", HandleAutobroadcastAddCommand, SEC_ADMINISTRATOR, Console::Yes },
37 { "locale", HandleAutobroadcastLocaleCommand, SEC_ADMINISTRATOR, Console::Yes },
38 { "remove", HandleAutobroadcastRemoveCommand, SEC_ADMINISTRATOR, Console::Yes }
39 };
40
41 static ChatCommandTable commandTable =
42 {
43 { "autobroadcast", autobroadcastCommandTable }
44 };
45
46 return commandTable;
47 }
@ SEC_ADMINISTRATOR
Definition Common.h:60
@ SEC_GAMEMASTER
Definition Common.h:59
static bool HandleAutobroadcastListCommand(ChatHandler *handler)
Definition cs_autobroadcast.cpp:49
static bool HandleAutobroadcastAddCommand(ChatHandler *handler, uint8 weight, Tail text)
Definition cs_autobroadcast.cpp:101
static bool HandleAutobroadcastLocaleCommand(ChatHandler *handler, uint32 id, std::string locale, Tail text)
Definition cs_autobroadcast.cpp:130
static bool HandleAutobroadcastRemoveCommand(ChatHandler *handler, uint32 id)
Definition cs_autobroadcast.cpp:169
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:46

References HandleAutobroadcastAddCommand(), HandleAutobroadcastListCommand(), HandleAutobroadcastLocaleCommand(), HandleAutobroadcastRemoveCommand(), SEC_ADMINISTRATOR, and SEC_GAMEMASTER.

◆ HandleAutobroadcastAddCommand()

static bool autobroadcast_commandscript::HandleAutobroadcastAddCommand ( ChatHandler handler,
uint8  weight,
Tail  text 
)
inlinestatic
102 {
103 if (text.empty())
104 return false;
105
106 uint32 realmId = sConfigMgr->GetOption<int32>("RealmID", 0);
107
109 stmt->SetData(0, realmId);
110 stmt->SetData(1, weight);
111 stmt->SetData(2, std::string(text));
112 LoginDatabase.DirectExecute(stmt);
113
114 // Retrieve the newly inserted ID
115 stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_AUTOBROADCAST_MAX_ID);
116 stmt->SetData(0, realmId);
117 PreparedQueryResult result = LoginDatabase.Query(stmt);
118
119 uint32 newId = 0;
120 if (result)
121 newId = result->Fetch()[0].Get<uint32>();
122
123 sAutobroadcastMgr->LoadAutobroadcasts();
124 sAutobroadcastMgr->LoadAutobroadcastsLocalized();
125
127 return true;
128 }
#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:1211
@ LOGIN_INS_AUTOBROADCAST
Definition LoginDatabase.h:103
@ LOGIN_SEL_AUTOBROADCAST_MAX_ID
Definition LoginDatabase.h:109
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:211
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
50 {
51 uint32 realmId = sConfigMgr->GetOption<int32>("RealmID", 0);
52
54 stmt->SetData(0, realmId);
55 PreparedQueryResult result = LoginDatabase.Query(stmt);
56
57 if (!result)
58 {
60 return true;
61 }
62
63 // Prefetch all locales and group by id
65 localeStmt->SetData(0, realmId);
66 PreparedQueryResult localeResult = LoginDatabase.Query(localeStmt);
67
68 std::unordered_map<uint32, std::vector<std::pair<std::string, std::string>>> localeMap;
69 if (localeResult)
70 {
71 do
72 {
73 Field* localeFields = localeResult->Fetch();
74 uint32 localeId = localeFields[0].Get<uint32>();
75 std::string locale = localeFields[1].Get<std::string>();
76 std::string localeText = localeFields[2].Get<std::string>();
77 localeMap[localeId].emplace_back(std::move(locale), std::move(localeText));
78 } while (localeResult->NextRow());
79 }
80
82
83 do
84 {
85 Field* fields = result->Fetch();
86 uint32 id = fields[0].Get<uint32>();
87 uint8 weight = fields[1].Get<uint8>();
88 std::string text = fields[2].Get<std::string>();
89
90 handler->PSendSysMessage(LANG_AUTOBROADCAST_LIST_ENTRY, id, weight, text);
91
92 auto itr = localeMap.find(id);
93 if (itr != localeMap.end())
94 for (auto const& [locale, localeText] : itr->second)
95 handler->PSendSysMessage(LANG_AUTOBROADCAST_LOCALE_ENTRY, locale, localeText);
96 } while (result->NextRow());
97
98 return true;
99 }
std::uint8_t uint8
Definition Define.h:109
@ LANG_AUTOBROADCAST_LIST_ENTRY
Definition Language.h:1209
@ LANG_AUTOBROADCAST_LIST_EMPTY
Definition Language.h:1210
@ LANG_AUTOBROADCAST_LIST_HEADER
Definition Language.h:1208
@ LANG_AUTOBROADCAST_LOCALE_ENTRY
Definition Language.h:1215
@ LOGIN_SEL_AUTOBROADCAST_LOCALIZED
Definition LoginDatabase.h:102
@ LOGIN_SEL_AUTOBROADCAST
Definition LoginDatabase.h:101
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:160
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
131 {
132 if (text.empty())
133 return false;
134
135 if (!IsLocaleValid(locale))
136 {
138 return true;
139 }
140
141 uint32 realmId = sConfigMgr->GetOption<int32>("RealmID", 0);
142
143 // Verify the autobroadcast entry exists
145 stmt->SetData(0, id);
146 stmt->SetData(1, realmId);
147 PreparedQueryResult result = LoginDatabase.Query(stmt);
148
149 if (!result)
150 {
152 return true;
153 }
154
155 stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_AUTOBROADCAST_LOCALE);
156 stmt->SetData(0, realmId);
157 stmt->SetData(1, id);
158 stmt->SetData(2, locale);
159 stmt->SetData(3, std::string(text));
160 LoginDatabase.DirectExecute(stmt);
161
162 sAutobroadcastMgr->LoadAutobroadcasts();
163 sAutobroadcastMgr->LoadAutobroadcastsLocalized();
164
166 return true;
167 }
bool IsLocaleValid(std::string const &locale)
Definition Common.cpp:33
@ LANG_AUTOBROADCAST_INVALID_LOCALE
Definition Language.h:1216
@ LANG_AUTOBROADCAST_LOCALE_SUCCESS
Definition Language.h:1214
@ LANG_AUTOBROADCAST_NOT_FOUND
Definition Language.h:1213
@ LOGIN_SEL_AUTOBROADCAST_BY_ID
Definition LoginDatabase.h:107
@ LOGIN_INS_AUTOBROADCAST_LOCALE
Definition LoginDatabase.h:105
void SendErrorMessage(uint32 entry)
Definition Chat.cpp:216

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
170 {
171 uint32 realmId = sConfigMgr->GetOption<int32>("RealmID", 0);
172
173 // Verify the autobroadcast entry exists
175 stmt->SetData(0, id);
176 stmt->SetData(1, realmId);
177 PreparedQueryResult result = LoginDatabase.Query(stmt);
178
179 if (!result)
180 {
182 return true;
183 }
184
185 // Delete the autobroadcast entry
186 stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_AUTOBROADCAST);
187 stmt->SetData(0, id);
188 stmt->SetData(1, realmId);
189 LoginDatabase.DirectExecute(stmt);
190
191 // Delete associated locale entries
192 stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_AUTOBROADCAST_LOCALE);
193 stmt->SetData(0, id);
194 stmt->SetData(1, realmId);
195 LoginDatabase.DirectExecute(stmt);
196
197 sAutobroadcastMgr->LoadAutobroadcasts();
198 sAutobroadcastMgr->LoadAutobroadcastsLocalized();
199
201 return true;
202 }
@ LANG_AUTOBROADCAST_REMOVE_SUCCESS
Definition Language.h:1212
@ LOGIN_DEL_AUTOBROADCAST
Definition LoginDatabase.h:104
@ LOGIN_DEL_AUTOBROADCAST_LOCALE
Definition LoginDatabase.h:106

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: