Core/Commands: Convert ban / unban / baninfo / banlist commands in commandscript
This commit is contained in:
@@ -67,31 +67,6 @@ static size_t appendCommandTable(ChatCommand* target, const ChatCommand* source)
|
||||
|
||||
ChatCommand* ChatHandler::getCommandTable()
|
||||
{
|
||||
static ChatCommand banCommandTable[] =
|
||||
{
|
||||
{ "account", SEC_ADMINISTRATOR, true, OldHandler<&ChatHandler::HandleBanAccountCommand>, "", NULL },
|
||||
{ "character", SEC_ADMINISTRATOR, true, OldHandler<&ChatHandler::HandleBanCharacterCommand>, "", NULL },
|
||||
{ "playeraccount", SEC_ADMINISTRATOR, true, OldHandler<&ChatHandler::HandleBanAccountByCharCommand>, "", NULL },
|
||||
{ "ip", SEC_ADMINISTRATOR, true, OldHandler<&ChatHandler::HandleBanIPCommand>, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
|
||||
static ChatCommand baninfoCommandTable[] =
|
||||
{
|
||||
{ "account", SEC_ADMINISTRATOR, true, OldHandler<&ChatHandler::HandleBanInfoAccountCommand>, "", NULL },
|
||||
{ "character", SEC_ADMINISTRATOR, true, OldHandler<&ChatHandler::HandleBanInfoCharacterCommand>, "", NULL },
|
||||
{ "ip", SEC_ADMINISTRATOR, true, OldHandler<&ChatHandler::HandleBanInfoIPCommand>, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
|
||||
static ChatCommand banlistCommandTable[] =
|
||||
{
|
||||
{ "account", SEC_ADMINISTRATOR, true, OldHandler<&ChatHandler::HandleBanListAccountCommand>, "", NULL },
|
||||
{ "character", SEC_ADMINISTRATOR, true, OldHandler<&ChatHandler::HandleBanListCharacterCommand>, "", NULL },
|
||||
{ "ip", SEC_ADMINISTRATOR, true, OldHandler<&ChatHandler::HandleBanListIPCommand>, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
|
||||
static ChatCommand channelSetCommandTable[] =
|
||||
{
|
||||
{ "ownership", SEC_ADMINISTRATOR, false, OldHandler<&ChatHandler::HandleChannelSetOwnership>, "", NULL },
|
||||
@@ -136,15 +111,6 @@ ChatCommand* ChatHandler::getCommandTable()
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
|
||||
static ChatCommand unbanCommandTable[] =
|
||||
{
|
||||
{ "account", SEC_ADMINISTRATOR, true, OldHandler<&ChatHandler::HandleUnBanAccountCommand>, "", NULL },
|
||||
{ "character", SEC_ADMINISTRATOR, true, OldHandler<&ChatHandler::HandleUnBanCharacterCommand>, "", NULL },
|
||||
{ "playeraccount", SEC_ADMINISTRATOR, true, OldHandler<&ChatHandler::HandleUnBanAccountByCharCommand>, "", NULL },
|
||||
{ "ip", SEC_ADMINISTRATOR, true, OldHandler<&ChatHandler::HandleUnBanIPCommand>, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
|
||||
static ChatCommand ticketResponseCommandTable[] =
|
||||
{
|
||||
{ "append", SEC_MODERATOR, true, OldHandler<&ChatHandler::HandleGMTicketResponseAppendCommand>, "", NULL },
|
||||
@@ -208,10 +174,6 @@ ChatCommand* ChatHandler::getCommandTable()
|
||||
{ "save", SEC_PLAYER, false, OldHandler<&ChatHandler::HandleSaveCommand>, "", NULL },
|
||||
{ "saveall", SEC_MODERATOR, true, OldHandler<&ChatHandler::HandleSaveAllCommand>, "", NULL },
|
||||
{ "kick", SEC_GAMEMASTER, true, OldHandler<&ChatHandler::HandleKickPlayerCommand>, "", NULL },
|
||||
{ "ban", SEC_ADMINISTRATOR, true, NULL, "", banCommandTable },
|
||||
{ "unban", SEC_ADMINISTRATOR, true, NULL, "", unbanCommandTable },
|
||||
{ "baninfo", SEC_ADMINISTRATOR, false, NULL, "", baninfoCommandTable },
|
||||
{ "banlist", SEC_ADMINISTRATOR, true, NULL, "", banlistCommandTable },
|
||||
{ "start", SEC_PLAYER, false, OldHandler<&ChatHandler::HandleStartCommand>, "", NULL },
|
||||
{ "taxicheat", SEC_MODERATOR, false, OldHandler<&ChatHandler::HandleTaxiCheatCommand>, "", NULL },
|
||||
{ "linkgrave", SEC_ADMINISTRATOR, false, OldHandler<&ChatHandler::HandleLinkGraveCommand>, "", NULL },
|
||||
|
||||
@@ -139,17 +139,6 @@ class ChatHandler
|
||||
bool HandleGMAnnounceCommand(const char* args);
|
||||
bool HandleGMNotifyCommand(const char* args);
|
||||
|
||||
bool HandleBanAccountCommand(const char* args);
|
||||
bool HandleBanAccountByCharCommand(const char* args);
|
||||
bool HandleBanCharacterCommand(const char* args);
|
||||
bool HandleBanIPCommand(const char* args);
|
||||
bool HandleBanInfoAccountCommand(const char* args);
|
||||
bool HandleBanInfoCharacterCommand(const char* args);
|
||||
bool HandleBanInfoIPCommand(const char* args);
|
||||
bool HandleBanListAccountCommand(const char* args);
|
||||
bool HandleBanListCharacterCommand(const char* args);
|
||||
bool HandleBanListIPCommand(const char* args);
|
||||
|
||||
bool HandleChannelSetOwnership(const char *args);
|
||||
|
||||
bool HandlePossessCommand(const char* args);
|
||||
@@ -165,11 +154,6 @@ class ChatHandler
|
||||
bool HandleSendMessageCommand(const char * args);
|
||||
bool HandleSendMoneyCommand(const char* args);
|
||||
|
||||
bool HandleUnBanAccountCommand(const char* args);
|
||||
bool HandleUnBanAccountByCharCommand(const char* args);
|
||||
bool HandleUnBanCharacterCommand(const char* args);
|
||||
bool HandleUnBanIPCommand(const char* args);
|
||||
|
||||
bool HandleHelpCommand(const char* args);
|
||||
bool HandleCommandsCommand(const char* args);
|
||||
bool HandleStartCommand(const char* args);
|
||||
@@ -272,11 +256,6 @@ class ChatHandler
|
||||
bool HandleSaveAllCommand(const char* args);
|
||||
|
||||
// Utility methods for commands
|
||||
bool LookupPlayerSearchCommand(PreparedQueryResult result, int32 limit);
|
||||
bool HandleBanListHelper(PreparedQueryResult result);
|
||||
bool HandleBanHelper(BanMode mode, char const* args);
|
||||
bool HandleBanInfoHelper(uint32 accountid, char const* accountname);
|
||||
bool HandleUnBanHelper(BanMode mode, char const* args);
|
||||
void HandleLearnSkillRecipesHelper(Player* player, uint32 skill_id);
|
||||
|
||||
private:
|
||||
|
||||
@@ -936,638 +936,6 @@ bool ChatHandler::HandleChangeWeather(const char *args)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ChatHandler::HandleBanAccountCommand(const char *args)
|
||||
{
|
||||
return HandleBanHelper(BAN_ACCOUNT, args);
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleBanAccountByCharCommand(const char *args)
|
||||
{
|
||||
return HandleBanHelper(BAN_CHARACTER, args);
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleBanCharacterCommand(const char *args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* cname = strtok((char*)args, " ");
|
||||
if (!cname)
|
||||
return false;
|
||||
|
||||
std::string name = cname;
|
||||
|
||||
char* duration = strtok(NULL, " ");
|
||||
if (!duration || !atoi(duration))
|
||||
return false;
|
||||
|
||||
char* reason = strtok(NULL, "");
|
||||
if (!reason)
|
||||
return false;
|
||||
|
||||
if (!normalizePlayerName(name))
|
||||
{
|
||||
SendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (sWorld->BanCharacter(name, duration, reason, m_session ? m_session->GetPlayerName() : ""))
|
||||
{
|
||||
case BAN_SUCCESS:
|
||||
{
|
||||
if (atoi(duration) > 0)
|
||||
PSendSysMessage(LANG_BAN_YOUBANNED, name.c_str(), secsToTimeString(TimeStringToSecs(duration), true).c_str(), reason);
|
||||
else
|
||||
PSendSysMessage(LANG_BAN_YOUPERMBANNED, name.c_str(), reason);
|
||||
break;
|
||||
}
|
||||
case BAN_NOTFOUND:
|
||||
{
|
||||
PSendSysMessage(LANG_BAN_NOTFOUND, "character", name.c_str());
|
||||
SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleBanIPCommand(const char *args)
|
||||
{
|
||||
return HandleBanHelper(BAN_IP, args);
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleBanHelper(BanMode mode, const char *args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* cnameOrIP = strtok ((char*)args, " ");
|
||||
if (!cnameOrIP)
|
||||
return false;
|
||||
|
||||
std::string nameOrIP = cnameOrIP;
|
||||
|
||||
char* duration = strtok (NULL, " ");
|
||||
if (!duration || !atoi(duration))
|
||||
return false;
|
||||
|
||||
char* reason = strtok (NULL, "");
|
||||
if (!reason)
|
||||
return false;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case BAN_ACCOUNT:
|
||||
if (!AccountMgr::normalizeString(nameOrIP))
|
||||
{
|
||||
PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, nameOrIP.c_str());
|
||||
SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case BAN_CHARACTER:
|
||||
if (!normalizePlayerName(nameOrIP))
|
||||
{
|
||||
SendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case BAN_IP:
|
||||
if (!IsIPAddress(nameOrIP.c_str()))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (sWorld->BanAccount(mode, nameOrIP, duration, reason, m_session ? m_session->GetPlayerName() : ""))
|
||||
{
|
||||
case BAN_SUCCESS:
|
||||
if (atoi(duration)>0)
|
||||
PSendSysMessage(LANG_BAN_YOUBANNED, nameOrIP.c_str(), secsToTimeString(TimeStringToSecs(duration), true).c_str(), reason);
|
||||
else
|
||||
PSendSysMessage(LANG_BAN_YOUPERMBANNED, nameOrIP.c_str(), reason);
|
||||
break;
|
||||
case BAN_SYNTAX_ERROR:
|
||||
return false;
|
||||
case BAN_NOTFOUND:
|
||||
switch (mode)
|
||||
{
|
||||
default:
|
||||
PSendSysMessage(LANG_BAN_NOTFOUND, "account", nameOrIP.c_str());
|
||||
break;
|
||||
case BAN_CHARACTER:
|
||||
PSendSysMessage(LANG_BAN_NOTFOUND, "character", nameOrIP.c_str());
|
||||
break;
|
||||
case BAN_IP:
|
||||
PSendSysMessage(LANG_BAN_NOTFOUND, "ip", nameOrIP.c_str());
|
||||
break;
|
||||
}
|
||||
SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleUnBanAccountCommand(const char *args)
|
||||
{
|
||||
return HandleUnBanHelper(BAN_ACCOUNT, args);
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleUnBanAccountByCharCommand(const char *args)
|
||||
{
|
||||
return HandleUnBanHelper(BAN_CHARACTER, args);
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleUnBanCharacterCommand(const char *args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* cname = strtok((char*)args, " ");
|
||||
if (!cname)
|
||||
return false;
|
||||
|
||||
std::string name = cname;
|
||||
|
||||
if (!normalizePlayerName(name))
|
||||
{
|
||||
SendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!sWorld->RemoveBanCharacter(name))
|
||||
{
|
||||
SendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleUnBanIPCommand(const char *args)
|
||||
{
|
||||
return HandleUnBanHelper(BAN_IP, args);
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleUnBanHelper(BanMode mode, const char *args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* cnameOrIP = strtok ((char*)args, " ");
|
||||
if (!cnameOrIP)
|
||||
return false;
|
||||
|
||||
std::string nameOrIP = cnameOrIP;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case BAN_ACCOUNT:
|
||||
if (!AccountMgr::normalizeString(nameOrIP))
|
||||
{
|
||||
PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, nameOrIP.c_str());
|
||||
SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case BAN_CHARACTER:
|
||||
if (!normalizePlayerName(nameOrIP))
|
||||
{
|
||||
SendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case BAN_IP:
|
||||
if (!IsIPAddress(nameOrIP.c_str()))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (sWorld->RemoveBanAccount(mode, nameOrIP))
|
||||
PSendSysMessage(LANG_UNBAN_UNBANNED, nameOrIP.c_str());
|
||||
else
|
||||
PSendSysMessage(LANG_UNBAN_ERROR, nameOrIP.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleBanInfoAccountCommand(const char *args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* cname = strtok((char*)args, "");
|
||||
if (!cname)
|
||||
return false;
|
||||
|
||||
std::string account_name = cname;
|
||||
if (!AccountMgr::normalizeString(account_name))
|
||||
{
|
||||
PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, account_name.c_str());
|
||||
SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 accountid = AccountMgr::GetId(account_name);
|
||||
if (!accountid)
|
||||
{
|
||||
PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, account_name.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
return HandleBanInfoHelper(accountid, account_name.c_str());
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleBanInfoCharacterCommand(const char *args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
Player* target = sObjectAccessor->FindPlayerByName(args);
|
||||
uint32 target_guid = 0;
|
||||
std::string name(args);
|
||||
|
||||
if (!target)
|
||||
{
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUID_BY_NAME);
|
||||
stmt->setString(0, name);
|
||||
PreparedQueryResult resultCharacter = CharacterDatabase.Query(stmt);
|
||||
|
||||
if (!resultCharacter)
|
||||
{
|
||||
PSendSysMessage(LANG_BANINFO_NOCHARACTER);
|
||||
return false;
|
||||
}
|
||||
|
||||
target_guid = (*resultCharacter)[0].GetUInt32();
|
||||
}
|
||||
else
|
||||
target_guid = target->GetGUIDLow();
|
||||
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_BANINFO);
|
||||
stmt->setUInt32(0, target_guid);
|
||||
PreparedQueryResult result = CharacterDatabase.Query(stmt);
|
||||
if (!result)
|
||||
{
|
||||
PSendSysMessage(LANG_CHAR_NOT_BANNED, name.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
PSendSysMessage(LANG_BANINFO_BANHISTORY, name.c_str());
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
time_t unbandate = time_t(fields[3].GetUInt32());
|
||||
bool active = false;
|
||||
if (fields[2].GetUInt8() && (!fields[1].GetUInt32() || unbandate >= time(NULL)))
|
||||
active = true;
|
||||
bool permanent = (fields[1].GetUInt32() == uint32(0));
|
||||
std::string bantime = permanent ? GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[1].GetUInt32(), true);
|
||||
PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
|
||||
fields[0].GetCString(), bantime.c_str(), active ? GetTrinityString(LANG_BANINFO_YES) : GetTrinityString(LANG_BANINFO_NO), fields[4].GetCString(), fields[5].GetCString());
|
||||
}
|
||||
while (result->NextRow());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
|
||||
{
|
||||
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);
|
||||
if (!result)
|
||||
{
|
||||
PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
|
||||
return true;
|
||||
}
|
||||
|
||||
PSendSysMessage(LANG_BANINFO_BANHISTORY, accountname);
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
time_t unbandate = time_t(fields[3].GetUInt64());
|
||||
bool active = false;
|
||||
if (fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)))
|
||||
active = true;
|
||||
bool permanent = (fields[1].GetUInt64() == (uint64)0);
|
||||
std::string bantime = permanent ? GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[1].GetUInt64(), true);
|
||||
PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
|
||||
fields[0].GetCString(), bantime.c_str(), active ? GetTrinityString(LANG_BANINFO_YES) : GetTrinityString(LANG_BANINFO_NO), fields[4].GetCString(), fields[5].GetCString());
|
||||
} while (result->NextRow());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleBanInfoIPCommand(const char *args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* cIP = strtok ((char*)args, "");
|
||||
if (!cIP)
|
||||
return false;
|
||||
|
||||
if (!IsIPAddress(cIP))
|
||||
return false;
|
||||
|
||||
std::string IP = cIP;
|
||||
|
||||
LoginDatabase.EscapeString(IP);
|
||||
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());
|
||||
if (!result)
|
||||
{
|
||||
PSendSysMessage(LANG_BANINFO_NOIP);
|
||||
return true;
|
||||
}
|
||||
|
||||
Field* fields = result->Fetch();
|
||||
bool permanent = !fields[6].GetUInt64();
|
||||
PSendSysMessage(LANG_BANINFO_IPENTRY,
|
||||
fields[0].GetCString(), fields[1].GetCString(), permanent ? GetTrinityString(LANG_BANINFO_NEVER) : fields[2].GetCString(),
|
||||
permanent ? GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetCString(), fields[5].GetCString());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleBanListCharacterCommand(const char *args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* cFilter = strtok((char*)args, " ");
|
||||
if (!cFilter)
|
||||
return false;
|
||||
|
||||
std::string filter(cFilter);
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUID_BY_NAME_FILTER);
|
||||
stmt->setString(0, filter);
|
||||
PreparedQueryResult result = CharacterDatabase.Query(stmt);
|
||||
if (!result)
|
||||
{
|
||||
PSendSysMessage(LANG_BANLIST_NOCHARACTER);
|
||||
return true;
|
||||
}
|
||||
|
||||
PSendSysMessage(LANG_BANLIST_MATCHINGCHARACTER);
|
||||
|
||||
// Chat short output
|
||||
if (m_session)
|
||||
{
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
PreparedStatement* stmt2 = CharacterDatabase.GetPreparedStatement(CHAR_SEL_BANNED_NAME);
|
||||
stmt2->setUInt32(0, fields[0].GetUInt32());
|
||||
PreparedQueryResult banresult = CharacterDatabase.Query(stmt2);
|
||||
if (banresult)
|
||||
PSendSysMessage("%s", (*banresult)[0].GetCString());
|
||||
}
|
||||
while (result->NextRow());
|
||||
}
|
||||
// Console wide output
|
||||
else
|
||||
{
|
||||
SendSysMessage(LANG_BANLIST_CHARACTERS);
|
||||
SendSysMessage(" =============================================================================== ");
|
||||
SendSysMessage(LANG_BANLIST_CHARACTERS_HEADER);
|
||||
do
|
||||
{
|
||||
SendSysMessage("-------------------------------------------------------------------------------");
|
||||
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
std::string char_name = fields[1].GetString();
|
||||
|
||||
PreparedStatement* stmt2 = CharacterDatabase.GetPreparedStatement(CHAR_SEL_BANINFO_LIST);
|
||||
stmt2->setUInt32(0, fields[0].GetUInt32());
|
||||
PreparedQueryResult banInfo = CharacterDatabase.Query(stmt2);
|
||||
if (banInfo)
|
||||
{
|
||||
Field* banFields = banInfo->Fetch();
|
||||
do
|
||||
{
|
||||
time_t t_ban = time_t(banFields[0].GetUInt32());
|
||||
tm* aTm_ban = localtime(&t_ban);
|
||||
|
||||
if (banFields[0].GetUInt32() == banFields[1].GetUInt32())
|
||||
{
|
||||
PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
|
||||
char_name.c_str(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
|
||||
banFields[2].GetCString(), banFields[3].GetCString());
|
||||
}
|
||||
else
|
||||
{
|
||||
time_t t_unban = time_t(banFields[1].GetUInt32());
|
||||
tm* aTm_unban = localtime(&t_unban);
|
||||
PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
|
||||
char_name.c_str(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
|
||||
aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
|
||||
banFields[2].GetCString(), banFields[3].GetCString());
|
||||
}
|
||||
}
|
||||
while (banInfo->NextRow());
|
||||
}
|
||||
}
|
||||
while (result->NextRow());
|
||||
SendSysMessage(" =============================================================================== ");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleBanListAccountCommand(const char *args)
|
||||
{
|
||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS);
|
||||
LoginDatabase.Execute(stmt);
|
||||
|
||||
char* cFilter = strtok((char*)args, " ");
|
||||
std::string filter = cFilter ? cFilter : "";
|
||||
|
||||
PreparedQueryResult result;
|
||||
|
||||
if (filter.empty())
|
||||
{
|
||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_BANNED_ALL);
|
||||
|
||||
result = LoginDatabase.Query(stmt);
|
||||
}
|
||||
else
|
||||
{
|
||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_BANNED_BY_USERNAME);
|
||||
|
||||
stmt->setString(0, filter);
|
||||
|
||||
result = LoginDatabase.Query(stmt);
|
||||
}
|
||||
|
||||
if (!result)
|
||||
{
|
||||
PSendSysMessage(LANG_BANLIST_NOACCOUNT);
|
||||
return true;
|
||||
}
|
||||
|
||||
return HandleBanListHelper(result);
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleBanListHelper(PreparedQueryResult result)
|
||||
{
|
||||
PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
|
||||
|
||||
// Chat short output
|
||||
if (m_session)
|
||||
{
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
uint32 accountid = fields[0].GetUInt32();
|
||||
|
||||
QueryResult banresult = LoginDatabase.PQuery("SELECT account.username FROM account, account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id", accountid);
|
||||
if (banresult)
|
||||
{
|
||||
Field* fields2 = banresult->Fetch();
|
||||
PSendSysMessage("%s", fields2[0].GetCString());
|
||||
}
|
||||
} while (result->NextRow());
|
||||
}
|
||||
// Console wide output
|
||||
else
|
||||
{
|
||||
SendSysMessage(LANG_BANLIST_ACCOUNTS);
|
||||
SendSysMessage(" ===============================================================================");
|
||||
SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
|
||||
do
|
||||
{
|
||||
SendSysMessage("-------------------------------------------------------------------------------");
|
||||
Field* fields = result->Fetch();
|
||||
uint32 account_id = fields[0].GetUInt32();
|
||||
|
||||
std::string account_name;
|
||||
|
||||
// "account" case, name can be get in same query
|
||||
if (result->GetFieldCount() > 1)
|
||||
account_name = fields[1].GetString();
|
||||
// "character" case, name need extract from another DB
|
||||
else
|
||||
AccountMgr::GetName (account_id, account_name);
|
||||
|
||||
// No SQL injection. id is uint32.
|
||||
QueryResult banInfo = LoginDatabase.PQuery("SELECT bandate, unbandate, bannedby, banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
|
||||
if (banInfo)
|
||||
{
|
||||
Field* fields2 = banInfo->Fetch();
|
||||
do
|
||||
{
|
||||
time_t t_ban = fields2[0].GetUInt64();
|
||||
tm* aTm_ban = localtime(&t_ban);
|
||||
|
||||
if (fields2[0].GetUInt64() == fields2[1].GetUInt64())
|
||||
{
|
||||
PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
|
||||
account_name.c_str(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
|
||||
fields2[2].GetCString(), fields2[3].GetCString());
|
||||
}
|
||||
else
|
||||
{
|
||||
time_t t_unban = fields2[1].GetUInt64();
|
||||
tm* aTm_unban = localtime(&t_unban);
|
||||
PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
|
||||
account_name.c_str(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
|
||||
aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
|
||||
fields2[2].GetCString(), fields2[3].GetCString());
|
||||
}
|
||||
} while (banInfo->NextRow());
|
||||
}
|
||||
}while (result->NextRow());
|
||||
SendSysMessage(" ===============================================================================");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleBanListIPCommand(const char *args)
|
||||
{
|
||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS);
|
||||
LoginDatabase.Execute(stmt);
|
||||
|
||||
char* cFilter = strtok((char*)args, " ");
|
||||
std::string filter = cFilter ? cFilter : "";
|
||||
LoginDatabase.EscapeString(filter);
|
||||
|
||||
PreparedQueryResult result;
|
||||
|
||||
if (filter.empty())
|
||||
{
|
||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_BANNED_ALL);
|
||||
|
||||
result = LoginDatabase.Query(stmt);
|
||||
}
|
||||
else
|
||||
{
|
||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_BANNED_BY_IP);
|
||||
|
||||
stmt->setString(0, filter);
|
||||
|
||||
result = LoginDatabase.Query(stmt);
|
||||
}
|
||||
|
||||
if (!result)
|
||||
{
|
||||
PSendSysMessage(LANG_BANLIST_NOIP);
|
||||
return true;
|
||||
}
|
||||
|
||||
PSendSysMessage(LANG_BANLIST_MATCHINGIP);
|
||||
// Chat short output
|
||||
if (m_session)
|
||||
{
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
PSendSysMessage("%s", fields[0].GetCString());
|
||||
} while (result->NextRow());
|
||||
}
|
||||
// Console wide output
|
||||
else
|
||||
{
|
||||
SendSysMessage(LANG_BANLIST_IPS);
|
||||
SendSysMessage(" ===============================================================================");
|
||||
SendSysMessage(LANG_BANLIST_IPS_HEADER);
|
||||
do
|
||||
{
|
||||
SendSysMessage("-------------------------------------------------------------------------------");
|
||||
Field* fields = result->Fetch();
|
||||
time_t t_ban = fields[1].GetUInt64();
|
||||
tm* aTm_ban = localtime(&t_ban);
|
||||
if (fields[1].GetUInt64() == fields[2].GetUInt64())
|
||||
{
|
||||
PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
|
||||
fields[0].GetCString(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
|
||||
fields[3].GetCString(), fields[4].GetCString());
|
||||
}
|
||||
else
|
||||
{
|
||||
time_t t_unban = fields[2].GetUInt64();
|
||||
tm* aTm_unban = localtime(&t_unban);
|
||||
PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
|
||||
fields[0].GetCString(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
|
||||
aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
|
||||
fields[3].GetCString(), fields[4].GetCString());
|
||||
}
|
||||
}while (result->NextRow());
|
||||
SendSysMessage(" ===============================================================================");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
|
||||
{
|
||||
Player* player = m_session->GetPlayer();
|
||||
|
||||
@@ -46,7 +46,9 @@ void AddSC_SmartSCripts();
|
||||
//Commands
|
||||
void AddSC_account_commandscript();
|
||||
void AddSC_achievement_commandscript();
|
||||
void AddSC_ban_commandscript();
|
||||
void AddSC_cast_commandscript();
|
||||
void AddSC_character_commandscript();
|
||||
void AddSC_debug_commandscript();
|
||||
void AddSC_event_commandscript();
|
||||
void AddSC_gm_commandscript();
|
||||
@@ -64,11 +66,10 @@ void AddSC_npc_commandscript();
|
||||
void AddSC_quest_commandscript();
|
||||
void AddSC_reload_commandscript();
|
||||
void AddSC_reset_commandscript();
|
||||
void AddSC_tele_commandscript();
|
||||
void AddSC_server_commandscript();
|
||||
void AddSC_tele_commandscript();
|
||||
void AddSC_titles_commandscript();
|
||||
void AddSC_wp_commandscript();
|
||||
void AddSC_character_commandscript();
|
||||
|
||||
#ifdef SCRIPTS
|
||||
//world
|
||||
@@ -656,7 +657,9 @@ void AddCommandScripts()
|
||||
{
|
||||
AddSC_account_commandscript();
|
||||
AddSC_achievement_commandscript();
|
||||
AddSC_ban_commandscript();
|
||||
AddSC_cast_commandscript();
|
||||
AddSC_character_commandscript();
|
||||
AddSC_debug_commandscript();
|
||||
AddSC_event_commandscript();
|
||||
AddSC_gm_commandscript();
|
||||
@@ -674,11 +677,10 @@ void AddCommandScripts()
|
||||
AddSC_quest_commandscript();
|
||||
AddSC_reload_commandscript();
|
||||
AddSC_reset_commandscript();
|
||||
AddSC_tele_commandscript();
|
||||
AddSC_server_commandscript();
|
||||
AddSC_tele_commandscript();
|
||||
AddSC_titles_commandscript();
|
||||
AddSC_wp_commandscript();
|
||||
AddSC_character_commandscript();
|
||||
}
|
||||
|
||||
void AddWorldScripts()
|
||||
|
||||
@@ -12,6 +12,7 @@ set(scripts_STAT_SRCS
|
||||
${scripts_STAT_SRCS}
|
||||
Commands/cs_account.cpp
|
||||
Commands/cs_achievement.cpp
|
||||
Commands/cs_ban.cpp
|
||||
Commands/cs_cast.cpp
|
||||
Commands/cs_character.cpp
|
||||
Commands/cs_debug.cpp
|
||||
@@ -65,10 +66,6 @@ set(scripts_STAT_SRCS
|
||||
# Commands/cs_save.cpp
|
||||
# Commands/cs_saveall.cpp
|
||||
# Commands/cs_kick.cpp
|
||||
# Commands/cs_ban.cpp
|
||||
# Commands/cs_unban.cpp
|
||||
# Commands/cs_baninfo.cpp
|
||||
# Commands/cs_banlist.cpp
|
||||
# Commands/cs_start.cpp
|
||||
# Commands/cs_taxicheat.cpp
|
||||
# Commands/cs_linkgrave.cpp
|
||||
|
||||
@@ -0,0 +1,718 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* ScriptData
|
||||
Name: ban_commandscript
|
||||
%Complete: 100
|
||||
Comment: All ban related commands
|
||||
Category: commandscripts
|
||||
EndScriptData */
|
||||
|
||||
#include "ScriptMgr.h"
|
||||
#include "Chat.h"
|
||||
#include "AccountMgr.h"
|
||||
#include "ObjectAccessor.h"
|
||||
#include "ObjectMgr.h"
|
||||
|
||||
class ban_commandscript : public CommandScript
|
||||
{
|
||||
public:
|
||||
ban_commandscript() : CommandScript("ban_commandscript") { }
|
||||
|
||||
ChatCommand* GetCommands() const
|
||||
{
|
||||
static ChatCommand unbanCommandTable[] =
|
||||
{
|
||||
{ "account", SEC_ADMINISTRATOR, true, &HandleUnBanAccountCommand, "", NULL },
|
||||
{ "character", SEC_ADMINISTRATOR, true, &HandleUnBanCharacterCommand, "", NULL },
|
||||
{ "playeraccount", SEC_ADMINISTRATOR, true, &HandleUnBanAccountByCharCommand, "", NULL },
|
||||
{ "ip", SEC_ADMINISTRATOR, true, &HandleUnBanIPCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
static ChatCommand banlistCommandTable[] =
|
||||
{
|
||||
{ "account", SEC_ADMINISTRATOR, true, &HandleBanListAccountCommand, "", NULL },
|
||||
{ "character", SEC_ADMINISTRATOR, true, &HandleBanListCharacterCommand, "", NULL },
|
||||
{ "ip", SEC_ADMINISTRATOR, true, &HandleBanListIPCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
static ChatCommand baninfoCommandTable[] =
|
||||
{
|
||||
{ "account", SEC_ADMINISTRATOR, true, &HandleBanInfoAccountCommand, "", NULL },
|
||||
{ "character", SEC_ADMINISTRATOR, true, &HandleBanInfoCharacterCommand, "", NULL },
|
||||
{ "ip", SEC_ADMINISTRATOR, true, &HandleBanInfoIPCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
static ChatCommand banCommandTable[] =
|
||||
{
|
||||
{ "account", SEC_ADMINISTRATOR, true, &HandleBanAccountCommand, "", NULL },
|
||||
{ "character", SEC_ADMINISTRATOR, true, &HandleBanCharacterCommand, "", NULL },
|
||||
{ "playeraccount", SEC_ADMINISTRATOR, true, &HandleBanAccountByCharCommand, "", NULL },
|
||||
{ "ip", SEC_ADMINISTRATOR, true, &HandleBanIPCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
static ChatCommand commandTable[] =
|
||||
{
|
||||
{ "ban", SEC_ADMINISTRATOR, true, NULL, "", banCommandTable },
|
||||
{ "baninfo", SEC_ADMINISTRATOR, true, NULL, "", baninfoCommandTable },
|
||||
{ "banlist", SEC_ADMINISTRATOR, true, NULL, "", banlistCommandTable },
|
||||
{ "unban", SEC_ADMINISTRATOR, true, NULL, "", unbanCommandTable },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
return commandTable;
|
||||
}
|
||||
|
||||
static bool HandleBanAccountCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
return HandleBanHelper(BAN_ACCOUNT, args, handler);
|
||||
}
|
||||
|
||||
static bool HandleBanCharacterCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* nameStr = strtok((char*)args, " ");
|
||||
if (!nameStr)
|
||||
return false;
|
||||
|
||||
std::string name = nameStr;
|
||||
|
||||
char* durationStr = strtok(NULL, " ");
|
||||
if (!durationStr || !atoi(durationStr))
|
||||
return false;
|
||||
|
||||
char* reasonStr = strtok(NULL, "");
|
||||
if (!reasonStr)
|
||||
return false;
|
||||
|
||||
if (!normalizePlayerName(name))
|
||||
{
|
||||
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (sWorld->BanCharacter(name, durationStr, reasonStr, handler->GetSession() ? handler->GetSession()->GetPlayerName() : ""))
|
||||
{
|
||||
case BAN_SUCCESS:
|
||||
{
|
||||
if (atoi(durationStr) > 0)
|
||||
handler->PSendSysMessage(LANG_BAN_YOUBANNED, name.c_str(), secsToTimeString(TimeStringToSecs(durationStr), true).c_str(), reasonStr);
|
||||
else
|
||||
handler->PSendSysMessage(LANG_BAN_YOUPERMBANNED, name.c_str(), reasonStr);
|
||||
break;
|
||||
}
|
||||
case BAN_NOTFOUND:
|
||||
{
|
||||
handler->PSendSysMessage(LANG_BAN_NOTFOUND, "character", name.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleBanAccountByCharCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
return HandleBanHelper(BAN_CHARACTER, args, handler);
|
||||
}
|
||||
|
||||
static bool HandleBanIPCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
return HandleBanHelper(BAN_IP, args, handler);
|
||||
}
|
||||
|
||||
static bool HandleBanHelper(BanMode mode, char const* args, ChatHandler* handler)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* cnameOrIP = strtok((char*)args, " ");
|
||||
if (!cnameOrIP)
|
||||
return false;
|
||||
|
||||
std::string nameOrIP = cnameOrIP;
|
||||
|
||||
char* durationStr = strtok(NULL, " ");
|
||||
if (!durationStr || !atoi(durationStr))
|
||||
return false;
|
||||
|
||||
char* reasonStr = strtok(NULL, "");
|
||||
if (!reasonStr)
|
||||
return false;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case BAN_ACCOUNT:
|
||||
if (!AccountMgr::normalizeString(nameOrIP))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, nameOrIP.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case BAN_CHARACTER:
|
||||
if (!normalizePlayerName(nameOrIP))
|
||||
{
|
||||
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case BAN_IP:
|
||||
if (!IsIPAddress(nameOrIP.c_str()))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (sWorld->BanAccount(mode, nameOrIP, durationStr, reasonStr, handler->GetSession() ? handler->GetSession()->GetPlayerName() : ""))
|
||||
{
|
||||
case BAN_SUCCESS:
|
||||
if (atoi(durationStr) > 0)
|
||||
handler->PSendSysMessage(LANG_BAN_YOUBANNED, nameOrIP.c_str(), secsToTimeString(TimeStringToSecs(durationStr), true).c_str(), reasonStr);
|
||||
else
|
||||
handler->PSendSysMessage(LANG_BAN_YOUPERMBANNED, nameOrIP.c_str(), reasonStr);
|
||||
break;
|
||||
case BAN_SYNTAX_ERROR:
|
||||
return false;
|
||||
case BAN_NOTFOUND:
|
||||
switch (mode)
|
||||
{
|
||||
default:
|
||||
handler->PSendSysMessage(LANG_BAN_NOTFOUND, "account", nameOrIP.c_str());
|
||||
break;
|
||||
case BAN_CHARACTER:
|
||||
handler->PSendSysMessage(LANG_BAN_NOTFOUND, "character", nameOrIP.c_str());
|
||||
break;
|
||||
case BAN_IP:
|
||||
handler->PSendSysMessage(LANG_BAN_NOTFOUND, "ip", nameOrIP.c_str());
|
||||
break;
|
||||
}
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleBanInfoAccountCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* nameStr = strtok((char*)args, "");
|
||||
if (!nameStr)
|
||||
return false;
|
||||
|
||||
std::string accountName = nameStr;
|
||||
if (!AccountMgr::normalizeString(accountName))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 accountId = AccountMgr::GetId(accountName);
|
||||
if (!accountId)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
return HandleBanInfoHelper(accountId, accountName.c_str(), handler);
|
||||
}
|
||||
|
||||
static bool HandleBanInfoHelper(uint32 accountId, char const* accountName, ChatHandler* handler)
|
||||
{
|
||||
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);
|
||||
if (!result)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountName);
|
||||
return true;
|
||||
}
|
||||
|
||||
handler->PSendSysMessage(LANG_BANINFO_BANHISTORY, accountName);
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
time_t unbanDate = time_t(fields[3].GetUInt32());
|
||||
bool active = false;
|
||||
if (fields[2].GetBool() && (fields[1].GetUInt64() == uint64(0) || unbanDate >= time(NULL)))
|
||||
active = true;
|
||||
bool permanent = (fields[1].GetUInt64() == uint64(0));
|
||||
std::string banTime = permanent ? handler->GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[1].GetUInt64(), true);
|
||||
handler->PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
|
||||
fields[0].GetCString(), banTime.c_str(), active ? handler->GetTrinityString(LANG_BANINFO_YES) : handler->GetTrinityString(LANG_BANINFO_NO), fields[4].GetCString(), fields[5].GetCString());
|
||||
}
|
||||
while (result->NextRow());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleBanInfoCharacterCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
Player* target = sObjectAccessor->FindPlayerByName(args);
|
||||
uint32 targetGuid = 0;
|
||||
std::string name(args);
|
||||
|
||||
if (!target)
|
||||
{
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUID_BY_NAME);
|
||||
stmt->setString(0, name);
|
||||
PreparedQueryResult resultCharacter = CharacterDatabase.Query(stmt);
|
||||
|
||||
if (!resultCharacter)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_BANINFO_NOCHARACTER);
|
||||
return false;
|
||||
}
|
||||
|
||||
targetGuid = (*resultCharacter)[0].GetUInt32();
|
||||
}
|
||||
else
|
||||
targetGuid = target->GetGUIDLow();
|
||||
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_BANINFO);
|
||||
stmt->setUInt32(0, targetGuid);
|
||||
PreparedQueryResult result = CharacterDatabase.Query(stmt);
|
||||
if (!result)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_CHAR_NOT_BANNED, name.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
handler->PSendSysMessage(LANG_BANINFO_BANHISTORY, name.c_str());
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
time_t unbanDate = time_t(fields[3].GetUInt32());
|
||||
bool active = false;
|
||||
if (fields[2].GetUInt8() && (!fields[1].GetUInt32() || unbanDate >= time(NULL)))
|
||||
active = true;
|
||||
bool permanent = (fields[1].GetUInt32() == uint32(0));
|
||||
std::string banTime = permanent ? handler->GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[1].GetUInt32(), true);
|
||||
handler->PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
|
||||
fields[0].GetCString(), banTime.c_str(), active ? handler->GetTrinityString(LANG_BANINFO_YES) : handler->GetTrinityString(LANG_BANINFO_NO), fields[4].GetCString(), fields[5].GetCString());
|
||||
}
|
||||
while (result->NextRow());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleBanInfoIPCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* ipStr = strtok((char*)args, "");
|
||||
if (!ipStr)
|
||||
return false;
|
||||
|
||||
if (!IsIPAddress(ipStr))
|
||||
return false;
|
||||
|
||||
std::string IP = ipStr;
|
||||
|
||||
LoginDatabase.EscapeString(IP);
|
||||
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());
|
||||
if (!result)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_BANINFO_NOIP);
|
||||
return true;
|
||||
}
|
||||
|
||||
Field* fields = result->Fetch();
|
||||
bool permanent = !fields[6].GetUInt64();
|
||||
handler->PSendSysMessage(LANG_BANINFO_IPENTRY,
|
||||
fields[0].GetCString(), fields[1].GetCString(), permanent ? handler->GetTrinityString(LANG_BANINFO_NEVER) : fields[2].GetCString(),
|
||||
permanent ? handler->GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetCString(), fields[5].GetCString());
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleBanListAccountCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS);
|
||||
LoginDatabase.Execute(stmt);
|
||||
|
||||
char* filterStr = strtok((char*)args, " ");
|
||||
std::string filter = filterStr ? filterStr : "";
|
||||
|
||||
PreparedQueryResult result;
|
||||
|
||||
if (filter.empty())
|
||||
{
|
||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_BANNED_ALL);
|
||||
result = LoginDatabase.Query(stmt);
|
||||
}
|
||||
else
|
||||
{
|
||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_BANNED_BY_USERNAME);
|
||||
stmt->setString(0, filter);
|
||||
result = LoginDatabase.Query(stmt);
|
||||
}
|
||||
|
||||
if (!result)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_BANLIST_NOACCOUNT);
|
||||
return true;
|
||||
}
|
||||
|
||||
return HandleBanListHelper(result, handler);
|
||||
}
|
||||
|
||||
static bool HandleBanListHelper(PreparedQueryResult result, ChatHandler* handler)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
|
||||
|
||||
// Chat short output
|
||||
if (handler->GetSession())
|
||||
{
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
uint32 accountid = fields[0].GetUInt32();
|
||||
|
||||
QueryResult banResult = LoginDatabase.PQuery("SELECT account.username FROM account, account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id", accountid);
|
||||
if (banResult)
|
||||
{
|
||||
Field* fields2 = banResult->Fetch();
|
||||
handler->PSendSysMessage("%s", fields2[0].GetCString());
|
||||
}
|
||||
}
|
||||
while (result->NextRow());
|
||||
}
|
||||
// Console wide output
|
||||
else
|
||||
{
|
||||
handler->SendSysMessage(LANG_BANLIST_ACCOUNTS);
|
||||
handler->SendSysMessage(" ===============================================================================");
|
||||
handler->SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
|
||||
do
|
||||
{
|
||||
handler->SendSysMessage("-------------------------------------------------------------------------------");
|
||||
Field* fields = result->Fetch();
|
||||
uint32 accountId = fields[0].GetUInt32();
|
||||
|
||||
std::string accountName;
|
||||
|
||||
// "account" case, name can be get in same query
|
||||
if (result->GetFieldCount() > 1)
|
||||
accountName = fields[1].GetString();
|
||||
// "character" case, name need extract from another DB
|
||||
else
|
||||
AccountMgr::GetName(accountId, accountName);
|
||||
|
||||
// No SQL injection. id is uint32.
|
||||
QueryResult banInfo = LoginDatabase.PQuery("SELECT bandate, unbandate, bannedby, banreason FROM account_banned WHERE id = %u ORDER BY unbandate", accountId);
|
||||
if (banInfo)
|
||||
{
|
||||
Field* fields2 = banInfo->Fetch();
|
||||
do
|
||||
{
|
||||
time_t timeBan = time_t(fields2[0].GetUInt32());
|
||||
tm* tmBan = localtime(&timeBan);
|
||||
|
||||
if (fields2[0].GetUInt32() == fields2[1].GetUInt32())
|
||||
{
|
||||
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
|
||||
accountName.c_str(), tmBan->tm_year%100, tmBan->tm_mon+1, tmBan->tm_mday, tmBan->tm_hour, tmBan->tm_min,
|
||||
fields2[2].GetCString(), fields2[3].GetCString());
|
||||
}
|
||||
else
|
||||
{
|
||||
time_t timeUnban = time_t(fields2[1].GetUInt32());
|
||||
tm* tmUnban = localtime(&timeUnban);
|
||||
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
|
||||
accountName.c_str(), tmBan->tm_year%100, tmBan->tm_mon+1, tmBan->tm_mday, tmBan->tm_hour, tmBan->tm_min,
|
||||
tmUnban->tm_year%100, tmUnban->tm_mon+1, tmUnban->tm_mday, tmUnban->tm_hour, tmUnban->tm_min,
|
||||
fields2[2].GetCString(), fields2[3].GetCString());
|
||||
}
|
||||
}
|
||||
while (banInfo->NextRow());
|
||||
}
|
||||
}
|
||||
while (result->NextRow());
|
||||
|
||||
handler->SendSysMessage(" ===============================================================================");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleBanListCharacterCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* filterStr = strtok((char*)args, " ");
|
||||
if (!filterStr)
|
||||
return false;
|
||||
|
||||
std::string filter(filterStr);
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUID_BY_NAME_FILTER);
|
||||
stmt->setString(0, filter);
|
||||
PreparedQueryResult result = CharacterDatabase.Query(stmt);
|
||||
if (!result)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_BANLIST_NOCHARACTER);
|
||||
return true;
|
||||
}
|
||||
|
||||
handler->PSendSysMessage(LANG_BANLIST_MATCHINGCHARACTER);
|
||||
|
||||
// Chat short output
|
||||
if (handler->GetSession())
|
||||
{
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
PreparedStatement* stmt2 = CharacterDatabase.GetPreparedStatement(CHAR_SEL_BANNED_NAME);
|
||||
stmt2->setUInt32(0, fields[0].GetUInt32());
|
||||
PreparedQueryResult banResult = CharacterDatabase.Query(stmt2);
|
||||
if (banResult)
|
||||
handler->PSendSysMessage("%s", (*banResult)[0].GetCString());
|
||||
}
|
||||
while (result->NextRow());
|
||||
}
|
||||
// Console wide output
|
||||
else
|
||||
{
|
||||
handler->SendSysMessage(LANG_BANLIST_CHARACTERS);
|
||||
handler->SendSysMessage(" =============================================================================== ");
|
||||
handler->SendSysMessage(LANG_BANLIST_CHARACTERS_HEADER);
|
||||
do
|
||||
{
|
||||
handler->SendSysMessage("-------------------------------------------------------------------------------");
|
||||
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
std::string char_name = fields[1].GetString();
|
||||
|
||||
PreparedStatement* stmt2 = CharacterDatabase.GetPreparedStatement(CHAR_SEL_BANINFO_LIST);
|
||||
stmt2->setUInt32(0, fields[0].GetUInt32());
|
||||
PreparedQueryResult banInfo = CharacterDatabase.Query(stmt2);
|
||||
if (banInfo)
|
||||
{
|
||||
Field* banFields = banInfo->Fetch();
|
||||
do
|
||||
{
|
||||
time_t timeBan = time_t(banFields[0].GetUInt32());
|
||||
tm* tmBan = localtime(&timeBan);
|
||||
|
||||
if (banFields[0].GetUInt32() == banFields[1].GetUInt32())
|
||||
{
|
||||
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
|
||||
char_name.c_str(), tmBan->tm_year%100, tmBan->tm_mon+1, tmBan->tm_mday, tmBan->tm_hour, tmBan->tm_min,
|
||||
banFields[2].GetCString(), banFields[3].GetCString());
|
||||
}
|
||||
else
|
||||
{
|
||||
time_t timeUnban = time_t(banFields[1].GetUInt32());
|
||||
tm* tmUnban = localtime(&timeUnban);
|
||||
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
|
||||
char_name.c_str(), tmBan->tm_year%100, tmBan->tm_mon+1, tmBan->tm_mday, tmBan->tm_hour, tmBan->tm_min,
|
||||
tmUnban->tm_year%100, tmUnban->tm_mon+1, tmUnban->tm_mday, tmUnban->tm_hour, tmUnban->tm_min,
|
||||
banFields[2].GetCString(), banFields[3].GetCString());
|
||||
}
|
||||
}
|
||||
while (banInfo->NextRow());
|
||||
}
|
||||
}
|
||||
while (result->NextRow());
|
||||
handler->SendSysMessage(" =============================================================================== ");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleBanListIPCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS);
|
||||
LoginDatabase.Execute(stmt);
|
||||
|
||||
char* filterStr = strtok((char*)args, " ");
|
||||
std::string filter = filterStr ? filterStr : "";
|
||||
LoginDatabase.EscapeString(filter);
|
||||
|
||||
PreparedQueryResult result;
|
||||
|
||||
if (filter.empty())
|
||||
{
|
||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_BANNED_ALL);
|
||||
result = LoginDatabase.Query(stmt);
|
||||
}
|
||||
else
|
||||
{
|
||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_BANNED_BY_IP);
|
||||
stmt->setString(0, filter);
|
||||
result = LoginDatabase.Query(stmt);
|
||||
}
|
||||
|
||||
if (!result)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_BANLIST_NOIP);
|
||||
return true;
|
||||
}
|
||||
|
||||
handler->PSendSysMessage(LANG_BANLIST_MATCHINGIP);
|
||||
// Chat short output
|
||||
if (handler->GetSession())
|
||||
{
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
handler->PSendSysMessage("%s", fields[0].GetCString());
|
||||
}
|
||||
while (result->NextRow());
|
||||
}
|
||||
// Console wide output
|
||||
else
|
||||
{
|
||||
handler->SendSysMessage(LANG_BANLIST_IPS);
|
||||
handler->SendSysMessage(" ===============================================================================");
|
||||
handler->SendSysMessage(LANG_BANLIST_IPS_HEADER);
|
||||
do
|
||||
{
|
||||
handler->SendSysMessage("-------------------------------------------------------------------------------");
|
||||
Field* fields = result->Fetch();
|
||||
time_t timeBan = time_t(fields[1].GetUInt32());
|
||||
tm* tmBan = localtime(&timeBan);
|
||||
if (fields[1].GetUInt32() == fields[2].GetUInt32())
|
||||
{
|
||||
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
|
||||
fields[0].GetCString(), tmBan->tm_year%100, tmBan->tm_mon+1, tmBan->tm_mday, tmBan->tm_hour, tmBan->tm_min,
|
||||
fields[3].GetCString(), fields[4].GetCString());
|
||||
}
|
||||
else
|
||||
{
|
||||
time_t timeUnban = time_t(fields[2].GetUInt32());
|
||||
tm* tmUnban = localtime(&timeUnban);
|
||||
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
|
||||
fields[0].GetCString(), tmBan->tm_year%100, tmBan->tm_mon+1, tmBan->tm_mday, tmBan->tm_hour, tmBan->tm_min,
|
||||
tmUnban->tm_year%100, tmUnban->tm_mon+1, tmUnban->tm_mday, tmUnban->tm_hour, tmUnban->tm_min,
|
||||
fields[3].GetCString(), fields[4].GetCString());
|
||||
}
|
||||
}
|
||||
while (result->NextRow());
|
||||
|
||||
handler->SendSysMessage(" ===============================================================================");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleUnBanAccountCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
return HandleUnBanHelper(BAN_ACCOUNT, args, handler);
|
||||
}
|
||||
|
||||
static bool HandleUnBanCharacterCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* nameStr = strtok((char*)args, " ");
|
||||
if (!nameStr)
|
||||
return false;
|
||||
|
||||
std::string name = nameStr;
|
||||
|
||||
if (!normalizePlayerName(name))
|
||||
{
|
||||
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!sWorld->RemoveBanCharacter(name))
|
||||
{
|
||||
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleUnBanAccountByCharCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
return HandleUnBanHelper(BAN_CHARACTER, args, handler);
|
||||
}
|
||||
|
||||
static bool HandleUnBanIPCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
return HandleUnBanHelper(BAN_IP, args, handler);
|
||||
}
|
||||
|
||||
static bool HandleUnBanHelper(BanMode mode, char const* args, ChatHandler* handler)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* nameOrIPStr = strtok((char*)args, " ");
|
||||
if (!nameOrIPStr)
|
||||
return false;
|
||||
|
||||
std::string nameOrIP = nameOrIPStr;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case BAN_ACCOUNT:
|
||||
if (!AccountMgr::normalizeString(nameOrIP))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, nameOrIP.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case BAN_CHARACTER:
|
||||
if (!normalizePlayerName(nameOrIP))
|
||||
{
|
||||
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case BAN_IP:
|
||||
if (!IsIPAddress(nameOrIP.c_str()))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (sWorld->RemoveBanAccount(mode, nameOrIP))
|
||||
handler->PSendSysMessage(LANG_UNBAN_UNBANNED, nameOrIP.c_str());
|
||||
else
|
||||
handler->PSendSysMessage(LANG_UNBAN_ERROR, nameOrIP.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_ban_commandscript()
|
||||
{
|
||||
new ban_commandscript();
|
||||
}
|
||||
@@ -1364,7 +1364,7 @@ public:
|
||||
do
|
||||
{
|
||||
Field* characterFields = result2->Fetch();
|
||||
uint64 guid = characterFields[0].GetUInt64();
|
||||
uint32 guid = characterFields[0].GetUInt32();
|
||||
std::string name = characterFields[1].GetString();
|
||||
|
||||
handler->PSendSysMessage(LANG_LOOKUP_PLAYER_CHARACTER, name.c_str(), guid);
|
||||
|
||||
Reference in New Issue
Block a user