2 * Copyright (C) 2005-2010 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"
28 #include "ObjectDefines.h"
31 #include "UpdateMask.h"
33 #include "ObjectAccessor.h"
35 #include "Database/DatabaseImpl.h"
36 #include "PlayerDump.h"
37 #include "SocialMgr.h"
39 #include "ArenaTeam.h"
42 // config option SkipCinematics supported values
43 enum CinematicsSkipMode
45 CINEMATICS_SKIP_NONE
= 0,
46 CINEMATICS_SKIP_SAME_RACE
= 1,
47 CINEMATICS_SKIP_ALL
= 2,
50 class LoginQueryHolder
: public SqlQueryHolder
56 LoginQueryHolder(uint32 accountId
, uint64 guid
)
57 : m_accountId(accountId
), m_guid(guid
) { }
58 uint64
GetGuid() const { return m_guid
; }
59 uint32
GetAccountId() const { return m_accountId
; }
63 bool LoginQueryHolder::Initialize()
65 SetSize(MAX_PLAYER_LOGIN_QUERY
);
69 // NOTE: all fields in `characters` must be read to prevent lost character data at next save in case wrong DB structure.
70 // !!! NOTE: including unused `zone`,`online`
71 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADFROM
, "SELECT guid, account, data, name, race, class, gender, level, xp, money, playerBytes, playerBytes2, playerFlags,"
72 "position_x, position_y, position_z, map, orientation, taximask, cinematic, totaltime, leveltime, rest_bonus, logout_time, is_logout_resting, resettalents_cost,"
73 "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,"
74 "arenaPoints, totalHonorPoints, todayHonorPoints, yesterdayHonorPoints, totalKills, todayKills, yesterdayKills, chosenTitle, knownCurrencies, watchedFaction, drunk,"
75 "health, power1, power2, power3, power4, power5, power6, power7, specCount, activeSpec FROM characters WHERE guid = '%u'", GUID_LOPART(m_guid
));
76 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADGROUP
, "SELECT groupId FROM group_member WHERE memberGuid ='%u'", GUID_LOPART(m_guid
));
77 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
));
78 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
));
79 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADSPELLS
, "SELECT spell,active,disabled FROM character_spell WHERE guid = '%u'", GUID_LOPART(m_guid
));
80 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
));
81 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADDAILYQUESTSTATUS
,"SELECT quest,time FROM character_queststatus_daily WHERE guid = '%u'", GUID_LOPART(m_guid
));
82 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADREPUTATION
, "SELECT faction,standing,flags FROM character_reputation WHERE guid = '%u'", GUID_LOPART(m_guid
));
83 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
));
84 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADACTIONS
, "SELECT spec,button,action,type FROM character_action WHERE guid = '%u' ORDER BY button", GUID_LOPART(m_guid
));
85 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADSOCIALLIST
, "SELECT friend,flags,note FROM character_social WHERE guid = '%u' LIMIT 255", GUID_LOPART(m_guid
));
86 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
));
87 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADSPELLCOOLDOWNS
, "SELECT spell,item,time FROM character_spell_cooldown WHERE guid = '%u'", GUID_LOPART(m_guid
));
88 if(sWorld
.getConfig(CONFIG_BOOL_DECLINED_NAMES_USED
))
89 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADDECLINEDNAMES
, "SELECT genitive, dative, accusative, instrumental, prepositional FROM character_declinedname WHERE guid = '%u'", GUID_LOPART(m_guid
));
90 // in other case still be dummy query
91 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADGUILD
, "SELECT guildid,rank FROM guild_member WHERE guid = '%u'", GUID_LOPART(m_guid
));
92 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADARENAINFO
, "SELECT arenateamid, played_week, played_season, wons_season, personal_rating FROM arena_team_member WHERE guid='%u'", GUID_LOPART(m_guid
));
93 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADACHIEVEMENTS
, "SELECT achievement, date FROM character_achievement WHERE guid = '%u'", GUID_LOPART(m_guid
));
94 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADCRITERIAPROGRESS
,"SELECT criteria, counter, date FROM character_achievement_progress WHERE guid = '%u'", GUID_LOPART(m_guid
));
95 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
));
96 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
));
97 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADACCOUNTDATA
, "SELECT type, time, data FROM character_account_data WHERE guid='%u'", GUID_LOPART(m_guid
));
98 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADSKILLS
, "SELECT skill, value, max FROM character_skills WHERE guid = '%u'", GUID_LOPART(m_guid
));
99 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADGLYPHS
, "SELECT spec, slot, glyph FROM character_glyphs WHERE guid='%u'", GUID_LOPART(m_guid
));
104 // don't call WorldSession directly
105 // it may get deleted before the query callbacks get executed
106 // instead pass an account id to this handler
107 class CharacterHandler
110 void HandleCharEnumCallback(QueryResult
* result
, uint32 account
)
112 WorldSession
* session
= sWorld
.FindSession(account
);
118 session
->HandleCharEnum(result
);
120 void HandlePlayerLoginCallback(QueryResult
* /*dummy*/, SqlQueryHolder
* holder
)
123 WorldSession
*session
= sWorld
.FindSession(((LoginQueryHolder
*)holder
)->GetAccountId());
129 session
->HandlePlayerLogin((LoginQueryHolder
*)holder
);
133 void WorldSession::HandleCharEnum(QueryResult
* result
)
135 WorldPacket
data(SMSG_CHAR_ENUM
, 100); // we guess size
145 uint32 guidlow
= (*result
)[0].GetUInt32();
146 sLog
.outDetail("Loading char guid %u from account %u.", guidlow
, GetAccountId());
147 if(Player::BuildEnumData(result
, &data
))
150 while( result
->NextRow() );
155 data
.put
<uint8
>(0, num
);
160 void WorldSession::HandleCharEnumOpcode( WorldPacket
& /*recv_data*/ )
162 /// get all the data necessary for loading all characters (along with their pets) on the account
163 CharacterDatabase
.AsyncPQuery(&chrHandler
, &CharacterHandler::HandleCharEnumCallback
, GetAccountId(),
164 !sWorld
.getConfig(CONFIG_BOOL_DECLINED_NAMES_USED
) ?
165 // ------- Query Without Declined Names --------
167 "SELECT characters.guid, characters.name, characters.race, characters.class, characters.gender, characters.playerBytes, characters.playerBytes2, characters.level, "
168 // 8 9 10 11 12 13 14
169 "characters.zone, characters.map, characters.position_x, characters.position_y, characters.position_z, guild_member.guildid, characters.playerFlags, "
171 "characters.at_login, character_pet.entry, character_pet.modelid, character_pet.level, characters.data "
172 "FROM characters LEFT JOIN character_pet ON characters.guid=character_pet.owner AND character_pet.slot='%u' "
173 "LEFT JOIN guild_member ON characters.guid = guild_member.guid "
174 "WHERE characters.account = '%u' ORDER BY characters.guid"
176 // --------- Query With Declined Names ---------
178 "SELECT characters.guid, characters.name, characters.race, characters.class, characters.gender, characters.playerBytes, characters.playerBytes2, characters.level, "
179 // 8 9 10 11 12 13 14
180 "characters.zone, characters.map, characters.position_x, characters.position_y, characters.position_z, guild_member.guildid, characters.playerFlags, "
182 "characters.at_login, character_pet.entry, character_pet.modelid, character_pet.level, characters.data, character_declinedname.genitive "
183 "FROM characters LEFT JOIN character_pet ON characters.guid = character_pet.owner AND character_pet.slot='%u' "
184 "LEFT JOIN character_declinedname ON characters.guid = character_declinedname.guid "
185 "LEFT JOIN guild_member ON characters.guid = guild_member.guid "
186 "WHERE characters.account = '%u' ORDER BY characters.guid",
187 PET_SAVE_AS_CURRENT
, GetAccountId());
190 void WorldSession::HandleCharCreateOpcode( WorldPacket
& recv_data
)
200 WorldPacket
data(SMSG_CHAR_CREATE
, 1); // returned with diff.values in all cases
202 if(GetSecurity() == SEC_PLAYER
)
204 if(uint32 mask
= sWorld
.getConfig(CONFIG_UINT32_CHARACTERS_CREATING_DISABLED
))
206 bool disabled
= false;
208 uint32 team
= Player::TeamForRace(race_
);
211 case ALLIANCE
: disabled
= mask
& (1 << 0); break;
212 case HORDE
: disabled
= mask
& (1 << 1); break;
217 data
<< (uint8
)CHAR_CREATE_DISABLED
;
224 ChrClassesEntry
const* classEntry
= sChrClassesStore
.LookupEntry(class_
);
225 ChrRacesEntry
const* raceEntry
= sChrRacesStore
.LookupEntry(race_
);
227 if( !classEntry
|| !raceEntry
)
229 data
<< (uint8
)CHAR_CREATE_FAILED
;
231 sLog
.outError("Class: %u or Race %u not found in DBC (Wrong DBC files?) or Cheater?", class_
, race_
);
235 // prevent character creating Expansion race without Expansion account
236 if (raceEntry
->expansion
> Expansion())
238 data
<< (uint8
)CHAR_CREATE_EXPANSION
;
239 sLog
.outError("Expansion %u account:[%d] tried to Create character with expansion %u race (%u)", Expansion(), GetAccountId(), raceEntry
->expansion
, race_
);
244 // prevent character creating Expansion class without Expansion account
245 if (classEntry
->expansion
> Expansion())
247 data
<< (uint8
)CHAR_CREATE_EXPANSION_CLASS
;
248 sLog
.outError("Expansion %u account:[%d] tried to Create character with expansion %u class (%u)", Expansion(), GetAccountId(), classEntry
->expansion
, class_
);
253 // prevent character creating with invalid name
254 if (!normalizePlayerName(name
))
256 data
<< (uint8
)CHAR_NAME_NO_NAME
;
258 sLog
.outError("Account:[%d] but tried to Create character with empty [name]", GetAccountId());
262 // check name limitations
263 uint8 res
= ObjectMgr::CheckPlayerName(name
, true);
264 if (res
!= CHAR_NAME_SUCCESS
)
271 if (GetSecurity() == SEC_PLAYER
&& sObjectMgr
.IsReservedName(name
))
273 data
<< (uint8
)CHAR_NAME_RESERVED
;
278 if (sObjectMgr
.GetPlayerGUIDByName(name
))
280 data
<< (uint8
)CHAR_CREATE_NAME_IN_USE
;
285 QueryResult
*resultacct
= loginDatabase
.PQuery("SELECT SUM(numchars) FROM realmcharacters WHERE acctid = '%d'", GetAccountId());
288 Field
*fields
=resultacct
->Fetch();
289 uint32 acctcharcount
= fields
[0].GetUInt32();
292 if (acctcharcount
>= sWorld
.getConfig(CONFIG_UINT32_CHARACTERS_PER_ACCOUNT
))
294 data
<< (uint8
)CHAR_CREATE_ACCOUNT_LIMIT
;
300 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT COUNT(guid) FROM characters WHERE account = '%d'", GetAccountId());
304 Field
*fields
= result
->Fetch();
305 charcount
= fields
[0].GetUInt8();
308 if (charcount
>= sWorld
.getConfig(CONFIG_UINT32_CHARACTERS_PER_REALM
))
310 data
<< (uint8
)CHAR_CREATE_SERVER_LIMIT
;
316 // speedup check for heroic class disabled case
317 uint32 heroic_free_slots
= sWorld
.getConfig(CONFIG_UINT32_HEROIC_CHARACTERS_PER_REALM
);
318 if(heroic_free_slots
== 0 && GetSecurity() == SEC_PLAYER
&& class_
== CLASS_DEATH_KNIGHT
)
320 data
<< (uint8
)CHAR_CREATE_UNIQUE_CLASS_LIMIT
;
325 // speedup check for heroic class disabled case
326 uint32 req_level_for_heroic
= sWorld
.getConfig(CONFIG_UINT32_MIN_LEVEL_FOR_HEROIC_CHARACTER_CREATING
);
327 if(GetSecurity() == SEC_PLAYER
&& class_
== CLASS_DEATH_KNIGHT
&& req_level_for_heroic
> sWorld
.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL
))
329 data
<< (uint8
)CHAR_CREATE_LEVEL_REQUIREMENT
;
334 bool AllowTwoSideAccounts
= sWorld
.getConfig(CONFIG_BOOL_ALLOW_TWO_SIDE_ACCOUNTS
) || GetSecurity() > SEC_PLAYER
;
335 CinematicsSkipMode skipCinematics
= CinematicsSkipMode(sWorld
.getConfig(CONFIG_UINT32_SKIP_CINEMATICS
));
337 bool have_same_race
= false;
339 // if 0 then allowed creating without any characters
340 bool have_req_level_for_heroic
= (req_level_for_heroic
==0);
342 if(!AllowTwoSideAccounts
|| skipCinematics
== CINEMATICS_SKIP_SAME_RACE
|| class_
== CLASS_DEATH_KNIGHT
)
344 QueryResult
*result2
= CharacterDatabase
.PQuery("SELECT level,race,class FROM characters WHERE account = '%u' %s",
345 GetAccountId(), (skipCinematics
== CINEMATICS_SKIP_SAME_RACE
|| class_
== CLASS_DEATH_KNIGHT
) ? "" : "LIMIT 1");
348 uint32 team_
= Player::TeamForRace(race_
);
350 Field
* field
= result2
->Fetch();
351 uint8 acc_race
= field
[1].GetUInt32();
353 if(GetSecurity() == SEC_PLAYER
&& class_
== CLASS_DEATH_KNIGHT
)
355 uint8 acc_class
= field
[2].GetUInt32();
356 if(acc_class
== CLASS_DEATH_KNIGHT
)
358 if(heroic_free_slots
> 0)
361 if(heroic_free_slots
== 0)
363 data
<< (uint8
)CHAR_CREATE_UNIQUE_CLASS_LIMIT
;
370 if(!have_req_level_for_heroic
)
372 uint32 acc_level
= field
[0].GetUInt32();
373 if(acc_level
>= req_level_for_heroic
)
374 have_req_level_for_heroic
= true;
378 // need to check team only for first character
379 // TODO: what to if account already has characters of both races?
380 if (!AllowTwoSideAccounts
)
384 acc_team
= Player::TeamForRace(acc_race
);
386 if(acc_team
!= team_
)
388 data
<< (uint8
)CHAR_CREATE_PVP_TEAMS_VIOLATION
;
395 // search same race for cinematic or same class if need
396 // TODO: check if cinematic already shown? (already logged in?; cinematic field)
397 while ((skipCinematics
== CINEMATICS_SKIP_SAME_RACE
&& !have_same_race
) || class_
== CLASS_DEATH_KNIGHT
)
399 if(!result2
->NextRow())
402 field
= result2
->Fetch();
403 acc_race
= field
[1].GetUInt32();
406 have_same_race
= race_
== acc_race
;
408 if(GetSecurity() == SEC_PLAYER
&& class_
== CLASS_DEATH_KNIGHT
)
410 uint8 acc_class
= field
[2].GetUInt32();
411 if(acc_class
== CLASS_DEATH_KNIGHT
)
413 if(heroic_free_slots
> 0)
416 if(heroic_free_slots
== 0)
418 data
<< (uint8
)CHAR_CREATE_UNIQUE_CLASS_LIMIT
;
425 if(!have_req_level_for_heroic
)
427 uint32 acc_level
= field
[0].GetUInt32();
428 if(acc_level
>= req_level_for_heroic
)
429 have_req_level_for_heroic
= true;
437 if(GetSecurity() == SEC_PLAYER
&& class_
== CLASS_DEATH_KNIGHT
&& !have_req_level_for_heroic
)
439 data
<< (uint8
)CHAR_CREATE_LEVEL_REQUIREMENT
;
444 // extract other data required for player creating
445 uint8 gender
, skin
, face
, hairStyle
, hairColor
, facialHair
, outfitId
;
446 recv_data
>> gender
>> skin
>> face
;
447 recv_data
>> hairStyle
>> hairColor
>> facialHair
>> outfitId
;
449 Player
*pNewChar
= new Player(this);
450 if(!pNewChar
->Create( sObjectMgr
.GenerateLowGuid(HIGHGUID_PLAYER
), name
, race_
, class_
, gender
, skin
, face
, hairStyle
, hairColor
, facialHair
, outfitId
))
452 // Player not create (race/class problem?)
455 data
<< (uint8
)CHAR_CREATE_ERROR
;
461 if ((have_same_race
&& skipCinematics
== CINEMATICS_SKIP_SAME_RACE
) || skipCinematics
== CINEMATICS_SKIP_ALL
)
462 pNewChar
->setCinematic(1); // not show intro
464 pNewChar
->SetAtLoginFlag(AT_LOGIN_FIRST
); // First login
466 // Player created, save it now
467 pNewChar
->SaveToDB();
470 loginDatabase
.PExecute("DELETE FROM realmcharacters WHERE acctid= '%d' AND realmid = '%d'", GetAccountId(), realmID
);
471 loginDatabase
.PExecute("INSERT INTO realmcharacters (numchars, acctid, realmid) VALUES (%u, %u, %u)", charcount
, GetAccountId(), realmID
);
473 delete pNewChar
; // created only to call SaveToDB()
475 data
<< (uint8
)CHAR_CREATE_SUCCESS
;
478 std::string IP_str
= GetRemoteAddress();
479 sLog
.outBasic("Account: %d (IP: %s) Create Character:[%s]", GetAccountId(), IP_str
.c_str(), name
.c_str());
480 sLog
.outChar("Account: %d (IP: %s) Create Character:[%s]", GetAccountId(), IP_str
.c_str(), name
.c_str());
483 void WorldSession::HandleCharDeleteOpcode( WorldPacket
& recv_data
)
488 // can't delete loaded character
489 if(sObjectMgr
.GetPlayer(guid
))
492 uint32 accountId
= 0;
496 if(sObjectMgr
.GetGuildByLeader(guid
))
498 WorldPacket
data(SMSG_CHAR_DELETE
, 1);
499 data
<< (uint8
)CHAR_DELETE_FAILED_GUILD_LEADER
;
504 // is arena team captain
505 if(sObjectMgr
.GetArenaTeamByCaptain(guid
))
507 WorldPacket
data(SMSG_CHAR_DELETE
, 1);
508 data
<< (uint8
)CHAR_DELETE_FAILED_ARENA_CAPTAIN
;
513 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT account,name FROM characters WHERE guid='%u'", GUID_LOPART(guid
));
516 Field
*fields
= result
->Fetch();
517 accountId
= fields
[0].GetUInt32();
518 name
= fields
[1].GetCppString();
522 // prevent deleting other players' characters using cheating tools
523 if(accountId
!= GetAccountId())
526 std::string IP_str
= GetRemoteAddress();
527 sLog
.outBasic("Account: %d (IP: %s) Delete Character:[%s] (guid: %u)", GetAccountId(), IP_str
.c_str(), name
.c_str(), GUID_LOPART(guid
));
528 sLog
.outChar("Account: %d (IP: %s) Delete Character:[%s] (guid: %u)", GetAccountId(), IP_str
.c_str(), name
.c_str(), GUID_LOPART(guid
));
530 if(sLog
.IsOutCharDump()) // optimize GetPlayerDump call
532 std::string dump
= PlayerDumpWriter().GetDump(GUID_LOPART(guid
));
533 sLog
.outCharDump(dump
.c_str(), GetAccountId(), GUID_LOPART(guid
), name
.c_str());
536 Player::DeleteFromDB(guid
, GetAccountId());
538 WorldPacket
data(SMSG_CHAR_DELETE
, 1);
539 data
<< (uint8
)CHAR_DELETE_SUCCESS
;
543 void WorldSession::HandlePlayerLoginOpcode( WorldPacket
& recv_data
)
545 if(PlayerLoading() || GetPlayer() != NULL
)
547 sLog
.outError("Player tryes to login again, AccountId = %d", GetAccountId());
551 m_playerLoading
= true;
552 uint64 playerGuid
= 0;
554 DEBUG_LOG( "WORLD: Recvd Player Logon Message" );
556 recv_data
>> playerGuid
;
558 LoginQueryHolder
*holder
= new LoginQueryHolder(GetAccountId(), playerGuid
);
559 if(!holder
->Initialize())
561 delete holder
; // delete all unprocessed queries
562 m_playerLoading
= false;
566 CharacterDatabase
.DelayQueryHolder(&chrHandler
, &CharacterHandler::HandlePlayerLoginCallback
, holder
);
569 void WorldSession::HandlePlayerLogin(LoginQueryHolder
*holder
)
571 uint64 playerGuid
= holder
->GetGuid();
573 Player
*pCurrChar
= new Player(this);
574 pCurrChar
->GetMotionMaster()->Initialize();
576 // "GetAccountId()==db stored account id" checked in LoadFromDB (prevent login not own character using cheating tools)
577 if(!pCurrChar
->LoadFromDB(GUID_LOPART(playerGuid
), holder
))
579 KickPlayer(); // disconnect client, player no set to session and it will not deleted or saved at kick
580 delete pCurrChar
; // delete it manually
581 delete holder
; // delete all unprocessed queries
582 m_playerLoading
= false;
586 SetPlayer(pCurrChar
);
588 pCurrChar
->SendDungeonDifficulty(false);
590 WorldPacket
data( SMSG_LOGIN_VERIFY_WORLD
, 20 );
591 data
<< pCurrChar
->GetMapId();
592 data
<< pCurrChar
->GetPositionX();
593 data
<< pCurrChar
->GetPositionY();
594 data
<< pCurrChar
->GetPositionZ();
595 data
<< pCurrChar
->GetOrientation();
598 // load player specific part before send times
599 LoadAccountData(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADACCOUNTDATA
),PER_CHARACTER_CACHE_MASK
);
600 SendAccountDataTimes(PER_CHARACTER_CACHE_MASK
);
602 data
.Initialize(SMSG_FEATURE_SYSTEM_STATUS
, 2); // added in 2.2.0
603 data
<< uint8(2); // unknown value
604 data
<< uint8(0); // enable(1)/disable(0) voice chat interface in client
609 data
.Initialize(SMSG_MOTD
, 50); // new in 2.0.1
613 std::string str_motd
= sWorld
.GetMotd();
614 std::string::size_type pos
, nextpos
;
617 while ( (nextpos
= str_motd
.find('@',pos
)) != std::string::npos
)
621 data
<< str_motd
.substr(pos
, nextpos
-pos
);
627 if (pos
< str_motd
.length())
629 data
<< str_motd
.substr(pos
);
633 data
.put(0, linecount
);
636 DEBUG_LOG( "WORLD: Sent motd (SMSG_MOTD)" );
639 //QueryResult *result = CharacterDatabase.PQuery("SELECT guildid,rank FROM guild_member WHERE guid = '%u'",pCurrChar->GetGUIDLow());
640 QueryResult
*resultGuild
= holder
->GetResult(PLAYER_LOGIN_QUERY_LOADGUILD
);
644 Field
*fields
= resultGuild
->Fetch();
645 pCurrChar
->SetInGuild(fields
[0].GetUInt32());
646 pCurrChar
->SetRank(fields
[1].GetUInt32());
649 else if(pCurrChar
->GetGuildId()) // clear guild related fields in case wrong data about non existed membership
651 pCurrChar
->SetInGuild(0);
652 pCurrChar
->SetRank(0);
655 if(pCurrChar
->GetGuildId() != 0)
657 Guild
* guild
= sObjectMgr
.GetGuildById(pCurrChar
->GetGuildId());
660 data
.Initialize(SMSG_GUILD_EVENT
, (1+1+guild
->GetMOTD().size()+1));
661 data
<< uint8(GE_MOTD
);
663 data
<< guild
->GetMOTD();
665 DEBUG_LOG( "WORLD: Sent guild-motd (SMSG_GUILD_EVENT)" );
667 guild
->DisplayGuildBankTabsInfo(this);
669 guild
->BroadcastEvent(GE_SIGNED_ON
, pCurrChar
->GetGUID(), 1, pCurrChar
->GetName(), "", "");
673 // remove wrong guild data
674 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());
675 pCurrChar
->SetInGuild(0);
679 data
.Initialize(SMSG_LEARNED_DANCE_MOVES
, 4+4);
684 pCurrChar
->SendInitialPacketsBeforeAddToMap();
686 //Show cinematic at the first time that player login
687 if( !pCurrChar
->getCinematic() )
689 pCurrChar
->setCinematic(1);
691 if(ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(pCurrChar
->getClass()))
693 if (cEntry
->CinematicSequence
)
694 pCurrChar
->SendCinematicStart(cEntry
->CinematicSequence
);
695 else if (ChrRacesEntry
const* rEntry
= sChrRacesStore
.LookupEntry(pCurrChar
->getRace()))
696 pCurrChar
->SendCinematicStart(rEntry
->CinematicSequence
);
700 if (!pCurrChar
->GetMap()->Add(pCurrChar
))
702 AreaTrigger
const* at
= sObjectMgr
.GetGoBackTrigger(pCurrChar
->GetMapId());
704 pCurrChar
->TeleportTo(at
->target_mapId
, at
->target_X
, at
->target_Y
, at
->target_Z
, pCurrChar
->GetOrientation());
706 pCurrChar
->TeleportToHomebind();
709 sObjectAccessor
.AddObject(pCurrChar
);
710 //sLog.outDebug("Player %s added to Map.",pCurrChar->GetName());
712 pCurrChar
->SendInitialPacketsAfterAddToMap();
714 CharacterDatabase
.PExecute("UPDATE characters SET online = 1 WHERE guid = '%u'", pCurrChar
->GetGUIDLow());
715 loginDatabase
.PExecute("UPDATE account SET active_realm_id = %d WHERE id = '%u'", realmID
, GetAccountId());
716 pCurrChar
->SetInGameTime( getMSTime() );
718 // announce group about member online (must be after add to player list to receive announce to self)
719 if(Group
*group
= pCurrChar
->GetGroup())
721 //pCurrChar->groupInfo.group->SendInit(this); // useless
726 sSocialMgr
.SendFriendStatus(pCurrChar
, FRIEND_ONLINE
, pCurrChar
->GetGUIDLow(), true);
728 // Place character in world (and load zone) before some object loading
729 pCurrChar
->LoadCorpse();
731 // setting Ghost+speed if dead
732 if (pCurrChar
->m_deathState
!= ALIVE
)
734 // not blizz like, we must correctly save and load player instead...
735 if(pCurrChar
->getRace() == RACE_NIGHTELF
)
736 pCurrChar
->CastSpell(pCurrChar
, 20584, true); // 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)
737 pCurrChar
->CastSpell(pCurrChar
, 8326, true); // auras SPELL_AURA_GHOST, SPELL_AURA_INCREASE_SPEED(why?), SPELL_AURA_INCREASE_SWIM_SPEED(why?)
739 pCurrChar
->SetMovement(MOVE_WATER_WALK
);
742 pCurrChar
->ContinueTaxiFlight();
744 // reset for all pets before pet loading
745 if(pCurrChar
->HasAtLoginFlag(AT_LOGIN_RESET_PET_TALENTS
))
746 Pet::resetTalentsForAllPetsOf(pCurrChar
);
748 // Load pet if any (if player not alive and in taxi flight or another then pet will remember as temporary unsummoned)
749 pCurrChar
->LoadPet();
751 // Set FFA PvP for non GM in non-rest mode
752 if(sWorld
.IsFFAPvPRealm() && !pCurrChar
->isGameMaster() && !pCurrChar
->HasFlag(PLAYER_FLAGS
,PLAYER_FLAGS_RESTING
) )
753 pCurrChar
->SetFFAPvP(true);
755 if(pCurrChar
->HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_CONTESTED_PVP
))
756 pCurrChar
->SetContestedPvP();
758 // Apply at_login requests
759 if(pCurrChar
->HasAtLoginFlag(AT_LOGIN_RESET_SPELLS
))
761 pCurrChar
->resetSpells();
762 SendNotification(LANG_RESET_SPELLS
);
765 if(pCurrChar
->HasAtLoginFlag(AT_LOGIN_RESET_TALENTS
))
767 pCurrChar
->resetTalents(true);
768 pCurrChar
->SendTalentsInfoData(false); // original talents send already in to SendInitialPacketsBeforeAddToMap, resend reset state
769 SendNotification(LANG_RESET_TALENTS
); // we can use SMSG_TALENTS_INVOLUNTARILY_RESET here
772 if (pCurrChar
->HasAtLoginFlag(AT_LOGIN_FIRST
))
773 pCurrChar
->RemoveAtLoginFlag(AT_LOGIN_FIRST
);
775 // show time before shutdown if shutdown planned.
776 if(sWorld
.IsShutdowning())
777 sWorld
.ShutdownMsg(true,pCurrChar
);
779 if(sWorld
.getConfig(CONFIG_BOOL_ALL_TAXI_PATHS
))
780 pCurrChar
->SetTaxiCheater(true);
782 if(pCurrChar
->isGameMaster())
783 SendNotification(LANG_GM_ON
);
785 std::string IP_str
= GetRemoteAddress();
786 sLog
.outChar("Account: %d (IP: %s) Login Character:[%s] (guid:%u)",
787 GetAccountId(), IP_str
.c_str(), pCurrChar
->GetName(), pCurrChar
->GetGUIDLow());
789 if(!pCurrChar
->IsStandState() && !pCurrChar
->hasUnitState(UNIT_STAT_STUNNED
))
790 pCurrChar
->SetStandState(UNIT_STAND_STATE_STAND
);
792 m_playerLoading
= false;
796 void WorldSession::HandleSetFactionAtWar( WorldPacket
& recv_data
)
798 DEBUG_LOG( "WORLD: Received CMSG_SET_FACTION_ATWAR" );
803 recv_data
>> repListID
;
806 GetPlayer()->GetReputationMgr().SetAtWar(repListID
, flag
);
809 //I think this function is never used :/ I dunno, but i guess this opcode not exists
810 void WorldSession::HandleSetFactionCheat( WorldPacket
& /*recv_data*/ )
812 sLog
.outError("WORLD SESSION: HandleSetFactionCheat, not expected call, please report.");
817 recv_data >> FactionID;
818 recv_data >> Standing;
820 std::list<struct Factions>::iterator itr;
822 for(itr = GetPlayer()->factions.begin(); itr != GetPlayer()->factions.end(); ++itr)
824 if(itr->ReputationListID == FactionID)
826 itr->Standing += Standing;
827 itr->Flags = (itr->Flags | 1);
832 GetPlayer()->GetReputationMgr().SendStates();
835 void WorldSession::HandleMeetingStoneInfo( WorldPacket
& /*recv_data*/ )
837 DEBUG_LOG( "WORLD: Received CMSG_MEETING_STONE_INFO" );
839 SendLfgUpdate(0, 0, 0);
842 void WorldSession::HandleTutorialFlag( WorldPacket
& recv_data
)
847 uint32 wInt
= (iFlag
/ 32);
850 //sLog.outError("CHEATER? Account:[%d] Guid[%u] tried to send wrong CMSG_TUTORIAL_FLAG", GetAccountId(),GetGUID());
853 uint32 rInt
= (iFlag
% 32);
855 uint32 tutflag
= GetTutorialInt( wInt
);
856 tutflag
|= (1 << rInt
);
857 SetTutorialInt( wInt
, tutflag
);
859 //sLog.outDebug("Received Tutorial Flag Set {%u}.", iFlag);
862 void WorldSession::HandleTutorialClear( WorldPacket
& /*recv_data*/ )
864 for (int i
= 0; i
< 8; ++i
)
865 SetTutorialInt( i
, 0xFFFFFFFF );
868 void WorldSession::HandleTutorialReset( WorldPacket
& /*recv_data*/ )
870 for (int i
= 0; i
< 8; ++i
)
871 SetTutorialInt( i
, 0x00000000 );
874 void WorldSession::HandleSetWatchedFactionOpcode(WorldPacket
& recv_data
)
876 DEBUG_LOG("WORLD: Received CMSG_SET_WATCHED_FACTION");
879 GetPlayer()->SetInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, repId
);
882 void WorldSession::HandleSetFactionInactiveOpcode(WorldPacket
& recv_data
)
884 DEBUG_LOG("WORLD: Received CMSG_SET_FACTION_INACTIVE");
887 recv_data
>> replistid
>> inactive
;
889 _player
->GetReputationMgr().SetInactive(replistid
, inactive
);
892 void WorldSession::HandleShowingHelmOpcode( WorldPacket
& /*recv_data*/ )
894 DEBUG_LOG("CMSG_SHOWING_HELM for %s", _player
->GetName());
895 _player
->ToggleFlag(PLAYER_FLAGS
, PLAYER_FLAGS_HIDE_HELM
);
898 void WorldSession::HandleShowingCloakOpcode( WorldPacket
& /*recv_data*/ )
900 DEBUG_LOG("CMSG_SHOWING_CLOAK for %s", _player
->GetName());
901 _player
->ToggleFlag(PLAYER_FLAGS
, PLAYER_FLAGS_HIDE_CLOAK
);
904 void WorldSession::HandleCharRenameOpcode(WorldPacket
& recv_data
)
910 recv_data
>> newname
;
912 // prevent character rename to invalid name
913 if (!normalizePlayerName(newname
))
915 WorldPacket
data(SMSG_CHAR_RENAME
, 1);
916 data
<< uint8(CHAR_NAME_NO_NAME
);
921 uint8 res
= ObjectMgr::CheckPlayerName(newname
,true);
922 if (res
!= CHAR_NAME_SUCCESS
)
924 WorldPacket
data(SMSG_CHAR_RENAME
, 1);
930 // check name limitations
931 if (GetSecurity() == SEC_PLAYER
&& sObjectMgr
.IsReservedName(newname
))
933 WorldPacket
data(SMSG_CHAR_RENAME
, 1);
934 data
<< uint8(CHAR_NAME_RESERVED
);
939 std::string escaped_newname
= newname
;
940 CharacterDatabase
.escape_string(escaped_newname
);
942 // make sure that the character belongs to the current account, that rename at login is enabled
943 // and that there is no character with the desired new name
944 CharacterDatabase
.AsyncPQuery(&WorldSession::HandleChangePlayerNameOpcodeCallBack
,
945 GetAccountId(), newname
,
946 "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')",
947 GUID_LOPART(guid
), GetAccountId(), AT_LOGIN_RENAME
, AT_LOGIN_RENAME
, escaped_newname
.c_str()
951 void WorldSession::HandleChangePlayerNameOpcodeCallBack(QueryResult
*result
, uint32 accountId
, std::string newname
)
953 WorldSession
* session
= sWorld
.FindSession(accountId
);
956 if(result
) delete result
;
962 WorldPacket
data(SMSG_CHAR_RENAME
, 1);
963 data
<< uint8(CHAR_CREATE_ERROR
);
964 session
->SendPacket( &data
);
968 uint32 guidLow
= result
->Fetch()[0].GetUInt32();
969 uint64 guid
= MAKE_NEW_GUID(guidLow
, 0, HIGHGUID_PLAYER
);
970 std::string oldname
= result
->Fetch()[1].GetCppString();
974 CharacterDatabase
.PExecute("UPDATE characters set name = '%s', at_login = at_login & ~ %u WHERE guid ='%u'", newname
.c_str(), uint32(AT_LOGIN_RENAME
), guidLow
);
975 CharacterDatabase
.PExecute("DELETE FROM character_declinedname WHERE guid ='%u'", guidLow
);
977 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());
979 WorldPacket
data(SMSG_CHAR_RENAME
, 1+8+(newname
.size()+1));
980 data
<< uint8(RESPONSE_SUCCESS
);
981 data
<< uint64(guid
);
983 session
->SendPacket(&data
);
986 void WorldSession::HandleSetPlayerDeclinedNames(WorldPacket
& recv_data
)
992 // not accept declined names for unsupported languages
994 if(!sObjectMgr
.GetPlayerNameByGUID(guid
, name
))
996 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
998 data
<< uint64(guid
);
1004 if(!Utf8toWStr(name
, wname
))
1006 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1008 data
<< uint64(guid
);
1013 if(!isCyrillicCharacter(wname
[0])) // name already stored as only single alphabet using
1015 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1017 data
<< uint64(guid
);
1023 DeclinedName declinedname
;
1027 if(name2
!= name
) // character have different name
1029 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1031 data
<< uint64(guid
);
1036 for(int i
= 0; i
< MAX_DECLINED_NAME_CASES
; ++i
)
1038 recv_data
>> declinedname
.name
[i
];
1039 if(!normalizePlayerName(declinedname
.name
[i
]))
1041 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1043 data
<< uint64(guid
);
1049 if(!ObjectMgr::CheckDeclinedNames(GetMainPartOfName(wname
, 0), declinedname
))
1051 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1053 data
<< uint64(guid
);
1058 for(int i
= 0; i
< MAX_DECLINED_NAME_CASES
; ++i
)
1059 CharacterDatabase
.escape_string(declinedname
.name
[i
]);
1061 CharacterDatabase
.BeginTransaction();
1062 CharacterDatabase
.PExecute("DELETE FROM character_declinedname WHERE guid = '%u'", GUID_LOPART(guid
));
1063 CharacterDatabase
.PExecute("INSERT INTO character_declinedname (guid, genitive, dative, accusative, instrumental, prepositional) VALUES ('%u','%s','%s','%s','%s','%s')",
1064 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());
1065 CharacterDatabase
.CommitTransaction();
1067 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1068 data
<< uint32(0); // OK
1069 data
<< uint64(guid
);
1073 void WorldSession::HandleAlterAppearance( WorldPacket
& recv_data
)
1075 sLog
.outDebug("CMSG_ALTER_APPEARANCE");
1077 uint32 Hair
, Color
, FacialHair
;
1078 recv_data
>> Hair
>> Color
>> FacialHair
;
1080 BarberShopStyleEntry
const* bs_hair
= sBarberShopStyleStore
.LookupEntry(Hair
);
1082 if(!bs_hair
|| bs_hair
->type
!= 0 || bs_hair
->race
!= _player
->getRace() || bs_hair
->gender
!= _player
->getGender())
1085 BarberShopStyleEntry
const* bs_facialHair
= sBarberShopStyleStore
.LookupEntry(FacialHair
);
1087 if(!bs_facialHair
|| bs_facialHair
->type
!= 2 || bs_facialHair
->race
!= _player
->getRace() || bs_facialHair
->gender
!= _player
->getGender())
1090 uint32 Cost
= _player
->GetBarberShopCost(bs_hair
->hair_id
, Color
, bs_facialHair
->hair_id
);
1093 // 1,3 - not enough money
1094 // 2 - you have to seat on barber chair
1095 if(_player
->GetMoney() < Cost
)
1097 WorldPacket
data(SMSG_BARBER_SHOP_RESULT
, 4);
1098 data
<< uint32(1); // no money
1104 WorldPacket
data(SMSG_BARBER_SHOP_RESULT
, 4);
1105 data
<< uint32(0); // ok
1109 _player
->ModifyMoney(-int32(Cost
)); // it isn't free
1110 _player
->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GOLD_SPENT_AT_BARBER
, Cost
);
1112 _player
->SetByteValue(PLAYER_BYTES
, 2, uint8(bs_hair
->hair_id
));
1113 _player
->SetByteValue(PLAYER_BYTES
, 3, uint8(Color
));
1114 _player
->SetByteValue(PLAYER_BYTES_2
, 0, uint8(bs_facialHair
->hair_id
));
1116 _player
->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_VISIT_BARBER_SHOP
, 1);
1118 _player
->SetStandState(0); // stand up
1121 void WorldSession::HandleRemoveGlyph( WorldPacket
& recv_data
)
1126 if(slot
>= MAX_GLYPH_SLOT_INDEX
)
1128 sLog
.outDebug("Client sent wrong glyph slot number in opcode CMSG_REMOVE_GLYPH %u", slot
);
1132 if(_player
->GetGlyph(slot
))
1134 _player
->ApplyGlyph(slot
, false);
1135 _player
->SetGlyph(slot
, 0);
1136 _player
->SendTalentsInfoData(false);
1140 void WorldSession::HandleCharCustomize(WorldPacket
& recv_data
)
1143 std::string newname
;
1146 recv_data
>> newname
;
1148 uint8 gender
, skin
, face
, hairStyle
, hairColor
, facialHair
;
1149 recv_data
>> gender
>> skin
>> hairColor
>> hairStyle
>> facialHair
>> face
;
1151 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT at_login FROM characters WHERE guid ='%u'", GUID_LOPART(guid
));
1154 WorldPacket
data(SMSG_CHAR_CUSTOMIZE
, 1);
1155 data
<< uint8(CHAR_CREATE_ERROR
);
1156 SendPacket( &data
);
1160 Field
*fields
= result
->Fetch();
1161 uint32 at_loginFlags
= fields
[0].GetUInt32();
1164 if (!(at_loginFlags
& AT_LOGIN_CUSTOMIZE
))
1166 WorldPacket
data(SMSG_CHAR_CUSTOMIZE
, 1);
1167 data
<< uint8(CHAR_CREATE_ERROR
);
1168 SendPacket( &data
);
1172 // prevent character rename to invalid name
1173 if (!normalizePlayerName(newname
))
1175 WorldPacket
data(SMSG_CHAR_CUSTOMIZE
, 1);
1176 data
<< uint8(CHAR_NAME_NO_NAME
);
1177 SendPacket( &data
);
1181 uint8 res
= ObjectMgr::CheckPlayerName(newname
,true);
1182 if (res
!= CHAR_NAME_SUCCESS
)
1184 WorldPacket
data(SMSG_CHAR_CUSTOMIZE
, 1);
1186 SendPacket( &data
);
1190 // check name limitations
1191 if (GetSecurity() == SEC_PLAYER
&& sObjectMgr
.IsReservedName(newname
))
1193 WorldPacket
data(SMSG_CHAR_CUSTOMIZE
, 1);
1194 data
<< uint8(CHAR_NAME_RESERVED
);
1195 SendPacket( &data
);
1199 // character with this name already exist
1200 if (uint64 newguid
= sObjectMgr
.GetPlayerGUIDByName(newname
))
1202 if (newguid
!= guid
)
1204 WorldPacket
data(SMSG_CHAR_CUSTOMIZE
, 1);
1205 data
<< uint8(CHAR_CREATE_NAME_IN_USE
);
1206 SendPacket( &data
);
1211 CharacterDatabase
.escape_string(newname
);
1212 Player::Customize(guid
, gender
, skin
, face
, hairStyle
, hairColor
, facialHair
);
1213 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
));
1214 CharacterDatabase
.PExecute("DELETE FROM character_declinedname WHERE guid ='%u'", GUID_LOPART(guid
));
1216 std::string IP_str
= GetRemoteAddress();
1217 sLog
.outChar("Account: %d (IP: %s), Character guid: %u Customized to: %s", GetAccountId(), IP_str
.c_str(), GUID_LOPART(guid
), newname
.c_str());
1219 WorldPacket
data(SMSG_CHAR_CUSTOMIZE
, 1+8+(newname
.size()+1)+6);
1220 data
<< uint8(RESPONSE_SUCCESS
);
1221 data
<< uint64(guid
);
1223 data
<< uint8(gender
);
1224 data
<< uint8(skin
);
1225 data
<< uint8(face
);
1226 data
<< uint8(hairStyle
);
1227 data
<< uint8(hairColor
);
1228 data
<< uint8(facialHair
);
1232 void WorldSession::HandleEquipmentSetSave(WorldPacket
&recv_data
)
1234 sLog
.outDebug("CMSG_EQUIPMENT_SET_SAVE");
1237 if(!recv_data
.readPackGUID(setGuid
))
1242 if(index
>= MAX_EQUIPMENT_SET_INDEX
) // client set slots amount
1248 std::string iconName
;
1249 recv_data
>> iconName
;
1253 eqSet
.Guid
= setGuid
;
1255 eqSet
.IconName
= iconName
;
1256 eqSet
.state
= EQUIPMENT_SET_NEW
;
1258 for(uint32 i
= 0; i
< EQUIPMENT_SLOT_END
; ++i
)
1261 if(!recv_data
.readPackGUID(itemGuid
))
1264 Item
*item
= _player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, i
);
1266 if(!item
&& itemGuid
) // cheating check 1
1269 if(item
&& item
->GetGUID() != itemGuid
) // cheating check 2
1272 eqSet
.Items
[i
] = GUID_LOPART(itemGuid
);
1275 _player
->SetEquipmentSet(index
, eqSet
);
1278 void WorldSession::HandleEquipmentSetDelete(WorldPacket
&recv_data
)
1280 sLog
.outDebug("CMSG_EQUIPMENT_SET_DELETE");
1283 if(!recv_data
.readPackGUID(setGuid
))
1286 _player
->DeleteEquipmentSet(setGuid
);
1289 void WorldSession::HandleEquipmentSetUse(WorldPacket
&recv_data
)
1291 sLog
.outDebug("CMSG_EQUIPMENT_SET_USE");
1292 recv_data
.hexlike();
1294 for(uint32 i
= 0; i
< EQUIPMENT_SLOT_END
; ++i
)
1297 if(!recv_data
.readPackGUID(itemGuid
))
1300 uint8 srcbag
, srcslot
;
1301 recv_data
>> srcbag
>> srcslot
;
1303 sLog
.outDebug("Item " I64FMT
": srcbag %u, srcslot %u", itemGuid
, srcbag
, srcslot
);
1305 Item
*item
= _player
->GetItemByGuid(itemGuid
);
1307 uint16 dstpos
= i
| (INVENTORY_SLOT_BAG_0
<< 8);
1311 Item
*uItem
= _player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, i
);
1315 ItemPosCountVec sDest
;
1316 uint8 msg
= _player
->CanStoreItem( NULL_BAG
, NULL_SLOT
, sDest
, uItem
, false );
1317 if(msg
== EQUIP_ERR_OK
)
1319 _player
->RemoveItem(INVENTORY_SLOT_BAG_0
, i
, true);
1320 _player
->StoreItem( sDest
, uItem
, true );
1323 _player
->SendEquipError(msg
, uItem
, NULL
);
1328 if(item
->GetPos() == dstpos
)
1331 _player
->SwapItem(item
->GetPos(), dstpos
);
1334 WorldPacket
data(SMSG_EQUIPMENT_SET_USE_RESULT
, 1);
1335 data
<< uint8(0); // 4 - equipment swap failed - inventory is full