2012-07-07 14:04:57 +02:00
/*
2020-01-02 06:44:10 +01:00
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
2012-07-07 14:04:57 +02:00
*
* 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 */
2020-09-04 13:38:24 +02:00
#include "ScriptMgr.h"
2012-07-07 14:04:57 +02:00
#include "AccountMgr.h"
2017-02-05 23:14:19 +01:00
#include "CharacterCache.h"
2012-11-20 12:30:30 +01:00
#include "Chat.h"
2017-05-18 23:52:58 +02:00
#include "DatabaseEnv.h"
2017-12-10 12:39:37 +01:00
#include "GameTime.h"
2012-11-20 12:30:30 +01:00
#include "Language.h"
2012-07-07 14:04:57 +02:00
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
2012-11-17 05:18:37 +01:00
#include "Player.h"
2017-05-18 23:52:58 +02:00
#include "World.h"
2017-06-04 01:00:45 +02:00
#include "WorldSession.h"
2012-07-07 14:04:57 +02:00
class ban_commandscript : public CommandScript
{
public :
ban_commandscript () : CommandScript ( "ban_commandscript" ) { }
2015-10-22 20:26:56 +02:00
std :: vector < ChatCommand > GetCommands () const override
2012-07-07 14:04:57 +02:00
{
2015-10-22 20:26:56 +02:00
static std :: vector < ChatCommand > unbanCommandTable =
2012-07-07 14:04:57 +02:00
{
2015-10-22 20:26:56 +02:00
{ "account" , rbac :: RBAC_PERM_COMMAND_UNBAN_ACCOUNT , true , & HandleUnBanAccountCommand , "" },
{ "character" , rbac :: RBAC_PERM_COMMAND_UNBAN_CHARACTER , true , & HandleUnBanCharacterCommand , "" },
{ "playeraccount" , rbac :: RBAC_PERM_COMMAND_UNBAN_PLAYERACCOUNT , true , & HandleUnBanAccountByCharCommand , "" },
{ "ip" , rbac :: RBAC_PERM_COMMAND_UNBAN_IP , true , & HandleUnBanIPCommand , "" },
2012-07-07 14:04:57 +02:00
};
2015-10-22 20:26:56 +02:00
static std :: vector < ChatCommand > banlistCommandTable =
2012-07-07 14:04:57 +02:00
{
2015-10-22 20:26:56 +02:00
{ "account" , rbac :: RBAC_PERM_COMMAND_BANLIST_ACCOUNT , true , & HandleBanListAccountCommand , "" },
{ "character" , rbac :: RBAC_PERM_COMMAND_BANLIST_CHARACTER , true , & HandleBanListCharacterCommand , "" },
{ "ip" , rbac :: RBAC_PERM_COMMAND_BANLIST_IP , true , & HandleBanListIPCommand , "" },
2012-07-07 14:04:57 +02:00
};
2015-10-22 20:26:56 +02:00
static std :: vector < ChatCommand > baninfoCommandTable =
2012-07-07 14:04:57 +02:00
{
2015-10-22 20:26:56 +02:00
{ "account" , rbac :: RBAC_PERM_COMMAND_BANINFO_ACCOUNT , true , & HandleBanInfoAccountCommand , "" },
{ "character" , rbac :: RBAC_PERM_COMMAND_BANINFO_CHARACTER , true , & HandleBanInfoCharacterCommand , "" },
{ "ip" , rbac :: RBAC_PERM_COMMAND_BANINFO_IP , true , & HandleBanInfoIPCommand , "" },
2012-07-07 14:04:57 +02:00
};
2015-10-22 20:26:56 +02:00
static std :: vector < ChatCommand > banCommandTable =
2012-07-07 14:04:57 +02:00
{
2015-10-22 20:26:56 +02:00
{ "account" , rbac :: RBAC_PERM_COMMAND_BAN_ACCOUNT , true , & HandleBanAccountCommand , "" },
{ "character" , rbac :: RBAC_PERM_COMMAND_BAN_CHARACTER , true , & HandleBanCharacterCommand , "" },
{ "playeraccount" , rbac :: RBAC_PERM_COMMAND_BAN_PLAYERACCOUNT , true , & HandleBanAccountByCharCommand , "" },
{ "ip" , rbac :: RBAC_PERM_COMMAND_BAN_IP , true , & HandleBanIPCommand , "" },
2012-07-07 14:04:57 +02:00
};
2015-10-22 20:26:56 +02:00
static std :: vector < ChatCommand > commandTable =
2012-07-07 14:04:57 +02:00
{
2020-08-14 17:06:03 +02:00
{ "ban" , rbac :: RBAC_PERM_COMMAND_BAN , true , nullptr , "" , banCommandTable },
{ "baninfo" , rbac :: RBAC_PERM_COMMAND_BANINFO , true , nullptr , "" , baninfoCommandTable },
{ "banlist" , rbac :: RBAC_PERM_COMMAND_BANLIST , true , nullptr , "" , banlistCommandTable },
{ "unban" , rbac :: RBAC_PERM_COMMAND_UNBAN , true , nullptr , "" , unbanCommandTable },
2012-07-07 14:04:57 +02:00
};
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 ;
2020-08-14 17:06:03 +02:00
char * durationStr = strtok ( nullptr , " " );
2012-07-07 14:04:57 +02:00
if ( ! durationStr || ! atoi ( durationStr ))
return false ;
2020-08-14 17:06:03 +02:00
char * reasonStr = strtok ( nullptr , "" );
2012-07-07 14:04:57 +02:00
if ( ! reasonStr )
return false ;
if ( ! normalizePlayerName ( name ))
{
handler -> SendSysMessage ( LANG_PLAYER_NOT_FOUND );
handler -> SetSentErrorMessage ( true );
return false ;
}
2014-08-14 16:09:14 +02:00
std :: string author = handler -> GetSession () ? handler -> GetSession () -> GetPlayerName () : "Server" ;
switch ( sWorld -> BanCharacter ( name , durationStr , reasonStr , author ))
2012-07-07 14:04:57 +02:00
{
case BAN_SUCCESS :
{
if ( atoi ( durationStr ) > 0 )
2014-01-02 22:34:04 +01:00
{
if ( sWorld -> getBoolConfig ( CONFIG_SHOW_BAN_IN_WORLD ))
2014-08-14 16:09:14 +02:00
sWorld -> SendWorldText ( LANG_BAN_CHARACTER_YOUBANNEDMESSAGE_WORLD , author . c_str (), name . c_str (), secsToTimeString ( TimeStringToSecs ( durationStr ), true ). c_str (), reasonStr );
2014-01-02 22:34:04 +01:00
else
handler -> PSendSysMessage ( LANG_BAN_YOUBANNED , name . c_str (), secsToTimeString ( TimeStringToSecs ( durationStr ), true ). c_str (), reasonStr );
}
2012-07-07 14:04:57 +02:00
else
2014-01-02 22:34:04 +01:00
{
if ( sWorld -> getBoolConfig ( CONFIG_SHOW_BAN_IN_WORLD ))
2014-08-14 16:09:14 +02:00
sWorld -> SendWorldText ( LANG_BAN_CHARACTER_YOUPERMBANNEDMESSAGE_WORLD , author . c_str (), name . c_str (), reasonStr );
2014-01-02 22:34:04 +01:00
else
handler -> PSendSysMessage ( LANG_BAN_YOUPERMBANNED , name . c_str (), reasonStr );
}
2012-07-07 14:04:57 +02:00
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 ;
2020-08-14 17:06:03 +02:00
char * durationStr = strtok ( nullptr , " " );
2012-07-07 14:04:57 +02:00
if ( ! durationStr || ! atoi ( durationStr ))
return false ;
2020-08-14 17:06:03 +02:00
char * reasonStr = strtok ( nullptr , "" );
2012-07-07 14:04:57 +02:00
if ( ! reasonStr )
return false ;
switch ( mode )
{
case BAN_ACCOUNT :
2014-05-06 23:43:29 +02:00
if ( ! Utf8ToUpperOnlyLatin ( nameOrIP ))
2012-07-07 14:04:57 +02:00
{
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 ;
}
2014-08-14 16:09:14 +02:00
std :: string author = handler -> GetSession () ? handler -> GetSession () -> GetPlayerName () : "Server" ;
switch ( sWorld -> BanAccount ( mode , nameOrIP , durationStr , reasonStr , author ))
2012-07-07 14:04:57 +02:00
{
case BAN_SUCCESS :
if ( atoi ( durationStr ) > 0 )
2014-01-02 22:34:04 +01:00
{
if ( sWorld -> getBoolConfig ( CONFIG_SHOW_BAN_IN_WORLD ))
2014-08-14 16:09:14 +02:00
sWorld -> SendWorldText ( LANG_BAN_ACCOUNT_YOUBANNEDMESSAGE_WORLD , author . c_str (), nameOrIP . c_str (), secsToTimeString ( TimeStringToSecs ( durationStr ), true ). c_str (), reasonStr );
2014-01-02 22:34:04 +01:00
else
handler -> PSendSysMessage ( LANG_BAN_YOUBANNED , nameOrIP . c_str (), secsToTimeString ( TimeStringToSecs ( durationStr ), true ). c_str (), reasonStr );
}
2014-01-21 20:18:46 +01:00
else
2014-01-02 22:34:04 +01:00
{
if ( sWorld -> getBoolConfig ( CONFIG_SHOW_BAN_IN_WORLD ))
2014-08-14 16:09:14 +02:00
sWorld -> SendWorldText ( LANG_BAN_ACCOUNT_YOUPERMBANNEDMESSAGE_WORLD , author . c_str (), nameOrIP . c_str (), reasonStr );
2014-01-02 22:34:04 +01:00
else
handler -> PSendSysMessage ( LANG_BAN_YOUPERMBANNED , nameOrIP . c_str (), reasonStr );
}
2012-07-07 14:04:57 +02:00
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 ;
2018-04-18 11:32:37 +01:00
case BAN_EXISTS :
handler -> PSendSysMessage ( LANG_BAN_EXISTS );
break ;
2012-07-07 14:04:57 +02:00
}
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 ;
2014-05-06 23:43:29 +02:00
if ( ! Utf8ToUpperOnlyLatin ( accountName ))
2012-07-07 14:04:57 +02:00
{
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 ;
2017-12-10 12:39:37 +01:00
if ( fields [ 2 ]. GetBool () && ( fields [ 1 ]. GetUInt64 () == uint64 ( 0 ) || unbanDate >= GameTime :: GetGameTime ()))
2012-07-07 14:04:57 +02:00
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 ,
2014-09-05 12:38:31 +02:00
fields [ 0 ]. GetCString (), banTime . c_str (), active ? handler -> GetTrinityString ( LANG_YES ) : handler -> GetTrinityString ( LANG_NO ), fields [ 4 ]. GetCString (), fields [ 5 ]. GetCString ());
2012-07-07 14:04:57 +02:00
}
while ( result -> NextRow ());
return true ;
}
static bool HandleBanInfoCharacterCommand ( ChatHandler * handler , char const * args )
{
if ( !* args )
return false ;
std :: string name ( args );
2017-01-28 01:27:39 -03:00
if ( ! normalizePlayerName ( name ))
{
handler -> SendSysMessage ( LANG_BANINFO_NOCHARACTER );
handler -> SetSentErrorMessage ( true );
return false ;
}
Player * target = ObjectAccessor :: FindPlayerByName ( name );
ObjectGuid targetGuid ;
2012-07-07 14:04:57 +02:00
if ( ! target )
{
2017-02-05 23:14:19 +01:00
targetGuid = sCharacterCache -> GetCharacterGuidByName ( name );
2014-10-23 21:34:03 +02:00
if ( targetGuid . IsEmpty ())
2012-07-07 14:04:57 +02:00
{
2017-01-28 01:27:39 -03:00
handler -> SendSysMessage ( LANG_BANINFO_NOCHARACTER );
handler -> SetSentErrorMessage ( true );
2012-07-07 14:04:57 +02:00
return false ;
}
}
else
2014-10-23 21:34:03 +02:00
targetGuid = target -> GetGUID ();
2012-07-07 14:04:57 +02:00
2019-07-27 01:00:37 +02:00
CharacterDatabasePreparedStatement * stmt = CharacterDatabase . GetPreparedStatement ( CHAR_SEL_BANINFO );
2014-10-23 21:34:03 +02:00
stmt -> setUInt64 ( 0 , targetGuid . GetCounter ());
2012-07-07 14:04:57 +02:00
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 ();
2021-04-05 23:47:05 +02:00
time_t unbanDate = fields [ 3 ]. GetInt64 ();
2012-07-07 14:04:57 +02:00
bool active = false ;
2017-12-10 12:39:37 +01:00
if ( fields [ 2 ]. GetUInt8 () && ( ! fields [ 1 ]. GetInt64 () || unbanDate >= GameTime :: GetGameTime ()))
2012-07-07 14:04:57 +02:00
active = true ;
2021-04-05 23:47:05 +02:00
bool permanent = ( fields [ 1 ]. GetInt64 () == SI64LIT ( 0 ));
std :: string banTime = permanent ? handler -> GetTrinityString ( LANG_BANINFO_INFINITE ) : secsToTimeString ( fields [ 1 ]. GetInt64 (), true );
2012-07-07 14:04:57 +02:00
handler -> PSendSysMessage ( LANG_BANINFO_HISTORYENTRY ,
2021-04-05 23:47:05 +02:00
TimeToTimestampStr ( fields [ 0 ]. GetInt64 ()). c_str (), banTime . c_str (), active ? handler -> GetTrinityString ( LANG_YES ) : handler -> GetTrinityString ( LANG_NO ), fields [ 4 ]. GetCString (), fields [ 5 ]. GetCString ());
2012-07-07 14:04:57 +02:00
}
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 )
{
2020-08-14 17:06:03 +02:00
LoginDatabasePreparedStatement * stmt = nullptr ;
2014-07-14 10:53:49 +02:00
stmt = LoginDatabase . GetPreparedStatement ( LOGIN_DEL_EXPIRED_IP_BANS );
2012-07-07 14:04:57 +02:00
LoginDatabase . Execute ( stmt );
char * filterStr = strtok (( char * ) args , " " );
std :: string filter = filterStr ? filterStr : "" ;
PreparedQueryResult result ;
if ( filter . empty ())
{
2014-07-14 10:53:49 +02:00
stmt = LoginDatabase . GetPreparedStatement ( LOGIN_SEL_ACCOUNT_BANNED_ALL );
2012-07-07 14:04:57 +02:00
result = LoginDatabase . Query ( stmt );
}
else
{
2014-07-14 10:53:49 +02:00
stmt = LoginDatabase . GetPreparedStatement ( LOGIN_SEL_ACCOUNT_BANNED_BY_USERNAME );
2012-07-07 14:04:57 +02:00
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 ();
2020-09-04 13:38:24 +02:00
QueryResult banResult = LoginDatabase . PQuery ( "SELECT account.username FROM account, account_banned WHERE account_banned.id='%u' AND account_banned.id = account.id" , accountid );
2012-07-07 14:04:57 +02:00
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 ());
2013-09-07 14:37:54 +02:00
tm tmBan ;
2014-06-22 15:42:46 +02:00
localtime_r ( & timeBan , & tmBan );
2012-07-07 14:04:57 +02:00
if ( fields2 [ 0 ]. GetUInt32 () == fields2 [ 1 ]. GetUInt32 ())
{
handler -> PSendSysMessage ( "|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|" ,
2013-09-07 14:37:54 +02:00
accountName . c_str (), tmBan . tm_year % 100 , tmBan . tm_mon + 1 , tmBan . tm_mday , tmBan . tm_hour , tmBan . tm_min ,
2012-07-07 14:04:57 +02:00
fields2 [ 2 ]. GetCString (), fields2 [ 3 ]. GetCString ());
}
else
{
time_t timeUnban = time_t ( fields2 [ 1 ]. GetUInt32 ());
2013-09-07 14:37:54 +02:00
tm tmUnban ;
2014-06-22 15:42:46 +02:00
localtime_r ( & timeUnban , & tmUnban );
2012-07-07 14:04:57 +02:00
handler -> PSendSysMessage ( "|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|" ,
2013-09-07 14:37:54 +02:00
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 ,
2012-07-07 14:04:57 +02:00
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 );
2019-07-27 01:00:37 +02:00
CharacterDatabasePreparedStatement * stmt = CharacterDatabase . GetPreparedStatement ( CHAR_SEL_GUID_BY_NAME_FILTER );
2012-07-07 14:04:57 +02:00
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 ();
2019-07-27 01:00:37 +02:00
CharacterDatabasePreparedStatement * stmt2 = CharacterDatabase . GetPreparedStatement ( CHAR_SEL_BANNED_NAME );
2014-10-23 21:34:03 +02:00
stmt2 -> setUInt64 ( 0 , fields [ 0 ]. GetUInt64 ());
2012-07-07 14:04:57 +02:00
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 ();
2019-07-27 01:00:37 +02:00
CharacterDatabasePreparedStatement * stmt2 = CharacterDatabase . GetPreparedStatement ( CHAR_SEL_BANINFO_LIST );
2014-10-23 21:34:03 +02:00
stmt2 -> setUInt64 ( 0 , fields [ 0 ]. GetUInt64 ());
2012-07-07 14:04:57 +02:00
PreparedQueryResult banInfo = CharacterDatabase . Query ( stmt2 );
if ( banInfo )
{
Field * banFields = banInfo -> Fetch ();
do
{
2021-04-05 23:47:05 +02:00
time_t timeBan = banFields [ 0 ]. GetInt64 ();
2013-09-07 14:37:54 +02:00
tm tmBan ;
2014-06-22 15:42:46 +02:00
localtime_r ( & timeBan , & tmBan );
2012-07-07 14:04:57 +02:00
2021-04-05 23:47:05 +02:00
if ( banFields [ 0 ]. GetInt64 () == banFields [ 1 ]. GetInt64 ())
2012-07-07 14:04:57 +02:00
{
handler -> PSendSysMessage ( "|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|" ,
2013-09-07 14:37:54 +02:00
char_name . c_str (), tmBan . tm_year % 100 , tmBan . tm_mon + 1 , tmBan . tm_mday , tmBan . tm_hour , tmBan . tm_min ,
2012-07-07 14:04:57 +02:00
banFields [ 2 ]. GetCString (), banFields [ 3 ]. GetCString ());
}
else
{
2021-04-05 23:47:05 +02:00
time_t timeUnban = banFields [ 1 ]. GetInt64 ();
2013-09-07 14:37:54 +02:00
tm tmUnban ;
2014-06-22 15:42:46 +02:00
localtime_r ( & timeUnban , & tmUnban );
2012-07-07 14:04:57 +02:00
handler -> PSendSysMessage ( "|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|" ,
2013-09-07 14:37:54 +02:00
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 ,
2012-07-07 14:04:57 +02:00
banFields [ 2 ]. GetCString (), banFields [ 3 ]. GetCString ());
}
}
while ( banInfo -> NextRow ());
}
}
while ( result -> NextRow ());
handler -> SendSysMessage ( " =============================================================================== " );
}
return true ;
}
static bool HandleBanListIPCommand ( ChatHandler * handler , char const * args )
{
2019-07-27 01:00:37 +02:00
LoginDatabasePreparedStatement * stmt = LoginDatabase . GetPreparedStatement ( LOGIN_DEL_EXPIRED_IP_BANS );
2012-07-07 14:04:57 +02:00
LoginDatabase . Execute ( stmt );
char * filterStr = strtok (( char * ) args , " " );
std :: string filter = filterStr ? filterStr : "" ;
LoginDatabase . EscapeString ( filter );
PreparedQueryResult result ;
if ( filter . empty ())
{
2014-07-14 10:53:49 +02:00
stmt = LoginDatabase . GetPreparedStatement ( LOGIN_SEL_IP_BANNED_ALL );
2012-07-07 14:04:57 +02:00
result = LoginDatabase . Query ( stmt );
}
else
{
2014-07-14 10:53:49 +02:00
stmt = LoginDatabase . GetPreparedStatement ( LOGIN_SEL_IP_BANNED_BY_IP );
2012-07-07 14:04:57 +02:00
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 ());
2013-09-07 14:37:54 +02:00
tm tmBan ;
2014-06-22 15:42:46 +02:00
localtime_r ( & timeBan , & tmBan );
2012-07-07 14:04:57 +02:00
if ( fields [ 1 ]. GetUInt32 () == fields [ 2 ]. GetUInt32 ())
{
handler -> PSendSysMessage ( "|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|" ,
2013-09-07 14:37:54 +02:00
fields [ 0 ]. GetCString (), tmBan . tm_year % 100 , tmBan . tm_mon + 1 , tmBan . tm_mday , tmBan . tm_hour , tmBan . tm_min ,
2012-07-07 14:04:57 +02:00
fields [ 3 ]. GetCString (), fields [ 4 ]. GetCString ());
}
else
{
time_t timeUnban = time_t ( fields [ 2 ]. GetUInt32 ());
2013-09-07 14:37:54 +02:00
tm tmUnban ;
2014-06-22 15:42:46 +02:00
localtime_r ( & timeUnban , & tmUnban );
2012-07-07 14:04:57 +02:00
handler -> PSendSysMessage ( "|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|" ,
2013-09-07 14:37:54 +02:00
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 ,
2012-07-07 14:04:57 +02:00
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 :
2014-05-06 23:43:29 +02:00
if ( ! Utf8ToUpperOnlyLatin ( nameOrIP ))
2012-07-07 14:04:57 +02:00
{
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 ();
}