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

Public Member Functions

 ban_commandscript ()
 
ChatCommandTable GetCommands () const override
 
virtual std::vector< Acore::ChatCommands::ChatCommandBuilderGetCommands () const =0
 
- 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 HandleBanAccountCommand (ChatHandler *handler, char const *args)
 
static bool HandleBanCharacterCommand (ChatHandler *handler, char const *args)
 
static bool HandleBanAccountByCharCommand (ChatHandler *handler, char const *args)
 
static bool HandleBanIPCommand (ChatHandler *handler, char const *args)
 
static bool HandleBanHelper (BanMode mode, char const *args, ChatHandler *handler)
 
static bool HandleBanInfoAccountCommand (ChatHandler *handler, char const *args)
 
static bool HandleBanInfoHelper (uint32 accountId, char const *accountName, ChatHandler *handler)
 
static bool HandleBanInfoCharacterCommand (ChatHandler *handler, char const *args)
 
static bool HandleBanInfoIPCommand (ChatHandler *handler, char const *args)
 
static bool HandleBanListAccountCommand (ChatHandler *handler, char const *args)
 
static bool HandleBanListHelper (PreparedQueryResult result, ChatHandler *handler)
 
static bool HandleBanListCharacterCommand (ChatHandler *handler, char const *args)
 
static bool HandleBanListIPCommand (ChatHandler *handler, char const *args)
 
static bool HandleUnBanAccountCommand (ChatHandler *handler, char const *args)
 
static bool HandleUnBanCharacterCommand (ChatHandler *handler, char const *args)
 
static bool HandleUnBanAccountByCharCommand (ChatHandler *handler, char const *args)
 
static bool HandleUnBanIPCommand (ChatHandler *handler, char const *args)
 
static bool HandleUnBanHelper (BanMode mode, char const *args, ChatHandler *handler)
 

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

◆ ban_commandscript()

ban_commandscript::ban_commandscript ( )
inline
53: CommandScript("ban_commandscript") { }
Definition: CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable ban_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

56 {
57 static ChatCommandTable unbanCommandTable =
58 {
59 { "account", HandleUnBanAccountCommand, SEC_ADMINISTRATOR, Console::Yes },
60 { "character", HandleUnBanCharacterCommand, SEC_ADMINISTRATOR, Console::Yes },
61 { "playeraccount", HandleUnBanAccountByCharCommand, SEC_ADMINISTRATOR, Console::Yes },
62 { "ip", HandleUnBanIPCommand, SEC_ADMINISTRATOR, Console::Yes }
63 };
64
65 static ChatCommandTable banlistCommandTable =
66 {
67 { "account", HandleBanListAccountCommand, SEC_GAMEMASTER, Console::Yes },
68 { "character", HandleBanListCharacterCommand, SEC_GAMEMASTER, Console::Yes },
69 { "ip", HandleBanListIPCommand, SEC_GAMEMASTER, Console::Yes }
70 };
71
72 static ChatCommandTable baninfoCommandTable =
73 {
74 { "account", HandleBanInfoAccountCommand, SEC_GAMEMASTER, Console::Yes },
75 { "character", HandleBanInfoCharacterCommand, SEC_GAMEMASTER, Console::Yes },
76 { "ip", HandleBanInfoIPCommand, SEC_GAMEMASTER, Console::Yes }
77 };
78
79 static ChatCommandTable banCommandTable =
80 {
81 { "account", HandleBanAccountCommand, SEC_GAMEMASTER, Console::Yes },
82 { "character", HandleBanCharacterCommand, SEC_GAMEMASTER, Console::Yes },
83 { "playeraccount",HandleBanAccountByCharCommand, SEC_GAMEMASTER, Console::Yes },
84 { "ip", HandleBanIPCommand, SEC_GAMEMASTER, Console::Yes }
85 };
86
87 static ChatCommandTable commandTable =
88 {
89 { "ban", banCommandTable },
90 { "baninfo", baninfoCommandTable },
91 { "banlist", banlistCommandTable },
92 { "unban", unbanCommandTable }
93 };
94
95 return commandTable;
96 }
@ SEC_ADMINISTRATOR
Definition: Common.h:60
@ SEC_GAMEMASTER
Definition: Common.h:59
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:46
static bool HandleBanAccountByCharCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:154
static bool HandleUnBanIPCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:696
static bool HandleUnBanAccountByCharCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:691
static bool HandleBanInfoAccountCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:261
static bool HandleBanListIPCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:588
static bool HandleBanIPCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:159
static bool HandleBanListCharacterCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:505
static bool HandleBanInfoIPCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:362
static bool HandleBanListAccountCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:400
static bool HandleBanCharacterCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:103
static bool HandleBanInfoCharacterCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:314
static bool HandleUnBanAccountCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:660
static bool HandleBanAccountCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:98
static bool HandleUnBanCharacterCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:665

References HandleBanAccountByCharCommand(), HandleBanAccountCommand(), HandleBanCharacterCommand(), HandleBanInfoAccountCommand(), HandleBanInfoCharacterCommand(), HandleBanInfoIPCommand(), HandleBanIPCommand(), HandleBanListAccountCommand(), HandleBanListCharacterCommand(), HandleBanListIPCommand(), HandleUnBanAccountByCharCommand(), HandleUnBanAccountCommand(), HandleUnBanCharacterCommand(), HandleUnBanIPCommand(), SEC_ADMINISTRATOR, and SEC_GAMEMASTER.

◆ HandleBanAccountByCharCommand()

static bool ban_commandscript::HandleBanAccountByCharCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
155 {
156 return HandleBanHelper(BAN_CHARACTER, args, handler);
157 }
@ BAN_CHARACTER
Definition: cs_ban.cpp:40
static bool HandleBanHelper(BanMode mode, char const *args, ChatHandler *handler)
Definition: cs_ban.cpp:164

References BAN_CHARACTER, and HandleBanHelper().

Referenced by GetCommands().

◆ HandleBanAccountCommand()

static bool ban_commandscript::HandleBanAccountCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
99 {
100 return HandleBanHelper(BAN_ACCOUNT, args, handler);
101 }
@ BAN_ACCOUNT
Definition: cs_ban.cpp:39

References BAN_ACCOUNT, and HandleBanHelper().

Referenced by GetCommands().

◆ HandleBanCharacterCommand()

static bool ban_commandscript::HandleBanCharacterCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
104 {
105 if (!*args)
106 return false;
107
108 char* nameStr = strtok((char*)args, " ");
109 if (!nameStr)
110 return false;
111
112 std::string name = nameStr;
113
114 char* durationStr = strtok(nullptr, " ");
115 if (!durationStr || !atoi(durationStr))
116 return false;
117
118 char* reasonStr = strtok(nullptr, "");
119 if (!reasonStr)
120 return false;
121
122 if (!normalizePlayerName(name))
123 {
125 return false;
126 }
127
128 switch (sBan->BanCharacter(name, durationStr, reasonStr, handler->GetSession() ? handler->GetSession()->GetPlayerName() : ""))
129 {
130 case BAN_SUCCESS:
131 if (atoi(durationStr) > 0)
132 {
133 if (!sWorld->getBoolConfig(CONFIG_SHOW_BAN_IN_WORLD))
134 handler->PSendSysMessage(LANG_BAN_YOUBANNED, name, secsToTimeString(TimeStringToSecs(durationStr), true), reasonStr);
135 }
136 else
137 {
138 if (!sWorld->getBoolConfig(CONFIG_SHOW_BAN_IN_WORLD))
139 handler->PSendSysMessage(LANG_BAN_YOUPERMBANNED, name, reasonStr);
140 }
141 break;
142 case BAN_NOTFOUND:
143 {
144 handler->SendErrorMessage(LANG_BAN_NOTFOUND, "character", name);
145 return false;
146 }
147 default:
148 break;
149 }
150
151 return true;
152 }
std::string secsToTimeString(uint64 timeInSecs, bool shortText)
Definition: Util.cpp:73
uint32 TimeStringToSecs(const std::string &timestring)
Definition: Util.cpp:163
bool normalizePlayerName(std::string &name)
Definition: ObjectMgr.cpp:208
@ BAN_NOTFOUND
Definition: BanMgr.h:28
@ BAN_SUCCESS
Definition: BanMgr.h:26
#define sBan
Definition: BanMgr.h:48
@ LANG_BAN_NOTFOUND
Definition: Language.h:437
@ LANG_BAN_YOUPERMBANNED
Definition: Language.h:436
@ LANG_BAN_YOUBANNED
Definition: Language.h:435
@ LANG_PLAYER_NOT_FOUND
Definition: Language.h:539
@ CONFIG_SHOW_BAN_IN_WORLD
Definition: IWorld.h:133
#define sWorld
Definition: World.h:443
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:210
WorldSession * GetSession()
Definition: Chat.h:242
void SendErrorMessage(uint32 entry)
Definition: Chat.cpp:215
std::string const & GetPlayerName() const
Definition: WorldSession.cpp:186

References BAN_NOTFOUND, BAN_SUCCESS, CONFIG_SHOW_BAN_IN_WORLD, WorldSession::GetPlayerName(), ChatHandler::GetSession(), LANG_BAN_NOTFOUND, LANG_BAN_YOUBANNED, LANG_BAN_YOUPERMBANNED, LANG_PLAYER_NOT_FOUND, normalizePlayerName(), ChatHandler::PSendSysMessage(), sBan, secsToTimeString(), ChatHandler::SendErrorMessage(), sWorld, and TimeStringToSecs().

Referenced by GetCommands().

◆ HandleBanHelper()

static bool ban_commandscript::HandleBanHelper ( BanMode  mode,
char const *  args,
ChatHandler handler 
)
inlinestatic
165 {
166 if (!*args)
167 return false;
168
169 char* cnameOrIP = strtok((char*)args, " ");
170 if (!cnameOrIP)
171 return false;
172
173 std::string nameOrIP = cnameOrIP;
174
175 char* durationStr = strtok(nullptr, " ");
176 if (!durationStr || !atoi(durationStr))
177 return false;
178
179 char* reasonStr = strtok(nullptr, "");
180 if (!reasonStr)
181 return false;
182
183 switch (mode)
184 {
185 case BAN_ACCOUNT:
186 if (!Utf8ToUpperOnlyLatin(nameOrIP))
187 {
188 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, nameOrIP);
189 return false;
190 }
191 break;
192 case BAN_CHARACTER:
193 if (!normalizePlayerName(nameOrIP))
194 {
196 return false;
197 }
198 break;
199 case BAN_IP:
200 if (!IsIPAddress(nameOrIP.c_str()))
201 return false;
202 break;
203 }
204
205 BanReturn banReturn;
206
207 switch (mode)
208 {
209 case BAN_ACCOUNT:
210 banReturn = sBan->BanAccount(nameOrIP, durationStr, reasonStr, handler->GetSession() ? handler->GetSession()->GetPlayerName() : "");
211 break;
212 case BAN_CHARACTER:
213 banReturn = sBan->BanAccountByPlayerName(nameOrIP, durationStr, reasonStr, handler->GetSession() ? handler->GetSession()->GetPlayerName() : "");
214 break;
215 case BAN_IP:
216 default:
217 banReturn = sBan->BanIP(nameOrIP, durationStr, reasonStr, handler->GetSession() ? handler->GetSession()->GetPlayerName() : "");
218 break;
219 }
220
221 switch (banReturn)
222 {
223 case BAN_SUCCESS:
224 if (atoi(durationStr) > 0)
225 {
226 if (!sWorld->getBoolConfig(CONFIG_SHOW_BAN_IN_WORLD))
227 handler->PSendSysMessage(LANG_BAN_YOUBANNED, nameOrIP, secsToTimeString(TimeStringToSecs(durationStr), true), reasonStr);
228 }
229 else
230 {
231 if (!sWorld->getBoolConfig(CONFIG_SHOW_BAN_IN_WORLD))
232 handler->PSendSysMessage(LANG_BAN_YOUPERMBANNED, nameOrIP, reasonStr);
233 }
234 break;
235 case BAN_SYNTAX_ERROR:
236 return false;
237 case BAN_NOTFOUND:
238 switch (mode)
239 {
240 default:
241 handler->SendErrorMessage(LANG_BAN_NOTFOUND, "account", nameOrIP);
242 break;
243 case BAN_CHARACTER:
244 handler->SendErrorMessage(LANG_BAN_NOTFOUND, "character", nameOrIP);
245 break;
246 case BAN_IP:
247 handler->SendErrorMessage(LANG_BAN_NOTFOUND, "ip", nameOrIP);
248 break;
249 }
250 return false;
252 handler->PSendSysMessage("Unsuccessful! A longer ban is already present on this account!");
253 break;
254 default:
255 break;
256 }
257
258 return true;
259 }
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:532
bool IsIPAddress(char const *ipaddress)
Check if the string is a valid ip address representation.
Definition: Util.cpp:205
@ BAN_IP
Definition: cs_ban.cpp:41
BanReturn
Ban function return codes.
Definition: BanMgr.h:25
@ BAN_SYNTAX_ERROR
Definition: BanMgr.h:27
@ BAN_LONGER_EXISTS
Definition: BanMgr.h:29
@ LANG_ACCOUNT_NOT_EXIST
Definition: Language.h:442

References BAN_ACCOUNT, BAN_CHARACTER, BAN_IP, BAN_LONGER_EXISTS, BAN_NOTFOUND, BAN_SUCCESS, BAN_SYNTAX_ERROR, CONFIG_SHOW_BAN_IN_WORLD, WorldSession::GetPlayerName(), ChatHandler::GetSession(), IsIPAddress(), LANG_ACCOUNT_NOT_EXIST, LANG_BAN_NOTFOUND, LANG_BAN_YOUBANNED, LANG_BAN_YOUPERMBANNED, LANG_PLAYER_NOT_FOUND, normalizePlayerName(), ChatHandler::PSendSysMessage(), sBan, secsToTimeString(), ChatHandler::SendErrorMessage(), sWorld, TimeStringToSecs(), and Utf8ToUpperOnlyLatin().

Referenced by HandleBanAccountByCharCommand(), HandleBanAccountCommand(), and HandleBanIPCommand().

◆ HandleBanInfoAccountCommand()

static bool ban_commandscript::HandleBanInfoAccountCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
262 {
263 if (!*args)
264 return false;
265
266 char* nameStr = strtok((char*)args, "");
267 if (!nameStr)
268 return false;
269
270 std::string accountName = nameStr;
271 if (!Utf8ToUpperOnlyLatin(accountName))
272 {
273 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
274 return false;
275 }
276
277 uint32 accountId = AccountMgr::GetId(accountName);
278 if (!accountId)
279 {
280 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
281 return true;
282 }
283
284 return HandleBanInfoHelper(accountId, accountName.c_str(), handler);
285 }
std::uint32_t uint32
Definition: Define.h:107
uint32 GetId(std::string const &username)
Definition: AccountMgr.cpp:229
static bool HandleBanInfoHelper(uint32 accountId, char const *accountName, ChatHandler *handler)
Definition: cs_ban.cpp:287

References AccountMgr::GetId(), HandleBanInfoHelper(), LANG_ACCOUNT_NOT_EXIST, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), and Utf8ToUpperOnlyLatin().

Referenced by GetCommands().

◆ HandleBanInfoCharacterCommand()

static bool ban_commandscript::HandleBanInfoCharacterCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
315 {
316 if (!*args)
317 return false;
318
319 Player* target = ObjectAccessor::FindPlayerByName(args, false);
320 ObjectGuid targetGuid;
321 std::string name(args);
322
323 if (!target)
324 {
325 targetGuid = sCharacterCache->GetCharacterGuidByName(name);
326 if (!targetGuid)
327 {
329 return false;
330 }
331 }
332 else
333 targetGuid = target->GetGUID();
334
336 stmt->SetData(0, targetGuid.GetCounter());
337
338 PreparedQueryResult result = CharacterDatabase.Query(stmt);
339 if (!result)
340 {
342 return true;
343 }
344
346 do
347 {
348 Field* fields = result->Fetch();
349 time_t unbanDate = time_t(fields[3].Get<uint32>());
350 bool active = false;
351 if (fields[2].Get<uint8>() && (!fields[1].Get<uint32>() || unbanDate >= GameTime::GetGameTime().count()))
352 active = true;
353 bool permanent = (fields[1].Get<uint32>() == uint32(0));
354 std::string banTime = permanent ? handler->GetAcoreString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[1].Get<uint64>(), true);
356 fields[0].Get<std::string>(), banTime, active ? handler->GetAcoreString(LANG_YES) : handler->GetAcoreString(LANG_NO), fields[4].Get<std::string>(), fields[5].Get<std::string>());
357 } while (result->NextRow());
358
359 return true;
360 }
@ LANG_YES
Definition: Language.h:451
@ LANG_BANINFO_INFINITE
Definition: Language.h:449
@ LANG_BANINFO_NOCHARACTER
Definition: Language.h:444
@ LANG_BANINFO_BANHISTORY
Definition: Language.h:447
@ LANG_CHAR_NOT_BANNED
Definition: Language.h:925
@ LANG_NO
Definition: Language.h:452
@ LANG_BANINFO_HISTORYENTRY
Definition: Language.h:448
#define sCharacterCache
Definition: CharacterCache.h:83
@ CHAR_SEL_BANINFO
Definition: CharacterDatabase.h:44
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: DatabaseEnvFwd.h:45
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
Player * FindPlayerByName(std::string const &name, bool checkInWorld=true)
Definition: ObjectAccessor.cpp:271
Seconds GetGameTime()
Definition: GameTime.cpp:38
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
virtual char const * GetAcoreString(uint32 entry) const
Definition: Chat.cpp:40
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:109
Definition: ObjectGuid.h:118
LowType GetCounter() const
Definition: ObjectGuid.h:145
Definition: Player.h:1064

References CHAR_SEL_BANINFO, CharacterDatabase, ObjectAccessor::FindPlayerByName(), Field::Get(), ChatHandler::GetAcoreString(), ObjectGuid::GetCounter(), GameTime::GetGameTime(), Object::GetGUID(), LANG_BANINFO_BANHISTORY, LANG_BANINFO_HISTORYENTRY, LANG_BANINFO_INFINITE, LANG_BANINFO_NOCHARACTER, LANG_CHAR_NOT_BANNED, LANG_NO, LANG_YES, ChatHandler::PSendSysMessage(), sCharacterCache, secsToTimeString(), and PreparedStatementBase::SetData().

Referenced by GetCommands().

◆ HandleBanInfoHelper()

static bool ban_commandscript::HandleBanInfoHelper ( uint32  accountId,
char const *  accountName,
ChatHandler handler 
)
inlinestatic
288 {
289 QueryResult result = LoginDatabase.Query("SELECT FROM_UNIXTIME(bandate, '%Y-%m-%d..%H:%i:%s') as bandate, unbandate-bandate, active, unbandate, banreason, bannedby FROM account_banned WHERE id = '{}' ORDER BY bandate ASC", accountId);
290 if (!result)
291 {
292 handler->PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountName);
293 return true;
294 }
295
296 handler->PSendSysMessage(LANG_BANINFO_BANHISTORY, accountName);
297 do
298 {
299 Field* fields = result->Fetch();
300
301 time_t unbanDate = time_t(fields[3].Get<uint32>());
302 bool active = false;
303 if (fields[2].Get<bool>() && (fields[1].Get<uint64>() == uint64(0) || unbanDate >= GameTime::GetGameTime().count()))
304 active = true;
305 bool permanent = (fields[1].Get<uint64>() == uint64(0));
306 std::string banTime = permanent ? handler->GetAcoreString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[1].Get<uint64>(), true);
308 fields[0].Get<std::string>(), banTime, active ? handler->GetAcoreString(LANG_YES) : handler->GetAcoreString(LANG_NO), fields[4].Get<std::string>(), fields[5].Get<std::string>());
309 } while (result->NextRow());
310
311 return true;
312 }
std::uint64_t uint64
Definition: Define.h:106
@ LANG_BANINFO_NOACCOUNTBAN
Definition: Language.h:446
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:27
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22

References Field::Get(), ChatHandler::GetAcoreString(), GameTime::GetGameTime(), LANG_BANINFO_BANHISTORY, LANG_BANINFO_HISTORYENTRY, LANG_BANINFO_INFINITE, LANG_BANINFO_NOACCOUNTBAN, LANG_NO, LANG_YES, LoginDatabase, ChatHandler::PSendSysMessage(), and secsToTimeString().

Referenced by HandleBanInfoAccountCommand().

◆ HandleBanInfoIPCommand()

static bool ban_commandscript::HandleBanInfoIPCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
363 {
364 if (!*args)
365 return false;
366
367 char* ipStr = strtok((char*)args, "");
368 if (!ipStr)
369 return false;
370
371 if (!IsIPAddress(ipStr))
372 return false;
373
374 std::string IP = ipStr;
375
376 LoginDatabase.EscapeString(IP);
377 QueryResult result = LoginDatabase.Query("\
378 SELECT \
379 ip, FROM_UNIXTIME(bandate, '%Y-%m-%d %H:%i:%s'), FROM_UNIXTIME(unbandate, '%Y-%m-%d %H:%i:%s'), \
380 IF (unbandate > UNIX_TIMESTAMP(), unbandate - UNIX_TIMESTAMP(), 0) AS timeRemaining, \
381 banreason, bannedby, unbandate - bandate = 0 AS permanent \
382 FROM ip_banned \
383 WHERE ip = '{}' \
384 ", IP);
385 if (!result)
386 {
388 return true;
389 }
390
391 Field* fields = result->Fetch();
392 bool permanent = fields[6].Get<uint64>() == 1;
394 fields[0].Get<std::string>(), fields[1].Get<std::string>(), permanent ? handler->GetAcoreString(LANG_BANINFO_NEVER) : fields[2].Get<std::string>(),
395 permanent ? handler->GetAcoreString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[3].Get<uint64>(), true), fields[4].Get<std::string>(), fields[5].Get<std::string>());
396
397 return true;
398 }
@ LANG_BANINFO_IPENTRY
Definition: Language.h:453
@ LANG_BANINFO_NEVER
Definition: Language.h:450
@ LANG_BANINFO_NOIP
Definition: Language.h:445

References Field::Get(), ChatHandler::GetAcoreString(), IsIPAddress(), LANG_BANINFO_INFINITE, LANG_BANINFO_IPENTRY, LANG_BANINFO_NEVER, LANG_BANINFO_NOIP, LoginDatabase, ChatHandler::PSendSysMessage(), and secsToTimeString().

Referenced by GetCommands().

◆ HandleBanIPCommand()

static bool ban_commandscript::HandleBanIPCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
160 {
161 return HandleBanHelper(BAN_IP, args, handler);
162 }

References BAN_IP, and HandleBanHelper().

Referenced by GetCommands().

◆ HandleBanListAccountCommand()

static bool ban_commandscript::HandleBanListAccountCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
401 {
403 LoginDatabase.Execute(stmt);
404
405 char* filterStr = strtok((char*)args, " ");
406 std::string filter = filterStr ? filterStr : "";
407
408 PreparedQueryResult result;
409
410 if (filter.empty())
411 {
413 result = LoginDatabase.Query(stmt2);
414 }
415 else
416 {
418 stmt2->SetData(0, filter);
419 result = LoginDatabase.Query(stmt2);
420 }
421
422 if (!result)
423 {
425 return true;
426 }
427
428 return HandleBanListHelper(result, handler);
429 }
@ LANG_BANLIST_NOACCOUNT
Definition: Language.h:456
@ LOGIN_DEL_EXPIRED_IP_BANS
Definition: LoginDatabase.h:32
@ LOGIN_SEL_ACCOUNT_BANNED_BY_USERNAME
Definition: LoginDatabase.h:39
@ LOGIN_SEL_ACCOUNT_BANNED_ALL
Definition: LoginDatabase.h:38
static bool HandleBanListHelper(PreparedQueryResult result, ChatHandler *handler)
Definition: cs_ban.cpp:431

References HandleBanListHelper(), LANG_BANLIST_NOACCOUNT, LOGIN_DEL_EXPIRED_IP_BANS, LOGIN_SEL_ACCOUNT_BANNED_ALL, LOGIN_SEL_ACCOUNT_BANNED_BY_USERNAME, LoginDatabase, ChatHandler::PSendSysMessage(), and PreparedStatementBase::SetData().

Referenced by GetCommands().

◆ HandleBanListCharacterCommand()

static bool ban_commandscript::HandleBanListCharacterCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
506 {
507 if (!*args)
508 return false;
509
510 char* filterStr = strtok((char*)args, " ");
511 if (!filterStr)
512 return false;
513
514 std::string filter(filterStr);
516 stmt->SetData(0, filter);
517 PreparedQueryResult result = CharacterDatabase.Query(stmt);
518 if (!result)
519 {
521 return true;
522 }
523
525
526 // Chat short output
527 if (handler->GetSession())
528 {
529 do
530 {
531 Field* fields = result->Fetch();
533 stmt2->SetData(0, fields[0].Get<uint32>());
534
535 PreparedQueryResult banResult = CharacterDatabase.Query(stmt2);
536 if (banResult)
537 handler->PSendSysMessage("%s", (*banResult)[0].Get<std::string>());
538 } while (result->NextRow());
539 }
540 // Console wide output
541 else
542 {
544 handler->SendSysMessage(" =============================================================================== ");
546 do
547 {
548 handler->SendSysMessage("-------------------------------------------------------------------------------");
549
550 Field* fields = result->Fetch();
551
552 std::string char_name = fields[1].Get<std::string>();
553
555 stmt2->SetData(0, fields[0].Get<uint32>());
556
557 PreparedQueryResult banInfo = CharacterDatabase.Query(stmt2);
558 if (banInfo)
559 {
560 Field* banFields = banInfo->Fetch();
561 do
562 {
563 tm tmBan = Acore::Time::TimeBreakdown(banFields[0].Get<uint32>());
564
565 if (banFields[0].Get<uint32>() == banFields[1].Get<uint32>())
566 {
567 handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
568 char_name, tmBan.tm_year % 100, tmBan.tm_mon + 1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
569 banFields[2].Get<std::string>(), banFields[3].Get<std::string>());
570 }
571 else
572 {
573 tm tmUnban = Acore::Time::TimeBreakdown(banFields[1].Get<uint32>());
574 handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
575 char_name, tmBan.tm_year % 100, tmBan.tm_mon + 1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
576 tmUnban.tm_year % 100, tmUnban.tm_mon + 1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min,
577 banFields[2].Get<std::string>(), banFields[3].Get<std::string>());
578 }
579 } while (banInfo->NextRow());
580 }
581 } while (result->NextRow());
582 handler->SendSysMessage(" =============================================================================== ");
583 }
584
585 return true;
586 }
@ LANG_BANLIST_CHARACTERS_HEADER
Definition: Language.h:922
@ LANG_BANLIST_MATCHINGCHARACTER
Definition: Language.h:920
@ LANG_BANLIST_NOCHARACTER
Definition: Language.h:457
@ LANG_BANLIST_CHARACTERS
Definition: Language.h:921
@ CHAR_SEL_BANNED_NAME
Definition: CharacterDatabase.h:47
@ CHAR_SEL_BANINFO_LIST
Definition: CharacterDatabase.h:46
@ CHAR_SEL_GUID_BY_NAME_FILTER
Definition: CharacterDatabase.h:45
AC_COMMON_API std::tm TimeBreakdown(time_t t=0)
Definition: Timer.cpp:233
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:159

References CHAR_SEL_BANINFO_LIST, CHAR_SEL_BANNED_NAME, CHAR_SEL_GUID_BY_NAME_FILTER, CharacterDatabase, Field::Get(), ChatHandler::GetSession(), LANG_BANLIST_CHARACTERS, LANG_BANLIST_CHARACTERS_HEADER, LANG_BANLIST_MATCHINGCHARACTER, LANG_BANLIST_NOCHARACTER, ChatHandler::PSendSysMessage(), ChatHandler::SendSysMessage(), PreparedStatementBase::SetData(), and Acore::Time::TimeBreakdown().

Referenced by GetCommands().

◆ HandleBanListHelper()

static bool ban_commandscript::HandleBanListHelper ( PreparedQueryResult  result,
ChatHandler handler 
)
inlinestatic
432 {
434
435 // Chat short output
436 if (handler->GetSession())
437 {
438 do
439 {
440 Field* fields = result->Fetch();
441 uint32 accountid = fields[0].Get<uint32>();
442
443 QueryResult banResult = LoginDatabase.Query("SELECT account.username FROM account, account_banned WHERE account_banned.id='{}' AND account_banned.id=account.id", accountid);
444 if (banResult)
445 {
446 Field* fields2 = banResult->Fetch();
447 handler->PSendSysMessage("%s", fields2[0].Get<std::string>());
448 }
449 } while (result->NextRow());
450 }
451 // Console wide output
452 else
453 {
455 handler->SendSysMessage(" ===============================================================================");
457 do
458 {
459 handler->SendSysMessage("-------------------------------------------------------------------------------");
460 Field* fields = result->Fetch();
461 uint32 accountId = fields[0].Get<uint32>();
462
463 std::string accountName;
464
465 // "account" case, name can be get in same query
466 if (result->GetFieldCount() > 1)
467 accountName = fields[1].Get<std::string>();
468 // "character" case, name need extract from another DB
469 else
470 AccountMgr::GetName(accountId, accountName);
471
472 // No SQL injection. id is uint32.
473 QueryResult banInfo = LoginDatabase.Query("SELECT bandate, unbandate, bannedby, banreason FROM account_banned WHERE id = {} ORDER BY unbandate", accountId);
474 if (banInfo)
475 {
476 Field* fields2 = banInfo->Fetch();
477 do
478 {
479 tm tmBan = Acore::Time::TimeBreakdown(fields2[0].Get<uint32>());
480
481 if (fields2[0].Get<uint32>() == fields2[1].Get<uint32>())
482 {
483 handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
484 accountName, tmBan.tm_year % 100, tmBan.tm_mon + 1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
485 fields2[2].Get<std::string>(), fields2[3].Get<std::string>());
486 }
487 else
488 {
489 tm tmUnban = Acore::Time::TimeBreakdown(fields2[1].Get<uint32>());
490 handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
491 accountName, tmBan.tm_year % 100, tmBan.tm_mon + 1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
492 tmUnban.tm_year % 100, tmUnban.tm_mon + 1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min,
493 fields2[2].Get<std::string>(), fields2[3].Get<std::string>());
494 }
495 } while (banInfo->NextRow());
496 }
497 } while (result->NextRow());
498
499 handler->SendSysMessage(" ===============================================================================");
500 }
501
502 return true;
503 }
@ LANG_BANLIST_MATCHINGACCOUNT
Definition: Language.h:459
@ LANG_BANLIST_ACCOUNTS_HEADER
Definition: Language.h:656
@ LANG_BANLIST_ACCOUNTS
Definition: Language.h:655
bool GetName(uint32 accountId, std::string &name)
Definition: AccountMgr.cpp:257

References Field::Get(), AccountMgr::GetName(), ChatHandler::GetSession(), LANG_BANLIST_ACCOUNTS, LANG_BANLIST_ACCOUNTS_HEADER, LANG_BANLIST_MATCHINGACCOUNT, LoginDatabase, ChatHandler::PSendSysMessage(), ChatHandler::SendSysMessage(), and Acore::Time::TimeBreakdown().

Referenced by HandleBanListAccountCommand().

◆ HandleBanListIPCommand()

static bool ban_commandscript::HandleBanListIPCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
589 {
591 LoginDatabase.Execute(stmt);
592
593 char* filterStr = strtok((char*)args, " ");
594 std::string filter = filterStr ? filterStr : "";
595 LoginDatabase.EscapeString(filter);
596
597 PreparedQueryResult result;
598
599 if (filter.empty())
600 {
602 result = LoginDatabase.Query(stmt2);
603 }
604 else
605 {
607 stmt2->SetData(0, filter);
608 result = LoginDatabase.Query(stmt2);
609 }
610
611 if (!result)
612 {
614 return true;
615 }
616
618 // Chat short output
619 if (handler->GetSession())
620 {
621 do
622 {
623 Field* fields = result->Fetch();
624 handler->PSendSysMessage("%s", fields[0].Get<std::string>());
625 } while (result->NextRow());
626 }
627 // Console wide output
628 else
629 {
631 handler->SendSysMessage(" ===============================================================================");
633 do
634 {
635 handler->SendSysMessage("-------------------------------------------------------------------------------");
636 Field* fields = result->Fetch();
637 tm tmBan = Acore::Time::TimeBreakdown(fields[1].Get<uint32>());
638 if (fields[1].Get<uint32>() == fields[2].Get<uint32>())
639 {
640 handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
641 fields[0].Get<std::string>(), tmBan.tm_year % 100, tmBan.tm_mon + 1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
642 fields[3].Get<std::string>(), fields[4].Get<std::string>());
643 }
644 else
645 {
646 tm tmUnban = Acore::Time::TimeBreakdown(fields[2].Get<uint32>());
647 handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
648 fields[0].Get<std::string>(), tmBan.tm_year % 100, tmBan.tm_mon + 1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
649 tmUnban.tm_year % 100, tmUnban.tm_mon + 1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min,
650 fields[3].Get<std::string>(), fields[4].Get<std::string>());
651 }
652 } while (result->NextRow());
653
654 handler->SendSysMessage(" ===============================================================================");
655 }
656
657 return true;
658 }
@ LANG_BANLIST_IPS_HEADER
Definition: Language.h:658
@ LANG_BANLIST_MATCHINGIP
Definition: Language.h:458
@ LANG_BANLIST_NOIP
Definition: Language.h:455
@ LANG_BANLIST_IPS
Definition: Language.h:657
@ LOGIN_SEL_IP_BANNED_BY_IP
Definition: LoginDatabase.h:58
@ LOGIN_SEL_IP_BANNED_ALL
Definition: LoginDatabase.h:57

References Field::Get(), ChatHandler::GetSession(), LANG_BANLIST_IPS, LANG_BANLIST_IPS_HEADER, LANG_BANLIST_MATCHINGIP, LANG_BANLIST_NOIP, LOGIN_DEL_EXPIRED_IP_BANS, LOGIN_SEL_IP_BANNED_ALL, LOGIN_SEL_IP_BANNED_BY_IP, LoginDatabase, ChatHandler::PSendSysMessage(), ChatHandler::SendSysMessage(), PreparedStatementBase::SetData(), and Acore::Time::TimeBreakdown().

Referenced by GetCommands().

◆ HandleUnBanAccountByCharCommand()

static bool ban_commandscript::HandleUnBanAccountByCharCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
692 {
693 return HandleUnBanHelper(BAN_CHARACTER, args, handler);
694 }
static bool HandleUnBanHelper(BanMode mode, char const *args, ChatHandler *handler)
Definition: cs_ban.cpp:701

References BAN_CHARACTER, and HandleUnBanHelper().

Referenced by GetCommands().

◆ HandleUnBanAccountCommand()

static bool ban_commandscript::HandleUnBanAccountCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
661 {
662 return HandleUnBanHelper(BAN_ACCOUNT, args, handler);
663 }

References BAN_ACCOUNT, and HandleUnBanHelper().

Referenced by GetCommands().

◆ HandleUnBanCharacterCommand()

static bool ban_commandscript::HandleUnBanCharacterCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
666 {
667 if (!*args)
668 return false;
669
670 char* nameStr = strtok((char*)args, " ");
671 if (!nameStr)
672 return false;
673
674 std::string CharacterName = nameStr;
675
676 if (!normalizePlayerName(CharacterName))
677 {
679 return false;
680 }
681
682 if (!sBan->RemoveBanCharacter(CharacterName))
683 {
685 return false;
686 }
687
688 return true;
689 }

References LANG_PLAYER_NOT_FOUND, normalizePlayerName(), sBan, and ChatHandler::SendErrorMessage().

Referenced by GetCommands().

◆ HandleUnBanHelper()

static bool ban_commandscript::HandleUnBanHelper ( BanMode  mode,
char const *  args,
ChatHandler handler 
)
inlinestatic
702 {
703 if (!*args)
704 return false;
705
706 char* nameOrIPStr = strtok((char*)args, " ");
707 if (!nameOrIPStr)
708 return false;
709
710 std::string nameOrIP = nameOrIPStr;
711
712 switch (mode)
713 {
714 case BAN_ACCOUNT:
715 if (!Utf8ToUpperOnlyLatin(nameOrIP))
716 {
717 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, nameOrIP);
718 return false;
719 }
720 break;
721 case BAN_CHARACTER:
722 if (!normalizePlayerName(nameOrIP))
723 {
725 return false;
726 }
727 break;
728 case BAN_IP:
729 if (!IsIPAddress(nameOrIP.c_str()))
730 return false;
731 break;
732 }
733
734 switch (mode)
735 {
736 case BAN_ACCOUNT:
737 if (sBan->RemoveBanAccount(nameOrIP))
738 handler->PSendSysMessage(LANG_UNBAN_UNBANNED, nameOrIP);
739 else
740 handler->PSendSysMessage(LANG_UNBAN_ERROR, nameOrIP);
741 break;
742 case BAN_CHARACTER:
743 if (sBan->RemoveBanAccountByPlayerName(nameOrIP))
744 handler->PSendSysMessage(LANG_UNBAN_UNBANNED, nameOrIP);
745 else
746 handler->PSendSysMessage(LANG_UNBAN_ERROR, nameOrIP);
747 break;
748 case BAN_IP:
749 if (sBan->RemoveBanIP(nameOrIP))
750 handler->PSendSysMessage(LANG_UNBAN_UNBANNED, nameOrIP);
751 else
752 handler->PSendSysMessage(LANG_UNBAN_ERROR, nameOrIP);
753 break;
754 default:
755 break;
756 }
757
758 return true;
759 }
@ LANG_UNBAN_UNBANNED
Definition: Language.h:439
@ LANG_UNBAN_ERROR
Definition: Language.h:440

References BAN_ACCOUNT, BAN_CHARACTER, BAN_IP, IsIPAddress(), LANG_ACCOUNT_NOT_EXIST, LANG_PLAYER_NOT_FOUND, LANG_UNBAN_ERROR, LANG_UNBAN_UNBANNED, normalizePlayerName(), ChatHandler::PSendSysMessage(), sBan, ChatHandler::SendErrorMessage(), and Utf8ToUpperOnlyLatin().

Referenced by HandleUnBanAccountByCharCommand(), HandleUnBanAccountCommand(), and HandleUnBanIPCommand().

◆ HandleUnBanIPCommand()

static bool ban_commandscript::HandleUnBanIPCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
697 {
698 return HandleUnBanHelper(BAN_IP, args, handler);
699 }

References BAN_IP, and HandleUnBanHelper().

Referenced by GetCommands().