2012-06-20 23:28:16 +01:00
/*
2019-01-01 10:13:49 +01:00
* Copyright (C) 2008-2019 TrinityCore <https://www.trinitycore.org/>
2012-06-20 23:28:16 +01: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: character_commandscript
%Complete: 100
Comment: All character related commands
Category: commandscripts
EndScriptData */
#include "AccountMgr.h"
2012-11-20 12:30:30 +01:00
#include "Chat.h"
2017-05-18 23:52:58 +02:00
#include "DatabaseEnv.h"
2017-06-04 01:00:45 +02:00
#include "DB2Stores.h"
2017-05-18 23:52:58 +02:00
#include "Log.h"
2017-06-04 01:00:45 +02:00
#include "ObjectAccessor.h"
2012-06-21 00:27:13 +01:00
#include "ObjectMgr.h"
2012-07-29 12:29:36 +02:00
#include "PlayerDump.h"
2012-11-17 05:18:37 +01:00
#include "Player.h"
2012-11-20 12:30:30 +01:00
#include "ReputationMgr.h"
#include "ScriptMgr.h"
2017-05-18 23:52:58 +02:00
#include "World.h"
2017-06-04 01:00:45 +02:00
#include "WorldSession.h"
2012-06-20 23:28:16 +01:00
class character_commandscript : public CommandScript
{
public :
character_commandscript () : CommandScript ( "character_commandscript" ) { }
2015-10-22 20:26:56 +02:00
std :: vector < ChatCommand > GetCommands () const override
2012-06-20 23:28:16 +01:00
{
2015-10-22 20:26:56 +02:00
static std :: vector < ChatCommand > pdumpCommandTable =
2012-07-29 12:29:36 +02:00
{
2015-10-22 20:26:56 +02:00
{ "load" , rbac :: RBAC_PERM_COMMAND_PDUMP_LOAD , true , & HandlePDumpLoadCommand , "" },
{ "write" , rbac :: RBAC_PERM_COMMAND_PDUMP_WRITE , true , & HandlePDumpWriteCommand , "" },
2012-07-29 12:29:36 +02:00
};
2015-10-22 20:26:56 +02:00
static std :: vector < ChatCommand > characterDeletedCommandTable =
2012-06-20 23:28:16 +01:00
{
2015-10-22 20:26:56 +02:00
{ "delete" , rbac :: RBAC_PERM_COMMAND_CHARACTER_DELETED_DELETE , true , & HandleCharacterDeletedDeleteCommand , "" },
{ "list" , rbac :: RBAC_PERM_COMMAND_CHARACTER_DELETED_LIST , true , & HandleCharacterDeletedListCommand , "" },
{ "restore" , rbac :: RBAC_PERM_COMMAND_CHARACTER_DELETED_RESTORE , true , & HandleCharacterDeletedRestoreCommand , "" },
{ "old" , rbac :: RBAC_PERM_COMMAND_CHARACTER_DELETED_OLD , true , & HandleCharacterDeletedOldCommand , "" },
2012-06-20 23:28:16 +01:00
};
2015-10-22 20:26:56 +02:00
static std :: vector < ChatCommand > characterCommandTable =
2012-06-20 23:28:16 +01:00
{
2015-10-22 20:26:56 +02:00
{ "customize" , rbac :: RBAC_PERM_COMMAND_CHARACTER_CUSTOMIZE , true , & HandleCharacterCustomizeCommand , "" , },
{ "changefaction" , rbac :: RBAC_PERM_COMMAND_CHARACTER_CHANGEFACTION , true , & HandleCharacterChangeFactionCommand , "" , },
{ "changerace" , rbac :: RBAC_PERM_COMMAND_CHARACTER_CHANGERACE , true , & HandleCharacterChangeRaceCommand , "" , },
2017-01-06 02:13:27 -03:00
{ "changeaccount" , rbac :: RBAC_PERM_COMMAND_CHARACTER_CHANGEACCOUNT , true , & HandleCharacterChangeAccountCommand , "" , },
2013-09-27 12:46:01 +02:00
{ "deleted" , rbac :: RBAC_PERM_COMMAND_CHARACTER_DELETED , true , NULL , "" , characterDeletedCommandTable },
2015-10-22 20:26:56 +02:00
{ "erase" , rbac :: RBAC_PERM_COMMAND_CHARACTER_ERASE , true , & HandleCharacterEraseCommand , "" , },
{ "level" , rbac :: RBAC_PERM_COMMAND_CHARACTER_LEVEL , true , & HandleCharacterLevelCommand , "" , },
{ "rename" , rbac :: RBAC_PERM_COMMAND_CHARACTER_RENAME , true , & HandleCharacterRenameCommand , "" , },
{ "reputation" , rbac :: RBAC_PERM_COMMAND_CHARACTER_REPUTATION , true , & HandleCharacterReputationCommand , "" , },
{ "titles" , rbac :: RBAC_PERM_COMMAND_CHARACTER_TITLES , true , & HandleCharacterTitlesCommand , "" , },
2012-06-20 23:28:16 +01:00
};
2015-10-22 20:26:56 +02:00
static std :: vector < ChatCommand > commandTable =
2012-06-20 23:28:16 +01:00
{
2013-09-27 12:46:01 +02:00
{ "character" , rbac :: RBAC_PERM_COMMAND_CHARACTER , true , NULL , "" , characterCommandTable },
2015-10-22 20:26:56 +02:00
{ "levelup" , rbac :: RBAC_PERM_COMMAND_LEVELUP , false , & HandleLevelUpCommand , "" },
2013-09-27 12:46:01 +02:00
{ "pdump" , rbac :: RBAC_PERM_COMMAND_PDUMP , true , NULL , "" , pdumpCommandTable },
2012-07-04 22:20:21 +02:00
};
2012-06-20 23:28:16 +01:00
return commandTable ;
}
// Stores informations about a deleted character
struct DeletedInfo
{
2014-09-14 16:54:21 +02:00
ObjectGuid guid ; ///< the GUID from the character
2012-06-20 23:28:16 +01:00
std :: string name ; ///< the character name
uint32 accountId ; ///< the account id
std :: string accountName ; ///< the account name
time_t deleteDate ; ///< the date at which the character has been deleted
};
typedef std :: list < DeletedInfo > DeletedInfoList ;
/**
* Collects all GUIDs (and related info) from deleted characters which are still in the database.
*
* @param foundList a reference to an std::list which will be filled with info data
* @param searchString the search string which either contains a player GUID or a part fo the character-name
* @return returns false if there was a problem while selecting the characters (e.g. player name not normalizeable)
*/
static bool GetDeletedCharacterInfoList ( DeletedInfoList & foundList , std :: string searchString )
{
PreparedQueryResult result ;
PreparedStatement * stmt ;
if ( ! searchString . empty ())
{
// search by GUID
if ( isNumeric ( searchString . c_str ()))
{
stmt = CharacterDatabase . GetPreparedStatement ( CHAR_SEL_CHAR_DEL_INFO_BY_GUID );
2014-11-03 19:11:14 +01:00
stmt -> setUInt64 ( 0 , strtoull ( searchString . c_str (), nullptr , 10 ));
2012-06-20 23:28:16 +01:00
result = CharacterDatabase . Query ( stmt );
}
// search by name
else
{
if ( ! normalizePlayerName ( searchString ))
return false ;
2012-06-21 18:21:34 +02:00
2012-07-04 22:20:21 +02:00
stmt = CharacterDatabase . GetPreparedStatement ( CHAR_SEL_CHAR_DEL_INFO_BY_NAME );
stmt -> setString ( 0 , searchString );
2012-06-20 23:28:16 +01:00
result = CharacterDatabase . Query ( stmt );
}
}
else
{
2012-07-04 22:20:21 +02:00
stmt = CharacterDatabase . GetPreparedStatement ( CHAR_SEL_CHAR_DEL_INFO );
2012-06-20 23:28:16 +01:00
result = CharacterDatabase . Query ( stmt );
}
2012-06-21 18:21:34 +02:00
2012-06-20 23:28:16 +01:00
if ( result )
{
do
{
Field * fields = result -> Fetch ();
2012-06-21 18:21:34 +02:00
2012-06-20 23:28:16 +01:00
DeletedInfo info ;
2012-06-21 18:21:34 +02:00
2014-10-29 21:13:21 +01:00
info . guid = ObjectGuid :: Create < HighGuid :: Player > ( fields [ 0 ]. GetUInt64 ());
2012-06-20 23:28:16 +01:00
info . name = fields [ 1 ]. GetString ();
info . accountId = fields [ 2 ]. GetUInt32 ();
2012-06-21 18:21:34 +02:00
2016-02-20 13:23:35 +01:00
// account name will be empty for nonexisting account
2012-06-20 23:28:16 +01:00
AccountMgr :: GetName ( info . accountId , info . accountName );
2012-07-04 22:20:21 +02:00
info . deleteDate = time_t ( fields [ 3 ]. GetUInt32 ());
2012-06-20 23:28:16 +01:00
foundList . push_back ( info );
2012-06-21 18:21:34 +02:00
}
while ( result -> NextRow ());
2012-06-20 23:28:16 +01:00
}
2012-06-21 18:21:34 +02:00
2012-06-20 23:28:16 +01:00
return true ;
}
/**
* Shows all deleted characters which matches the given search string, expected non empty list
*
* @see HandleCharacterDeletedListCommand
* @see HandleCharacterDeletedRestoreCommand
* @see HandleCharacterDeletedDeleteCommand
* @see DeletedInfoList
*
* @param foundList contains a list with all found deleted characters
*/
static void HandleCharacterDeletedListHelper ( DeletedInfoList const & foundList , ChatHandler * handler )
{
if ( ! handler -> GetSession ())
{
handler -> SendSysMessage ( LANG_CHARACTER_DELETED_LIST_BAR );
handler -> SendSysMessage ( LANG_CHARACTER_DELETED_LIST_HEADER );
handler -> SendSysMessage ( LANG_CHARACTER_DELETED_LIST_BAR );
}
2012-06-21 18:21:34 +02:00
2012-06-20 23:28:16 +01:00
for ( DeletedInfoList :: const_iterator itr = foundList . begin (); itr != foundList . end (); ++ itr )
{
std :: string dateStr = TimeToTimestampStr ( itr -> deleteDate );
2012-06-21 18:21:34 +02:00
2012-06-20 23:28:16 +01:00
if ( ! handler -> GetSession ())
handler -> PSendSysMessage ( LANG_CHARACTER_DELETED_LIST_LINE_CONSOLE ,
2016-02-20 13:23:35 +01:00
itr -> guid . ToString (). c_str (), itr -> name . c_str (), itr -> accountName . empty () ? "<Not existing>" : itr -> accountName . c_str (),
2012-06-20 23:28:16 +01:00
itr -> accountId , dateStr . c_str ());
else
handler -> PSendSysMessage ( LANG_CHARACTER_DELETED_LIST_LINE_CHAT ,
2016-02-20 13:23:35 +01:00
itr -> guid . ToString (). c_str (), itr -> name . c_str (), itr -> accountName . empty () ? "<Not existing>" : itr -> accountName . c_str (),
2012-06-20 23:28:16 +01:00
itr -> accountId , dateStr . c_str ());
}
2012-06-21 18:21:34 +02:00
2012-06-20 23:28:16 +01:00
if ( ! handler -> GetSession ())
handler -> SendSysMessage ( LANG_CHARACTER_DELETED_LIST_BAR );
}
/**
* Restore a previously deleted character
*
* @see HandleCharacterDeletedListHelper
* @see HandleCharacterDeletedRestoreCommand
* @see HandleCharacterDeletedDeleteCommand
* @see DeletedInfoList
*
* @param delInfo the informations about the character which will be restored
*/
static void HandleCharacterDeletedRestoreHelper ( DeletedInfo const & delInfo , ChatHandler * handler )
{
2016-02-20 13:23:35 +01:00
if ( delInfo . accountName . empty ()) // account does not exist
2012-06-20 23:28:16 +01:00
{
2014-10-22 15:46:25 +02:00
handler -> PSendSysMessage ( LANG_CHARACTER_DELETED_SKIP_ACCOUNT , delInfo . name . c_str (), delInfo . guid . ToString (). c_str (), delInfo . accountId );
2012-06-20 23:28:16 +01:00
return ;
}
2012-06-21 18:21:34 +02:00
2012-06-20 23:28:16 +01:00
// check character count
uint32 charcount = AccountMgr :: GetCharactersCount ( delInfo . accountId );
2014-11-03 19:11:14 +01:00
if ( charcount >= sWorld -> getIntConfig ( CONFIG_CHARACTERS_PER_REALM ))
2012-06-20 23:28:16 +01:00
{
2014-10-22 15:46:25 +02:00
handler -> PSendSysMessage ( LANG_CHARACTER_DELETED_SKIP_FULL , delInfo . name . c_str (), delInfo . guid . ToString (). c_str (), delInfo . accountId );
2012-06-20 23:28:16 +01:00
return ;
}
2012-06-21 18:21:34 +02:00
2014-11-12 19:16:14 +01:00
if ( ! ObjectMgr :: GetPlayerGUIDByName ( delInfo . name ). IsEmpty ())
2012-06-20 23:28:16 +01:00
{
2014-10-22 15:46:25 +02:00
handler -> PSendSysMessage ( LANG_CHARACTER_DELETED_SKIP_NAME , delInfo . name . c_str (), delInfo . guid . ToString (). c_str (), delInfo . accountId );
2012-06-20 23:28:16 +01:00
return ;
}
2012-06-21 18:21:34 +02:00
2014-03-02 00:00:39 +01:00
PreparedStatement * stmt = CharacterDatabase . GetPreparedStatement ( CHAR_UPD_RESTORE_DELETE_INFO );
2012-06-20 23:28:16 +01:00
stmt -> setString ( 0 , delInfo . name );
stmt -> setUInt32 ( 1 , delInfo . accountId );
2014-10-24 19:56:17 +02:00
stmt -> setUInt64 ( 2 , delInfo . guid . GetCounter ());
2012-06-20 23:28:16 +01:00
CharacterDatabase . Execute ( stmt );
2012-06-21 18:21:34 +02:00
2014-11-12 19:16:14 +01:00
sWorld -> UpdateCharacterInfoDeleted ( delInfo . guid , false , & delInfo . name );
2012-06-20 23:28:16 +01:00
}
2014-09-14 16:14:12 +02:00
static void HandleCharacterLevel ( Player * player , ObjectGuid playerGuid , uint32 oldLevel , uint32 newLevel , ChatHandler * handler )
2012-07-21 22:29:14 +02:00
{
if ( player )
{
player -> GiveLevel ( newLevel );
player -> InitTalentForLevel ();
2019-06-03 20:40:34 +02:00
player -> SetXP ( 0 );
2012-07-21 22:29:14 +02:00
if ( handler -> needReportToTarget ( player ))
{
if ( oldLevel == newLevel )
2012-11-17 05:18:37 +01:00
ChatHandler ( player -> GetSession ()). PSendSysMessage ( LANG_YOURS_LEVEL_PROGRESS_RESET , handler -> GetNameLink (). c_str ());
2012-07-21 22:29:14 +02:00
else if ( oldLevel < newLevel )
2012-11-17 05:18:37 +01:00
ChatHandler ( player -> GetSession ()). PSendSysMessage ( LANG_YOURS_LEVEL_UP , handler -> GetNameLink (). c_str (), newLevel );
2012-07-21 22:29:14 +02:00
else // if (oldlevel > newlevel)
2012-11-17 05:18:37 +01:00
ChatHandler ( player -> GetSession ()). PSendSysMessage ( LANG_YOURS_LEVEL_DOWN , handler -> GetNameLink (). c_str (), newLevel );
2012-07-21 22:29:14 +02:00
}
}
else
{
// Update level and reset XP, everything else will be updated at login
PreparedStatement * stmt = CharacterDatabase . GetPreparedStatement ( CHAR_UPD_LEVEL );
stmt -> setUInt8 ( 0 , uint8 ( newLevel ));
2014-10-24 19:56:17 +02:00
stmt -> setUInt64 ( 1 , playerGuid . GetCounter ());
2012-07-21 22:29:14 +02:00
CharacterDatabase . Execute ( stmt );
}
}
2012-06-20 23:28:16 +01:00
static bool HandleCharacterTitlesCommand ( ChatHandler * handler , char const * args )
{
if ( !* args )
return false ;
Player * target ;
if ( ! handler -> extractPlayerTarget (( char * ) args , & target ))
return false ;
LocaleConstant loc = handler -> GetSessionDbcLocale ();
2012-10-24 13:29:34 +02:00
char const * targetName = target -> GetName (). c_str ();
2012-06-20 23:28:16 +01:00
char const * knownStr = handler -> GetTrinityString ( LANG_KNOWN );
// Search in CharTitles.dbc
for ( uint32 id = 0 ; id < sCharTitlesStore . GetNumRows (); id ++ )
{
CharTitlesEntry const * titleInfo = sCharTitlesStore . LookupEntry ( id );
if ( titleInfo && target -> HasTitle ( titleInfo ))
{
2018-03-12 18:20:26 +01:00
std :: string name = ( target -> getGender () == GENDER_MALE ? titleInfo -> Name : titleInfo -> Name1 ) -> Str [ handler -> GetSessionDbcLocale ()];
2012-06-20 23:28:16 +01:00
if ( name . empty ())
continue ;
2019-06-03 20:40:34 +02:00
char const * activeStr = * target -> m_playerData -> PlayerTitle == titleInfo -> MaskID
2012-06-20 23:28:16 +01:00
? handler -> GetTrinityString ( LANG_ACTIVE )
: "" ;
2017-07-22 10:22:17 +03:00
std :: string titleNameStr = Trinity :: StringFormat ( name . c_str (), targetName );
2012-06-20 23:28:16 +01:00
// send title in "id (idx:idx) - [namedlink locale]" format
if ( handler -> GetSession ())
2017-07-22 10:22:17 +03:00
handler -> PSendSysMessage ( LANG_TITLE_LIST_CHAT , id , titleInfo -> MaskID , id , titleNameStr . c_str (), localeNames [ loc ], knownStr , activeStr );
2012-06-20 23:28:16 +01:00
else
2014-11-07 14:32:47 +02:00
handler -> PSendSysMessage ( LANG_TITLE_LIST_CONSOLE , id , titleInfo -> MaskID , name . c_str (), localeNames [ loc ], knownStr , activeStr );
2012-06-20 23:28:16 +01:00
}
}
2012-06-21 18:21:34 +02:00
2012-06-20 23:28:16 +01:00
return true ;
}
//rename characters
static bool HandleCharacterRenameCommand ( ChatHandler * handler , char const * args )
{
Player * target ;
2014-09-14 16:14:12 +02:00
ObjectGuid targetGuid ;
2012-06-20 23:28:16 +01:00
std :: string targetName ;
if ( ! handler -> extractPlayerTarget (( char * ) args , & target , & targetGuid , & targetName ))
return false ;
2013-04-23 15:33:42 +02:00
char const * newNameStr = strtok ( NULL , " " );
if ( newNameStr )
2012-06-20 23:28:16 +01:00
{
2013-04-23 15:33:42 +02:00
std :: string playerOldName ;
std :: string newName = newNameStr ;
if ( target )
{
// check online security
2014-09-14 16:54:21 +02:00
if ( handler -> HasLowerSecurity ( target , ObjectGuid :: Empty ))
2013-04-23 15:33:42 +02:00
return false ;
2013-05-21 08:37:28 +02:00
2013-04-23 15:33:42 +02:00
playerOldName = target -> GetName ();
}
else
{
// check offline security
if ( handler -> HasLowerSecurity ( NULL , targetGuid ))
return false ;
2014-11-12 19:16:14 +01:00
ObjectMgr :: GetPlayerNameByGUID ( targetGuid , playerOldName );
2013-04-23 15:33:42 +02:00
}
if ( ! normalizePlayerName ( newName ))
{
handler -> SendSysMessage ( LANG_BAD_VALUE );
handler -> SetSentErrorMessage ( true );
2012-06-20 23:28:16 +01:00
return false ;
2013-04-23 15:33:42 +02:00
}
2015-08-30 00:17:08 +02:00
if ( ObjectMgr :: CheckPlayerName ( newName , target ? target -> GetSession () -> GetSessionDbcLocale () : sWorld -> GetDefaultDbcLocale (), true ) != CHAR_NAME_SUCCESS )
2013-04-23 15:33:42 +02:00
{
handler -> SendSysMessage ( LANG_BAD_VALUE );
handler -> SetSentErrorMessage ( true );
return false ;
}
2013-05-21 08:37:28 +02:00
2013-04-23 15:33:42 +02:00
if ( WorldSession * session = handler -> GetSession ())
{
2013-09-27 12:46:01 +02:00
if ( ! session -> HasPermission ( rbac :: RBAC_PERM_SKIP_CHECK_CHARACTER_CREATION_RESERVEDNAME ) && sObjectMgr -> IsReservedName ( newName ))
2013-04-23 15:33:42 +02:00
{
handler -> SendSysMessage ( LANG_RESERVED_NAME );
handler -> SetSentErrorMessage ( true );
return false ;
}
}
PreparedStatement * stmt = CharacterDatabase . GetPreparedStatement ( CHAR_SEL_CHECK_NAME );
stmt -> setString ( 0 , newName );
PreparedQueryResult result = CharacterDatabase . Query ( stmt );
if ( result )
{
handler -> PSendSysMessage ( LANG_RENAME_PLAYER_ALREADY_EXISTS , newName . c_str ());
handler -> SetSentErrorMessage ( true );
return false ;
}
2012-06-20 23:28:16 +01:00
2013-04-23 15:33:42 +02:00
// Remove declined name from db
2014-11-12 16:36:05 +01:00
stmt = CharacterDatabase . GetPreparedStatement ( CHAR_DEL_CHAR_DECLINED_NAME );
2014-10-23 21:34:03 +02:00
stmt -> setUInt64 ( 0 , targetGuid . GetCounter ());
2013-04-23 15:33:42 +02:00
CharacterDatabase . Execute ( stmt );
if ( target )
{
target -> SetName ( newName );
if ( WorldSession * session = target -> GetSession ())
session -> KickPlayer ();
}
else
{
stmt = CharacterDatabase . GetPreparedStatement ( CHAR_UPD_NAME_BY_GUID );
stmt -> setString ( 0 , newName );
2014-10-24 19:56:17 +02:00
stmt -> setUInt64 ( 1 , targetGuid . GetCounter ());
2013-04-23 15:33:42 +02:00
CharacterDatabase . Execute ( stmt );
}
2014-11-12 19:16:14 +01:00
sWorld -> UpdateCharacterInfo ( targetGuid , newName );
2013-04-23 15:33:42 +02:00
handler -> PSendSysMessage ( LANG_RENAME_PLAYER_WITH_NEW_NAME , playerOldName . c_str (), newName . c_str ());
if ( WorldSession * session = handler -> GetSession ())
{
if ( Player * player = session -> GetPlayer ())
2014-11-12 19:16:14 +01:00
sLog -> outCommand ( session -> GetAccountId (), "GM %s (Account: %u) forced rename %s to player %s (Account: %u)" , player -> GetName (). c_str (), session -> GetAccountId (), newName . c_str (), playerOldName . c_str (), ObjectMgr :: GetPlayerAccountIdByGUID ( targetGuid ));
2013-04-23 15:33:42 +02:00
}
else
2014-09-14 16:14:12 +02:00
sLog -> outCommand ( 0 , "CONSOLE forced rename '%s' to '%s' (%s)" , playerOldName . c_str (), newName . c_str (), targetGuid . ToString (). c_str ());
2012-06-20 23:28:16 +01:00
}
else
{
2013-04-23 15:33:42 +02:00
if ( target )
{
// check online security
2014-09-14 16:54:21 +02:00
if ( handler -> HasLowerSecurity ( target , ObjectGuid :: Empty ))
2013-04-23 15:33:42 +02:00
return false ;
handler -> PSendSysMessage ( LANG_RENAME_PLAYER , handler -> GetNameLink ( target ). c_str ());
target -> SetAtLoginFlag ( AT_LOGIN_RENAME );
}
else
{
// check offline security
if ( handler -> HasLowerSecurity ( NULL , targetGuid ))
return false ;
2012-06-20 23:28:16 +01:00
2013-04-23 15:33:42 +02:00
std :: string oldNameLink = handler -> playerLink ( targetName );
2014-10-22 15:46:25 +02:00
handler -> PSendSysMessage ( LANG_RENAME_PLAYER_GUID , oldNameLink . c_str (), targetGuid . ToString (). c_str ());
2012-06-21 18:21:34 +02:00
2013-04-23 15:33:42 +02:00
PreparedStatement * stmt = CharacterDatabase . GetPreparedStatement ( CHAR_UPD_ADD_AT_LOGIN_FLAG );
stmt -> setUInt16 ( 0 , uint16 ( AT_LOGIN_RENAME ));
2014-10-24 19:56:17 +02:00
stmt -> setUInt64 ( 1 , targetGuid . GetCounter ());
2013-04-23 15:33:42 +02:00
CharacterDatabase . Execute ( stmt );
}
2012-06-20 23:28:16 +01:00
}
2012-06-21 18:21:34 +02:00
2012-06-20 23:28:16 +01:00
return true ;
}
static bool HandleCharacterLevelCommand ( ChatHandler * handler , char const * args )
{
char * nameStr ;
char * levelStr ;
handler -> extractOptFirstArg (( char * ) args , & nameStr , & levelStr );
if ( ! levelStr )
return false ;
// exception opt second arg: .character level $name
if ( isalpha ( levelStr [ 0 ]))
{
nameStr = levelStr ;
2016-01-20 23:43:13 +01:00
levelStr = nullptr ; // current level will used
2012-06-20 23:28:16 +01:00
}
Player * target ;
2014-09-14 16:14:12 +02:00
ObjectGuid targetGuid ;
2012-06-21 18:21:34 +02:00
std :: string targetName ;
if ( ! handler -> extractPlayerTarget ( nameStr , & target , & targetGuid , & targetName ))
return false ;
2012-06-20 23:28:16 +01:00
2012-06-21 18:21:34 +02:00
int32 oldlevel = target ? target -> getLevel () : Player :: GetLevelFromDB ( targetGuid );
2012-06-20 23:28:16 +01:00
int32 newlevel = levelStr ? atoi ( levelStr ) : oldlevel ;
if ( newlevel < 1 )
return false ; // invalid level
if ( newlevel > STRONG_MAX_LEVEL ) // hardcoded maximum level
newlevel = STRONG_MAX_LEVEL ;
2012-07-21 22:29:14 +02:00
HandleCharacterLevel ( target , targetGuid , oldlevel , newlevel , handler );
2012-06-20 23:28:16 +01:00
if ( ! handler -> GetSession () || handler -> GetSession () -> GetPlayer () != target ) // including player == NULL
{
2012-06-21 18:21:34 +02:00
std :: string nameLink = handler -> playerLink ( targetName );
2012-06-20 23:28:16 +01:00
handler -> PSendSysMessage ( LANG_YOU_CHANGE_LVL , nameLink . c_str (), newlevel );
}
return true ;
}
// customize characters
static bool HandleCharacterCustomizeCommand ( ChatHandler * handler , char const * args )
{
Player * target ;
2014-09-14 16:14:12 +02:00
ObjectGuid targetGuid ;
2012-06-20 23:28:16 +01:00
std :: string targetName ;
if ( ! handler -> extractPlayerTarget (( char * ) args , & target , & targetGuid , & targetName ))
return false ;
PreparedStatement * stmt = CharacterDatabase . GetPreparedStatement ( CHAR_UPD_ADD_AT_LOGIN_FLAG );
stmt -> setUInt16 ( 0 , uint16 ( AT_LOGIN_CUSTOMIZE ));
if ( target )
{
handler -> PSendSysMessage ( LANG_CUSTOMIZE_PLAYER , handler -> GetNameLink ( target ). c_str ());
target -> SetAtLoginFlag ( AT_LOGIN_CUSTOMIZE );
2014-10-24 19:56:17 +02:00
stmt -> setUInt64 ( 1 , target -> GetGUID (). GetCounter ());
2012-06-20 23:28:16 +01:00
}
else
{
std :: string oldNameLink = handler -> playerLink ( targetName );
2014-10-24 19:56:17 +02:00
stmt -> setUInt64 ( 1 , targetGuid . GetCounter ());
2014-10-22 15:46:25 +02:00
handler -> PSendSysMessage ( LANG_CUSTOMIZE_PLAYER_GUID , oldNameLink . c_str (), targetGuid . ToString (). c_str ());
2012-06-20 23:28:16 +01:00
}
CharacterDatabase . Execute ( stmt );
return true ;
}
static bool HandleCharacterChangeFactionCommand ( ChatHandler * handler , char const * args )
{
Player * target ;
2014-09-14 16:14:12 +02:00
ObjectGuid targetGuid ;
2012-06-20 23:28:16 +01:00
std :: string targetName ;
if ( ! handler -> extractPlayerTarget (( char * ) args , & target , & targetGuid , & targetName ))
return false ;
PreparedStatement * stmt = CharacterDatabase . GetPreparedStatement ( CHAR_UPD_ADD_AT_LOGIN_FLAG );
stmt -> setUInt16 ( 0 , uint16 ( AT_LOGIN_CHANGE_FACTION ));
if ( target )
{
handler -> PSendSysMessage ( LANG_CUSTOMIZE_PLAYER , handler -> GetNameLink ( target ). c_str ());
target -> SetAtLoginFlag ( AT_LOGIN_CHANGE_FACTION );
2014-10-24 19:56:17 +02:00
stmt -> setUInt64 ( 1 , target -> GetGUID (). GetCounter ());
2012-06-20 23:28:16 +01:00
}
else
{
std :: string oldNameLink = handler -> playerLink ( targetName );
2014-10-22 15:46:25 +02:00
handler -> PSendSysMessage ( LANG_CUSTOMIZE_PLAYER_GUID , oldNameLink . c_str (), targetGuid . ToString (). c_str ());
2014-10-24 19:56:17 +02:00
stmt -> setUInt64 ( 1 , targetGuid . GetCounter ());
2012-06-20 23:28:16 +01:00
}
CharacterDatabase . Execute ( stmt );
return true ;
}
static bool HandleCharacterChangeRaceCommand ( ChatHandler * handler , char const * args )
{
Player * target ;
2014-09-14 16:14:12 +02:00
ObjectGuid targetGuid ;
2012-06-20 23:28:16 +01:00
std :: string targetName ;
if ( ! handler -> extractPlayerTarget (( char * ) args , & target , & targetGuid , & targetName ))
return false ;
PreparedStatement * stmt = CharacterDatabase . GetPreparedStatement ( CHAR_UPD_ADD_AT_LOGIN_FLAG );
stmt -> setUInt16 ( 0 , uint16 ( AT_LOGIN_CHANGE_RACE ));
if ( target )
{
2013-03-08 21:41:30 +01:00
/// @todo add text into database
2012-06-20 23:28:16 +01:00
handler -> PSendSysMessage ( LANG_CUSTOMIZE_PLAYER , handler -> GetNameLink ( target ). c_str ());
target -> SetAtLoginFlag ( AT_LOGIN_CHANGE_RACE );
2014-10-24 19:56:17 +02:00
stmt -> setUInt64 ( 1 , target -> GetGUID (). GetCounter ());
2012-06-20 23:28:16 +01:00
}
else
{
std :: string oldNameLink = handler -> playerLink ( targetName );
2013-03-08 21:41:30 +01:00
/// @todo add text into database
2014-10-22 15:46:25 +02:00
handler -> PSendSysMessage ( LANG_CUSTOMIZE_PLAYER_GUID , oldNameLink . c_str (), targetGuid . ToString (). c_str ());
2014-10-24 19:56:17 +02:00
stmt -> setUInt64 ( 1 , targetGuid . GetCounter ());
2012-06-20 23:28:16 +01:00
}
CharacterDatabase . Execute ( stmt );
return true ;
}
2017-01-06 02:13:27 -03:00
static bool HandleCharacterChangeAccountCommand ( ChatHandler * handler , char const * args )
{
char * playerNameStr ;
char * accountNameStr ;
handler -> extractOptFirstArg ( const_cast < char *> ( args ), & playerNameStr , & accountNameStr );
if ( ! accountNameStr )
return false ;
ObjectGuid targetGuid ;
std :: string targetName ;
if ( ! handler -> extractPlayerTarget ( playerNameStr , nullptr , & targetGuid , & targetName ))
return false ;
CharacterInfo const * characterInfo = sWorld -> GetCharacterInfo ( targetGuid );
if ( ! characterInfo )
{
handler -> SendSysMessage ( LANG_PLAYER_NOT_FOUND );
handler -> SetSentErrorMessage ( true );
return false ;
}
uint32 oldAccountId = characterInfo -> AccountId ;
uint32 newAccountId = oldAccountId ;
std :: string accountName ( accountNameStr );
if ( ! Utf8ToUpperOnlyLatin ( accountName ))
{
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_EXIST , accountName . c_str ());
handler -> SetSentErrorMessage ( true );
return false ;
}
PreparedStatement * stmt = LoginDatabase . GetPreparedStatement ( LOGIN_SEL_ACCOUNT_ID_BY_NAME );
stmt -> setString ( 0 , accountName );
if ( PreparedQueryResult result = LoginDatabase . Query ( stmt ))
newAccountId = ( * result )[ 0 ]. GetUInt32 ();
else
{
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_EXIST , accountName . c_str ());
handler -> SetSentErrorMessage ( true );
return false ;
}
// nothing to do :)
if ( newAccountId == oldAccountId )
return true ;
if ( uint32 charCount = AccountMgr :: GetCharactersCount ( newAccountId ))
{
if ( charCount >= sWorld -> getIntConfig ( CONFIG_CHARACTERS_PER_REALM ))
{
handler -> PSendSysMessage ( LANG_ACCOUNT_CHARACTER_LIST_FULL , accountName . c_str (), newAccountId );
handler -> SetSentErrorMessage ( true );
return false ;
}
}
stmt = CharacterDatabase . GetPreparedStatement ( CHAR_UPD_ACCOUNT_BY_GUID );
stmt -> setUInt32 ( 0 , newAccountId );
stmt -> setUInt32 ( 1 , targetGuid . GetCounter ());
CharacterDatabase . DirectExecute ( stmt );
sWorld -> UpdateRealmCharCount ( oldAccountId );
sWorld -> UpdateRealmCharCount ( newAccountId );
sWorld -> UpdateCharacterInfoAccount ( targetGuid , newAccountId );
handler -> PSendSysMessage ( LANG_CHANGEACCOUNT_SUCCESS , targetName . c_str (), accountName . c_str ());
std :: string logString = Trinity :: StringFormat ( "changed ownership of player %s (%s) from account %u to account %u" , targetName . c_str (), targetGuid . ToString (). c_str (), oldAccountId , newAccountId );
if ( WorldSession * session = handler -> GetSession ())
{
if ( Player * player = session -> GetPlayer ())
sLog -> outCommand ( session -> GetAccountId (), "GM %s (Account: %u) %s" , player -> GetName (). c_str (), session -> GetAccountId (), logString . c_str ());
}
else
sLog -> outCommand ( 0 , "%s %s" , handler -> GetTrinityString ( LANG_CONSOLE ), logString . c_str ());
return true ;
}
2012-06-20 23:28:16 +01:00
static bool HandleCharacterReputationCommand ( ChatHandler * handler , char const * args )
{
Player * target ;
if ( ! handler -> extractPlayerTarget (( char * ) args , & target ))
return false ;
LocaleConstant loc = handler -> GetSessionDbcLocale ();
FactionStateList const & targetFSL = target -> GetReputationMgr (). GetStateList ();
for ( FactionStateList :: const_iterator itr = targetFSL . begin (); itr != targetFSL . end (); ++ itr )
{
2012-06-21 18:21:34 +02:00
FactionState const & faction = itr -> second ;
2012-06-20 23:28:16 +01:00
FactionEntry const * factionEntry = sFactionStore . LookupEntry ( faction . ID );
2016-04-25 22:03:34 +02:00
char const * factionName = factionEntry ? factionEntry -> Name -> Str [ loc ] : "#Not found#" ;
2012-06-20 23:28:16 +01:00
ReputationRank rank = target -> GetReputationMgr (). GetRank ( factionEntry );
std :: string rankName = handler -> GetTrinityString ( ReputationRankStrIndex [ rank ]);
std :: ostringstream ss ;
if ( handler -> GetSession ())
ss << faction . ID << " - |cffffffff|Hfaction:" << faction . ID << "|h[" << factionName << ' ' << localeNames [ loc ] << "]|h|r" ;
else
ss << faction . ID << " - " << factionName << ' ' << localeNames [ loc ];
ss << ' ' << rankName << " (" << target -> GetReputationMgr (). GetReputation ( factionEntry ) << ')' ;
if ( faction . Flags & FACTION_FLAG_VISIBLE )
ss << handler -> GetTrinityString ( LANG_FACTION_VISIBLE );
if ( faction . Flags & FACTION_FLAG_AT_WAR )
ss << handler -> GetTrinityString ( LANG_FACTION_ATWAR );
if ( faction . Flags & FACTION_FLAG_PEACE_FORCED )
ss << handler -> GetTrinityString ( LANG_FACTION_PEACE_FORCED );
if ( faction . Flags & FACTION_FLAG_HIDDEN )
ss << handler -> GetTrinityString ( LANG_FACTION_HIDDEN );
if ( faction . Flags & FACTION_FLAG_INVISIBLE_FORCED )
ss << handler -> GetTrinityString ( LANG_FACTION_INVISIBLE_FORCED );
if ( faction . Flags & FACTION_FLAG_INACTIVE )
ss << handler -> GetTrinityString ( LANG_FACTION_INACTIVE );
2012-06-21 18:21:34 +02:00
2012-06-20 23:28:16 +01:00
handler -> SendSysMessage ( ss . str (). c_str ());
}
2012-06-21 18:21:34 +02:00
2012-06-20 23:28:16 +01:00
return true ;
}
/**
* Handles the '.character deleted list' command, which shows all deleted characters which matches the given search string
*
* @see HandleCharacterDeletedListHelper
* @see HandleCharacterDeletedRestoreCommand
* @see HandleCharacterDeletedDeleteCommand
* @see DeletedInfoList
*
* @param args the search string which either contains a player GUID or a part fo the character-name
*/
static bool HandleCharacterDeletedListCommand ( ChatHandler * handler , char const * args )
{
DeletedInfoList foundList ;
if ( ! GetDeletedCharacterInfoList ( foundList , args ))
return false ;
// if no characters have been found, output a warning
if ( foundList . empty ())
{
handler -> SendSysMessage ( LANG_CHARACTER_DELETED_LIST_EMPTY );
return false ;
}
HandleCharacterDeletedListHelper ( foundList , handler );
2012-06-21 18:21:34 +02:00
2012-06-20 23:28:16 +01:00
return true ;
}
/**
* Handles the '.character deleted restore' command, which restores all deleted characters which matches the given search string
*
* The command automatically calls '.character deleted list' command with the search string to show all restored characters.
*
* @see HandleCharacterDeletedRestoreHelper
* @see HandleCharacterDeletedListCommand
* @see HandleCharacterDeletedDeleteCommand
*
* @param args the search string which either contains a player GUID or a part of the character-name
*/
static bool HandleCharacterDeletedRestoreCommand ( ChatHandler * handler , char const * args )
{
// It is required to submit at least one argument
if ( !* args )
return false ;
std :: string searchString ;
std :: string newCharName ;
uint32 newAccount = 0 ;
// GCC by some strange reason fail build code without temporary variable
std :: istringstream params ( args );
params >> searchString >> newCharName >> newAccount ;
DeletedInfoList foundList ;
if ( ! GetDeletedCharacterInfoList ( foundList , searchString ))
return false ;
if ( foundList . empty ())
{
handler -> SendSysMessage ( LANG_CHARACTER_DELETED_LIST_EMPTY );
return false ;
}
handler -> SendSysMessage ( LANG_CHARACTER_DELETED_RESTORE );
HandleCharacterDeletedListHelper ( foundList , handler );
if ( newCharName . empty ())
{
2016-02-20 13:23:35 +01:00
// Drop nonexisting account cases
2012-06-20 23:28:16 +01:00
for ( DeletedInfoList :: iterator itr = foundList . begin (); itr != foundList . end (); ++ itr )
HandleCharacterDeletedRestoreHelper ( * itr , handler );
}
else if ( foundList . size () == 1 && normalizePlayerName ( newCharName ))
{
DeletedInfo delInfo = foundList . front ();
// update name
delInfo . name = newCharName ;
// if new account provided update deleted info
if ( newAccount && newAccount != delInfo . accountId )
{
delInfo . accountId = newAccount ;
AccountMgr :: GetName ( newAccount , delInfo . accountName );
}
HandleCharacterDeletedRestoreHelper ( delInfo , handler );
}
else
handler -> SendSysMessage ( LANG_CHARACTER_DELETED_ERR_RENAME );
return true ;
}
/**
* Handles the '.character deleted delete' command, which completely deletes all deleted characters which matches the given search string
*
* @see Player::GetDeletedCharacterGUIDs
* @see Player::DeleteFromDB
* @see HandleCharacterDeletedListCommand
* @see HandleCharacterDeletedRestoreCommand
*
* @param args the search string which either contains a player GUID or a part fo the character-name
*/
static bool HandleCharacterDeletedDeleteCommand ( ChatHandler * handler , char const * args )
{
// It is required to submit at least one argument
if ( !* args )
return false ;
DeletedInfoList foundList ;
if ( ! GetDeletedCharacterInfoList ( foundList , args ))
return false ;
if ( foundList . empty ())
{
handler -> SendSysMessage ( LANG_CHARACTER_DELETED_LIST_EMPTY );
return false ;
}
handler -> SendSysMessage ( LANG_CHARACTER_DELETED_DELETE );
HandleCharacterDeletedListHelper ( foundList , handler );
// Call the appropriate function to delete them (current account for deleted characters is 0)
for ( DeletedInfoList :: const_iterator itr = foundList . begin (); itr != foundList . end (); ++ itr )
2014-09-14 16:54:21 +02:00
Player :: DeleteFromDB ( itr -> guid , 0 , false , true );
2012-06-20 23:28:16 +01:00
return true ;
}
/**
* Handles the '.character deleted old' command, which completely deletes all deleted characters deleted with some days ago
*
* @see Player::DeleteOldCharacters
* @see Player::DeleteFromDB
* @see HandleCharacterDeletedDeleteCommand
* @see HandleCharacterDeletedListCommand
* @see HandleCharacterDeletedRestoreCommand
*
* @param args the search string which either contains a player GUID or a part fo the character-name
*/
2012-06-21 18:21:34 +02:00
static bool HandleCharacterDeletedOldCommand ( ChatHandler * /*handler*/ , char const * args )
2012-06-20 23:28:16 +01:00
{
int32 keepDays = sWorld -> getIntConfig ( CONFIG_CHARDELETE_KEEP_DAYS );
2012-06-21 18:21:34 +02:00
char * daysStr = strtok (( char * ) args , " " );
if ( daysStr )
2012-06-20 23:28:16 +01:00
{
2012-06-21 18:21:34 +02:00
if ( ! isNumeric ( daysStr ))
2012-06-20 23:28:16 +01:00
return false ;
2012-06-21 18:21:34 +02:00
keepDays = atoi ( daysStr );
2012-06-20 23:28:16 +01:00
if ( keepDays < 0 )
return false ;
}
// config option value 0 -> disabled and can't be used
else if ( keepDays <= 0 )
return false ;
2012-06-21 18:21:34 +02:00
Player :: DeleteOldCharacters ( uint32 ( keepDays ));
2012-06-20 23:28:16 +01:00
return true ;
}
static bool HandleCharacterEraseCommand ( ChatHandler * handler , char const * args )
{
if ( !* args )
return false ;
2012-06-21 18:21:34 +02:00
char * characterName_str = strtok (( char * ) args , " " );
if ( ! characterName_str )
2012-06-20 23:28:16 +01:00
return false ;
2012-06-21 18:21:34 +02:00
std :: string characterName = characterName_str ;
if ( ! normalizePlayerName ( characterName ))
2012-06-20 23:28:16 +01:00
return false ;
2014-09-14 16:14:12 +02:00
ObjectGuid characterGuid ;
2012-06-21 18:21:34 +02:00
uint32 accountId ;
2012-06-20 23:28:16 +01:00
2014-10-18 15:13:29 +02:00
Player * player = ObjectAccessor :: FindPlayerByName ( characterName );
2012-06-20 23:28:16 +01:00
if ( player )
{
2012-06-21 18:21:34 +02:00
characterGuid = player -> GetGUID ();
accountId = player -> GetSession () -> GetAccountId ();
2012-06-20 23:28:16 +01:00
player -> GetSession () -> KickPlayer ();
}
else
{
2014-11-12 19:16:14 +01:00
characterGuid = ObjectMgr :: GetPlayerGUIDByName ( characterName );
2012-06-21 18:21:34 +02:00
if ( ! characterGuid )
2012-06-20 23:28:16 +01:00
{
2012-06-21 18:21:34 +02:00
handler -> PSendSysMessage ( LANG_NO_PLAYER , characterName . c_str ());
2012-06-20 23:28:16 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2014-11-12 19:16:14 +01:00
accountId = ObjectMgr :: GetPlayerAccountIdByGUID ( characterGuid );
2012-06-20 23:28:16 +01:00
}
2012-06-21 18:21:34 +02:00
std :: string accountName ;
AccountMgr :: GetName ( accountId , accountName );
Player :: DeleteFromDB ( characterGuid , accountId , true , true );
2014-10-22 15:46:25 +02:00
handler -> PSendSysMessage ( LANG_CHARACTER_DELETED , characterName . c_str (), characterGuid . ToString (). c_str (), accountName . c_str (), accountId );
2012-06-20 23:28:16 +01:00
return true ;
}
2012-07-21 22:29:14 +02:00
static bool HandleLevelUpCommand ( ChatHandler * handler , char const * args )
{
char * nameStr ;
char * levelStr ;
handler -> extractOptFirstArg (( char * ) args , & nameStr , & levelStr );
// exception opt second arg: .character level $name
if ( levelStr && isalpha ( levelStr [ 0 ]))
{
nameStr = levelStr ;
2016-02-20 13:23:35 +01:00
levelStr = NULL ; // current level will be used
2012-07-21 22:29:14 +02:00
}
Player * target ;
2014-09-14 16:14:12 +02:00
ObjectGuid targetGuid ;
2012-07-21 22:29:14 +02:00
std :: string targetName ;
if ( ! handler -> extractPlayerTarget ( nameStr , & target , & targetGuid , & targetName ))
return false ;
int32 oldlevel = target ? target -> getLevel () : Player :: GetLevelFromDB ( targetGuid );
int32 addlevel = levelStr ? atoi ( levelStr ) : 1 ;
int32 newlevel = oldlevel + addlevel ;
if ( newlevel < 1 )
newlevel = 1 ;
if ( newlevel > STRONG_MAX_LEVEL ) // hardcoded maximum level
newlevel = STRONG_MAX_LEVEL ;
HandleCharacterLevel ( target , targetGuid , oldlevel , newlevel , handler );
if ( ! handler -> GetSession () || handler -> GetSession () -> GetPlayer () != target ) // including chr == NULL
{
std :: string nameLink = handler -> playerLink ( targetName );
handler -> PSendSysMessage ( LANG_YOU_CHANGE_LVL , nameLink . c_str (), newlevel );
}
return true ;
}
2012-07-29 12:29:36 +02:00
static bool HandlePDumpLoadCommand ( ChatHandler * handler , char const * args )
{
if ( !* args )
return false ;
char * fileStr = strtok (( char * ) args , " " );
if ( ! fileStr )
return false ;
char * accountStr = strtok ( NULL , " " );
if ( ! accountStr )
return false ;
std :: string accountName = accountStr ;
2014-05-06 23:43:29 +02:00
if ( ! Utf8ToUpperOnlyLatin ( accountName ))
2012-07-29 12:29:36 +02:00
{
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_EXIST , accountName . c_str ());
handler -> SetSentErrorMessage ( true );
return false ;
}
uint32 accountId = AccountMgr :: GetId ( accountName );
if ( ! accountId )
{
accountId = atoi ( accountStr ); // use original string
if ( ! accountId )
{
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_EXIST , accountName . c_str ());
handler -> SetSentErrorMessage ( true );
return false ;
}
}
if ( ! AccountMgr :: GetName ( accountId , accountName ))
{
handler -> PSendSysMessage ( LANG_ACCOUNT_NOT_EXIST , accountName . c_str ());
handler -> SetSentErrorMessage ( true );
return false ;
}
char * guidStr = NULL ;
char * nameStr = strtok ( NULL , " " );
std :: string name ;
if ( nameStr )
{
name = nameStr ;
// normalize the name if specified and check if it exists
if ( ! normalizePlayerName ( name ))
{
handler -> PSendSysMessage ( LANG_INVALID_CHARACTER_NAME );
handler -> SetSentErrorMessage ( true );
return false ;
}
2015-08-30 00:17:08 +02:00
if ( ObjectMgr :: CheckPlayerName ( name , sWorld -> GetDefaultDbcLocale (), true ) != CHAR_NAME_SUCCESS )
2012-07-29 12:29:36 +02:00
{
handler -> PSendSysMessage ( LANG_INVALID_CHARACTER_NAME );
handler -> SetSentErrorMessage ( true );
return false ;
}
guidStr = strtok ( NULL , " " );
}
2014-10-26 02:57:28 +02:00
ObjectGuid :: LowType guid = UI64LIT ( 0 );
2012-07-29 12:29:36 +02:00
if ( guidStr )
{
2014-10-26 02:57:28 +02:00
guid = strtoull ( guidStr , nullptr , 10 );
2012-07-29 12:29:36 +02:00
if ( ! guid )
{
handler -> PSendSysMessage ( LANG_INVALID_CHARACTER_GUID );
handler -> SetSentErrorMessage ( true );
return false ;
}
2014-11-12 19:16:14 +01:00
if ( ObjectMgr :: GetPlayerAccountIdByGUID ( ObjectGuid :: Create < HighGuid :: Player > ( guid )))
2012-07-29 12:29:36 +02:00
{
2017-07-22 10:22:17 +03:00
handler -> PSendSysMessage ( LANG_CHARACTER_GUID_IN_USE , std :: to_string ( guid ). c_str ());
2012-07-29 12:29:36 +02:00
handler -> SetSentErrorMessage ( true );
return false ;
}
}
switch ( PlayerDumpReader (). LoadDump ( fileStr , accountId , name , guid ))
{
case DUMP_SUCCESS :
handler -> PSendSysMessage ( LANG_COMMAND_IMPORT_SUCCESS );
break ;
case DUMP_FILE_OPEN_ERROR :
handler -> PSendSysMessage ( LANG_FILE_OPEN_FAIL , fileStr );
handler -> SetSentErrorMessage ( true );
return false ;
case DUMP_FILE_BROKEN :
handler -> PSendSysMessage ( LANG_DUMP_BROKEN , fileStr );
handler -> SetSentErrorMessage ( true );
return false ;
case DUMP_TOO_MANY_CHARS :
handler -> PSendSysMessage ( LANG_ACCOUNT_CHARACTER_LIST_FULL , accountName . c_str (), accountId );
handler -> SetSentErrorMessage ( true );
return false ;
default :
handler -> PSendSysMessage ( LANG_COMMAND_IMPORT_FAILED );
handler -> SetSentErrorMessage ( true );
return false ;
}
return true ;
}
static bool HandlePDumpWriteCommand ( ChatHandler * handler , char const * args )
{
if ( !* args )
return false ;
char * fileStr = strtok (( char * ) args , " " );
char * playerStr = strtok ( NULL , " " );
if ( ! fileStr || ! playerStr )
return false ;
2014-09-14 16:14:12 +02:00
ObjectGuid guid ;
2012-07-29 12:29:36 +02:00
// character name can't start from number
if ( isNumeric ( playerStr ))
2014-10-29 21:13:21 +01:00
guid = ObjectGuid :: Create < HighGuid :: Player > ( strtoull ( playerStr , nullptr , 10 ));
2012-07-29 12:29:36 +02:00
else
{
std :: string name = handler -> extractPlayerNameFromLink ( playerStr );
if ( name . empty ())
{
handler -> SendSysMessage ( LANG_PLAYER_NOT_FOUND );
handler -> SetSentErrorMessage ( true );
return false ;
}
2014-11-12 19:16:14 +01:00
guid = ObjectMgr :: GetPlayerGUIDByName ( name );
2012-07-29 12:29:36 +02:00
}
2014-11-12 19:16:14 +01:00
if ( ! ObjectMgr :: GetPlayerAccountIdByGUID ( guid ))
2012-07-29 12:29:36 +02:00
{
handler -> PSendSysMessage ( LANG_PLAYER_NOT_FOUND );
handler -> SetSentErrorMessage ( true );
return false ;
}
2014-10-26 02:57:28 +02:00
switch ( PlayerDumpWriter (). WriteDump ( fileStr , guid . GetCounter ()))
2012-07-29 12:29:36 +02:00
{
case DUMP_SUCCESS :
handler -> PSendSysMessage ( LANG_COMMAND_EXPORT_SUCCESS );
break ;
case DUMP_FILE_OPEN_ERROR :
handler -> PSendSysMessage ( LANG_FILE_OPEN_FAIL , fileStr );
handler -> SetSentErrorMessage ( true );
return false ;
case DUMP_CHARACTER_DELETED :
handler -> PSendSysMessage ( LANG_COMMAND_EXPORT_DELETED_CHAR );
handler -> SetSentErrorMessage ( true );
return false ;
default :
handler -> PSendSysMessage ( LANG_COMMAND_EXPORT_FAILED );
handler -> SetSentErrorMessage ( true );
return false ;
}
return true ;
}
2012-06-20 23:28:16 +01:00
};
void AddSC_character_commandscript ()
{
new character_commandscript ();
2012-06-21 18:21:34 +02:00
}