2010-10-07 15:35:36 +02:00
/*
* Copyright (C) 2008-2010 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* 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/>.
2008-10-11 14:16:25 -05:00
*/
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
#include "Common.h"
2010-06-08 15:50:23 -06:00
#include "DatabaseEnv.h"
2010-01-21 11:19:34 +02:00
#include "DBCStores.h"
2008-10-11 14:16:25 -05:00
#include "ObjectMgr.h"
#include "Player.h"
#include "Item.h"
#include "GameObject.h"
2010-06-08 15:50:23 -06:00
#include "Opcodes.h"
2008-10-11 14:16:25 -05:00
#include "Chat.h"
#include "MapManager.h"
2010-06-08 15:50:23 -06:00
#include "Language.h"
2008-10-11 14:16:25 -05:00
#include "World.h"
2009-03-06 19:36:47 -06:00
#include "GameEventMgr.h"
2008-10-11 14:16:25 -05:00
#include "SpellMgr.h"
2010-06-25 03:50:19 -06:00
#include "PoolMgr.h"
2008-10-11 14:16:25 -05:00
#include "AccountMgr.h"
2010-06-08 15:50:23 -06:00
#include "WaypointManager.h"
#include "Util.h"
2008-10-11 14:16:25 -05:00
#include <cctype>
#include <iostream>
#include <fstream>
#include <map>
2009-11-02 16:18:30 +01:00
#include "OutdoorPvPMgr.h"
2010-07-30 21:54:46 -07:00
#include "Transport.h"
2008-10-29 17:09:32 -05:00
#include "TargetedMovementGenerator.h" // for HandleNpcUnFollowCommand
2009-04-06 20:33:52 -05:00
#include "CreatureGroups.h"
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
//mute player for some times
bool ChatHandler :: HandleMuteCommand ( const char * args )
{
2009-05-17 10:57:55 -05:00
char * nameStr ;
char * delayStr ;
extractOptFirstArg (( char * ) args , & nameStr , & delayStr );
2010-04-07 19:14:10 +02:00
if ( ! delayStr )
2008-10-11 14:16:25 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2009-06-29 15:03:07 +02:00
char * mutereason = strtok ( NULL , " \r " );
std :: string mutereasonstr = "No reason" ;
2010-04-07 19:14:10 +02:00
if ( mutereason != NULL )
2009-06-29 15:03:07 +02:00
mutereasonstr = mutereason ;
2009-10-17 16:20:24 -07:00
2009-05-17 10:57:55 -05:00
Player * target ;
uint64 target_guid ;
std :: string target_name ;
2010-04-07 19:14:10 +02:00
if ( ! extractPlayerTarget ( nameStr , & target , & target_guid , & target_name ))
2008-10-11 14:16:25 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2010-12-22 21:25:23 +01:00
uint32 account_id = target ? target -> GetSession () -> GetAccountId () : sObjectMgr -> GetPlayerAccountIdByGUID ( target_guid );
2009-10-17 15:51:44 -07:00
2009-05-17 10:57:55 -05:00
// find only player from same account if any
2010-04-07 19:14:10 +02:00
if ( ! target )
2010-12-23 23:25:44 +01:00
if ( WorldSession * session = sWorld -> FindSession ( account_id ))
2009-05-17 10:57:55 -05:00
target = session -> GetPlayer ();
2009-10-17 15:51:44 -07:00
2009-05-17 10:57:55 -05:00
uint32 notspeaktime = ( uint32 ) atoi ( delayStr );
2009-10-17 15:51:44 -07:00
2009-01-07 11:56:57 -06:00
// must have strong lesser security level
2010-04-07 19:14:10 +02:00
if ( HasLowerSecurity ( target , target_guid , true ))
2008-10-11 14:16:25 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2009-12-24 10:20:15 +01:00
time_t mutetime = time ( NULL ) + notspeaktime * 60 ;
2009-10-17 15:51:44 -07:00
2009-05-17 10:57:55 -05:00
if ( target )
target -> GetSession () -> m_muteTime = mutetime ;
2009-10-17 15:51:44 -07:00
2010-05-08 05:03:32 +02:00
LoginDatabase . PExecute ( "UPDATE account SET mutetime = " UI64FMTD " WHERE id = '%u'" , uint64 ( mutetime ), account_id );
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( target )
2009-06-27 17:38:18 +02:00
ChatHandler ( target ). PSendSysMessage ( LANG_YOUR_CHAT_DISABLED , notspeaktime , mutereasonstr . c_str ());
2009-10-17 15:51:44 -07:00
2009-05-17 10:57:55 -05:00
std :: string nameLink = playerLink ( target_name );
2009-10-17 15:51:44 -07:00
2009-06-29 15:03:07 +02:00
PSendSysMessage ( LANG_YOU_DISABLE_CHAT , nameLink . c_str (), notspeaktime , mutereasonstr . c_str ());
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
return true ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
//unmute player
bool ChatHandler :: HandleUnmuteCommand ( const char * args )
{
2009-05-17 10:57:55 -05:00
Player * target ;
uint64 target_guid ;
std :: string target_name ;
2010-04-07 19:14:10 +02:00
if ( ! extractPlayerTarget (( char * ) args , & target , & target_guid , & target_name ))
2008-10-11 14:16:25 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2010-12-22 21:25:23 +01:00
uint32 account_id = target ? target -> GetSession () -> GetAccountId () : sObjectMgr -> GetPlayerAccountIdByGUID ( target_guid );
2009-10-17 15:51:44 -07:00
2009-05-17 10:57:55 -05:00
// find only player from same account if any
2010-04-07 19:14:10 +02:00
if ( ! target )
2010-12-23 23:25:44 +01:00
if ( WorldSession * session = sWorld -> FindSession ( account_id ))
2009-05-17 10:57:55 -05:00
target = session -> GetPlayer ();
2009-10-17 15:51:44 -07:00
2009-01-07 11:56:57 -06:00
// must have strong lesser security level
2010-04-07 19:14:10 +02:00
if ( HasLowerSecurity ( target , target_guid , true ))
2008-10-11 14:16:25 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2009-05-17 10:57:55 -05:00
if ( target )
2008-10-11 14:16:25 -05:00
{
2010-04-07 19:14:10 +02:00
if ( target -> CanSpeak ())
2008-10-11 14:16:25 -05:00
{
SendSysMessage ( LANG_CHAT_ALREADY_ENABLED );
SetSentErrorMessage ( true );
return false ;
}
2009-10-17 15:51:44 -07:00
2009-05-17 10:57:55 -05:00
target -> GetSession () -> m_muteTime = 0 ;
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2010-05-08 05:03:32 +02:00
LoginDatabase . PExecute ( "UPDATE account SET mutetime = '0' WHERE id = '%u'" , account_id );
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( target )
2009-05-17 10:57:55 -05:00
ChatHandler ( target ). PSendSysMessage ( LANG_YOUR_CHAT_ENABLED );
2009-10-17 15:51:44 -07:00
2009-05-17 10:57:55 -05:00
std :: string nameLink = playerLink ( target_name );
2009-10-17 15:51:44 -07:00
2009-02-02 09:50:13 -06:00
PSendSysMessage ( LANG_YOU_ENABLE_CHAT , nameLink . c_str ());
2008-10-11 14:16:25 -05:00
return true ;
}
2009-10-17 15:51:44 -07:00
2010-11-12 20:47:03 +01:00
bool ChatHandler :: HandleGUIDCommand ( const char * /*args*/ )
2008-10-11 14:16:25 -05:00
{
2010-11-12 20:47:03 +01:00
uint64 guid = m_session -> GetPlayer () -> GetSelection ();
2009-10-17 15:51:44 -07:00
2009-03-19 15:16:02 -06:00
if ( guid == 0 )
{
SendSysMessage ( LANG_NO_SELECTION );
2010-11-12 20:47:03 +01:00
SetSentErrorMessage ( true );
return false ;
2010-11-10 05:22:27 +01:00
}
2010-11-12 20:47:03 +01:00
PSendSysMessage ( LANG_OBJECT_GUID , GUID_LOPART ( guid ), GUID_HIPART ( guid ));
2009-03-19 15:16:02 -06:00
return true ;
}
2009-10-17 15:51:44 -07:00
2010-11-12 20:47:03 +01:00
//move item to other slot
2009-03-19 15:16:02 -06:00
bool ChatHandler :: HandleItemMoveCommand ( const char * args )
{
2010-04-07 19:14:10 +02:00
if ( !* args )
2009-03-19 15:16:02 -06:00
return false ;
uint8 srcslot , dstslot ;
2009-10-17 15:51:44 -07:00
2009-03-19 15:16:02 -06:00
char * pParam1 = strtok (( char * ) args , " " );
if ( ! pParam1 )
return false ;
2009-10-17 15:51:44 -07:00
2009-03-19 15:16:02 -06:00
char * pParam2 = strtok ( NULL , " " );
if ( ! pParam2 )
return false ;
2009-10-17 15:51:44 -07:00
2009-03-19 15:16:02 -06:00
srcslot = ( uint8 ) atoi ( pParam1 );
dstslot = ( uint8 ) atoi ( pParam2 );
2009-10-17 15:51:44 -07:00
2010-04-07 23:25:02 +02:00
if ( srcslot == dstslot )
2009-03-19 15:16:02 -06:00
return true ;
2009-10-17 15:51:44 -07:00
2010-08-05 22:08:07 +06:00
if ( ! m_session -> GetPlayer () -> IsValidPos ( INVENTORY_SLOT_BAG_0 , srcslot , true ))
2009-03-19 15:16:02 -06:00
return false ;
2009-10-17 15:51:44 -07:00
2010-08-05 22:08:07 +06:00
if ( ! m_session -> GetPlayer () -> IsValidPos ( INVENTORY_SLOT_BAG_0 , dstslot , false ))
2009-03-19 15:16:02 -06:00
return false ;
2009-10-17 15:51:44 -07:00
2009-03-19 15:16:02 -06:00
uint16 src = (( INVENTORY_SLOT_BAG_0 << 8 ) | srcslot );
uint16 dst = (( INVENTORY_SLOT_BAG_0 << 8 ) | dstslot );
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
m_session -> GetPlayer () -> SwapItem ( src , dst );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
return true ;
}
2009-10-17 15:51:44 -07:00
2009-03-09 17:34:54 -06:00
//demorph player or unit
bool ChatHandler :: HandleDeMorphCommand ( const char * /*args*/ )
2008-10-11 14:16:25 -05:00
{
Unit * target = getSelectedUnit ();
2010-04-07 19:14:10 +02:00
if ( ! target )
2008-10-11 14:16:25 -05:00
target = m_session -> GetPlayer ();
2008-12-29 17:27:50 -06:00
// check online security
else if ( target -> GetTypeId () == TYPEID_PLAYER && HasLowerSecurity (( Player * ) target , 0 ))
return false ;
2009-10-17 15:51:44 -07:00
2009-03-09 17:34:54 -06:00
target -> DeMorph ();
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
return true ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
//kick player
bool ChatHandler :: HandleKickPlayerCommand ( const char * args )
{
2010-11-24 15:31:20 +01:00
Player * target = NULL ;
std :: string playerName ;
if ( ! extractPlayerTarget (( char * ) args , & target , NULL , & playerName ))
return false ;
2009-10-17 15:51:44 -07:00
2010-11-24 15:31:20 +01:00
if ( m_session && target == m_session -> GetPlayer ())
2009-02-09 08:16:34 -05:00
{
2010-11-24 15:31:20 +01:00
SendSysMessage ( LANG_COMMAND_KICKSELF );
SetSentErrorMessage ( true );
return false ;
}
2009-10-17 16:20:24 -07:00
2010-11-24 15:31:20 +01:00
// check online security
if ( HasLowerSecurity ( target , 0 ))
return false ;
2009-10-17 15:51:44 -07:00
2010-12-23 23:25:44 +01:00
if ( sWorld -> getBoolConfig ( CONFIG_SHOW_KICK_IN_WORLD ))
sWorld -> SendWorldText ( LANG_COMMAND_KICKMESSAGE , playerName . c_str ());
2010-11-24 15:31:20 +01:00
else
PSendSysMessage ( LANG_COMMAND_KICKMESSAGE , playerName . c_str ());
2009-10-17 15:51:44 -07:00
2010-11-24 15:31:20 +01:00
target -> GetSession () -> KickPlayer ();
2009-02-09 08:16:34 -05:00
return true ;
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
//show info of player
bool ChatHandler :: HandlePInfoCommand ( const char * args )
{
2009-05-17 10:57:55 -05:00
Player * target ;
uint64 target_guid ;
std :: string target_name ;
2010-04-07 19:14:10 +02:00
if ( ! extractPlayerTarget (( char * ) args , & target , & target_guid , & target_name ))
2008-10-11 14:16:25 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint32 accId = 0 ;
uint32 money = 0 ;
uint32 total_player_time = 0 ;
2009-11-01 17:53:07 -08:00
uint8 level = 0 ;
2008-10-11 14:16:25 -05:00
uint32 latency = 0 ;
2009-08-15 01:20:18 +02:00
uint8 race ;
uint8 Class ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// get additional information from Player object
2010-04-07 19:14:10 +02:00
if ( target )
2008-10-11 14:16:25 -05:00
{
2008-12-29 17:27:50 -06:00
// check online security
if ( HasLowerSecurity ( target , 0 ))
return false ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
accId = target -> GetSession () -> GetAccountId ();
money = target -> GetMoney ();
total_player_time = target -> GetTotalPlayedTime ();
level = target -> getLevel ();
latency = target -> GetSession () -> GetLatency ();
2009-08-15 01:20:18 +02:00
race = target -> getRace ();
Class = target -> getClass ();
2008-10-11 14:16:25 -05:00
}
// get additional information from DB
else
{
2008-12-29 17:27:50 -06:00
// check offline security
2009-05-17 10:57:55 -05:00
if ( HasLowerSecurity ( NULL , target_guid ))
2008-12-29 17:27:50 -06:00
return false ;
2009-10-17 15:51:44 -07:00
2009-08-15 01:20:18 +02:00
// 0 1 2 3 4 5
2010-09-11 21:10:54 +02:00
QueryResult result = CharacterDatabase . PQuery ( "SELECT totaltime, level, money, account, race, class FROM characters WHERE guid = '%u'" , GUID_LOPART ( target_guid ));
2008-11-05 20:10:19 -06:00
if ( ! result )
return false ;
2009-10-17 15:51:44 -07:00
2008-11-05 20:10:19 -06:00
Field * fields = result -> Fetch ();
total_player_time = fields [ 0 ]. GetUInt32 ();
2009-06-27 17:39:51 -05:00
level = fields [ 1 ]. GetUInt32 ();
money = fields [ 2 ]. GetUInt32 ();
accId = fields [ 3 ]. GetUInt32 ();
2009-08-15 01:20:18 +02:00
race = fields [ 4 ]. GetUInt8 ();
Class = fields [ 5 ]. GetUInt8 ();
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-14 11:57:03 -05:00
std :: string username = GetTrinityString ( LANG_ERROR );
2009-07-05 00:37:05 +02:00
std :: string email = GetTrinityString ( LANG_ERROR );
2008-10-14 11:57:03 -05:00
std :: string last_ip = GetTrinityString ( LANG_ERROR );
2008-10-11 14:16:25 -05:00
uint32 security = 0 ;
2008-10-14 11:57:03 -05:00
std :: string last_login = GetTrinityString ( LANG_ERROR );
2009-10-17 15:51:44 -07:00
2010-09-11 21:10:54 +02:00
QueryResult result = LoginDatabase . PQuery ( "SELECT a.username,aa.gmlevel,a.email,a.last_ip,a.last_login "
2009-12-21 21:08:29 -06:00
"FROM account a "
"LEFT JOIN account_access aa "
"ON (a.id = aa.id) "
"WHERE a.id = '%u'" , accId );
2010-04-07 19:14:10 +02:00
if ( result )
2008-10-11 14:16:25 -05:00
{
Field * fields = result -> Fetch ();
2010-09-24 22:16:21 +02:00
username = fields [ 0 ]. GetString ();
2008-10-11 14:16:25 -05:00
security = fields [ 1 ]. GetUInt32 ();
2010-09-24 22:16:21 +02:00
email = fields [ 2 ]. GetString ();
2009-10-17 15:51:44 -07:00
2010-11-16 21:27:25 +01:00
if ( email . empty ())
email = "-" ;
2009-10-17 15:51:44 -07:00
2010-11-16 21:27:25 +01:00
if ( ! m_session || m_session -> GetSecurity () >= AccountTypes ( security ))
2008-10-11 14:16:25 -05:00
{
2010-11-16 21:27:25 +01:00
last_ip = fields [ 3 ]. GetString ();
last_login = fields [ 4 ]. GetString ();
2008-10-11 14:16:25 -05:00
}
2010-11-16 21:27:25 +01:00
else
2008-10-11 14:16:25 -05:00
{
2010-11-16 21:27:25 +01:00
last_ip = "-" ;
last_login = "-" ;
2009-08-22 16:54:14 +02:00
}
2010-11-16 21:27:25 +01:00
}
2009-10-17 15:51:44 -07:00
2010-11-16 21:27:25 +01:00
std :: string nameLink = playerLink ( target_name );
2009-10-17 15:51:44 -07:00
2010-11-16 21:27:25 +01:00
PSendSysMessage ( LANG_PINFO_ACCOUNT , ( target ? "" : GetTrinityString ( LANG_OFFLINE )), nameLink . c_str (), GUID_LOPART ( target_guid ), username . c_str (), accId , email . c_str (), security , last_ip . c_str (), last_login . c_str (), latency );
std :: string race_s , Class_s ;
switch ( race )
{
case RACE_HUMAN : race_s = "Human" ; break ;
case RACE_ORC : race_s = "Orc" ; break ;
case RACE_DWARF : race_s = "Dwarf" ; break ;
case RACE_NIGHTELF : race_s = "Night Elf" ; break ;
case RACE_UNDEAD_PLAYER : race_s = "Undead" ; break ;
case RACE_TAUREN : race_s = "Tauren" ; break ;
case RACE_GNOME : race_s = "Gnome" ; break ;
case RACE_TROLL : race_s = "Troll" ; break ;
case RACE_BLOODELF : race_s = "Blood Elf" ; break ;
case RACE_DRAENEI : race_s = "Draenei" ; break ;
}
switch ( Class )
{
case CLASS_WARRIOR : Class_s = "Warrior" ; break ;
case CLASS_PALADIN : Class_s = "Paladin" ; break ;
case CLASS_HUNTER : Class_s = "Hunter" ; break ;
case CLASS_ROGUE : Class_s = "Rogue" ; break ;
case CLASS_PRIEST : Class_s = "Priest" ; break ;
case CLASS_DEATH_KNIGHT : Class_s = "Death Knight" ; break ;
case CLASS_SHAMAN : Class_s = "Shaman" ; break ;
case CLASS_MAGE : Class_s = "Mage" ; break ;
case CLASS_WARLOCK : Class_s = "Warlock" ; break ;
case CLASS_DRUID : Class_s = "Druid" ; break ;
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2010-11-16 21:27:25 +01:00
std :: string timeStr = secsToTimeString ( total_player_time , true , true );
uint32 gold = money / GOLD ;
uint32 silv = ( money % GOLD ) / SILVER ;
uint32 copp = ( money % GOLD ) % SILVER ;
PSendSysMessage ( LANG_PINFO_LEVEL , race_s . c_str (), Class_s . c_str (), timeStr . c_str (), level , gold , silv , copp );
2008-10-11 14:16:25 -05:00
return true ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
//rename characters
2009-04-24 11:45:25 -05:00
bool ChatHandler :: HandleCharacterRenameCommand ( const char * args )
2008-10-11 14:16:25 -05:00
{
2009-05-17 10:57:55 -05:00
Player * target ;
uint64 target_guid ;
std :: string target_name ;
2010-04-07 19:14:10 +02:00
if ( ! extractPlayerTarget (( char * ) args , & target , & target_guid , & target_name ))
2008-10-11 14:16:25 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( target )
2008-10-11 14:16:25 -05:00
{
2008-12-29 17:27:50 -06:00
// check online security
if ( HasLowerSecurity ( target , 0 ))
return false ;
2009-10-17 15:51:44 -07:00
2009-02-02 15:36:52 -06:00
PSendSysMessage ( LANG_RENAME_PLAYER , GetNameLink ( target ). c_str ());
2008-10-11 14:16:25 -05:00
target -> SetAtLoginFlag ( AT_LOGIN_RENAME );
}
else
{
2008-12-29 17:27:50 -06:00
// check offline security
2009-05-17 10:57:55 -05:00
if ( HasLowerSecurity ( NULL , target_guid ))
2008-12-29 17:27:50 -06:00
return false ;
2009-10-17 15:51:44 -07:00
2009-05-17 10:57:55 -05:00
std :: string oldNameLink = playerLink ( target_name );
2009-10-17 15:51:44 -07:00
2009-05-17 10:57:55 -05:00
PSendSysMessage ( LANG_RENAME_PLAYER_GUID , oldNameLink . c_str (), GUID_LOPART ( target_guid ));
CharacterDatabase . PExecute ( "UPDATE characters SET at_login = at_login | '1' WHERE guid = '%u'" , GUID_LOPART ( target_guid ));
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
return true ;
}
2009-10-17 15:51:44 -07:00
2008-12-24 09:58:26 -06:00
// customize characters
2009-04-24 11:45:25 -05:00
bool ChatHandler :: HandleCharacterCustomizeCommand ( const char * args )
2008-12-24 09:58:26 -06:00
{
2009-05-17 10:57:55 -05:00
Player * target ;
uint64 target_guid ;
std :: string target_name ;
2010-04-07 19:14:10 +02:00
if ( ! extractPlayerTarget (( char * ) args , & target , & target_guid , & target_name ))
2008-12-24 09:58:26 -06:00
return false ;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( target )
2008-12-24 09:58:26 -06:00
{
2009-02-02 15:36:52 -06:00
PSendSysMessage ( LANG_CUSTOMIZE_PLAYER , GetNameLink ( target ). c_str ());
2008-12-24 09:58:26 -06:00
target -> SetAtLoginFlag ( AT_LOGIN_CUSTOMIZE );
CharacterDatabase . PExecute ( "UPDATE characters SET at_login = at_login | '8' WHERE guid = '%u'" , target -> GetGUIDLow ());
}
else
{
2009-05-17 10:57:55 -05:00
std :: string oldNameLink = playerLink ( target_name );
2009-10-17 15:51:44 -07:00
2009-05-17 10:57:55 -05:00
PSendSysMessage ( LANG_CUSTOMIZE_PLAYER_GUID , oldNameLink . c_str (), GUID_LOPART ( target_guid ));
CharacterDatabase . PExecute ( "UPDATE characters SET at_login = at_login | '8' WHERE guid = '%u'" , GUID_LOPART ( target_guid ));
2008-12-24 09:58:26 -06:00
}
2009-10-17 15:51:44 -07:00
2008-12-24 09:58:26 -06:00
return true ;
}
2009-10-17 15:51:44 -07:00
2010-09-05 13:12:24 -07:00
bool ChatHandler :: HandleCharacterChangeFactionCommand ( const char * args )
{
Player * target ;
uint64 target_guid ;
std :: string target_name ;
if ( ! extractPlayerTarget (( char * ) args , & target , & target_guid , & target_name ))
return false ;
if ( target )
{
// TODO : add text into database
PSendSysMessage ( LANG_CUSTOMIZE_PLAYER , GetNameLink ( target ). c_str ());
target -> SetAtLoginFlag ( AT_LOGIN_CHANGE_FACTION );
CharacterDatabase . PExecute ( "UPDATE characters SET at_login = at_login | '64' WHERE guid = %u" , target -> GetGUIDLow ());
}
else
{
std :: string oldNameLink = playerLink ( target_name );
// TODO : add text into database
PSendSysMessage ( LANG_CUSTOMIZE_PLAYER_GUID , oldNameLink . c_str (), GUID_LOPART ( target_guid ));
CharacterDatabase . PExecute ( "UPDATE characters SET at_login = at_login | '64' WHERE guid = %u" , GUID_LOPART ( target_guid ));
}
return true ;
}
bool ChatHandler :: HandleCharacterChangeRaceCommand ( const char * args )
{
Player * target ;
uint64 target_guid ;
std :: string target_name ;
if ( ! extractPlayerTarget (( char * ) args , & target , & target_guid , & target_name ))
return false ;
if ( target )
{
// TODO : add text into database
PSendSysMessage ( LANG_CUSTOMIZE_PLAYER , GetNameLink ( target ). c_str ());
target -> SetAtLoginFlag ( AT_LOGIN_CHANGE_RACE );
CharacterDatabase . PExecute ( "UPDATE characters SET at_login = at_login | '128' WHERE guid = %u" , target -> GetGUIDLow ());
}
else
{
std :: string oldNameLink = playerLink ( target_name );
// TODO : add text into database
PSendSysMessage ( LANG_CUSTOMIZE_PLAYER_GUID , oldNameLink . c_str (), GUID_LOPART ( target_guid ));
CharacterDatabase . PExecute ( "UPDATE characters SET at_login = at_login | '128' WHERE guid = %u" , GUID_LOPART ( target_guid ));
}
return true ;
}
2009-05-19 15:34:07 -05:00
bool ChatHandler :: HandleCharacterReputationCommand ( const char * args )
{
Player * target ;
2010-04-07 19:14:10 +02:00
if ( ! extractPlayerTarget (( char * ) args , & target ))
2009-05-19 15:34:07 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2009-05-19 15:34:07 -05:00
LocaleConstant loc = GetSessionDbcLocale ();
2009-10-17 15:51:44 -07:00
2009-05-19 15:34:07 -05:00
FactionStateList const & targetFSL = target -> GetReputationMgr (). GetStateList ();
2009-10-17 16:20:24 -07:00
for ( FactionStateList :: const_iterator itr = targetFSL . begin (); itr != targetFSL . end (); ++ itr )
2009-05-19 15:34:07 -05:00
{
FactionEntry const * factionEntry = sFactionStore . LookupEntry ( itr -> second . ID );
char const * factionName = factionEntry ? factionEntry -> name [ loc ] : "#Not found#" ;
ReputationRank rank = target -> GetReputationMgr (). GetRank ( factionEntry );
2009-12-20 15:20:04 +01:00
std :: string rankName = GetTrinityString ( ReputationRankStrIndex [ rank ]);
2009-05-19 15:34:07 -05:00
std :: ostringstream ss ;
if ( m_session )
ss << itr -> second . ID << " - |cffffffff|Hfaction:" << itr -> second . ID << "|h[" << factionName << " " << localeNames [ loc ] << "]|h|r" ;
else
ss << itr -> second . ID << " - " << factionName << " " << localeNames [ loc ];
2009-10-17 15:51:44 -07:00
2009-05-19 15:34:07 -05:00
ss << " " << rankName << " (" << target -> GetReputationMgr (). GetReputation ( factionEntry ) << ")" ;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( itr -> second . Flags & FACTION_FLAG_VISIBLE )
2009-12-20 15:20:04 +01:00
ss << GetTrinityString ( LANG_FACTION_VISIBLE );
2010-04-07 19:14:10 +02:00
if ( itr -> second . Flags & FACTION_FLAG_AT_WAR )
2009-12-20 15:20:04 +01:00
ss << GetTrinityString ( LANG_FACTION_ATWAR );
2010-04-07 19:14:10 +02:00
if ( itr -> second . Flags & FACTION_FLAG_PEACE_FORCED )
2009-12-20 15:20:04 +01:00
ss << GetTrinityString ( LANG_FACTION_PEACE_FORCED );
2010-04-07 19:14:10 +02:00
if ( itr -> second . Flags & FACTION_FLAG_HIDDEN )
2009-12-20 15:20:04 +01:00
ss << GetTrinityString ( LANG_FACTION_HIDDEN );
2010-04-07 19:14:10 +02:00
if ( itr -> second . Flags & FACTION_FLAG_INVISIBLE_FORCED )
2009-12-20 15:20:04 +01:00
ss << GetTrinityString ( LANG_FACTION_INVISIBLE_FORCED );
2010-04-07 19:14:10 +02:00
if ( itr -> second . Flags & FACTION_FLAG_INACTIVE )
2009-12-20 15:20:04 +01:00
ss << GetTrinityString ( LANG_FACTION_INACTIVE );
2009-10-17 15:51:44 -07:00
2009-05-19 15:34:07 -05:00
SendSysMessage ( ss . str (). c_str ());
}
return true ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
bool ChatHandler :: HandleLookupEventCommand ( const char * args )
{
2010-04-07 19:14:10 +02:00
if ( !* args )
2008-10-11 14:16:25 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
std :: string namepart = args ;
std :: wstring wnamepart ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// converting string that we try to find to lower case
2010-04-07 19:14:10 +02:00
if ( ! Utf8toWStr ( namepart , wnamepart ))
2008-10-11 14:16:25 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
wstrToLower ( wnamepart );
2009-10-17 15:51:44 -07:00
2009-07-05 01:19:49 +02:00
bool found = false ;
2010-09-08 09:28:21 +03:00
uint32 count = 0 ;
2010-12-23 23:25:44 +01:00
uint32 maxResults = sWorld -> getIntConfig ( CONFIG_MAX_RESULTS_LOOKUP_COMMANDS );
2009-10-17 15:51:44 -07:00
2010-12-22 21:25:23 +01:00
GameEventMgr :: GameEventDataMap const & events = sGameEventMgr -> GetEventMap ();
GameEventMgr :: ActiveEvents const & activeEvents = sGameEventMgr -> GetActiveEventList ();
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
for ( uint32 id = 0 ; id < events . size (); ++ id )
2008-10-11 14:16:25 -05:00
{
GameEventData const & eventData = events [ id ];
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
std :: string descr = eventData . description ;
2010-04-07 19:14:10 +02:00
if ( descr . empty ())
2008-10-11 14:16:25 -05:00
continue ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
if ( Utf8FitTo ( descr , wnamepart ))
{
2010-09-08 09:28:21 +03:00
if ( maxResults && count ++ == maxResults )
{
PSendSysMessage ( LANG_COMMAND_LOOKUP_MAX_RESULTS , maxResults );
return true ;
}
2008-12-30 16:12:56 -06:00
char const * active = activeEvents . find ( id ) != activeEvents . end () ? GetTrinityString ( LANG_ACTIVE ) : "" ;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( m_session )
2010-04-07 22:59:46 +02:00
PSendSysMessage ( LANG_EVENT_ENTRY_LIST_CHAT , id , id , eventData . description . c_str (), active );
2008-12-29 17:27:50 -06:00
else
2010-04-07 22:59:46 +02:00
PSendSysMessage ( LANG_EVENT_ENTRY_LIST_CONSOLE , id , eventData . description . c_str (), active );
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( ! found )
2009-07-05 01:19:49 +02:00
found = true ;
2008-10-11 14:16:25 -05:00
}
}
2009-10-17 15:51:44 -07:00
2009-07-05 01:19:49 +02:00
if ( ! found )
2008-10-11 14:16:25 -05:00
SendSysMessage ( LANG_NOEVENTFOUND );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
return true ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
bool ChatHandler :: HandleCombatStopCommand ( const char * args )
{
2009-05-17 10:57:55 -05:00
Player * target ;
2010-04-07 19:14:10 +02:00
if ( ! extractPlayerTarget (( char * ) args , & target ))
2009-05-17 10:57:55 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2008-12-29 17:27:50 -06:00
// check online security
2009-05-17 10:57:55 -05:00
if ( HasLowerSecurity ( target , 0 ))
2008-12-29 17:27:50 -06:00
return false ;
2009-10-17 15:51:44 -07:00
2009-05-17 10:57:55 -05:00
target -> CombatStop ();
2010-03-09 11:11:10 +01:00
target -> getHostileRefManager (). deleteReferences ();
2008-10-11 14:16:25 -05:00
return true ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
bool ChatHandler :: HandleLookupPlayerIpCommand ( const char * args )
{
2009-10-17 15:51:44 -07:00
2008-10-26 13:32:42 -05:00
if ( !* args )
2008-10-11 14:16:25 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2008-10-26 13:32:42 -05:00
std :: string ip = strtok (( char * ) args , " " );
2008-12-29 17:27:50 -06:00
char * limit_str = strtok ( NULL , " " );
int32 limit = limit_str ? atoi ( limit_str ) : - 1 ;
2009-10-17 15:51:44 -07:00
2010-05-08 05:03:32 +02:00
LoginDatabase . escape_string ( ip );
2009-10-17 15:51:44 -07:00
2010-09-11 21:10:54 +02:00
QueryResult result = LoginDatabase . PQuery ( "SELECT id,username FROM account WHERE last_ip = '%s'" , ip . c_str ());
2009-10-17 15:51:44 -07:00
2008-10-26 13:32:42 -05:00
return LookupPlayerSearchCommand ( result , limit );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
bool ChatHandler :: HandleLookupPlayerAccountCommand ( const char * args )
{
2008-10-26 13:32:42 -05:00
if ( !* args )
2008-10-11 14:16:25 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2008-10-26 13:32:42 -05:00
std :: string account = strtok (( char * ) args , " " );
2008-12-29 17:27:50 -06:00
char * limit_str = strtok ( NULL , " " );
int32 limit = limit_str ? atoi ( limit_str ) : - 1 ;
2009-10-17 15:51:44 -07:00
2009-05-21 19:46:56 +02:00
if ( ! AccountMgr :: normalizeString ( account ))
2008-10-11 14:16:25 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2010-05-08 05:03:32 +02:00
LoginDatabase . escape_string ( account );
2009-10-17 15:51:44 -07:00
2010-09-11 21:10:54 +02:00
QueryResult result = LoginDatabase . PQuery ( "SELECT id,username FROM account WHERE username = '%s'" , account . c_str ());
2009-10-17 15:51:44 -07:00
2008-10-26 13:32:42 -05:00
return LookupPlayerSearchCommand ( result , limit );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
bool ChatHandler :: HandleLookupPlayerEmailCommand ( const char * args )
{
2009-10-17 15:51:44 -07:00
2008-10-26 13:32:42 -05:00
if ( !* args )
2008-10-11 14:16:25 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2008-10-26 13:32:42 -05:00
std :: string email = strtok (( char * ) args , " " );
2008-12-29 17:27:50 -06:00
char * limit_str = strtok ( NULL , " " );
int32 limit = limit_str ? atoi ( limit_str ) : - 1 ;
2009-10-17 15:51:44 -07:00
2010-05-08 05:03:32 +02:00
LoginDatabase . escape_string ( email );
2009-10-17 15:51:44 -07:00
2010-09-11 21:10:54 +02:00
QueryResult result = LoginDatabase . PQuery ( "SELECT id,username FROM account WHERE email = '%s'" , email . c_str ());
2009-10-17 15:51:44 -07:00
2008-10-26 13:32:42 -05:00
return LookupPlayerSearchCommand ( result , limit );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2010-09-11 21:10:54 +02:00
bool ChatHandler :: LookupPlayerSearchCommand ( QueryResult result , int32 limit )
2008-10-11 14:16:25 -05:00
{
2010-04-07 19:14:10 +02:00
if ( ! result )
2008-10-11 14:16:25 -05:00
{
PSendSysMessage ( LANG_NO_PLAYERS_FOUND );
SetSentErrorMessage ( true );
return false ;
}
2009-10-17 15:51:44 -07:00
2010-08-06 00:15:29 +06:00
int i = 0 ;
2010-09-08 09:28:21 +03:00
uint32 count = 0 ;
2010-12-23 23:25:44 +01:00
uint32 maxResults = sWorld -> getIntConfig ( CONFIG_MAX_RESULTS_LOOKUP_COMMANDS );
2008-10-11 14:16:25 -05:00
do
{
2010-09-08 09:28:21 +03:00
if ( maxResults && count ++ == maxResults )
{
PSendSysMessage ( LANG_COMMAND_LOOKUP_MAX_RESULTS , maxResults );
return true ;
}
2008-10-11 14:16:25 -05:00
Field * fields = result -> Fetch ();
uint32 acc_id = fields [ 0 ]. GetUInt32 ();
2010-09-24 22:16:21 +02:00
std :: string acc_name = fields [ 1 ]. GetString ();
2009-10-17 15:51:44 -07:00
2010-09-11 21:10:54 +02:00
QueryResult chars = CharacterDatabase . PQuery ( "SELECT guid,name FROM characters WHERE account = '%u'" , acc_id );
2010-04-07 19:14:10 +02:00
if ( chars )
2008-10-11 14:16:25 -05:00
{
PSendSysMessage ( LANG_LOOKUP_PLAYER_ACCOUNT , acc_name . c_str (), acc_id );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint64 guid = 0 ;
std :: string name ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
do
{
Field * charfields = chars -> Fetch ();
guid = charfields [ 0 ]. GetUInt64 ();
2010-09-24 22:16:21 +02:00
name = charfields [ 1 ]. GetString ();
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
PSendSysMessage ( LANG_LOOKUP_PLAYER_CHARACTER , name . c_str (), guid );
++ i ;
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
} while ( chars -> NextRow () && ( limit == - 1 || i < limit ));
2008-10-11 14:16:25 -05:00
}
2010-04-07 19:13:19 +02:00
} while ( result -> NextRow ());
2009-10-17 15:51:44 -07:00
2010-04-07 23:25:02 +02:00
if ( i == 0 ) // empty accounts only
2009-03-24 17:44:47 -06:00
{
PSendSysMessage ( LANG_NO_PLAYERS_FOUND );
SetSentErrorMessage ( true );
return false ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
return true ;
}
2009-10-17 15:51:44 -07:00
2008-10-26 13:32:42 -05:00
/// Triggering corpses expire check in world
bool ChatHandler :: HandleServerCorpsesCommand ( const char * /*args*/ )
{
2010-12-23 23:25:44 +01:00
sObjectAccessor -> RemoveOldCorpses ();
2008-12-29 17:27:50 -06:00
return true ;
2008-10-26 13:32:42 -05:00
}
2009-10-17 15:51:44 -07:00
2009-05-17 10:57:55 -05:00
bool ChatHandler :: HandleRepairitemsCommand ( const char * args )
2008-10-29 17:09:32 -05:00
{
2009-05-17 10:57:55 -05:00
Player * target ;
2010-04-07 19:14:10 +02:00
if ( ! extractPlayerTarget (( char * ) args , & target ))
2008-10-29 17:09:32 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2008-12-29 17:27:50 -06:00
// check online security
if ( HasLowerSecurity ( target , 0 ))
return false ;
2009-10-17 15:51:44 -07:00
2008-10-29 17:09:32 -05:00
// Repair items
target -> DurabilityRepairAll ( false , 0 , false );
2009-10-17 15:51:44 -07:00
2009-02-02 15:36:52 -06:00
PSendSysMessage ( LANG_YOU_REPAIR_ITEMS , GetNameLink ( target ). c_str ());
2010-04-07 19:14:10 +02:00
if ( needReportToTarget ( target ))
2009-02-02 15:36:52 -06:00
ChatHandler ( target ). PSendSysMessage ( LANG_YOUR_ITEMS_REPAIRED , GetNameLink (). c_str ());
2008-10-29 17:09:32 -05:00
return true ;
}
2009-10-17 15:51:44 -07:00
2008-12-24 09:58:26 -06:00
bool ChatHandler :: HandleWaterwalkCommand ( const char * args )
{
2010-04-07 19:14:10 +02:00
if ( !* args )
2008-12-24 09:58:26 -06:00
return false ;
2009-10-17 15:51:44 -07:00
2008-12-24 09:58:26 -06:00
Player * player = getSelectedPlayer ();
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( ! player )
2008-12-24 09:58:26 -06:00
{
PSendSysMessage ( LANG_NO_CHAR_SELECTED );
SetSentErrorMessage ( true );
return false ;
}
2009-10-17 15:51:44 -07:00
2008-12-29 17:27:50 -06:00
// check online security
if ( HasLowerSecurity ( player , 0 ))
return false ;
2009-10-17 15:51:44 -07:00
2008-12-24 09:58:26 -06:00
if ( strncmp ( args , "on" , 3 ) == 0 )
player -> SetMovement ( MOVE_WATER_WALK ); // ON
else if ( strncmp ( args , "off" , 4 ) == 0 )
player -> SetMovement ( MOVE_LAND_WALK ); // OFF
else
{
SendSysMessage ( LANG_USE_BOL );
return false ;
}
2009-10-17 15:51:44 -07:00
2009-02-02 15:36:52 -06:00
PSendSysMessage ( LANG_YOU_SET_WATERWALK , args , GetNameLink ( player ). c_str ());
2010-04-07 19:14:10 +02:00
if ( needReportToTarget ( player ))
2009-02-02 15:36:52 -06:00
ChatHandler ( player ). PSendSysMessage ( LANG_YOUR_WATERWALK_SET , args , GetNameLink (). c_str ());
2008-12-24 09:58:26 -06:00
return true ;
}
2009-10-17 15:51:44 -07:00
2010-04-19 09:26:37 +02:00
bool ChatHandler :: HandleCreatePetCommand ( const char * /*args*/ )
2008-11-04 13:32:08 -06:00
{
2009-02-09 08:16:34 -05:00
Player * player = m_session -> GetPlayer ();
Creature * creatureTarget = getSelectedCreature ();
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( ! creatureTarget || creatureTarget -> isPet () || creatureTarget -> GetTypeId () == TYPEID_PLAYER )
2009-02-09 08:16:34 -05:00
{
PSendSysMessage ( LANG_SELECT_CREATURE );
SetSentErrorMessage ( true );
return false ;
}
2009-10-17 15:51:44 -07:00
2010-12-22 20:23:47 +01:00
CreatureInfo const * cInfo = ObjectMgr :: GetCreatureTemplate ( creatureTarget -> GetEntry ());
2009-02-09 08:16:34 -05:00
// Creatures with family 0 crashes the server
2010-04-07 19:14:10 +02:00
if ( cInfo -> family == 0 )
2009-02-09 08:16:34 -05:00
{
PSendSysMessage ( "This creature cannot be tamed. (family id: 0)." );
SetSentErrorMessage ( true );
return false ;
}
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( player -> GetPetGUID ())
2009-02-09 08:16:34 -05:00
{
PSendSysMessage ( "You already have a pet" );
SetSentErrorMessage ( true );
return false ;
}
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
// Everything looks OK, create new pet
2009-03-25 21:32:34 -06:00
Pet * pet = new Pet ( player , HUNTER_PET );
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( ! pet )
2009-05-13 14:06:33 +02:00
return false ;
2009-10-17 16:20:24 -07:00
2010-04-07 19:14:10 +02:00
if ( ! pet -> CreateBaseAtCreature ( creatureTarget ))
2009-02-09 08:16:34 -05:00
{
delete pet ;
PSendSysMessage ( "Error 1" );
return false ;
}
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
creatureTarget -> setDeathState ( JUST_DIED );
creatureTarget -> RemoveCorpse ();
creatureTarget -> SetHealth ( 0 ); // just for nice GM-mode view
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
pet -> SetUInt64Value ( UNIT_FIELD_CREATEDBY , player -> GetGUID ());
pet -> SetUInt32Value ( UNIT_FIELD_FACTIONTEMPLATE , player -> getFaction ());
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( ! pet -> InitStatsForLevel ( creatureTarget -> getLevel ()))
2009-02-09 08:16:34 -05:00
{
2010-12-23 23:25:44 +01:00
sLog -> outError ( "InitStatsForLevel() in EffectTameCreature failed! Pet deleted." );
2009-02-09 08:16:34 -05:00
PSendSysMessage ( "Error 2" );
2009-05-13 14:06:33 +02:00
delete pet ;
2009-02-09 08:16:34 -05:00
return false ;
}
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
// prepare visual effect for levelup
pet -> SetUInt32Value ( UNIT_FIELD_LEVEL , creatureTarget -> getLevel () - 1 );
2009-10-17 15:51:44 -07:00
2010-12-22 21:25:23 +01:00
pet -> GetCharmInfo () -> SetPetNumber ( sObjectMgr -> GeneratePetNumber (), true );
2010-08-26 01:20:57 +06:00
// this enables pet details window (Shift+P)
pet -> InitPetCreateSpells ();
pet -> SetFullHealth ();
2009-10-17 15:51:44 -07:00
2010-08-26 01:20:57 +06:00
pet -> GetMap () -> Add ( pet -> ToCreature ());
2009-10-17 15:51:44 -07:00
2010-08-26 01:20:57 +06:00
// visual effect for levelup
pet -> SetUInt32Value ( UNIT_FIELD_LEVEL , creatureTarget -> getLevel ());
2009-10-17 15:51:44 -07:00
2010-08-26 01:20:57 +06:00
player -> SetMinion ( pet , true );
pet -> SavePetToDB ( PET_SAVE_AS_CURRENT );
player -> PetSpellInitialize ();
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
return true ;
2008-11-04 13:32:08 -06:00
}
2009-10-17 15:51:44 -07:00
2008-11-04 13:32:08 -06:00
bool ChatHandler :: HandlePetLearnCommand ( const char * args )
{
2010-04-07 19:14:10 +02:00
if ( !* args )
2009-02-09 08:16:34 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
Player * plr = m_session -> GetPlayer ();
Pet * pet = plr -> GetPet ();
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( ! pet )
2009-02-09 08:16:34 -05:00
{
PSendSysMessage ( "You have no pet" );
SetSentErrorMessage ( true );
return false ;
}
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
uint32 spellId = extractSpellIdFromLink (( char * ) args );
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( ! spellId || ! sSpellStore . LookupEntry ( spellId ))
2008-11-04 13:32:08 -06:00
return false ;
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
// Check if pet already has it
2010-04-07 19:14:10 +02:00
if ( pet -> HasSpell ( spellId ))
2009-02-09 08:16:34 -05:00
{
PSendSysMessage ( "Pet already has spell: %u" , spellId );
SetSentErrorMessage ( true );
2008-11-04 13:32:08 -06:00
return false ;
2009-02-09 08:16:34 -05:00
}
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
// Check if spell is valid
SpellEntry const * spellInfo = sSpellStore . LookupEntry ( spellId );
2010-04-07 19:14:10 +02:00
if ( ! spellInfo || ! SpellMgr :: IsSpellValid ( spellInfo ))
2008-11-04 13:32:08 -06:00
{
PSendSysMessage ( LANG_COMMAND_SPELL_BROKEN , spellId );
SetSentErrorMessage ( true );
return false ;
}
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
pet -> learnSpell ( spellId );
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
PSendSysMessage ( "Pet has learned spell %u" , spellId );
return true ;
2008-11-04 13:32:08 -06:00
}
2009-10-17 15:51:44 -07:00
2008-11-04 13:32:08 -06:00
bool ChatHandler :: HandlePetUnlearnCommand ( const char * args )
{
2010-04-07 19:14:10 +02:00
if ( !* args )
2009-02-09 08:16:34 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
Player * plr = m_session -> GetPlayer ();
Pet * pet = plr -> GetPet ();
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( ! pet )
2009-02-09 08:16:34 -05:00
{
PSendSysMessage ( "You have no pet" );
SetSentErrorMessage ( true );
return false ;
}
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
uint32 spellId = extractSpellIdFromLink (( char * ) args );
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( pet -> HasSpell ( spellId ))
2009-05-17 10:57:55 -05:00
pet -> removeSpell ( spellId , false );
2009-02-09 08:16:34 -05:00
else
PSendSysMessage ( "Pet doesn't have that spell" );
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
return true ;
2008-11-04 13:32:08 -06:00
}
2009-10-17 15:51:44 -07:00
2008-11-04 13:32:08 -06:00
bool ChatHandler :: HandlePetTpCommand ( const char * args )
{
2010-04-07 19:14:10 +02:00
if ( !* args )
2009-02-09 08:16:34 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
Player * plr = m_session -> GetPlayer ();
Pet * pet = plr -> GetPet ();
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( ! pet )
2009-02-09 08:16:34 -05:00
{
PSendSysMessage ( "You have no pet" );
SetSentErrorMessage ( true );
return false ;
}
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
uint32 tp = atol ( args );
2009-10-17 15:51:44 -07:00
2009-04-07 10:51:45 +02:00
//pet->SetTP(tp);
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
PSendSysMessage ( "Pet's tp changed to %u" , tp );
return true ;
2008-11-04 13:32:08 -06:00
}
2009-10-17 15:51:44 -07:00
2010-01-21 11:19:34 +02:00
bool ChatHandler :: HandleLookupTitleCommand ( const char * args )
{
2010-04-07 19:14:10 +02:00
if ( !* args )
2010-01-21 11:19:34 +02:00
return false ;
// can be NULL in console call
Player * target = getSelectedPlayer ();
// title name have single string arg for player name
char const * targetName = target ? target -> GetName () : "NAME" ;
std :: string namepart = args ;
std :: wstring wnamepart ;
2010-04-07 19:14:10 +02:00
if ( ! Utf8toWStr ( namepart , wnamepart ))
2010-01-21 11:19:34 +02:00
return false ;
// converting string that we try to find to lower case
2010-04-07 22:59:46 +02:00
wstrToLower ( wnamepart );
2010-01-21 11:19:34 +02:00
uint32 counter = 0 ; // Counter for figure out that we found smth.
2010-12-23 23:25:44 +01:00
uint32 maxResults = sWorld -> getIntConfig ( CONFIG_MAX_RESULTS_LOOKUP_COMMANDS );
2010-01-21 11:19:34 +02:00
// Search in CharTitles.dbc
for ( uint32 id = 0 ; id < sCharTitlesStore . GetNumRows (); id ++ )
{
CharTitlesEntry const * titleInfo = sCharTitlesStore . LookupEntry ( id );
2010-04-07 19:14:10 +02:00
if ( titleInfo )
2010-01-21 11:19:34 +02:00
{
int loc = GetSessionDbcLocale ();
std :: string name = titleInfo -> name [ loc ];
2010-04-07 19:14:10 +02:00
if ( name . empty ())
2010-01-21 11:19:34 +02:00
continue ;
if ( ! Utf8FitTo ( name , wnamepart ))
{
loc = 0 ;
2010-09-28 08:21:51 +03:00
for (; loc < TOTAL_LOCALES ; ++ loc )
2010-01-21 11:19:34 +02:00
{
2010-04-07 23:25:02 +02:00
if ( loc == GetSessionDbcLocale ())
2010-01-21 11:19:34 +02:00
continue ;
name = titleInfo -> name [ loc ];
2010-04-07 19:14:10 +02:00
if ( name . empty ())
2010-01-21 11:19:34 +02:00
continue ;
if ( Utf8FitTo ( name , wnamepart ))
break ;
}
}
2010-09-28 08:21:51 +03:00
if ( loc < TOTAL_LOCALES )
2010-01-21 11:19:34 +02:00
{
2010-09-08 09:28:21 +03:00
if ( maxResults && counter == maxResults )
{
PSendSysMessage ( LANG_COMMAND_LOOKUP_MAX_RESULTS , maxResults );
return true ;
}
2010-01-21 11:19:34 +02:00
char const * knownStr = target && target -> HasTitle ( titleInfo ) ? GetTrinityString ( LANG_KNOWN ) : "" ;
2010-04-07 23:25:02 +02:00
char const * activeStr = target && target -> GetUInt32Value ( PLAYER_CHOSEN_TITLE ) == titleInfo -> bit_index
2010-01-21 11:19:34 +02:00
? GetTrinityString ( LANG_ACTIVE )
: "" ;
char titleNameStr [ 80 ];
snprintf ( titleNameStr , 80 , name . c_str (), targetName );
// send title in "id (idx:idx) - [namedlink locale]" format
if ( m_session )
PSendSysMessage ( LANG_TITLE_LIST_CHAT , id , titleInfo -> bit_index , id , titleNameStr , localeNames [ loc ], knownStr , activeStr );
else
PSendSysMessage ( LANG_TITLE_LIST_CONSOLE , id , titleInfo -> bit_index , titleNameStr , localeNames [ loc ], knownStr , activeStr );
++ counter ;
}
}
}
if ( counter == 0 ) // if counter == 0 then we found nth
SendSysMessage ( LANG_COMMAND_NOTITLEFOUND );
return true ;
}
bool ChatHandler :: HandleCharacterTitlesCommand ( const char * args )
{
2010-09-16 10:59:02 +02:00
if ( !* args )
return false ;
2010-01-21 11:19:34 +02:00
Player * target ;
2010-04-07 19:14:10 +02:00
if ( ! extractPlayerTarget (( char * ) args , & target ))
2010-01-21 11:19:34 +02:00
return false ;
LocaleConstant loc = GetSessionDbcLocale ();
char const * targetName = target -> GetName ();
char const * knownStr = 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 ))
{
std :: string name = titleInfo -> name [ loc ];
2010-04-07 19:14:10 +02:00
if ( name . empty ())
2010-01-21 11:19:34 +02:00
continue ;
2010-04-07 23:25:02 +02:00
char const * activeStr = target && target -> GetUInt32Value ( PLAYER_CHOSEN_TITLE ) == titleInfo -> bit_index
2010-01-21 11:19:34 +02:00
? GetTrinityString ( LANG_ACTIVE )
: "" ;
char titleNameStr [ 80 ];
snprintf ( titleNameStr , 80 , name . c_str (), targetName );
// send title in "id (idx:idx) - [namedlink locale]" format
if ( m_session )
PSendSysMessage ( LANG_TITLE_LIST_CHAT , id , titleInfo -> bit_index , id , titleNameStr , localeNames [ loc ], knownStr , activeStr );
else
PSendSysMessage ( LANG_TITLE_LIST_CONSOLE , id , titleInfo -> bit_index , name . c_str (), localeNames [ loc ], knownStr , activeStr );
}
}
return true ;
}