2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "SharedDefines.h"
23 #include "WorldSession.h"
27 #include "ObjectMgr.h"
30 #include "UpdateMask.h"
32 #include "ObjectAccessor.h"
34 #include "Database/DatabaseImpl.h"
35 #include "PlayerDump.h"
36 #include "SocialMgr.h"
38 #include "ArenaTeam.h"
41 class LoginQueryHolder
: public SqlQueryHolder
47 LoginQueryHolder(uint32 accountId
, uint64 guid
)
48 : m_accountId(accountId
), m_guid(guid
) { }
49 uint64
GetGuid() const { return m_guid
; }
50 uint32
GetAccountId() const { return m_accountId
; }
54 bool LoginQueryHolder::Initialize()
56 SetSize(MAX_PLAYER_LOGIN_QUERY
);
60 // NOTE: all fields in `characters` must be read to prevent lost character data at next save in case wrong DB structure.
61 // !!! NOTE: including unused `zone`,`online`
62 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADFROM
, "SELECT guid, account, data, name, race, class, gender, level, xp, money, playerBytes, playerBytes2, playerFlags, position_x, position_y, position_z, map, orientation, taximask, cinematic, totaltime, leveltime, rest_bonus, logout_time, is_logout_resting, resettalents_cost, resettalents_time, trans_x, trans_y, trans_z, trans_o, transguid, extra_flags, stable_slots, at_login, zone, online, death_expire_time, taxi_path, dungeon_difficulty, arena_pending_points FROM characters WHERE guid = '%u'", GUID_LOPART(m_guid
));
63 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADGROUP
, "SELECT leaderGuid FROM group_member WHERE memberGuid ='%u'", GUID_LOPART(m_guid
));
64 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADBOUNDINSTANCES
, "SELECT id, permanent, map, difficulty, resettime FROM character_instance LEFT JOIN instance ON instance = id WHERE guid = '%u'", GUID_LOPART(m_guid
));
65 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADAURAS
, "SELECT caster_guid,spell,effect_index,stackcount,amount,maxduration,remaintime,remaincharges FROM character_aura WHERE guid = '%u'", GUID_LOPART(m_guid
));
66 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADSPELLS
, "SELECT spell,active,disabled FROM character_spell WHERE guid = '%u'", GUID_LOPART(m_guid
));
67 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADQUESTSTATUS
, "SELECT quest,status,rewarded,explored,timer,mobcount1,mobcount2,mobcount3,mobcount4,itemcount1,itemcount2,itemcount3,itemcount4 FROM character_queststatus WHERE guid = '%u'", GUID_LOPART(m_guid
));
68 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADDAILYQUESTSTATUS
,"SELECT quest,time FROM character_queststatus_daily WHERE guid = '%u'", GUID_LOPART(m_guid
));
69 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADREPUTATION
, "SELECT faction,standing,flags FROM character_reputation WHERE guid = '%u'", GUID_LOPART(m_guid
));
70 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADINVENTORY
, "SELECT data,bag,slot,item,item_template FROM character_inventory JOIN item_instance ON character_inventory.item = item_instance.guid WHERE character_inventory.guid = '%u' ORDER BY bag,slot", GUID_LOPART(m_guid
));
71 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADACTIONS
, "SELECT button,action,type FROM character_action WHERE guid = '%u' ORDER BY button", GUID_LOPART(m_guid
));
72 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADMAILCOUNT
, "SELECT COUNT(id) FROM mail WHERE receiver = '%u' AND (checked & 1)=0 AND deliver_time <= '" UI64FMTD
"'", GUID_LOPART(m_guid
),(uint64
)time(NULL
));
73 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADMAILDATE
, "SELECT MIN(deliver_time) FROM mail WHERE receiver = '%u' AND (checked & 1)=0", GUID_LOPART(m_guid
));
74 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADSOCIALLIST
, "SELECT friend,flags,note FROM character_social WHERE guid = '%u' LIMIT 255", GUID_LOPART(m_guid
));
75 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADHOMEBIND
, "SELECT map,zone,position_x,position_y,position_z FROM character_homebind WHERE guid = '%u'", GUID_LOPART(m_guid
));
76 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADSPELLCOOLDOWNS
, "SELECT spell,item,time FROM character_spell_cooldown WHERE guid = '%u'", GUID_LOPART(m_guid
));
77 if(sWorld
.getConfig(CONFIG_DECLINED_NAMES_USED
))
78 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADDECLINEDNAMES
, "SELECT genitive, dative, accusative, instrumental, prepositional FROM character_declinedname WHERE guid = '%u'",GUID_LOPART(m_guid
));
79 // in other case still be dummy query
80 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADGUILD
, "SELECT guildid,rank FROM guild_member WHERE guid = '%u'", GUID_LOPART(m_guid
));
81 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADARENAINFO
, "SELECT arenateamid, played_week, played_season, personal_rating FROM arena_team_member WHERE guid='%u'", GUID_LOPART(m_guid
));
82 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADACHIEVEMENTS
, "SELECT achievement, date FROM character_achievement WHERE guid = '%u'", GUID_LOPART(m_guid
));
83 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADCRITERIAPROGRESS
,"SELECT criteria, counter, date FROM character_achievement_progress WHERE guid = '%u'", GUID_LOPART(m_guid
));
84 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADEQUIPMENTSETS
, "SELECT setguid, setindex, name, iconname, item0, item1, item2, item3, item4, item5, item6, item7, item8, item9, item10, item11, item12, item13, item14, item15, item16, item17, item18 FROM character_equipmentsets WHERE guid = '%u' ORDER BY setindex", GUID_LOPART(m_guid
));
85 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADBGDATA
, "SELECT instance_id, team, join_x, join_y, join_z, join_o, join_map, taxi_start, taxi_end, mount_spell FROM character_battleground_data WHERE guid = '%u'", GUID_LOPART(m_guid
));
86 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADACCOUNTDATA
, "SELECT type, time, data FROM character_account_data WHERE guid='%u'", GUID_LOPART(m_guid
));
91 // don't call WorldSession directly
92 // it may get deleted before the query callbacks get executed
93 // instead pass an account id to this handler
94 class CharacterHandler
97 void HandleCharEnumCallback(QueryResult
* result
, uint32 account
)
99 WorldSession
* session
= sWorld
.FindSession(account
);
105 session
->HandleCharEnum(result
);
107 void HandlePlayerLoginCallback(QueryResult
* /*dummy*/, SqlQueryHolder
* holder
)
110 WorldSession
*session
= sWorld
.FindSession(((LoginQueryHolder
*)holder
)->GetAccountId());
116 session
->HandlePlayerLogin((LoginQueryHolder
*)holder
);
120 void WorldSession::HandleCharEnum(QueryResult
* result
)
122 WorldPacket
data(SMSG_CHAR_ENUM
, 100); // we guess size
132 uint32 guidlow
= (*result
)[0].GetUInt32();
133 sLog
.outDetail("Loading char guid %u from account %u.",guidlow
,GetAccountId());
134 if(Player::BuildEnumData(result
, &data
))
137 while( result
->NextRow() );
142 data
.put
<uint8
>(0, num
);
147 void WorldSession::HandleCharEnumOpcode( WorldPacket
& /*recv_data*/ )
149 /// get all the data necessary for loading all characters (along with their pets) on the account
150 CharacterDatabase
.AsyncPQuery(&chrHandler
, &CharacterHandler::HandleCharEnumCallback
, GetAccountId(),
151 !sWorld
.getConfig(CONFIG_DECLINED_NAMES_USED
) ?
152 // ------- Query Without Declined Names --------
154 "SELECT characters.guid, characters.name, characters.race, characters.class, characters.gender, characters.playerBytes, characters.playerBytes2, characters.level, "
155 // 8 9 10 11 12 13 14
156 "characters.zone, characters.map, characters.position_x, characters.position_y, characters.position_z, guild_member.guildid, characters.playerFlags, "
158 "characters.at_login, character_pet.entry, character_pet.modelid, character_pet.level, characters.data "
159 "FROM characters LEFT JOIN character_pet ON characters.guid=character_pet.owner AND character_pet.slot='%u' "
160 "LEFT JOIN guild_member ON characters.guid = guild_member.guid "
161 "WHERE characters.account = '%u' ORDER BY characters.guid"
163 // --------- Query With Declined Names ---------
165 "SELECT characters.guid, characters.name, characters.race, characters.class, characters.gender, characters.playerBytes, characters.playerBytes2, characters.level, "
166 // 8 9 10 11 12 13 14
167 "characters.zone, characters.map, characters.position_x, characters.position_y, characters.position_z, guild_member.guildid, characters.playerFlags, "
169 "characters.at_login, character_pet.entry, character_pet.modelid, character_pet.level, characters.data, character_declinedname.genitive "
170 "FROM characters LEFT JOIN character_pet ON characters.guid = character_pet.owner AND character_pet.slot='%u' "
171 "LEFT JOIN character_declinedname ON characters.guid = character_declinedname.guid "
172 "LEFT JOIN guild_member ON characters.guid = guild_member.guid "
173 "WHERE characters.account = '%u' ORDER BY characters.guid",
174 PET_SAVE_AS_CURRENT
,GetAccountId());
177 void WorldSession::HandleCharCreateOpcode( WorldPacket
& recv_data
)
187 WorldPacket
data(SMSG_CHAR_CREATE
, 1); // returned with diff.values in all cases
189 if(GetSecurity() == SEC_PLAYER
)
191 if(uint32 mask
= sWorld
.getConfig(CONFIG_CHARACTERS_CREATING_DISABLED
))
193 bool disabled
= false;
195 uint32 team
= Player::TeamForRace(race_
);
198 case ALLIANCE
: disabled
= mask
& (1<<0); break;
199 case HORDE
: disabled
= mask
& (1<<1); break;
204 data
<< (uint8
)CHAR_CREATE_DISABLED
;
211 ChrClassesEntry
const* classEntry
= sChrClassesStore
.LookupEntry(class_
);
212 ChrRacesEntry
const* raceEntry
= sChrRacesStore
.LookupEntry(race_
);
214 if( !classEntry
|| !raceEntry
)
216 data
<< (uint8
)CHAR_CREATE_FAILED
;
218 sLog
.outError("Class: %u or Race %u not found in DBC (Wrong DBC files?) or Cheater?", class_
, race_
);
222 // prevent character creating Expansion race without Expansion account
223 if (raceEntry
->addon
> Expansion())
225 data
<< (uint8
)CHAR_CREATE_EXPANSION
;
226 sLog
.outError("Expansion %u account:[%d] tried to Create character with expansion %u race (%u)",Expansion(),GetAccountId(),raceEntry
->addon
,race_
);
231 // prevent character creating Expansion class without Expansion account
232 if (classEntry
->addon
> Expansion())
234 data
<< (uint8
)CHAR_CREATE_EXPANSION_CLASS
;
235 sLog
.outError("Expansion %u account:[%d] tried to Create character with expansion %u class (%u)",Expansion(),GetAccountId(),classEntry
->addon
,class_
);
240 // prevent character creating with invalid name
241 if (!normalizePlayerName(name
))
243 data
<< (uint8
)CHAR_NAME_NO_NAME
;
245 sLog
.outError("Account:[%d] but tried to Create character with empty [name] ",GetAccountId());
249 // check name limitations
250 uint8 res
= ObjectMgr::CheckPlayerName(name
,true);
251 if (res
!= CHAR_NAME_SUCCESS
)
258 if (GetSecurity() == SEC_PLAYER
&& objmgr
.IsReservedName(name
))
260 data
<< (uint8
)CHAR_NAME_RESERVED
;
265 if (objmgr
.GetPlayerGUIDByName(name
))
267 data
<< (uint8
)CHAR_CREATE_NAME_IN_USE
;
272 QueryResult
*resultacct
= loginDatabase
.PQuery("SELECT SUM(numchars) FROM realmcharacters WHERE acctid = '%d'", GetAccountId());
275 Field
*fields
=resultacct
->Fetch();
276 uint32 acctcharcount
= fields
[0].GetUInt32();
279 if (acctcharcount
>= sWorld
.getConfig(CONFIG_CHARACTERS_PER_ACCOUNT
))
281 data
<< (uint8
)CHAR_CREATE_ACCOUNT_LIMIT
;
287 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT COUNT(guid) FROM characters WHERE account = '%d'", GetAccountId());
291 Field
*fields
=result
->Fetch();
292 charcount
= fields
[0].GetUInt8();
295 if (charcount
>= sWorld
.getConfig(CONFIG_CHARACTERS_PER_REALM
))
297 data
<< (uint8
)CHAR_CREATE_SERVER_LIMIT
;
303 // speedup check for heroic class disabled case
304 uint32 heroic_free_slots
= sWorld
.getConfig(CONFIG_HEROIC_CHARACTERS_PER_REALM
);
305 if(heroic_free_slots
==0 && GetSecurity()==SEC_PLAYER
&& class_
== CLASS_DEATH_KNIGHT
)
307 data
<< (uint8
)CHAR_CREATE_UNIQUE_CLASS_LIMIT
;
312 // speedup check for heroic class disabled case
313 uint32 req_level_for_heroic
= sWorld
.getConfig(CONFIG_MIN_LEVEL_FOR_HEROIC_CHARACTER_CREATING
);
314 if(GetSecurity()==SEC_PLAYER
&& class_
== CLASS_DEATH_KNIGHT
&& req_level_for_heroic
> sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
316 data
<< (uint8
)CHAR_CREATE_LEVEL_REQUIREMENT
;
321 bool AllowTwoSideAccounts
= !sWorld
.IsPvPRealm() || sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_ACCOUNTS
) || GetSecurity() > SEC_PLAYER
;
322 uint32 skipCinematics
= sWorld
.getConfig(CONFIG_SKIP_CINEMATICS
);
324 bool have_same_race
= false;
326 // if 0 then allowed creating without any characters
327 bool have_req_level_for_heroic
= (req_level_for_heroic
==0);
329 if(!AllowTwoSideAccounts
|| skipCinematics
== 1 || class_
== CLASS_DEATH_KNIGHT
)
331 QueryResult
*result2
= CharacterDatabase
.PQuery("SELECT level,race,class FROM characters WHERE account = '%u' %s",
332 GetAccountId(), (skipCinematics
== 1 || class_
== CLASS_DEATH_KNIGHT
) ? "" : "LIMIT 1");
335 uint32 team_
= Player::TeamForRace(race_
);
337 Field
* field
= result2
->Fetch();
338 uint8 acc_race
= field
[1].GetUInt32();
340 if(GetSecurity()==SEC_PLAYER
&& class_
== CLASS_DEATH_KNIGHT
)
342 uint8 acc_class
= field
[2].GetUInt32();
343 if(acc_class
== CLASS_DEATH_KNIGHT
)
345 if(heroic_free_slots
> 0)
348 if(heroic_free_slots
==0)
350 data
<< (uint8
)CHAR_CREATE_UNIQUE_CLASS_LIMIT
;
356 if(!have_req_level_for_heroic
)
358 uint32 acc_level
= field
[0].GetUInt32();
359 if(acc_level
>= req_level_for_heroic
)
360 have_req_level_for_heroic
= true;
364 // need to check team only for first character
365 // TODO: what to if account already has characters of both races?
366 if (!AllowTwoSideAccounts
)
370 acc_team
= Player::TeamForRace(acc_race
);
372 if(acc_team
!= team_
)
374 data
<< (uint8
)CHAR_CREATE_PVP_TEAMS_VIOLATION
;
381 // search same race for cinematic or same class if need
382 // TODO: check if cinematic already shown? (already logged in?; cinematic field)
383 while ((skipCinematics
== 1 && !have_same_race
) || class_
== CLASS_DEATH_KNIGHT
)
385 if(!result2
->NextRow())
388 field
= result2
->Fetch();
389 acc_race
= field
[1].GetUInt32();
392 have_same_race
= race_
== acc_race
;
394 if(GetSecurity()==SEC_PLAYER
&& class_
== CLASS_DEATH_KNIGHT
)
396 uint8 acc_class
= field
[2].GetUInt32();
397 if(acc_class
== CLASS_DEATH_KNIGHT
)
399 if(heroic_free_slots
> 0)
402 if(heroic_free_slots
==0)
404 data
<< (uint8
)CHAR_CREATE_UNIQUE_CLASS_LIMIT
;
410 if(!have_req_level_for_heroic
)
412 uint32 acc_level
= field
[0].GetUInt32();
413 if(acc_level
>= req_level_for_heroic
)
414 have_req_level_for_heroic
= true;
422 if(GetSecurity()==SEC_PLAYER
&& class_
== CLASS_DEATH_KNIGHT
&& !have_req_level_for_heroic
)
424 data
<< (uint8
)CHAR_CREATE_LEVEL_REQUIREMENT
;
429 // extract other data required for player creating
430 uint8 gender
, skin
, face
, hairStyle
, hairColor
, facialHair
, outfitId
;
431 recv_data
>> gender
>> skin
>> face
;
432 recv_data
>> hairStyle
>> hairColor
>> facialHair
>> outfitId
;
434 Player
* pNewChar
= new Player(this);
435 if(!pNewChar
->Create( objmgr
.GenerateLowGuid(HIGHGUID_PLAYER
), name
, race_
, class_
, gender
, skin
, face
, hairStyle
, hairColor
, facialHair
, outfitId
))
437 // Player not create (race/class problem?)
440 data
<< (uint8
)CHAR_CREATE_ERROR
;
446 if ((have_same_race
&& skipCinematics
== 1) || skipCinematics
== 2)
447 pNewChar
->setCinematic(1); // not show intro
449 // Player created, save it now
450 pNewChar
->SaveToDB();
453 loginDatabase
.PExecute("DELETE FROM realmcharacters WHERE acctid= '%d' AND realmid = '%d'", GetAccountId(), realmID
);
454 loginDatabase
.PExecute("INSERT INTO realmcharacters (numchars, acctid, realmid) VALUES (%u, %u, %u)", charcount
, GetAccountId(), realmID
);
456 delete pNewChar
; // created only to call SaveToDB()
458 data
<< (uint8
)CHAR_CREATE_SUCCESS
;
461 std::string IP_str
= GetRemoteAddress();
462 sLog
.outBasic("Account: %d (IP: %s) Create Character:[%s]",GetAccountId(),IP_str
.c_str(),name
.c_str());
463 sLog
.outChar("Account: %d (IP: %s) Create Character:[%s]",GetAccountId(),IP_str
.c_str(),name
.c_str());
466 void WorldSession::HandleCharDeleteOpcode( WorldPacket
& recv_data
)
471 // can't delete loaded character
472 if(objmgr
.GetPlayer(guid
))
475 uint32 accountId
= 0;
479 if(objmgr
.GetGuildByLeader(guid
))
481 WorldPacket
data(SMSG_CHAR_DELETE
, 1);
482 data
<< (uint8
)CHAR_DELETE_FAILED_GUILD_LEADER
;
487 // is arena team captain
488 if(objmgr
.GetArenaTeamByCaptain(guid
))
490 WorldPacket
data(SMSG_CHAR_DELETE
, 1);
491 data
<< (uint8
)CHAR_DELETE_FAILED_ARENA_CAPTAIN
;
496 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT account,name FROM characters WHERE guid='%u'", GUID_LOPART(guid
));
499 Field
*fields
= result
->Fetch();
500 accountId
= fields
[0].GetUInt32();
501 name
= fields
[1].GetCppString();
505 // prevent deleting other players' characters using cheating tools
506 if(accountId
!= GetAccountId())
509 std::string IP_str
= GetRemoteAddress();
510 sLog
.outBasic("Account: %d (IP: %s) Delete Character:[%s] (guid: %u)",GetAccountId(),IP_str
.c_str(),name
.c_str(),GUID_LOPART(guid
));
511 sLog
.outChar("Account: %d (IP: %s) Delete Character:[%s] (guid: %u)",GetAccountId(),IP_str
.c_str(),name
.c_str(),GUID_LOPART(guid
));
513 if(sLog
.IsOutCharDump()) // optimize GetPlayerDump call
515 std::string dump
= PlayerDumpWriter().GetDump(GUID_LOPART(guid
));
516 sLog
.outCharDump(dump
.c_str(),GetAccountId(),GUID_LOPART(guid
),name
.c_str());
519 Player::DeleteFromDB(guid
, GetAccountId());
521 WorldPacket
data(SMSG_CHAR_DELETE
, 1);
522 data
<< (uint8
)CHAR_DELETE_SUCCESS
;
526 void WorldSession::HandlePlayerLoginOpcode( WorldPacket
& recv_data
)
528 if(PlayerLoading() || GetPlayer() != NULL
)
530 sLog
.outError("Player tryes to login again, AccountId = %d",GetAccountId());
534 m_playerLoading
= true;
535 uint64 playerGuid
= 0;
537 DEBUG_LOG( "WORLD: Recvd Player Logon Message" );
539 recv_data
>> playerGuid
;
541 LoginQueryHolder
*holder
= new LoginQueryHolder(GetAccountId(), playerGuid
);
542 if(!holder
->Initialize())
544 delete holder
; // delete all unprocessed queries
545 m_playerLoading
= false;
549 CharacterDatabase
.DelayQueryHolder(&chrHandler
, &CharacterHandler::HandlePlayerLoginCallback
, holder
);
552 void WorldSession::HandlePlayerLogin(LoginQueryHolder
* holder
)
554 uint64 playerGuid
= holder
->GetGuid();
556 Player
* pCurrChar
= new Player(this);
557 pCurrChar
->GetMotionMaster()->Initialize();
559 // "GetAccountId()==db stored account id" checked in LoadFromDB (prevent login not own character using cheating tools)
560 if(!pCurrChar
->LoadFromDB(GUID_LOPART(playerGuid
), holder
))
562 KickPlayer(); // disconnect client, player no set to session and it will not deleted or saved at kick
563 delete pCurrChar
; // delete it manually
564 delete holder
; // delete all unprocessed queries
565 m_playerLoading
= false;
569 SetPlayer(pCurrChar
);
571 pCurrChar
->SendDungeonDifficulty(false);
573 WorldPacket
data( SMSG_LOGIN_VERIFY_WORLD
, 20 );
574 data
<< pCurrChar
->GetMapId();
575 data
<< pCurrChar
->GetPositionX();
576 data
<< pCurrChar
->GetPositionY();
577 data
<< pCurrChar
->GetPositionZ();
578 data
<< pCurrChar
->GetOrientation();
581 // load player specific part before send times
582 LoadAccountData(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADACCOUNTDATA
),PER_CHARACTER_CACHE_MASK
);
583 SendAccountDataTimes();
585 data
.Initialize(SMSG_FEATURE_SYSTEM_STATUS
, 2); // added in 2.2.0
586 data
<< uint8(2); // unknown value
587 data
<< uint8(0); // enable(1)/disable(0) voice chat interface in client
592 data
.Initialize(SMSG_MOTD
, 50); // new in 2.0.1
596 std::string str_motd
= sWorld
.GetMotd();
597 std::string::size_type pos
, nextpos
;
600 while ( (nextpos
= str_motd
.find('@',pos
)) != std::string::npos
)
604 data
<< str_motd
.substr(pos
,nextpos
-pos
);
610 if (pos
<str_motd
.length())
612 data
<< str_motd
.substr(pos
);
616 data
.put(0, linecount
);
619 DEBUG_LOG( "WORLD: Sent motd (SMSG_MOTD)" );
622 data
.Initialize(SMSG_LEARNED_DANCE_MOVES
, 4+4);
627 //QueryResult *result = CharacterDatabase.PQuery("SELECT guildid,rank FROM guild_member WHERE guid = '%u'",pCurrChar->GetGUIDLow());
628 QueryResult
*resultGuild
= holder
->GetResult(PLAYER_LOGIN_QUERY_LOADGUILD
);
632 Field
*fields
= resultGuild
->Fetch();
633 pCurrChar
->SetInGuild(fields
[0].GetUInt32());
634 pCurrChar
->SetRank(fields
[1].GetUInt32());
637 else if(pCurrChar
->GetGuildId()) // clear guild related fields in case wrong data about non existed membership
639 pCurrChar
->SetInGuild(0);
640 pCurrChar
->SetRank(0);
643 if(pCurrChar
->GetGuildId() != 0)
645 Guild
* guild
= objmgr
.GetGuildById(pCurrChar
->GetGuildId());
648 data
.Initialize(SMSG_GUILD_EVENT
, (2+guild
->GetMOTD().size()+1));
649 data
<< (uint8
)GE_MOTD
;
651 data
<< guild
->GetMOTD();
653 DEBUG_LOG( "WORLD: Sent guild-motd (SMSG_GUILD_EVENT)" );
655 data
.Initialize(SMSG_GUILD_EVENT
, (5+10)); // we guess size
656 data
<<(uint8
)GE_SIGNED_ON
;
658 data
<<pCurrChar
->GetName();
659 data
<<pCurrChar
->GetGUID();
660 guild
->BroadcastPacket(&data
);
661 DEBUG_LOG( "WORLD: Sent guild-signed-on (SMSG_GUILD_EVENT)" );
663 // Increment online members of the guild
664 guild
->IncOnlineMemberCount();
668 // remove wrong guild data
669 sLog
.outError("Player %s (GUID: %u) marked as member not existed guild (id: %u), removing guild membership for player.",pCurrChar
->GetName(),pCurrChar
->GetGUIDLow(),pCurrChar
->GetGuildId());
670 pCurrChar
->SetInGuild(0);
674 if(!pCurrChar
->isAlive())
675 pCurrChar
->SendCorpseReclaimDelay(true);
677 pCurrChar
->SendInitialPacketsBeforeAddToMap();
679 //Show cinematic at the first time that player login
680 if( !pCurrChar
->getCinematic() )
682 pCurrChar
->setCinematic(1);
684 if(ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(pCurrChar
->getClass()))
686 if (cEntry
->CinematicSequence
)
687 pCurrChar
->SendCinematicStart(cEntry
->CinematicSequence
);
688 else if (ChrRacesEntry
const* rEntry
= sChrRacesStore
.LookupEntry(pCurrChar
->getRace()))
689 pCurrChar
->SendCinematicStart(rEntry
->CinematicSequence
);
693 if (!pCurrChar
->GetMap()->Add(pCurrChar
))
695 AreaTrigger
const* at
= objmgr
.GetGoBackTrigger(pCurrChar
->GetMapId());
697 pCurrChar
->TeleportTo(at
->target_mapId
, at
->target_X
, at
->target_Y
, at
->target_Z
, pCurrChar
->GetOrientation());
699 pCurrChar
->TeleportTo(pCurrChar
->m_homebindMapId
, pCurrChar
->m_homebindX
, pCurrChar
->m_homebindY
, pCurrChar
->m_homebindZ
, pCurrChar
->GetOrientation());
702 ObjectAccessor::Instance().AddObject(pCurrChar
);
703 //sLog.outDebug("Player %s added to Map.",pCurrChar->GetName());
705 pCurrChar
->SendInitialPacketsAfterAddToMap();
707 CharacterDatabase
.PExecute("UPDATE characters SET online = 1 WHERE guid = '%u'", pCurrChar
->GetGUIDLow());
708 loginDatabase
.PExecute("UPDATE account SET online = 1 WHERE id = '%u'", GetAccountId());
709 pCurrChar
->SetInGameTime( getMSTime() );
711 // announce group about member online (must be after add to player list to receive announce to self)
712 if(Group
*group
= pCurrChar
->GetGroup())
714 //pCurrChar->groupInfo.group->SendInit(this); // useless
719 sSocialMgr
.SendFriendStatus(pCurrChar
, FRIEND_ONLINE
, pCurrChar
->GetGUIDLow(), true);
721 // Place character in world (and load zone) before some object loading
722 pCurrChar
->LoadCorpse();
724 // setting Ghost+speed if dead
725 if (pCurrChar
->m_deathState
!= ALIVE
)
727 // not blizz like, we must correctly save and load player instead...
728 if(pCurrChar
->getRace() == RACE_NIGHTELF
)
729 pCurrChar
->CastSpell(pCurrChar
, 20584, true, 0);// auras SPELL_AURA_INCREASE_SPEED(+speed in wisp form), SPELL_AURA_INCREASE_SWIM_SPEED(+swim speed in wisp form), SPELL_AURA_TRANSFORM (to wisp form)
730 pCurrChar
->CastSpell(pCurrChar
, 8326, true, 0); // auras SPELL_AURA_GHOST, SPELL_AURA_INCREASE_SPEED(why?), SPELL_AURA_INCREASE_SWIM_SPEED(why?)
732 pCurrChar
->SetMovement(MOVE_WATER_WALK
);
735 pCurrChar
->ContinueTaxiFlight();
737 // reset for all pets before pet loading
738 if(pCurrChar
->HasAtLoginFlag(AT_LOGIN_RESET_PET_TALENTS
))
739 Pet::resetTalentsForAllPetsOf(pCurrChar
);
741 // Load pet if any (if player not alive and in taxi flight or another then pet will remember as temporary unsummoned)
742 pCurrChar
->LoadPet();
744 // Set FFA PvP for non GM in non-rest mode
745 if(sWorld
.IsFFAPvPRealm() && !pCurrChar
->isGameMaster() && !pCurrChar
->HasFlag(PLAYER_FLAGS
,PLAYER_FLAGS_RESTING
) )
746 pCurrChar
->SetByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
748 if(pCurrChar
->HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_CONTESTED_PVP
))
749 pCurrChar
->SetContestedPvP();
751 // Apply at_login requests
752 if(pCurrChar
->HasAtLoginFlag(AT_LOGIN_RESET_SPELLS
))
754 pCurrChar
->resetSpells();
755 SendNotification(LANG_RESET_SPELLS
);
758 if(pCurrChar
->HasAtLoginFlag(AT_LOGIN_RESET_TALENTS
))
760 pCurrChar
->resetTalents(true);
761 pCurrChar
->SendTalentsInfoData(false); // original talents send already in to SendInitialPacketsBeforeAddToMap, resend reset state
762 SendNotification(LANG_RESET_TALENTS
);
765 // show time before shutdown if shutdown planned.
766 if(sWorld
.IsShutdowning())
767 sWorld
.ShutdownMsg(true,pCurrChar
);
769 if(sWorld
.getConfig(CONFIG_ALL_TAXI_PATHS
))
770 pCurrChar
->SetTaxiCheater(true);
772 if(pCurrChar
->isGameMaster())
773 SendNotification(LANG_GM_ON
);
775 std::string IP_str
= GetRemoteAddress();
776 sLog
.outChar("Account: %d (IP: %s) Login Character:[%s] (guid:%u)",
777 GetAccountId(),IP_str
.c_str(),pCurrChar
->GetName() ,pCurrChar
->GetGUIDLow());
779 if(!pCurrChar
->IsStandState() && !pCurrChar
->hasUnitState(UNIT_STAT_STUNNED
))
780 pCurrChar
->SetStandState(UNIT_STAND_STATE_STAND
);
782 m_playerLoading
= false;
786 void WorldSession::HandleSetFactionAtWar( WorldPacket
& recv_data
)
788 DEBUG_LOG( "WORLD: Received CMSG_SET_FACTION_ATWAR" );
793 recv_data
>> repListID
;
796 GetPlayer()->GetReputationMgr().SetAtWar(repListID
,flag
);
799 //I think this function is never used :/ I dunno, but i guess this opcode not exists
800 void WorldSession::HandleSetFactionCheat( WorldPacket
& /*recv_data*/ )
802 sLog
.outError("WORLD SESSION: HandleSetFactionCheat, not expected call, please report.");
807 recv_data >> FactionID;
808 recv_data >> Standing;
810 std::list<struct Factions>::iterator itr;
812 for(itr = GetPlayer()->factions.begin(); itr != GetPlayer()->factions.end(); ++itr)
814 if(itr->ReputationListID == FactionID)
816 itr->Standing += Standing;
817 itr->Flags = (itr->Flags | 1);
822 GetPlayer()->GetReputationMgr().SendStates();
825 void WorldSession::HandleMeetingStoneInfo( WorldPacket
& /*recv_data*/ )
827 DEBUG_LOG( "WORLD: Received CMSG_MEETING_STONE_INFO" );
829 SendLfgUpdate(0, 0, 0);
832 void WorldSession::HandleTutorialFlag( WorldPacket
& recv_data
)
837 uint32 wInt
= (iFlag
/ 32);
840 //sLog.outError("CHEATER? Account:[%d] Guid[%u] tried to send wrong CMSG_TUTORIAL_FLAG", GetAccountId(),GetGUID());
843 uint32 rInt
= (iFlag
% 32);
845 uint32 tutflag
= GetTutorialInt( wInt
);
846 tutflag
|= (1 << rInt
);
847 SetTutorialInt( wInt
, tutflag
);
849 //sLog.outDebug("Received Tutorial Flag Set {%u}.", iFlag);
852 void WorldSession::HandleTutorialClear( WorldPacket
& /*recv_data*/ )
854 for (int i
= 0; i
< 8; ++i
)
855 SetTutorialInt( i
, 0xFFFFFFFF );
858 void WorldSession::HandleTutorialReset( WorldPacket
& /*recv_data*/ )
860 for (int i
= 0; i
< 8; ++i
)
861 SetTutorialInt( i
, 0x00000000 );
864 void WorldSession::HandleSetWatchedFactionOpcode(WorldPacket
& recv_data
)
866 DEBUG_LOG("WORLD: Received CMSG_SET_WATCHED_FACTION");
869 GetPlayer()->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, fact
);
872 void WorldSession::HandleSetFactionInactiveOpcode(WorldPacket
& recv_data
)
874 DEBUG_LOG("WORLD: Received CMSG_SET_FACTION_INACTIVE");
877 recv_data
>> replistid
>> inactive
;
879 _player
->GetReputationMgr().SetInactive(replistid
, inactive
);
882 void WorldSession::HandleShowingHelmOpcode( WorldPacket
& /*recv_data*/ )
884 DEBUG_LOG("CMSG_SHOWING_HELM for %s", _player
->GetName());
885 _player
->ToggleFlag(PLAYER_FLAGS
, PLAYER_FLAGS_HIDE_HELM
);
888 void WorldSession::HandleShowingCloakOpcode( WorldPacket
& /*recv_data*/ )
890 DEBUG_LOG("CMSG_SHOWING_CLOAK for %s", _player
->GetName());
891 _player
->ToggleFlag(PLAYER_FLAGS
, PLAYER_FLAGS_HIDE_CLOAK
);
894 void WorldSession::HandleCharRenameOpcode(WorldPacket
& recv_data
)
900 recv_data
>> newname
;
902 // prevent character rename to invalid name
903 if (!normalizePlayerName(newname
))
905 WorldPacket
data(SMSG_CHAR_RENAME
, 1);
906 data
<< uint8(CHAR_NAME_NO_NAME
);
911 uint8 res
= ObjectMgr::CheckPlayerName(newname
,true);
912 if (res
!= CHAR_NAME_SUCCESS
)
914 WorldPacket
data(SMSG_CHAR_RENAME
, 1);
920 // check name limitations
921 if (GetSecurity() == SEC_PLAYER
&& objmgr
.IsReservedName(newname
))
923 WorldPacket
data(SMSG_CHAR_RENAME
, 1);
924 data
<< uint8(CHAR_NAME_RESERVED
);
929 std::string escaped_newname
= newname
;
930 CharacterDatabase
.escape_string(escaped_newname
);
932 // make sure that the character belongs to the current account, that rename at login is enabled
933 // and that there is no character with the desired new name
934 CharacterDatabase
.AsyncPQuery(&WorldSession::HandleChangePlayerNameOpcodeCallBack
,
935 GetAccountId(), newname
,
936 "SELECT guid, name FROM characters WHERE guid = %d AND account = %d AND (at_login & %d) = %d AND NOT EXISTS (SELECT NULL FROM characters WHERE name = '%s')",
937 GUID_LOPART(guid
), GetAccountId(), AT_LOGIN_RENAME
, AT_LOGIN_RENAME
, escaped_newname
.c_str()
941 void WorldSession::HandleChangePlayerNameOpcodeCallBack(QueryResult
*result
, uint32 accountId
, std::string newname
)
943 WorldSession
* session
= sWorld
.FindSession(accountId
);
946 if(result
) delete result
;
952 WorldPacket
data(SMSG_CHAR_RENAME
, 1);
953 data
<< uint8(CHAR_CREATE_ERROR
);
954 session
->SendPacket( &data
);
958 uint32 guidLow
= result
->Fetch()[0].GetUInt32();
959 uint64 guid
= MAKE_NEW_GUID(guidLow
, 0, HIGHGUID_PLAYER
);
960 std::string oldname
= result
->Fetch()[1].GetCppString();
964 CharacterDatabase
.PExecute("UPDATE characters set name = '%s', at_login = at_login & ~ %u WHERE guid ='%u'", newname
.c_str(), uint32(AT_LOGIN_RENAME
), guidLow
);
965 CharacterDatabase
.PExecute("DELETE FROM character_declinedname WHERE guid ='%u'", guidLow
);
967 sLog
.outChar("Account: %d (IP: %s) Character:[%s] (guid:%u) Changed name to: %s", session
->GetAccountId(), session
->GetRemoteAddress().c_str(), oldname
.c_str(), guidLow
, newname
.c_str());
969 WorldPacket
data(SMSG_CHAR_RENAME
, 1+8+(newname
.size()+1));
970 data
<< uint8(RESPONSE_SUCCESS
);
971 data
<< uint64(guid
);
973 session
->SendPacket(&data
);
976 void WorldSession::HandleSetPlayerDeclinedNames(WorldPacket
& recv_data
)
982 // not accept declined names for unsupported languages
984 if(!objmgr
.GetPlayerNameByGUID(guid
, name
))
986 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
988 data
<< uint64(guid
);
994 if(!Utf8toWStr(name
, wname
))
996 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
998 data
<< uint64(guid
);
1003 if(!isCyrillicCharacter(wname
[0])) // name already stored as only single alphabet using
1005 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1007 data
<< uint64(guid
);
1013 DeclinedName declinedname
;
1017 if(name2
!= name
) // character have different name
1019 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1021 data
<< uint64(guid
);
1026 for(int i
= 0; i
< MAX_DECLINED_NAME_CASES
; ++i
)
1028 recv_data
>> declinedname
.name
[i
];
1029 if(!normalizePlayerName(declinedname
.name
[i
]))
1031 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1033 data
<< uint64(guid
);
1039 if(!ObjectMgr::CheckDeclinedNames(GetMainPartOfName(wname
, 0), declinedname
))
1041 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1043 data
<< uint64(guid
);
1048 for(int i
= 0; i
< MAX_DECLINED_NAME_CASES
; ++i
)
1049 CharacterDatabase
.escape_string(declinedname
.name
[i
]);
1051 CharacterDatabase
.BeginTransaction();
1052 CharacterDatabase
.PExecute("DELETE FROM character_declinedname WHERE guid = '%u'", GUID_LOPART(guid
));
1053 CharacterDatabase
.PExecute("INSERT INTO character_declinedname (guid, genitive, dative, accusative, instrumental, prepositional) VALUES ('%u','%s','%s','%s','%s','%s')",
1054 GUID_LOPART(guid
), declinedname
.name
[0].c_str(), declinedname
.name
[1].c_str(), declinedname
.name
[2].c_str(), declinedname
.name
[3].c_str(), declinedname
.name
[4].c_str());
1055 CharacterDatabase
.CommitTransaction();
1057 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1058 data
<< uint32(0); // OK
1059 data
<< uint64(guid
);
1063 void WorldSession::HandleAlterAppearance( WorldPacket
& recv_data
)
1065 sLog
.outDebug("CMSG_ALTER_APPEARANCE");
1067 uint32 Hair
, Color
, FacialHair
;
1068 recv_data
>> Hair
>> Color
>> FacialHair
;
1070 BarberShopStyleEntry
const* bs_hair
= sBarberShopStyleStore
.LookupEntry(Hair
);
1072 if(!bs_hair
|| bs_hair
->type
!= 0 || bs_hair
->race
!= _player
->getRace() || bs_hair
->gender
!= _player
->getGender())
1075 BarberShopStyleEntry
const* bs_facialHair
= sBarberShopStyleStore
.LookupEntry(FacialHair
);
1077 if(!bs_facialHair
|| bs_facialHair
->type
!= 2 || bs_facialHair
->race
!= _player
->getRace() || bs_facialHair
->gender
!= _player
->getGender())
1080 uint32 Cost
= _player
->GetBarberShopCost(bs_hair
->hair_id
, Color
, bs_facialHair
->hair_id
);
1083 // 1,3 - not enough money
1084 // 2 - you have to seat on barber chair
1085 if(_player
->GetMoney() < Cost
)
1087 WorldPacket
data(SMSG_BARBER_SHOP_RESULT
, 4);
1088 data
<< uint32(1); // no money
1094 WorldPacket
data(SMSG_BARBER_SHOP_RESULT
, 4);
1095 data
<< uint32(0); // ok
1099 _player
->ModifyMoney(-int32(Cost
)); // it isn't free
1100 _player
->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GOLD_SPENT_AT_BARBER
, Cost
);
1102 _player
->SetByteValue(PLAYER_BYTES
, 2, uint8(bs_hair
->hair_id
));
1103 _player
->SetByteValue(PLAYER_BYTES
, 3, uint8(Color
));
1104 _player
->SetByteValue(PLAYER_BYTES_2
, 0, uint8(bs_facialHair
->hair_id
));
1106 _player
->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_VISIT_BARBER_SHOP
, 1);
1108 _player
->SetStandState(0); // stand up
1111 void WorldSession::HandleRemoveGlyph( WorldPacket
& recv_data
)
1116 if(slot
>= MAX_GLYPH_SLOT_INDEX
)
1118 sLog
.outDebug("Client sent wrong glyph slot number in opcode CMSG_REMOVE_GLYPH %u", slot
);
1122 if(uint32 glyph
= _player
->GetGlyph(slot
))
1124 if(GlyphPropertiesEntry
const *gp
= sGlyphPropertiesStore
.LookupEntry(glyph
))
1126 _player
->RemoveAurasDueToSpell(gp
->SpellId
);
1127 _player
->SetGlyph(slot
, 0);
1128 _player
->SendTalentsInfoData(false);
1133 void WorldSession::HandleCharCustomize(WorldPacket
& recv_data
)
1136 std::string newname
;
1139 recv_data
>> newname
;
1141 uint8 gender
, skin
, face
, hairStyle
, hairColor
, facialHair
;
1142 recv_data
>> gender
>> skin
>> hairColor
>> hairStyle
>> facialHair
>> face
;
1144 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT at_login FROM characters WHERE guid ='%u'", GUID_LOPART(guid
));
1147 WorldPacket
data(SMSG_CHAR_CUSTOMIZE
, 1);
1148 data
<< uint8(CHAR_CREATE_ERROR
);
1149 SendPacket( &data
);
1153 Field
*fields
= result
->Fetch();
1154 uint32 at_loginFlags
= fields
[0].GetUInt32();
1157 if (!(at_loginFlags
& AT_LOGIN_CUSTOMIZE
))
1159 WorldPacket
data(SMSG_CHAR_CUSTOMIZE
, 1);
1160 data
<< uint8(CHAR_CREATE_ERROR
);
1161 SendPacket( &data
);
1165 // prevent character rename to invalid name
1166 if (!normalizePlayerName(newname
))
1168 WorldPacket
data(SMSG_CHAR_CUSTOMIZE
, 1);
1169 data
<< uint8(CHAR_NAME_NO_NAME
);
1170 SendPacket( &data
);
1174 uint8 res
= ObjectMgr::CheckPlayerName(newname
,true);
1175 if (res
!= CHAR_NAME_SUCCESS
)
1177 WorldPacket
data(SMSG_CHAR_CUSTOMIZE
, 1);
1179 SendPacket( &data
);
1183 // check name limitations
1184 if (GetSecurity() == SEC_PLAYER
&& objmgr
.IsReservedName(newname
))
1186 WorldPacket
data(SMSG_CHAR_CUSTOMIZE
, 1);
1187 data
<< uint8(CHAR_NAME_RESERVED
);
1188 SendPacket( &data
);
1192 // character with this name already exist
1193 if (uint64 newguid
= objmgr
.GetPlayerGUIDByName(newname
))
1195 if (newguid
!= guid
)
1197 WorldPacket
data(SMSG_CHAR_CUSTOMIZE
, 1);
1198 data
<< uint8(CHAR_CREATE_NAME_IN_USE
);
1199 SendPacket( &data
);
1204 CharacterDatabase
.escape_string(newname
);
1205 Player::Customize(guid
, gender
, skin
, face
, hairStyle
, hairColor
, facialHair
);
1206 CharacterDatabase
.PExecute("UPDATE characters set name = '%s', at_login = at_login & ~ %u WHERE guid ='%u'", newname
.c_str(), uint32(AT_LOGIN_CUSTOMIZE
), GUID_LOPART(guid
));
1207 CharacterDatabase
.PExecute("DELETE FROM character_declinedname WHERE guid ='%u'", GUID_LOPART(guid
));
1209 std::string IP_str
= GetRemoteAddress();
1210 sLog
.outChar("Account: %d (IP: %s), Character guid: %u Customized to: %s", GetAccountId(), IP_str
.c_str(), GUID_LOPART(guid
), newname
.c_str());
1212 WorldPacket
data(SMSG_CHAR_CUSTOMIZE
, 1+8+(newname
.size()+1)+6);
1213 data
<< uint8(RESPONSE_SUCCESS
);
1214 data
<< uint64(guid
);
1216 data
<< uint8(gender
);
1217 data
<< uint8(skin
);
1218 data
<< uint8(face
);
1219 data
<< uint8(hairStyle
);
1220 data
<< uint8(hairColor
);
1221 data
<< uint8(facialHair
);
1225 void WorldSession::HandleEquipmentSetSave(WorldPacket
&recv_data
)
1227 sLog
.outDebug("CMSG_EQUIPMENT_SET_SAVE");
1230 if(!recv_data
.readPackGUID(setGuid
))
1235 if(index
>= MAX_EQUIPMENT_SET_INDEX
) // client set slots amount
1241 std::string iconName
;
1242 recv_data
>> iconName
;
1246 eqSet
.Guid
= setGuid
;
1248 eqSet
.IconName
= iconName
;
1249 eqSet
.state
= EQUIPMENT_SET_NEW
;
1251 for(uint32 i
= 0; i
< EQUIPMENT_SLOT_END
; ++i
)
1254 if(!recv_data
.readPackGUID(itemGuid
))
1257 Item
*item
= _player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, i
);
1259 if(!item
&& itemGuid
) // cheating check 1
1262 if(item
&& item
->GetGUID() != itemGuid
) // cheating check 2
1265 eqSet
.Items
[i
] = GUID_LOPART(itemGuid
);
1268 _player
->SetEquipmentSet(index
, eqSet
);
1271 void WorldSession::HandleEquipmentSetDelete(WorldPacket
&recv_data
)
1273 sLog
.outDebug("CMSG_EQUIPMENT_SET_DELETE");
1276 if(!recv_data
.readPackGUID(setGuid
))
1279 _player
->DeleteEquipmentSet(setGuid
);
1282 void WorldSession::HandleEquipmentSetUse(WorldPacket
&recv_data
)
1284 sLog
.outDebug("CMSG_EQUIPMENT_SET_USE");
1285 recv_data
.hexlike();
1287 for(uint32 i
= 0; i
< EQUIPMENT_SLOT_END
; ++i
)
1290 if(!recv_data
.readPackGUID(itemGuid
))
1293 uint8 srcbag
, srcslot
;
1294 recv_data
>> srcbag
>> srcslot
;
1296 sLog
.outDebug("Item " I64FMT
": srcbag %u, srcslot %u", itemGuid
, srcbag
, srcslot
);
1298 Item
*item
= _player
->GetItemByGuid(itemGuid
);
1300 uint16 dstpos
= i
| (INVENTORY_SLOT_BAG_0
<< 8);
1304 Item
*uItem
= _player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, i
);
1308 ItemPosCountVec sDest
;
1309 uint8 msg
= _player
->CanStoreItem( NULL_BAG
, NULL_SLOT
, sDest
, uItem
, false );
1310 if(msg
== EQUIP_ERR_OK
)
1312 _player
->RemoveItem(INVENTORY_SLOT_BAG_0
, i
, true);
1313 _player
->StoreItem( sDest
, uItem
, true );
1316 _player
->SendEquipError(msg
, uItem
, NULL
);
1321 if(item
->GetPos() == dstpos
)
1324 _player
->SwapItem(item
->GetPos(), dstpos
);
1327 WorldPacket
data(SMSG_EQUIPMENT_SET_USE_RESULT
, 1);
1328 data
<< uint8(0); // 4 - equipment swap failed - inventory is full