TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ban_commandscript Class Reference

Public Member Functions

 ban_commandscript ()
 
std::vector< ChatCommandGetCommands () const override
 
- Public Member Functions inherited from ScriptObject
const std::string & GetName () const
 

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)
 
virtual ~ScriptObject ()
 

Constructor & Destructor Documentation

ban_commandscript::ban_commandscript ( )
inline
36 : CommandScript("ban_commandscript") { }
CommandScript(const char *name)
Definition: ScriptMgr.cpp:1616

Member Function Documentation

std::vector<ChatCommand> ban_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

39  {
40  static std::vector<ChatCommand> unbanCommandTable =
41  {
46  };
47  static std::vector<ChatCommand> banlistCommandTable =
48  {
52  };
53  static std::vector<ChatCommand> baninfoCommandTable =
54  {
58  };
59  static std::vector<ChatCommand> banCommandTable =
60  {
65  };
66  static std::vector<ChatCommand> commandTable =
67  {
68  { "ban", rbac::RBAC_PERM_COMMAND_BAN, true, NULL, "", banCommandTable },
69  { "baninfo", rbac::RBAC_PERM_COMMAND_BANINFO, true, NULL, "", baninfoCommandTable },
70  { "banlist", rbac::RBAC_PERM_COMMAND_BANLIST, true, NULL, "", banlistCommandTable },
71  { "unban", rbac::RBAC_PERM_COMMAND_UNBAN, true, NULL, "", unbanCommandTable },
72  };
73  return commandTable;
74  }
static bool HandleUnBanIPCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:691
static bool HandleBanInfoIPCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:340
static bool HandleBanListAccountCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:372
static bool HandleBanListCharacterCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:486
static bool HandleBanAccountByCharCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:142
static bool HandleBanListIPCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:574
Definition: RBAC.h:155
static bool HandleUnBanAccountCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:653
arena_t NULL
Definition: jemalloc_internal.h:624
static bool HandleUnBanAccountByCharCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:686
static bool HandleUnBanCharacterCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:658
static bool HandleBanCharacterCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:81
Definition: RBAC.h:159
static bool HandleBanIPCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:147
Definition: RBAC.h:146
Definition: RBAC.h:151
static bool HandleBanInfoCharacterCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:292
Definition: RBAC.h:162
static bool HandleBanInfoAccountCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:237
static bool HandleBanAccountCommand(ChatHandler *handler, char const *args)
Definition: cs_ban.cpp:76
Definition: RBAC.h:149

+ Here is the call graph for this function:

static bool ban_commandscript::HandleBanAccountByCharCommand ( ChatHandler handler,
char const args 
)
inlinestatic
143  {
144  return HandleBanHelper(BAN_CHARACTER, args, handler);
145  }
static bool HandleBanHelper(BanMode mode, char const *args, ChatHandler *handler)
Definition: cs_ban.cpp:152
Definition: SharedDefines.h:4536

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool ban_commandscript::HandleBanAccountCommand ( ChatHandler handler,
char const args 
)
inlinestatic
77  {
78  return HandleBanHelper(BAN_ACCOUNT, args, handler);
79  }
Definition: SharedDefines.h:4535
static bool HandleBanHelper(BanMode mode, char const *args, ChatHandler *handler)
Definition: cs_ban.cpp:152

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool ban_commandscript::HandleBanCharacterCommand ( ChatHandler handler,
char const args 
)
inlinestatic
82  {
83  if (!*args)
84  return false;
85 
86  char* nameStr = strtok((char*)args, " ");
87  if (!nameStr)
88  return false;
89 
90  std::string name = nameStr;
91 
92  char* durationStr = strtok(NULL, " ");
93  if (!durationStr || !atoi(durationStr))
94  return false;
95 
96  char* reasonStr = strtok(NULL, "");
97  if (!reasonStr)
98  return false;
99 
100  if (!normalizePlayerName(name))
101  {
103  handler->SetSentErrorMessage(true);
104  return false;
105  }
106 
107  std::string author = handler->GetSession() ? handler->GetSession()->GetPlayerName() : "Server";
108 
109  switch (sWorld->BanCharacter(name, durationStr, reasonStr, author))
110  {
111  case BAN_SUCCESS:
112  {
113  if (atoi(durationStr) > 0)
114  {
115  if (sWorld->getBoolConfig(CONFIG_SHOW_BAN_IN_WORLD))
116  sWorld->SendWorldText(LANG_BAN_CHARACTER_YOUBANNEDMESSAGE_WORLD, author.c_str(), name.c_str(), secsToTimeString(TimeStringToSecs(durationStr), true).c_str(), reasonStr);
117  else
118  handler->PSendSysMessage(LANG_BAN_YOUBANNED, name.c_str(), secsToTimeString(TimeStringToSecs(durationStr), true).c_str(), reasonStr);
119  }
120  else
121  {
122  if (sWorld->getBoolConfig(CONFIG_SHOW_BAN_IN_WORLD))
123  sWorld->SendWorldText(LANG_BAN_CHARACTER_YOUPERMBANNEDMESSAGE_WORLD, author.c_str(), name.c_str(), reasonStr);
124  else
125  handler->PSendSysMessage(LANG_BAN_YOUPERMBANNED, name.c_str(), reasonStr);
126  }
127  break;
128  }
129  case BAN_NOTFOUND:
130  {
131  handler->PSendSysMessage(LANG_BAN_NOTFOUND, "character", name.c_str());
132  handler->SetSentErrorMessage(true);
133  return false;
134  }
135  default:
136  break;
137  }
138 
139  return true;
140  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
std::string secsToTimeString(uint64 timeInSecs, bool shortText, bool hoursOnly)
Definition: Util.cpp:109
std::string const & GetPlayerName() const
Definition: WorldSession.cpp:190
Definition: World.h:152
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: Language.h:405
#define sWorld
Definition: World.h:887
bool normalizePlayerName(std::string &name)
Definition: ObjectMgr.cpp:133
Definition: SharedDefines.h:4545
uint32 TimeStringToSecs(const std::string &timestring)
Definition: Util.cpp:163
Definition: Language.h:407
Definition: SharedDefines.h:4543
Definition: Language.h:406
WorldSession * GetSession()
Definition: Chat.h:59
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
Definition: Language.h:509

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool ban_commandscript::HandleBanHelper ( BanMode  mode,
char const args,
ChatHandler handler 
)
inlinestatic
153  {
154  if (!*args)
155  return false;
156 
157  char* cnameOrIP = strtok((char*)args, " ");
158  if (!cnameOrIP)
159  return false;
160 
161  std::string nameOrIP = cnameOrIP;
162 
163  char* durationStr = strtok(NULL, " ");
164  if (!durationStr || !atoi(durationStr))
165  return false;
166 
167  char* reasonStr = strtok(NULL, "");
168  if (!reasonStr)
169  return false;
170 
171  switch (mode)
172  {
173  case BAN_ACCOUNT:
174  if (!Utf8ToUpperOnlyLatin(nameOrIP))
175  {
176  handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, nameOrIP.c_str());
177  handler->SetSentErrorMessage(true);
178  return false;
179  }
180  break;
181  case BAN_CHARACTER:
182  if (!normalizePlayerName(nameOrIP))
183  {
185  handler->SetSentErrorMessage(true);
186  return false;
187  }
188  break;
189  case BAN_IP:
190  if (!IsIPAddress(nameOrIP.c_str()))
191  return false;
192  break;
193  }
194 
195  std::string author = handler->GetSession() ? handler->GetSession()->GetPlayerName() : "Server";
196 
197  switch (sWorld->BanAccount(mode, nameOrIP, durationStr, reasonStr, author))
198  {
199  case BAN_SUCCESS:
200  if (atoi(durationStr) > 0)
201  {
202  if (sWorld->getBoolConfig(CONFIG_SHOW_BAN_IN_WORLD))
203  sWorld->SendWorldText(LANG_BAN_ACCOUNT_YOUBANNEDMESSAGE_WORLD, author.c_str(), nameOrIP.c_str(), secsToTimeString(TimeStringToSecs(durationStr), true).c_str(), reasonStr);
204  else
205  handler->PSendSysMessage(LANG_BAN_YOUBANNED, nameOrIP.c_str(), secsToTimeString(TimeStringToSecs(durationStr), true).c_str(), reasonStr);
206  }
207  else
208  {
209  if (sWorld->getBoolConfig(CONFIG_SHOW_BAN_IN_WORLD))
210  sWorld->SendWorldText(LANG_BAN_ACCOUNT_YOUPERMBANNEDMESSAGE_WORLD, author.c_str(), nameOrIP.c_str(), reasonStr);
211  else
212  handler->PSendSysMessage(LANG_BAN_YOUPERMBANNED, nameOrIP.c_str(), reasonStr);
213  }
214  break;
215  case BAN_SYNTAX_ERROR:
216  return false;
217  case BAN_NOTFOUND:
218  switch (mode)
219  {
220  default:
221  handler->PSendSysMessage(LANG_BAN_NOTFOUND, "account", nameOrIP.c_str());
222  break;
223  case BAN_CHARACTER:
224  handler->PSendSysMessage(LANG_BAN_NOTFOUND, "character", nameOrIP.c_str());
225  break;
226  case BAN_IP:
227  handler->PSendSysMessage(LANG_BAN_NOTFOUND, "ip", nameOrIP.c_str());
228  break;
229  }
230  handler->SetSentErrorMessage(true);
231  return false;
232  }
233 
234  return true;
235  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
std::string secsToTimeString(uint64 timeInSecs, bool shortText, bool hoursOnly)
Definition: Util.cpp:109
std::string const & GetPlayerName() const
Definition: WorldSession.cpp:190
Definition: World.h:152
Definition: SharedDefines.h:4544
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: SharedDefines.h:4537
Definition: Language.h:405
#define sWorld
Definition: World.h:887
Definition: SharedDefines.h:4535
bool normalizePlayerName(std::string &name)
Definition: ObjectMgr.cpp:133
Definition: SharedDefines.h:4545
uint32 TimeStringToSecs(const std::string &timestring)
Definition: Util.cpp:163
Definition: Language.h:407
bool IsIPAddress(char const *ipaddress)
Check if the string is a valid ip address representation.
Definition: Util.cpp:211
Definition: SharedDefines.h:4536
Definition: Language.h:1211
Definition: SharedDefines.h:4543
Definition: Language.h:406
WorldSession * GetSession()
Definition: Chat.h:59
Definition: Language.h:412
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:498
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
Definition: Language.h:509

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool ban_commandscript::HandleBanInfoAccountCommand ( ChatHandler handler,
char const args 
)
inlinestatic
238  {
239  if (!*args)
240  return false;
241 
242  char* nameStr = strtok((char*)args, "");
243  if (!nameStr)
244  return false;
245 
246  std::string accountName = nameStr;
247  if (!Utf8ToUpperOnlyLatin(accountName))
248  {
249  handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
250  handler->SetSentErrorMessage(true);
251  return false;
252  }
253 
254  uint32 accountId = AccountMgr::GetId(accountName);
255  if (!accountId)
256  {
257  handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
258  return true;
259  }
260 
261  return HandleBanInfoHelper(accountId, accountName.c_str(), handler);
262  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
static uint32 GetId(std::string const &username)
Definition: AccountMgr.cpp:275
uint32_t uint32
Definition: Define.h:150
static bool HandleBanInfoHelper(uint32 accountId, char const *accountName, ChatHandler *handler)
Definition: cs_ban.cpp:264
Definition: Language.h:412
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:498

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool ban_commandscript::HandleBanInfoCharacterCommand ( ChatHandler handler,
char const args 
)
inlinestatic
293  {
294  if (!*args)
295  return false;
296 
298  ObjectGuid targetGuid;
299  std::string name(args);
300 
301  if (!target)
302  {
303  targetGuid = ObjectMgr::GetPlayerGUIDByName(name);
304  if (targetGuid.IsEmpty())
305  {
307  return false;
308  }
309  }
310  else
311  targetGuid = target->GetGUID();
312 
314  stmt->setUInt64(0, targetGuid.GetCounter());
316  if (!result)
317  {
318  handler->PSendSysMessage(LANG_CHAR_NOT_BANNED, name.c_str());
319  return true;
320  }
321 
322  handler->PSendSysMessage(LANG_BANINFO_BANHISTORY, name.c_str());
323  do
324  {
325  Field* fields = result->Fetch();
326  time_t unbanDate = time_t(fields[3].GetUInt32());
327  bool active = false;
328  if (fields[2].GetUInt8() && (!fields[1].GetUInt32() || unbanDate >= time(NULL)))
329  active = true;
330  bool permanent = (fields[1].GetUInt32() == uint32(0));
331  std::string banTime = permanent ? handler->GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[1].GetUInt32(), true);
333  TimeToTimestampStr(fields[0].GetUInt32()).c_str(), banTime.c_str(), active ? handler->GetTrinityString(LANG_YES) : handler->GetTrinityString(LANG_NO), fields[4].GetCString(), fields[5].GetCString());
334  }
335  while (result->NextRow());
336 
337  return true;
338  }
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Definition: Language.h:417
std::string secsToTimeString(uint64 timeInSecs, bool shortText, bool hoursOnly)
Definition: Util.cpp:109
Class used to access individual fields of database query result.
Definition: Field.h:56
Definition: Language.h:414
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: PreparedStatement.h:74
char const * GetCString() const
Definition: Field.h:260
static ObjectGuid GetPlayerGUIDByName(std::string const &name)
Definition: ObjectMgr.cpp:2247
std::string TimeToTimestampStr(time_t t)
Definition: Util.cpp:195
TC_GAME_API Player * FindPlayerByName(std::string const &name)
Definition: ObjectAccessor.cpp:220
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
Definition: CharacterDatabase.h:44
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
Definition: Language.h:422
virtual char const * GetTrinityString(uint32 entry) const
Definition: Chat.cpp:67
uint32 GetUInt32() const
Definition: Field.h:146
void setUInt64(const uint8 index, const uint64 value)
Definition: PreparedStatement.cpp:124
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
Definition: Language.h:418
Definition: Language.h:939
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: ObjectGuid.h:189
uint32_t uint32
Definition: g3dmath.h:168
Definition: Language.h:421
bool IsEmpty() const
Definition: ObjectGuid.h:242
LowType GetCounter() const
Definition: ObjectGuid.h:221
Definition: Language.h:419

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool ban_commandscript::HandleBanInfoHelper ( uint32  accountId,
char const accountName,
ChatHandler handler 
)
inlinestatic
265  {
266  QueryResult result = LoginDatabase.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate, banreason, bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC", accountId);
267  if (!result)
268  {
269  handler->PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountName);
270  return true;
271  }
272 
273  handler->PSendSysMessage(LANG_BANINFO_BANHISTORY, accountName);
274  do
275  {
276  Field* fields = result->Fetch();
277 
278  time_t unbanDate = time_t(fields[3].GetUInt32());
279  bool active = false;
280  if (fields[2].GetBool() && (fields[1].GetUInt64() == uint64(0) || unbanDate >= time(NULL)))
281  active = true;
282  bool permanent = (fields[1].GetUInt64() == uint64(0));
283  std::string banTime = permanent ? handler->GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[1].GetUInt64(), true);
285  fields[0].GetCString(), banTime.c_str(), active ? handler->GetTrinityString(LANG_YES) : handler->GetTrinityString(LANG_NO), fields[4].GetCString(), fields[5].GetCString());
286  }
287  while (result->NextRow());
288 
289  return true;
290  }
Definition: Language.h:417
uint64 GetUInt64() const
Definition: Field.h:184
std::string secsToTimeString(uint64 timeInSecs, bool shortText, bool hoursOnly)
Definition: Util.cpp:109
QueryResult PQuery(Format &&sql, T *conn, Args &&...args)
Definition: DatabaseWorkerPool.h:165
Class used to access individual fields of database query result.
Definition: Field.h:56
arena_t NULL
Definition: jemalloc_internal.h:624
uint64_t uint64
Definition: g3dmath.h:170
Definition: Language.h:416
char const * GetCString() const
Definition: Field.h:260
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
Definition: Language.h:422
virtual char const * GetTrinityString(uint32 entry) const
Definition: Chat.cpp:67
Definition: Language.h:418
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: Language.h:421
Definition: Language.h:419

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool ban_commandscript::HandleBanInfoIPCommand ( ChatHandler handler,
char const args 
)
inlinestatic
341  {
342  if (!*args)
343  return false;
344 
345  char* ipStr = strtok((char*)args, "");
346  if (!ipStr)
347  return false;
348 
349  if (!IsIPAddress(ipStr))
350  return false;
351 
352  std::string IP = ipStr;
353 
355  QueryResult result = LoginDatabase.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason, bannedby, unbandate-bandate FROM ip_banned WHERE ip = '%s'", IP.c_str());
356  if (!result)
357  {
359  return true;
360  }
361 
362  Field* fields = result->Fetch();
363  bool permanent = !fields[6].GetUInt64();
365  fields[0].GetCString(), fields[1].GetCString(), permanent ? handler->GetTrinityString(LANG_BANINFO_NEVER) : fields[2].GetCString(),
366  permanent ? handler->GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetCString(), fields[5].GetCString());
367 
368 
369  return true;
370  }
uint64 GetUInt64() const
Definition: Field.h:184
std::string secsToTimeString(uint64 timeInSecs, bool shortText, bool hoursOnly)
Definition: Util.cpp:109
QueryResult PQuery(Format &&sql, T *conn, Args &&...args)
Definition: DatabaseWorkerPool.h:165
Class used to access individual fields of database query result.
Definition: Field.h:56
char const * GetCString() const
Definition: Field.h:260
Definition: Language.h:415
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
void EscapeString(std::string &str)
Apply escape string'ing for current collation. (utf8)
Definition: DatabaseWorkerPool.cpp:231
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
bool IsIPAddress(char const *ipaddress)
Check if the string is a valid ip address representation.
Definition: Util.cpp:211
virtual char const * GetTrinityString(uint32 entry) const
Definition: Chat.cpp:67
Definition: Language.h:420
Definition: Language.h:423
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: Language.h:419

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool ban_commandscript::HandleBanIPCommand ( ChatHandler handler,
char const args 
)
inlinestatic
148  {
149  return HandleBanHelper(BAN_IP, args, handler);
150  }
Definition: SharedDefines.h:4537
static bool HandleBanHelper(BanMode mode, char const *args, ChatHandler *handler)
Definition: cs_ban.cpp:152

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool ban_commandscript::HandleBanListAccountCommand ( ChatHandler handler,
char const args 
)
inlinestatic
373  {
374  PreparedStatement* stmt = NULL;
375 
377  LoginDatabase.Execute(stmt);
378 
379  char* filterStr = strtok((char*)args, " ");
380  std::string filter = filterStr ? filterStr : "";
381 
382  PreparedQueryResult result;
383 
384  if (filter.empty())
385  {
387  result = LoginDatabase.Query(stmt);
388  }
389  else
390  {
392  stmt->setString(0, filter);
393  result = LoginDatabase.Query(stmt);
394  }
395 
396  if (!result)
397  {
399  return true;
400  }
401 
402  return HandleBanListHelper(result, handler);
403  }
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Definition: LoginDatabase.h:33
void setString(const uint8 index, const std::string &value)
Definition: PreparedStatement.cpp:187
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: PreparedStatement.h:74
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
static bool HandleBanListHelper(PreparedQueryResult result, ChatHandler *handler)
Definition: cs_ban.cpp:405
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
Definition: Language.h:426
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: LoginDatabase.h:37
Definition: LoginDatabase.h:38

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool ban_commandscript::HandleBanListCharacterCommand ( ChatHandler handler,
char const args 
)
inlinestatic
487  {
488  if (!*args)
489  return false;
490 
491  char* filterStr = strtok((char*)args, " ");
492  if (!filterStr)
493  return false;
494 
495  std::string filter(filterStr);
497  stmt->setString(0, filter);
499  if (!result)
500  {
502  return true;
503  }
504 
506 
507  // Chat short output
508  if (handler->GetSession())
509  {
510  do
511  {
512  Field* fields = result->Fetch();
514  stmt2->setUInt64(0, fields[0].GetUInt64());
515  PreparedQueryResult banResult = CharacterDatabase.Query(stmt2);
516  if (banResult)
517  handler->PSendSysMessage("%s", (*banResult)[0].GetCString());
518  }
519  while (result->NextRow());
520  }
521  // Console wide output
522  else
523  {
525  handler->SendSysMessage(" =============================================================================== ");
527  do
528  {
529  handler->SendSysMessage("-------------------------------------------------------------------------------");
530 
531  Field* fields = result->Fetch();
532 
533  std::string char_name = fields[1].GetString();
534 
536  stmt2->setUInt64(0, fields[0].GetUInt64());
538  if (banInfo)
539  {
540  Field* banFields = banInfo->Fetch();
541  do
542  {
543  time_t timeBan = time_t(banFields[0].GetUInt32());
544  tm tmBan;
545  localtime_r(&timeBan, &tmBan);
546 
547  if (banFields[0].GetUInt32() == banFields[1].GetUInt32())
548  {
549  handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
550  char_name.c_str(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
551  banFields[2].GetCString(), banFields[3].GetCString());
552  }
553  else
554  {
555  time_t timeUnban = time_t(banFields[1].GetUInt32());
556  tm tmUnban;
557  localtime_r(&timeUnban, &tmUnban);
558  handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
559  char_name.c_str(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
560  tmUnban.tm_year%100, tmUnban.tm_mon+1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min,
561  banFields[2].GetCString(), banFields[3].GetCString());
562  }
563  }
564  while (banInfo->NextRow());
565  }
566  }
567  while (result->NextRow());
568  handler->SendSysMessage(" =============================================================================== ");
569  }
570 
571  return true;
572  }
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Definition: Language.h:936
Class used to access individual fields of database query result.
Definition: Field.h:56
Definition: Language.h:934
void setString(const uint8 index, const std::string &value)
Definition: PreparedStatement.cpp:187
Definition: Language.h:935
Definition: PreparedStatement.h:74
char const * GetCString() const
Definition: Field.h:260
Definition: CharacterDatabase.h:46
Definition: CharacterDatabase.h:47
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
TC_COMMON_API struct tm * localtime_r(const time_t *time, struct tm *result)
Definition: CharacterDatabase.h:45
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
void setUInt64(const uint8 index, const uint64 value)
Definition: PreparedStatement.cpp:124
WorldSession * GetSession()
Definition: Chat.h:59
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: Language.h:427
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
std::string GetString() const
Definition: Field.h:276

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool ban_commandscript::HandleBanListHelper ( PreparedQueryResult  result,
ChatHandler handler 
)
inlinestatic
406  {
408 
409  // Chat short output
410  if (handler->GetSession())
411  {
412  do
413  {
414  Field* fields = result->Fetch();
415  uint32 accountid = fields[0].GetUInt32();
416 
417  QueryResult banResult = LoginDatabase.PQuery("SELECT account.username FROM account, account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id", accountid);
418  if (banResult)
419  {
420  Field* fields2 = banResult->Fetch();
421  handler->PSendSysMessage("%s", fields2[0].GetCString());
422  }
423  }
424  while (result->NextRow());
425  }
426  // Console wide output
427  else
428  {
430  handler->SendSysMessage(" ===============================================================================");
432  do
433  {
434  handler->SendSysMessage("-------------------------------------------------------------------------------");
435  Field* fields = result->Fetch();
436  uint32 accountId = fields[0].GetUInt32();
437 
438  std::string accountName;
439 
440  // "account" case, name can be get in same query
441  if (result->GetFieldCount() > 1)
442  accountName = fields[1].GetString();
443  // "character" case, name need extract from another DB
444  else
445  AccountMgr::GetName(accountId, accountName);
446 
447  // No SQL injection. id is uint32.
448  QueryResult banInfo = LoginDatabase.PQuery("SELECT bandate, unbandate, bannedby, banreason FROM account_banned WHERE id = %u ORDER BY unbandate", accountId);
449  if (banInfo)
450  {
451  Field* fields2 = banInfo->Fetch();
452  do
453  {
454  time_t timeBan = time_t(fields2[0].GetUInt32());
455  tm tmBan;
456  localtime_r(&timeBan, &tmBan);
457 
458  if (fields2[0].GetUInt32() == fields2[1].GetUInt32())
459  {
460  handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
461  accountName.c_str(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
462  fields2[2].GetCString(), fields2[3].GetCString());
463  }
464  else
465  {
466  time_t timeUnban = time_t(fields2[1].GetUInt32());
467  tm tmUnban;
468  localtime_r(&timeUnban, &tmUnban);
469  handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
470  accountName.c_str(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
471  tmUnban.tm_year%100, tmUnban.tm_mon+1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min,
472  fields2[2].GetCString(), fields2[3].GetCString());
473  }
474  }
475  while (banInfo->NextRow());
476  }
477  }
478  while (result->NextRow());
479 
480  handler->SendSysMessage(" ===============================================================================");
481  }
482 
483  return true;
484  }
Definition: Language.h:429
Definition: Language.h:623
QueryResult PQuery(Format &&sql, T *conn, Args &&...args)
Definition: DatabaseWorkerPool.h:165
Class used to access individual fields of database query result.
Definition: Field.h:56
Definition: Language.h:622
static bool GetName(uint32 accountId, std::string &name)
Definition: AccountMgr.cpp:303
char const * GetCString() const
Definition: Field.h:260
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
uint32_t uint32
Definition: Define.h:150
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
TC_COMMON_API struct tm * localtime_r(const time_t *time, struct tm *result)
uint32 GetUInt32() const
Definition: Field.h:146
WorldSession * GetSession()
Definition: Chat.h:59
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool ban_commandscript::HandleBanListIPCommand ( ChatHandler handler,
char const args 
)
inlinestatic
575  {
576  PreparedStatement* stmt = NULL;
578  LoginDatabase.Execute(stmt);
579 
580  char* filterStr = strtok((char*)args, " ");
581  std::string filter = filterStr ? filterStr : "";
582  LoginDatabase.EscapeString(filter);
583 
584  PreparedQueryResult result;
585 
586  if (filter.empty())
587  {
589  result = LoginDatabase.Query(stmt);
590  }
591  else
592  {
594  stmt->setString(0, filter);
595  result = LoginDatabase.Query(stmt);
596  }
597 
598  if (!result)
599  {
601  return true;
602  }
603 
605  // Chat short output
606  if (handler->GetSession())
607  {
608  do
609  {
610  Field* fields = result->Fetch();
611  handler->PSendSysMessage("%s", fields[0].GetCString());
612  }
613  while (result->NextRow());
614  }
615  // Console wide output
616  else
617  {
619  handler->SendSysMessage(" ===============================================================================");
621  do
622  {
623  handler->SendSysMessage("-------------------------------------------------------------------------------");
624  Field* fields = result->Fetch();
625  time_t timeBan = time_t(fields[1].GetUInt32());
626  tm tmBan;
627  localtime_r(&timeBan, &tmBan);
628  if (fields[1].GetUInt32() == fields[2].GetUInt32())
629  {
630  handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
631  fields[0].GetCString(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
632  fields[3].GetCString(), fields[4].GetCString());
633  }
634  else
635  {
636  time_t timeUnban = time_t(fields[2].GetUInt32());
637  tm tmUnban;
638  localtime_r(&timeUnban, &tmUnban);
639  handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
640  fields[0].GetCString(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
641  tmUnban.tm_year%100, tmUnban.tm_mon+1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min,
642  fields[3].GetCString(), fields[4].GetCString());
643  }
644  }
645  while (result->NextRow());
646 
647  handler->SendSysMessage(" ===============================================================================");
648  }
649 
650  return true;
651  }
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Class used to access individual fields of database query result.
Definition: Field.h:56
Definition: LoginDatabase.h:33
void setString(const uint8 index, const std::string &value)
Definition: PreparedStatement.cpp:187
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: Language.h:425
Definition: PreparedStatement.h:74
char const * GetCString() const
Definition: Field.h:260
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
Definition: Language.h:625
Definition: Language.h:624
Definition: LoginDatabase.h:52
void EscapeString(std::string &str)
Apply escape string'ing for current collation. (utf8)
Definition: DatabaseWorkerPool.cpp:231
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
TC_COMMON_API struct tm * localtime_r(const time_t *time, struct tm *result)
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
WorldSession * GetSession()
Definition: Chat.h:59
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: LoginDatabase.h:51
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
Definition: Language.h:428

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool ban_commandscript::HandleUnBanAccountByCharCommand ( ChatHandler handler,
char const args 
)
inlinestatic
687  {
688  return HandleUnBanHelper(BAN_CHARACTER, args, handler);
689  }
static bool HandleUnBanHelper(BanMode mode, char const *args, ChatHandler *handler)
Definition: cs_ban.cpp:696
Definition: SharedDefines.h:4536

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool ban_commandscript::HandleUnBanAccountCommand ( ChatHandler handler,
char const args 
)
inlinestatic
654  {
655  return HandleUnBanHelper(BAN_ACCOUNT, args, handler);
656  }
Definition: SharedDefines.h:4535
static bool HandleUnBanHelper(BanMode mode, char const *args, ChatHandler *handler)
Definition: cs_ban.cpp:696

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool ban_commandscript::HandleUnBanCharacterCommand ( ChatHandler handler,
char const args 
)
inlinestatic
659  {
660  if (!*args)
661  return false;
662 
663  char* nameStr = strtok((char*)args, " ");
664  if (!nameStr)
665  return false;
666 
667  std::string name = nameStr;
668 
669  if (!normalizePlayerName(name))
670  {
672  handler->SetSentErrorMessage(true);
673  return false;
674  }
675 
676  if (!sWorld->RemoveBanCharacter(name))
677  {
679  handler->SetSentErrorMessage(true);
680  return false;
681  }
682 
683  return true;
684  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
#define sWorld
Definition: World.h:887
bool normalizePlayerName(std::string &name)
Definition: ObjectMgr.cpp:133
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
Definition: Language.h:509

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool ban_commandscript::HandleUnBanHelper ( BanMode  mode,
char const args,
ChatHandler handler 
)
inlinestatic
697  {
698  if (!*args)
699  return false;
700 
701  char* nameOrIPStr = strtok((char*)args, " ");
702  if (!nameOrIPStr)
703  return false;
704 
705  std::string nameOrIP = nameOrIPStr;
706 
707  switch (mode)
708  {
709  case BAN_ACCOUNT:
710  if (!Utf8ToUpperOnlyLatin(nameOrIP))
711  {
712  handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, nameOrIP.c_str());
713  handler->SetSentErrorMessage(true);
714  return false;
715  }
716  break;
717  case BAN_CHARACTER:
718  if (!normalizePlayerName(nameOrIP))
719  {
721  handler->SetSentErrorMessage(true);
722  return false;
723  }
724  break;
725  case BAN_IP:
726  if (!IsIPAddress(nameOrIP.c_str()))
727  return false;
728  break;
729  }
730 
731  if (sWorld->RemoveBanAccount(mode, nameOrIP))
732  handler->PSendSysMessage(LANG_UNBAN_UNBANNED, nameOrIP.c_str());
733  else
734  handler->PSendSysMessage(LANG_UNBAN_ERROR, nameOrIP.c_str());
735 
736  return true;
737  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
Definition: SharedDefines.h:4537
#define sWorld
Definition: World.h:887
Definition: Language.h:410
Definition: SharedDefines.h:4535
Definition: Language.h:409
bool normalizePlayerName(std::string &name)
Definition: ObjectMgr.cpp:133
bool IsIPAddress(char const *ipaddress)
Check if the string is a valid ip address representation.
Definition: Util.cpp:211
Definition: SharedDefines.h:4536
Definition: Language.h:412
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:498
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
Definition: Language.h:509

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool ban_commandscript::HandleUnBanIPCommand ( ChatHandler handler,
char const args 
)
inlinestatic
692  {
693  return HandleUnBanHelper(BAN_IP, args, handler);
694  }
Definition: SharedDefines.h:4537
static bool HandleUnBanHelper(BanMode mode, char const *args, ChatHandler *handler)
Definition: cs_ban.cpp:696

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


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