2012-06-20 23:28:16 +01:00
/*
2020-01-02 06:44:10 +01:00
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
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 */
2020-09-04 13:38:24 +02:00
#include "ScriptMgr.h"
2012-06-20 23:28:16 +01: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"
2022-02-11 21:57:45 +01:00
#include "ChatCommand.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"
2012-06-21 00:27:13 +01:00
#include "ObjectMgr.h"
2012-11-17 05:18:37 +01:00
#include "Player.h"
2020-09-04 13:38:24 +02:00
#include "PlayerDump.h"
2012-11-20 12:30:30 +01:00
#include "ReputationMgr.h"
2017-05-18 23:52:58 +02:00
#include "World.h"
2017-06-04 01:00:45 +02:00
#include "WorldSession.h"
2020-04-03 18:12:07 +02:00
#include <sstream>
2012-06-20 23:28:16 +01:00
2020-09-07 15:38:23 +02:00
using namespace Trinity :: ChatCommands ;
2020-09-20 02:50:38 +02:00
2012-06-20 23:28:16 +01:00
class character_commandscript : public CommandScript
{
public :
character_commandscript () : CommandScript ( "character_commandscript" ) { }
2020-09-20 02:50:38 +02:00
ChatCommandTable GetCommands () const override
2012-06-20 23:28:16 +01:00
{
2020-09-20 02:50:38 +02:00
static ChatCommandTable pdumpCommandTable =
2012-07-29 12:29:36 +02:00
{
2020-09-20 02:50:38 +02:00
{ "copy" , HandlePDumpCopyCommand , rbac :: RBAC_PERM_COMMAND_PDUMP_COPY , Console :: Yes },
{ "load" , HandlePDumpLoadCommand , rbac :: RBAC_PERM_COMMAND_PDUMP_LOAD , Console :: Yes },
{ "write" , HandlePDumpWriteCommand , rbac :: RBAC_PERM_COMMAND_PDUMP_WRITE , Console :: Yes },
2012-07-29 12:29:36 +02:00
};
2020-09-20 02:50:38 +02:00
static ChatCommandTable characterDeletedCommandTable =
2012-06-20 23:28:16 +01:00
{
2020-09-20 02:50:38 +02:00
{ "delete" , HandleCharacterDeletedDeleteCommand , rbac :: RBAC_PERM_COMMAND_CHARACTER_DELETED_DELETE , Console :: Yes },
{ "list" , HandleCharacterDeletedListCommand , rbac :: RBAC_PERM_COMMAND_CHARACTER_DELETED_LIST , Console :: Yes },
{ "restore" , HandleCharacterDeletedRestoreCommand , rbac :: RBAC_PERM_COMMAND_CHARACTER_DELETED_RESTORE , Console :: Yes },
{ "old" , HandleCharacterDeletedOldCommand , rbac :: RBAC_PERM_COMMAND_CHARACTER_DELETED_OLD , Console :: Yes },
2012-06-20 23:28:16 +01:00
};
2020-09-20 02:50:38 +02:00
static ChatCommandTable characterCommandTable =
2012-06-20 23:28:16 +01:00
{
2020-09-20 02:50:38 +02:00
{ "customize" , HandleCharacterCustomizeCommand , rbac :: RBAC_PERM_COMMAND_CHARACTER_CUSTOMIZE , Console :: Yes },
{ "changefaction" , HandleCharacterChangeFactionCommand , rbac :: RBAC_PERM_COMMAND_CHARACTER_CHANGEFACTION , Console :: Yes },
{ "changerace" , HandleCharacterChangeRaceCommand , rbac :: RBAC_PERM_COMMAND_CHARACTER_CHANGERACE , Console :: Yes },
{ "changeaccount" , HandleCharacterChangeAccountCommand , rbac :: RBAC_PERM_COMMAND_CHARACTER_CHANGEACCOUNT , Console :: Yes },
{ "deleted" , characterDeletedCommandTable },
{ "erase" , HandleCharacterEraseCommand , rbac :: RBAC_PERM_COMMAND_CHARACTER_ERASE , Console :: Yes },
{ "level" , HandleLevelUpCommand , rbac :: RBAC_PERM_COMMAND_CHARACTER_LEVEL , Console :: Yes },
{ "rename" , HandleCharacterRenameCommand , rbac :: RBAC_PERM_COMMAND_CHARACTER_RENAME , Console :: Yes },
{ "reputation" , HandleCharacterReputationCommand , rbac :: RBAC_PERM_COMMAND_CHARACTER_REPUTATION , Console :: Yes },
{ "titles" , HandleCharacterTitlesCommand , rbac :: RBAC_PERM_COMMAND_CHARACTER_TITLES , Console :: Yes },
2012-06-20 23:28:16 +01:00
};
2020-09-20 02:50:38 +02:00
static ChatCommandTable commandTable =
2012-06-20 23:28:16 +01:00
{
2020-09-20 02:50:38 +02:00
{ "character" , characterCommandTable },
{ "levelup" , HandleLevelUpCommand , rbac :: RBAC_PERM_COMMAND_LEVELUP , Console :: No },
{ "pdump" , 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)
*/
2020-09-07 15:38:23 +02:00
static bool GetDeletedCharacterInfoList ( DeletedInfoList & foundList , std :: string & searchString )
2012-06-20 23:28:16 +01:00
{
PreparedQueryResult result ;
2019-07-27 01:00:37 +02:00
CharacterDatabasePreparedStatement * stmt ;
2012-06-20 23:28:16 +01:00
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 );
2021-04-05 23:47:05 +02:00
info . deleteDate = fields [ 3 ]. GetInt64 ();
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
2017-02-05 23:14:19 +01:00
if ( ! sCharacterCache -> GetCharacterGuidByName ( 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
2019-07-27 01:00:37 +02:00
CharacterDatabasePreparedStatement * 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
2017-02-05 23:14:19 +01:00
sCharacterCache -> UpdateCharacterInfoDeleted ( delInfo . guid , false , & delInfo . name );
2012-06-20 23:28:16 +01:00
}
2020-09-07 15:38:23 +02:00
static bool HandleCharacterTitlesCommand ( ChatHandler * handler , Optional < PlayerIdentifier > player )
2012-07-21 22:29:14 +02:00
{
2020-09-07 15:38:23 +02:00
if ( ! player )
player = PlayerIdentifier :: FromTargetOrSelf ( handler );
if ( ! player || ! player -> IsConnected ())
2012-07-21 22:29:14 +02:00
{
2020-09-07 15:38:23 +02:00
handler -> SendSysMessage ( LANG_PLAYER_NOT_FOUND );
handler -> SetSentErrorMessage ( true );
2012-06-20 23:28:16 +01:00
return false ;
2020-09-07 15:38:23 +02:00
}
2012-06-20 23:28:16 +01:00
2020-09-07 15:38:23 +02:00
Player const * target = player -> GetConnectedPlayer ();
2012-06-20 23:28:16 +01:00
LocaleConstant loc = handler -> GetSessionDbcLocale ();
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 ))
{
2020-09-07 15:38:23 +02:00
char const * name = target -> GetNativeGender () == GENDER_MALE ? titleInfo -> Name [ loc ] : titleInfo -> Name1 [ loc ];
if ( !* name )
name = ( target -> GetNativeGender () == GENDER_MALE ? titleInfo -> Name [ sWorld -> GetDefaultDbcLocale ()] : titleInfo -> Name1 [ sWorld -> GetDefaultDbcLocale ()]);
if ( !* name )
2012-06-20 23:28:16 +01:00
continue ;
2020-09-07 15:38:23 +02:00
char const * activeStr = "" ;
if ( * target -> m_playerData -> PlayerTitle == titleInfo -> MaskID )
activeStr = handler -> GetTrinityString ( LANG_ACTIVE );
2012-06-20 23:28:16 +01:00
2020-09-10 13:10:01 +02:00
std :: string titleName = Trinity :: StringFormat ( name , player -> GetName (). c_str ());
2012-06-20 23:28:16 +01:00
// send title in "id (idx:idx) - [namedlink locale]" format
if ( handler -> GetSession ())
2020-09-07 15:38:23 +02:00
handler -> PSendSysMessage ( LANG_TITLE_LIST_CHAT , id , titleInfo -> MaskID , id , titleName . c_str (), localeNames [ loc ], knownStr , activeStr );
2012-06-20 23:28:16 +01:00
else
2020-09-07 15:38:23 +02:00
handler -> PSendSysMessage ( LANG_TITLE_LIST_CONSOLE , id , titleInfo -> MaskID , name , 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
2020-09-07 15:38:23 +02:00
static bool HandleCharacterRenameCommand ( ChatHandler * handler , Optional < PlayerIdentifier > player , Optional < std :: string_view > newNameV )
2012-06-20 23:28:16 +01:00
{
2020-09-07 15:38:23 +02:00
if ( ! player && newNameV )
2012-06-20 23:28:16 +01:00
return false ;
2020-09-07 15:38:23 +02:00
if ( ! player )
player = PlayerIdentifier :: FromTarget ( handler );
if ( ! player )
return false ;
2013-04-23 15:33:42 +02:00
2020-09-07 15:38:23 +02:00
if ( handler -> HasLowerSecurity ( nullptr , player -> GetGUID ()))
return false ;
2013-04-23 15:33:42 +02:00
2020-09-07 15:38:23 +02:00
if ( newNameV )
{
std :: string newName { * newNameV };
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
}
2020-09-07 15:38:23 +02:00
if ( ObjectMgr :: CheckPlayerName ( newName , player -> IsConnected () ? player -> GetConnectedPlayer () -> 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 ;
}
}
2019-07-27 01:00:37 +02:00
CharacterDatabasePreparedStatement * stmt = CharacterDatabase . GetPreparedStatement ( CHAR_SEL_CHECK_NAME );
2013-04-23 15:33:42 +02:00
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 );
2020-09-07 15:38:23 +02:00
stmt -> setUInt64 ( 0 , player -> GetGUID (). GetCounter ());
2013-04-23 15:33:42 +02:00
CharacterDatabase . Execute ( stmt );
2020-09-07 15:38:23 +02:00
if ( Player * target = player -> GetConnectedPlayer ())
2013-04-23 15:33:42 +02:00
{
target -> SetName ( newName );
if ( WorldSession * session = target -> GetSession ())
2020-04-08 21:05:01 +02:00
session -> KickPlayer ( "HandleCharacterRenameCommand GM Command renaming character" );
2013-04-23 15:33:42 +02:00
}
else
{
stmt = CharacterDatabase . GetPreparedStatement ( CHAR_UPD_NAME_BY_GUID );
stmt -> setString ( 0 , newName );
2020-09-07 15:38:23 +02:00
stmt -> setUInt64 ( 1 , player -> GetGUID (). GetCounter ());
2013-04-23 15:33:42 +02:00
CharacterDatabase . Execute ( stmt );
}
2020-09-07 15:38:23 +02:00
sCharacterCache -> UpdateCharacterData ( * player , newName );
2013-04-23 15:33:42 +02:00
2020-09-07 15:38:23 +02:00
handler -> PSendSysMessage ( LANG_RENAME_PLAYER_WITH_NEW_NAME , player -> GetName (). c_str (), newName . c_str ());
2013-04-23 15:33:42 +02:00
if ( WorldSession * session = handler -> GetSession ())
{
if ( Player * player = session -> GetPlayer ())
2020-09-07 15:38:23 +02: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 (), player -> GetName (). c_str (), sCharacterCache -> GetCharacterAccountIdByGuid ( player -> GetGUID ()));
2013-04-23 15:33:42 +02:00
}
else
2020-09-07 15:38:23 +02:00
sLog -> outCommand ( 0 , "CONSOLE forced rename '%s' to '%s' (%s)" , player -> GetName (). c_str (), newName . c_str (), player -> GetGUID (). ToString (). c_str ());
2012-06-20 23:28:16 +01:00
}
else
{
2020-09-07 15:38:23 +02:00
if ( Player * target = player -> GetConnectedPlayer ())
2013-04-23 15:33:42 +02:00
{
handler -> PSendSysMessage ( LANG_RENAME_PLAYER , handler -> GetNameLink ( target ). c_str ());
target -> SetAtLoginFlag ( AT_LOGIN_RENAME );
}
else
{
// check offline security
2020-09-07 15:38:23 +02:00
if ( handler -> HasLowerSecurity ( nullptr , player -> GetGUID ()))
2013-04-23 15:33:42 +02:00
return false ;
2012-06-20 23:28:16 +01:00
2020-09-10 13:10:01 +02:00
handler -> PSendSysMessage ( LANG_RENAME_PLAYER_GUID , handler -> playerLink ( * player ). c_str (), player -> GetGUID (). ToString (). c_str ());
2012-06-21 18:21:34 +02:00
2019-07-27 01:00:37 +02:00
CharacterDatabasePreparedStatement * stmt = CharacterDatabase . GetPreparedStatement ( CHAR_UPD_ADD_AT_LOGIN_FLAG );
2013-04-23 15:33:42 +02:00
stmt -> setUInt16 ( 0 , uint16 ( AT_LOGIN_RENAME ));
2020-09-07 15:38:23 +02:00
stmt -> setUInt64 ( 1 , player -> GetGUID (). 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 ;
}
// customize characters
2020-09-07 15:38:23 +02:00
static bool HandleCharacterCustomizeCommand ( ChatHandler * handler , Optional < PlayerIdentifier > player )
2012-06-20 23:28:16 +01:00
{
2020-09-07 15:38:23 +02:00
if ( ! player )
player = PlayerIdentifier :: FromTarget ( handler );
if ( ! player )
2012-06-20 23:28:16 +01:00
return false ;
2020-09-07 15:38:23 +02:00
if ( Player * target = player -> GetConnectedPlayer ())
2012-06-20 23:28:16 +01:00
{
handler -> PSendSysMessage ( LANG_CUSTOMIZE_PLAYER , handler -> GetNameLink ( target ). c_str ());
target -> SetAtLoginFlag ( AT_LOGIN_CUSTOMIZE );
}
else
{
2020-09-10 13:10:01 +02:00
handler -> PSendSysMessage ( LANG_CUSTOMIZE_PLAYER_GUID , handler -> playerLink ( * player ). c_str (), player -> GetGUID (). GetCounter ());
2020-09-07 15:38:23 +02:00
CharacterDatabasePreparedStatement * stmt = CharacterDatabase . GetPreparedStatement ( CHAR_UPD_ADD_AT_LOGIN_FLAG );
stmt -> setUInt16 ( 0 , static_cast < uint16 > ( AT_LOGIN_CUSTOMIZE ));
stmt -> setUInt64 ( 1 , player -> GetGUID (). GetCounter ());
CharacterDatabase . Execute ( stmt );
2012-06-20 23:28:16 +01:00
}
return true ;
}
2020-09-07 15:38:23 +02:00
static bool HandleCharacterChangeFactionCommand ( ChatHandler * handler , Optional < PlayerIdentifier > player )
2012-06-20 23:28:16 +01:00
{
2020-09-07 15:38:23 +02:00
if ( ! player )
player = PlayerIdentifier :: FromTarget ( handler );
if ( ! player )
2012-06-20 23:28:16 +01:00
return false ;
2020-09-07 15:38:23 +02:00
if ( Player * target = player -> GetConnectedPlayer ())
2012-06-20 23:28:16 +01:00
{
handler -> PSendSysMessage ( LANG_CUSTOMIZE_PLAYER , handler -> GetNameLink ( target ). c_str ());
target -> SetAtLoginFlag ( AT_LOGIN_CHANGE_FACTION );
}
else
{
2020-09-10 13:10:01 +02:00
handler -> PSendSysMessage ( LANG_CUSTOMIZE_PLAYER_GUID , handler -> playerLink ( * player ). c_str (), player -> GetGUID (). GetCounter ());
2020-09-07 15:38:23 +02:00
CharacterDatabasePreparedStatement * stmt = CharacterDatabase . GetPreparedStatement ( CHAR_UPD_ADD_AT_LOGIN_FLAG );
stmt -> setUInt16 ( 0 , uint16 ( AT_LOGIN_CHANGE_FACTION ));
stmt -> setUInt64 ( 1 , player -> GetGUID (). GetCounter ());
CharacterDatabase . Execute ( stmt );
2012-06-20 23:28:16 +01:00
}
return true ;
}
2020-09-07 15:38:23 +02:00
static bool HandleCharacterChangeRaceCommand ( ChatHandler * handler , Optional < PlayerIdentifier > player )
2012-06-20 23:28:16 +01:00
{
2020-09-07 15:38:23 +02:00
if ( ! player )
player = PlayerIdentifier :: FromTarget ( handler );
if ( ! player )
2012-06-20 23:28:16 +01:00
return false ;
2020-09-07 15:38:23 +02:00
if ( Player * target = player -> GetConnectedPlayer ())
2012-06-20 23:28:16 +01:00
{
handler -> PSendSysMessage ( LANG_CUSTOMIZE_PLAYER , handler -> GetNameLink ( target ). c_str ());
target -> SetAtLoginFlag ( AT_LOGIN_CHANGE_RACE );
}
else
{
2020-09-10 13:10:01 +02:00
handler -> PSendSysMessage ( LANG_CUSTOMIZE_PLAYER_GUID , handler -> playerLink ( * player ). c_str (), player -> GetGUID (). GetCounter ());
2020-09-07 15:38:23 +02:00
CharacterDatabasePreparedStatement * stmt = CharacterDatabase . GetPreparedStatement ( CHAR_UPD_ADD_AT_LOGIN_FLAG );
stmt -> setUInt16 ( 0 , uint16 ( AT_LOGIN_CHANGE_RACE ));
stmt -> setUInt64 ( 1 , player -> GetGUID (). GetCounter ());
CharacterDatabase . Execute ( stmt );
2012-06-20 23:28:16 +01:00
}
return true ;
}
2020-09-07 15:38:23 +02:00
static bool HandleCharacterChangeAccountCommand ( ChatHandler * handler , Optional < PlayerIdentifier > player , AccountIdentifier newAccount )
2017-01-06 02:13:27 -03:00
{
2020-09-07 15:38:23 +02:00
if ( ! player )
player = PlayerIdentifier :: FromTarget ( handler );
if ( ! player )
2017-01-06 02:13:27 -03:00
return false ;
2020-09-07 15:38:23 +02:00
CharacterCacheEntry const * characterInfo = sCharacterCache -> GetCharacterCacheByGuid ( player -> GetGUID ());
2017-01-06 02:13:27 -03:00
if ( ! characterInfo )
{
handler -> SendSysMessage ( LANG_PLAYER_NOT_FOUND );
handler -> SetSentErrorMessage ( true );
return false ;
}
uint32 oldAccountId = characterInfo -> AccountId ;
// nothing to do :)
2020-09-07 15:38:23 +02:00
if ( newAccount . GetID () == oldAccountId )
2017-01-06 02:13:27 -03:00
return true ;
2020-09-07 15:38:23 +02:00
if ( uint32 charCount = AccountMgr :: GetCharactersCount ( newAccount . GetID ()))
2017-01-06 02:13:27 -03:00
{
if ( charCount >= sWorld -> getIntConfig ( CONFIG_CHARACTERS_PER_REALM ))
{
2020-09-07 15:38:23 +02:00
handler -> PSendSysMessage ( LANG_ACCOUNT_CHARACTER_LIST_FULL , newAccount . GetName (). c_str (), newAccount . GetID ());
2017-01-06 02:13:27 -03:00
handler -> SetSentErrorMessage ( true );
return false ;
}
}
2020-10-12 20:16:23 +02:00
if ( Player * onlinePlayer = player -> GetConnectedPlayer ())
onlinePlayer -> GetSession () -> KickPlayer ( "HandleCharacterChangeAccountCommand GM Command transferring character to another account" );
2019-07-27 01:00:37 +02:00
CharacterDatabasePreparedStatement * charStmt = CharacterDatabase . GetPreparedStatement ( CHAR_UPD_ACCOUNT_BY_GUID );
2020-09-07 15:38:23 +02:00
charStmt -> setUInt32 ( 0 , newAccount . GetID ());
charStmt -> setUInt64 ( 1 , player -> GetGUID (). GetCounter ());
2019-07-27 01:00:37 +02:00
CharacterDatabase . DirectExecute ( charStmt );
2017-01-06 02:13:27 -03:00
sWorld -> UpdateRealmCharCount ( oldAccountId );
2020-09-07 15:38:23 +02:00
sWorld -> UpdateRealmCharCount ( newAccount . GetID ());
2017-01-06 02:13:27 -03:00
2020-09-07 15:38:23 +02:00
sCharacterCache -> UpdateCharacterAccountId ( * player , newAccount . GetID ());
2017-01-06 02:13:27 -03:00
2020-09-07 15:38:23 +02:00
handler -> PSendSysMessage ( LANG_CHANGEACCOUNT_SUCCESS , player -> GetName (). c_str (), newAccount . GetName (). c_str ());
2017-01-06 02:13:27 -03:00
2020-09-07 15:38:23 +02:00
std :: string logString = Trinity :: StringFormat ( "changed ownership of player %s (%s) from account %u to account %u" , player -> GetName (). c_str (), player -> GetGUID (). ToString (). c_str (), oldAccountId , newAccount . GetID ());
2017-01-06 02:13:27 -03:00
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 ;
}
2020-09-07 15:38:23 +02:00
static bool HandleCharacterReputationCommand ( ChatHandler * handler , Optional < PlayerIdentifier > player )
2012-06-20 23:28:16 +01:00
{
2020-09-07 15:38:23 +02:00
if ( ! player )
player = PlayerIdentifier :: FromTargetOrSelf ( handler );
if ( ! player || ! player -> IsConnected ())
{
handler -> SendSysMessage ( LANG_PLAYER_NOT_FOUND );
handler -> SetSentErrorMessage ( true );
2012-06-20 23:28:16 +01:00
return false ;
2020-09-07 15:38:23 +02:00
}
2012-06-20 23:28:16 +01:00
2020-09-07 15:38:23 +02:00
Player const * target = player -> GetConnectedPlayer ();
2012-06-20 23:28:16 +01:00
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 );
2020-06-27 13:33:17 +02:00
char const * factionName = factionEntry ? factionEntry -> Name [ loc ] : "#Not found#" ;
2021-06-04 19:27:26 +02:00
std :: string rankName = target -> GetReputationMgr (). GetReputationRankName ( factionEntry );
2012-06-20 23:28:16 +01:00
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 ) << ')' ;
2021-06-05 23:00:06 +02:00
if ( faction . Flags . HasFlag ( ReputationFlags :: Visible ))
2012-06-20 23:28:16 +01:00
ss << handler -> GetTrinityString ( LANG_FACTION_VISIBLE );
2021-06-05 23:00:06 +02:00
if ( faction . Flags . HasFlag ( ReputationFlags :: AtWar ))
2012-06-20 23:28:16 +01:00
ss << handler -> GetTrinityString ( LANG_FACTION_ATWAR );
2021-06-05 23:00:06 +02:00
if ( faction . Flags . HasFlag ( ReputationFlags :: Peaceful ))
2012-06-20 23:28:16 +01:00
ss << handler -> GetTrinityString ( LANG_FACTION_PEACE_FORCED );
2021-06-05 23:00:06 +02:00
if ( faction . Flags . HasFlag ( ReputationFlags :: Hidden ))
2012-06-20 23:28:16 +01:00
ss << handler -> GetTrinityString ( LANG_FACTION_HIDDEN );
2021-06-05 23:00:06 +02:00
if ( faction . Flags . HasFlag ( ReputationFlags :: Header ))
2012-06-20 23:28:16 +01:00
ss << handler -> GetTrinityString ( LANG_FACTION_INVISIBLE_FORCED );
2021-06-05 23:00:06 +02:00
if ( faction . Flags . HasFlag ( ReputationFlags :: Inactive ))
2012-06-20 23:28:16 +01:00
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
*/
2020-09-07 15:38:23 +02:00
static bool HandleCharacterDeletedListCommand ( ChatHandler * handler , Optional < std :: string_view > needleStr )
2012-06-20 23:28:16 +01:00
{
2020-09-07 15:38:23 +02:00
std :: string needle ;
if ( needleStr )
needle . assign ( * needleStr );
2012-06-20 23:28:16 +01:00
DeletedInfoList foundList ;
2020-09-07 15:38:23 +02:00
if ( ! GetDeletedCharacterInfoList ( foundList , needle ))
2012-06-20 23:28:16 +01:00
return false ;
// if no characters have been found, output a warning
if ( foundList . empty ())
{
handler -> SendSysMessage ( LANG_CHARACTER_DELETED_LIST_EMPTY );
2020-09-07 15:38:23 +02:00
handler -> SetSentErrorMessage ( true );
2012-06-20 23:28:16 +01:00
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
*/
2020-09-07 15:38:23 +02:00
static bool HandleCharacterDeletedRestoreCommand ( ChatHandler * handler , std :: string needle , Optional < std :: string_view > newCharName , Optional < AccountIdentifier > newAccount )
2012-06-20 23:28:16 +01:00
{
DeletedInfoList foundList ;
2020-09-07 15:38:23 +02:00
if ( ! GetDeletedCharacterInfoList ( foundList , needle ))
2012-06-20 23:28:16 +01:00
return false ;
if ( foundList . empty ())
{
handler -> SendSysMessage ( LANG_CHARACTER_DELETED_LIST_EMPTY );
2020-09-07 15:38:23 +02:00
handler -> SetSentErrorMessage ( true );
2012-06-20 23:28:16 +01:00
return false ;
}
handler -> SendSysMessage ( LANG_CHARACTER_DELETED_RESTORE );
HandleCharacterDeletedListHelper ( foundList , handler );
2020-09-07 15:38:23 +02:00
if ( ! newCharName )
2012-06-20 23:28:16 +01:00
{
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 );
2020-09-07 15:38:23 +02:00
return true ;
2012-06-20 23:28:16 +01:00
}
2020-09-07 15:38:23 +02:00
if ( foundList . size () == 1 )
2012-06-20 23:28:16 +01:00
{
2020-09-07 15:38:23 +02:00
std :: string newName { * newCharName };
2012-06-20 23:28:16 +01:00
DeletedInfo delInfo = foundList . front ();
// update name
2020-09-07 15:38:23 +02:00
delInfo . name = newName ;
2012-06-20 23:28:16 +01:00
// if new account provided update deleted info
2020-09-07 15:38:23 +02:00
if ( newAccount )
2012-06-20 23:28:16 +01:00
{
2020-09-07 15:38:23 +02:00
delInfo . accountId = newAccount -> GetID ();
delInfo . accountName = newAccount -> GetName ();
2012-06-20 23:28:16 +01:00
}
HandleCharacterDeletedRestoreHelper ( delInfo , handler );
2020-09-07 15:38:23 +02:00
return true ;
2012-06-20 23:28:16 +01:00
}
2020-09-07 15:38:23 +02:00
handler -> SendSysMessage ( LANG_CHARACTER_DELETED_ERR_RENAME );
handler -> SetSentErrorMessage ( true );
return false ;
2012-06-20 23:28:16 +01:00
}
/**
* 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
*/
2020-09-07 15:38:23 +02:00
static bool HandleCharacterDeletedDeleteCommand ( ChatHandler * handler , std :: string needle )
2012-06-20 23:28:16 +01:00
{
DeletedInfoList foundList ;
2020-09-07 15:38:23 +02:00
if ( ! GetDeletedCharacterInfoList ( foundList , needle ))
2012-06-20 23:28:16 +01:00
return false ;
if ( foundList . empty ())
{
handler -> SendSysMessage ( LANG_CHARACTER_DELETED_LIST_EMPTY );
2020-09-07 15:38:23 +02:00
handler -> SetSentErrorMessage ( true );
2012-06-20 23:28:16 +01:00
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
*/
2020-09-07 15:38:23 +02:00
static bool HandleCharacterDeletedOldCommand ( ChatHandler * /*handler*/ , Optional < uint16 > days )
2012-06-20 23:28:16 +01:00
{
2020-09-07 15:38:23 +02:00
int32 keepDays = static_cast < int32 > ( sWorld -> getIntConfig ( CONFIG_CHARDELETE_KEEP_DAYS ));
2012-06-20 23:28:16 +01:00
2020-09-07 15:38:23 +02:00
if ( days )
keepDays = static_cast < int32 > ( * days );
else if ( keepDays <= 0 ) // config option value 0 -> disabled and can't be used
2012-06-20 23:28:16 +01:00
return false ;
2020-09-07 15:38:23 +02:00
Player :: DeleteOldCharacters ( static_cast < uint32 > ( keepDays ));
2012-06-21 18:21:34 +02:00
2012-06-20 23:28:16 +01:00
return true ;
}
2020-09-07 15:38:23 +02:00
static bool HandleCharacterEraseCommand ( ChatHandler * handler , PlayerIdentifier player )
2012-06-20 23:28:16 +01:00
{
2012-06-21 18:21:34 +02:00
uint32 accountId ;
2020-09-10 13:10:01 +02:00
if ( Player * target = player . GetConnectedPlayer ())
2012-06-20 23:28:16 +01:00
{
2020-09-10 13:10:01 +02:00
accountId = target -> GetSession () -> GetAccountId ();
target -> GetSession () -> KickPlayer ( "HandleCharacterEraseCommand GM Command deleting character" );
2012-06-20 23:28:16 +01:00
}
else
2020-09-07 15:38:23 +02:00
accountId = sCharacterCache -> GetCharacterAccountIdByGuid ( player );
2012-06-20 23:28:16 +01:00
2012-06-21 18:21:34 +02:00
std :: string accountName ;
AccountMgr :: GetName ( accountId , accountName );
2020-09-07 15:38:23 +02:00
Player :: DeleteFromDB ( player , accountId , true , true );
handler -> PSendSysMessage ( LANG_CHARACTER_DELETED , player . GetName (). c_str (), player . GetGUID (). 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
2020-09-17 00:12:07 +02:00
static bool HandleLevelUpCommand ( ChatHandler * handler , Optional < PlayerIdentifier > player , int16 level )
2012-07-21 22:29:14 +02:00
{
2020-09-07 15:38:23 +02:00
if ( ! player )
player = PlayerIdentifier :: FromTargetOrSelf ( handler );
if ( ! player )
2012-07-21 22:29:14 +02:00
return false ;
2020-09-07 15:38:23 +02:00
uint8 oldlevel = static_cast < uint8 > ( player -> IsConnected () ? player -> GetConnectedPlayer () -> GetLevel () : sCharacterCache -> GetCharacterLevelByGuid ( * player ));
2020-09-17 00:12:07 +02:00
int16 newlevel = static_cast < int16 > ( oldlevel ) + level ;
2012-07-21 22:29:14 +02:00
if ( newlevel < 1 )
newlevel = 1 ;
2020-09-07 15:38:23 +02:00
if ( newlevel > static_cast < int16 > ( STRONG_MAX_LEVEL ))
newlevel = static_cast < int16 > ( STRONG_MAX_LEVEL );
2012-07-21 22:29:14 +02:00
2020-09-07 15:38:23 +02:00
if ( Player * target = player -> GetConnectedPlayer ())
2012-07-21 22:29:14 +02:00
{
2020-09-07 15:38:23 +02:00
target -> GiveLevel ( static_cast < uint8 > ( newlevel ));
target -> InitTalentForLevel ();
target -> SetXP ( 0 );
2012-07-29 12:29:36 +02:00
2020-09-07 15:38:23 +02:00
if ( handler -> needReportToTarget ( target ))
2012-07-29 12:29:36 +02:00
{
2020-09-07 15:38:23 +02:00
if ( oldlevel == newlevel )
ChatHandler ( target -> GetSession ()). PSendSysMessage ( LANG_YOURS_LEVEL_PROGRESS_RESET , handler -> GetNameLink (). c_str ());
else if ( oldlevel < static_cast < uint8 > ( newlevel ))
ChatHandler ( target -> GetSession ()). PSendSysMessage ( LANG_YOURS_LEVEL_UP , handler -> GetNameLink (). c_str (), newlevel );
else // if (oldlevel > newlevel)
ChatHandler ( target -> GetSession ()). PSendSysMessage ( LANG_YOURS_LEVEL_DOWN , handler -> GetNameLink (). c_str (), newlevel );
2012-07-29 12:29:36 +02:00
}
}
2020-09-07 15:38:23 +02:00
else
2012-07-29 12:29:36 +02:00
{
2020-09-07 15:38:23 +02:00
// Update level and reset XP, everything else will be updated at login
CharacterDatabasePreparedStatement * stmt = CharacterDatabase . GetPreparedStatement ( CHAR_UPD_LEVEL );
stmt -> setUInt8 ( 0 , static_cast < uint8 > ( newlevel ));
stmt -> setUInt64 ( 1 , player -> GetGUID (). GetCounter ());
CharacterDatabase . Execute ( stmt );
2012-07-29 12:29:36 +02:00
}
2020-09-07 15:38:23 +02:00
if ( ! handler -> GetSession () || ( handler -> GetSession () -> GetPlayer () != player -> GetConnectedPlayer ())) // including chr == NULL
2020-09-10 13:10:01 +02:00
handler -> PSendSysMessage ( LANG_YOU_CHANGE_LVL , handler -> playerLink ( * player ). c_str (), newlevel );
2020-09-07 15:38:23 +02:00
return true ;
}
2012-07-29 12:29:36 +02:00
2020-09-17 21:49:52 +02:00
static bool HandlePDumpCopyCommand ( ChatHandler * handler , PlayerIdentifier player , AccountIdentifier account , Optional < std :: string_view > characterName , Optional < ObjectGuid :: LowType > characterGUID )
2020-09-07 15:38:23 +02:00
{
2012-07-29 12:29:36 +02:00
std :: string name ;
2020-09-17 21:49:52 +02:00
if ( ! ValidatePDumpTarget ( handler , name , characterName , characterGUID ))
return false ;
std :: string dump ;
switch ( PlayerDumpWriter (). WriteDumpToString ( dump , player . GetGUID (). GetCounter ()))
2012-07-29 12:29:36 +02:00
{
2020-09-17 21:49:52 +02:00
case DUMP_SUCCESS :
break ;
case DUMP_CHARACTER_DELETED :
handler -> PSendSysMessage ( LANG_COMMAND_EXPORT_DELETED_CHAR );
2012-07-29 12:29:36 +02:00
handler -> SetSentErrorMessage ( true );
return false ;
2020-09-17 21:49:52 +02:00
case DUMP_FILE_OPEN_ERROR : // this error code should not happen
default :
handler -> PSendSysMessage ( LANG_COMMAND_EXPORT_FAILED );
2012-07-29 12:29:36 +02:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2020-09-17 21:49:52 +02:00
switch ( PlayerDumpReader (). LoadDumpFromString ( dump , account , name , characterGUID . value_or ( 0 )))
2012-07-29 12:29:36 +02:00
{
2020-09-17 21:49:52 +02:00
case DUMP_SUCCESS :
break ;
case DUMP_TOO_MANY_CHARS :
handler -> PSendSysMessage ( LANG_ACCOUNT_CHARACTER_LIST_FULL , account . GetName (). c_str (), account . GetID ());
handler -> SetSentErrorMessage ( true );
return false ;
case DUMP_FILE_OPEN_ERROR : // this error code should not happen
case DUMP_FILE_BROKEN : // this error code should not happen
default :
handler -> PSendSysMessage ( LANG_COMMAND_IMPORT_FAILED );
2012-07-29 12:29:36 +02:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2020-09-17 21:49:52 +02:00
// ToDo: use a new trinity_string for this commands
handler -> PSendSysMessage ( LANG_COMMAND_IMPORT_SUCCESS );
return true ;
}
static bool HandlePDumpLoadCommand ( ChatHandler * handler , std :: string fileName , AccountIdentifier account , Optional < std :: string_view > characterName , Optional < ObjectGuid :: LowType > characterGUID )
{
std :: string name ;
if ( ! ValidatePDumpTarget ( handler , name , characterName , characterGUID ))
return false ;
switch ( PlayerDumpReader (). LoadDumpFromFile ( fileName , account , name , characterGUID . value_or ( 0 )))
2012-07-29 12:29:36 +02:00
{
case DUMP_SUCCESS :
handler -> PSendSysMessage ( LANG_COMMAND_IMPORT_SUCCESS );
break ;
case DUMP_FILE_OPEN_ERROR :
2020-09-07 15:38:23 +02:00
handler -> PSendSysMessage ( LANG_FILE_OPEN_FAIL , fileName . c_str ());
2012-07-29 12:29:36 +02:00
handler -> SetSentErrorMessage ( true );
return false ;
case DUMP_FILE_BROKEN :
2020-09-07 15:38:23 +02:00
handler -> PSendSysMessage ( LANG_DUMP_BROKEN , fileName . c_str ());
2012-07-29 12:29:36 +02:00
handler -> SetSentErrorMessage ( true );
return false ;
case DUMP_TOO_MANY_CHARS :
2020-09-07 15:38:23 +02:00
handler -> PSendSysMessage ( LANG_ACCOUNT_CHARACTER_LIST_FULL , account . GetName (). c_str (), account . GetID ());
2012-07-29 12:29:36 +02:00
handler -> SetSentErrorMessage ( true );
return false ;
default :
handler -> PSendSysMessage ( LANG_COMMAND_IMPORT_FAILED );
handler -> SetSentErrorMessage ( true );
return false ;
}
return true ;
}
2020-09-17 21:49:52 +02:00
static bool ValidatePDumpTarget ( ChatHandler * handler , std :: string & name , Optional < std :: string_view > characterName , Optional < ObjectGuid :: LowType > characterGUID )
{
if ( characterName )
{
name . assign ( * characterName );
// normalize the name if specified and check if it exists
if ( ! normalizePlayerName ( name ))
{
handler -> PSendSysMessage ( LANG_INVALID_CHARACTER_NAME );
handler -> SetSentErrorMessage ( true );
return false ;
}
if ( ObjectMgr :: CheckPlayerName ( name , sWorld -> GetDefaultDbcLocale (), true ) != CHAR_NAME_SUCCESS )
{
handler -> PSendSysMessage ( LANG_INVALID_CHARACTER_NAME );
handler -> SetSentErrorMessage ( true );
return false ;
}
}
if ( characterGUID )
{
if ( sCharacterCache -> GetCharacterCacheByGuid ( ObjectGuid :: Create < HighGuid :: Player > ( * characterGUID )))
{
handler -> PSendSysMessage ( LANG_CHARACTER_GUID_IN_USE , * characterGUID );
handler -> SetSentErrorMessage ( true );
return false ;
}
}
return true ;
}
2020-09-07 15:38:23 +02:00
static bool HandlePDumpWriteCommand ( ChatHandler * handler , std :: string fileName , PlayerIdentifier player )
2012-07-29 12:29:36 +02:00
{
2020-09-17 21:49:52 +02:00
switch ( PlayerDumpWriter (). WriteDumpToFile ( fileName , player . GetGUID (). GetCounter ()))
2012-07-29 12:29:36 +02:00
{
case DUMP_SUCCESS :
handler -> PSendSysMessage ( LANG_COMMAND_EXPORT_SUCCESS );
break ;
case DUMP_FILE_OPEN_ERROR :
2020-09-07 15:38:23 +02:00
handler -> PSendSysMessage ( LANG_FILE_OPEN_FAIL , fileName . c_str ());
2012-07-29 12:29:36 +02:00
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
}