2 * Copyright (C) 2005-2008 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 "MapManager.h"
33 #include "ObjectAccessor.h"
35 #include "Database/DatabaseImpl.h"
36 #include "PlayerDump.h"
37 #include "SocialMgr.h"
39 #include "ArenaTeam.h"
42 class LoginQueryHolder
: public SqlQueryHolder
48 LoginQueryHolder(uint32 accountId
, uint64 guid
)
49 : m_accountId(accountId
), m_guid(guid
) { }
50 uint64
GetGuid() const { return m_guid
; }
51 uint32
GetAccountId() const { return m_accountId
; }
55 bool LoginQueryHolder::Initialize()
57 SetSize(MAX_PLAYER_LOGIN_QUERY
);
61 // NOTE: all fields in `characters` must be read to prevent lost character data at next save in case wrong DB structure.
62 // !!! NOTE: including unused `zone`,`online`
63 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADFROM
, "SELECT guid, account, data, name, race, class, 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
));
64 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADGROUP
, "SELECT leaderGuid FROM group_member WHERE memberGuid ='%u'", GUID_LOPART(m_guid
));
65 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
));
66 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
));
67 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADSPELLS
, "SELECT spell,slot,active,disabled FROM character_spell WHERE guid = '%u'", GUID_LOPART(m_guid
));
68 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
));
69 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADDAILYQUESTSTATUS
,"SELECT quest,time FROM character_queststatus_daily WHERE guid = '%u'", GUID_LOPART(m_guid
));
70 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADTUTORIALS
, "SELECT tut0,tut1,tut2,tut3,tut4,tut5,tut6,tut7 FROM character_tutorial WHERE account = '%u' AND realmid = '%u'", GetAccountId(), realmID
);
71 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADREPUTATION
, "SELECT faction,standing,flags FROM character_reputation WHERE guid = '%u'", GUID_LOPART(m_guid
));
72 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
));
73 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADACTIONS
, "SELECT button,action,type,misc FROM character_action WHERE guid = '%u' ORDER BY button", GUID_LOPART(m_guid
));
74 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADMAILCOUNT
, "SELECT COUNT(id) FROM mail WHERE receiver = '%u' AND (checked & 1)=0 AND deliver_time <= '" I64FMTD
"'", GUID_LOPART(m_guid
),(uint64
)time(NULL
));
75 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADMAILDATE
, "SELECT MIN(deliver_time) FROM mail WHERE receiver = '%u' AND (checked & 1)=0", GUID_LOPART(m_guid
));
76 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADSOCIALLIST
, "SELECT friend,flags,note FROM character_social WHERE guid = '%u' LIMIT 255", GUID_LOPART(m_guid
));
77 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
));
78 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADSPELLCOOLDOWNS
, "SELECT spell,item,time FROM character_spell_cooldown WHERE guid = '%u'", GUID_LOPART(m_guid
));
79 if(sWorld
.getConfig(CONFIG_DECLINED_NAMES_USED
))
80 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADDECLINEDNAMES
, "SELECT genitive, dative, accusative, instrumental, prepositional FROM character_declinedname WHERE guid = '%u'",GUID_LOPART(m_guid
));
81 // in other case still be dummy query
82 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADGUILD
, "SELECT guildid,rank FROM guild_member WHERE guid = '%u'", GUID_LOPART(m_guid
));
83 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
));
84 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADACHIEVEMENTS
, "SELECT achievement, date FROM character_achievement WHERE guid = '%u'", GUID_LOPART(m_guid
));
85 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADCRITERIAPROGRESS
,"SELECT criteria, counter, date FROM character_achievement_progress WHERE guid = '%u'", GUID_LOPART(m_guid
));
90 // don't call WorldSession directly
91 // it may get deleted before the query callbacks get executed
92 // instead pass an account id to this handler
93 class CharacterHandler
96 void HandleCharEnumCallback(QueryResult
* result
, uint32 account
)
98 WorldSession
* session
= sWorld
.FindSession(account
);
104 session
->HandleCharEnum(result
);
106 void HandlePlayerLoginCallback(QueryResult
* /*dummy*/, SqlQueryHolder
* holder
)
109 WorldSession
*session
= sWorld
.FindSession(((LoginQueryHolder
*)holder
)->GetAccountId());
115 session
->HandlePlayerLogin((LoginQueryHolder
*)holder
);
119 void WorldSession::HandleCharEnum(QueryResult
* result
)
121 // keys can be non cleared if player open realm list and close it by 'cancel'
122 loginDatabase
.PExecute("UPDATE account SET v = '0', s = '0' WHERE id = '%u'", GetAccountId());
124 WorldPacket
data(SMSG_CHAR_ENUM
, 100); // we guess size
132 Player
*plr
= new Player(this);
135 uint32 guidlow
= (*result
)[0].GetUInt32();
136 sLog
.outDetail("Loading char guid %u from account %u.",guidlow
,GetAccountId());
138 if(plr
->MinimalLoadFromDB( result
, guidlow
))
140 plr
->BuildEnumData( result
, &data
);
144 while( result
->NextRow() );
150 data
.put
<uint8
>(0, num
);
155 void WorldSession::HandleCharEnumOpcode( WorldPacket
& /*recv_data*/ )
157 /// get all the data necessary for loading all characters (along with their pets) on the account
158 CharacterDatabase
.AsyncPQuery(&chrHandler
, &CharacterHandler::HandleCharEnumCallback
, GetAccountId(),
159 !sWorld
.getConfig(CONFIG_DECLINED_NAMES_USED
) ?
160 // ------- Query Without Declined Names --------
162 "SELECT characters.guid, characters.data, characters.name, characters.position_x, characters.position_y, characters.position_z, characters.map, characters.totaltime, characters.leveltime, "
164 "characters.at_login, character_pet.entry, character_pet.modelid, character_pet.level, guild_member.guildid "
165 "FROM characters LEFT JOIN character_pet ON characters.guid=character_pet.owner AND character_pet.slot='0' "
166 "LEFT JOIN guild_member ON characters.guid = guild_member.guid "
167 "WHERE characters.account = '%u' ORDER BY characters.guid"
169 // --------- Query With Declined Names ---------
171 "SELECT characters.guid, characters.data, characters.name, characters.position_x, characters.position_y, characters.position_z, characters.map, characters.totaltime, characters.leveltime, "
173 "characters.at_login, character_pet.entry, character_pet.modelid, character_pet.level, guild_member.guildid, genitive "
174 "FROM characters LEFT JOIN character_pet ON characters.guid = character_pet.owner AND character_pet.slot='0' "
175 "LEFT JOIN character_declinedname ON characters.guid = character_declinedname.guid "
176 "LEFT JOIN guild_member ON characters.guid = guild_member.guid "
177 "WHERE characters.account = '%u' ORDER BY characters.guid",
181 void WorldSession::HandleCharCreateOpcode( WorldPacket
& recv_data
)
183 CHECK_PACKET_SIZE(recv_data
,1+1+1+1+1+1+1+1+1+1);
190 // recheck with known string size
191 CHECK_PACKET_SIZE(recv_data
,(name
.size()+1)+1+1+1+1+1+1+1+1+1);
196 WorldPacket
data(SMSG_CHAR_CREATE
, 1); // returned with diff.values in all cases
198 if(GetSecurity() == SEC_PLAYER
)
200 if(uint32 mask
= sWorld
.getConfig(CONFIG_CHARACTERS_CREATING_DISABLED
))
202 bool disabled
= false;
204 uint32 team
= Player::TeamForRace(race_
);
207 case ALLIANCE
: disabled
= mask
& (1<<0); break;
208 case HORDE
: disabled
= mask
& (1<<1); break;
213 data
<< (uint8
)CHAR_CREATE_DISABLED
;
220 ChrClassesEntry
const* classEntry
= sChrClassesStore
.LookupEntry(class_
);
221 ChrRacesEntry
const* raceEntry
= sChrRacesStore
.LookupEntry(race_
);
223 if( !classEntry
|| !raceEntry
)
225 data
<< (uint8
)CHAR_CREATE_FAILED
;
227 sLog
.outError("Class: %u or Race %u not found in DBC (Wrong DBC files?) or Cheater?", class_
, race_
);
231 // prevent character creating Expansion race without Expansion account
232 if (raceEntry
->addon
> Expansion())
234 data
<< (uint8
)CHAR_CREATE_EXPANSION
;
235 sLog
.outError("Expansion %u account:[%d] tried to Create character with expansion %u race (%u)",Expansion(),GetAccountId(),raceEntry
->addon
,race_
);
240 // prevent character creating Expansion class without Expansion account
241 if (classEntry
->addon
> Expansion())
243 data
<< (uint8
)CHAR_CREATE_EXPANSION_CLASS
;
244 sLog
.outError("Expansion %u account:[%d] tried to Create character with expansion %u class (%u)",Expansion(),GetAccountId(),classEntry
->addon
,class_
);
249 // prevent character creating with invalid name
250 if(!normalizePlayerName(name
))
252 data
<< (uint8
)CHAR_NAME_INVALID_CHARACTER
;
254 sLog
.outError("Account:[%d] but tried to Create character with empty [name] ",GetAccountId());
258 // check name limitations
259 if(!ObjectMgr::IsValidName(name
,true))
261 data
<< (uint8
)CHAR_NAME_INVALID_CHARACTER
;
266 if(GetSecurity() == SEC_PLAYER
&& objmgr
.IsReservedName(name
))
268 data
<< (uint8
)CHAR_NAME_RESERVED
;
273 if(objmgr
.GetPlayerGUIDByName(name
))
275 data
<< (uint8
)CHAR_CREATE_NAME_IN_USE
;
280 QueryResult
*resultacct
= loginDatabase
.PQuery("SELECT SUM(numchars) FROM realmcharacters WHERE acctid = '%d'", GetAccountId());
283 Field
*fields
=resultacct
->Fetch();
284 uint32 acctcharcount
= fields
[0].GetUInt32();
287 if (acctcharcount
>= sWorld
.getConfig(CONFIG_CHARACTERS_PER_ACCOUNT
))
289 data
<< (uint8
)CHAR_CREATE_ACCOUNT_LIMIT
;
295 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT COUNT(guid) FROM characters WHERE account = '%d'", GetAccountId());
299 Field
*fields
=result
->Fetch();
300 charcount
= fields
[0].GetUInt8();
303 if (charcount
>= sWorld
.getConfig(CONFIG_CHARACTERS_PER_REALM
))
305 data
<< (uint8
)CHAR_CREATE_SERVER_LIMIT
;
311 // speedup check for heroic class disabled case
312 uint32 heroic_free_slots
= sWorld
.getConfig(CONFIG_HEROIC_CHARACTERS_PER_REALM
);
313 if(heroic_free_slots
==0 && GetSecurity()==SEC_PLAYER
&& class_
== CLASS_DEATH_KNIGHT
)
315 data
<< (uint8
)CHAR_CREATE_UNIQUE_CLASS_LIMIT
;
320 // speedup check for heroic class disabled case
321 uint32 req_level_for_heroic
= sWorld
.getConfig(CONFIG_MIN_LEVEL_FOR_HEROIC_CHARACTER_CREATING
);
322 if(GetSecurity()==SEC_PLAYER
&& class_
== CLASS_DEATH_KNIGHT
&& req_level_for_heroic
> sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
324 data
<< (uint8
)CHAR_CREATE_LEVEL_REQUIREMENT
;
329 bool AllowTwoSideAccounts
= !sWorld
.IsPvPRealm() || sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_ACCOUNTS
) || GetSecurity() > SEC_PLAYER
;
330 uint32 skipCinematics
= sWorld
.getConfig(CONFIG_SKIP_CINEMATICS
);
332 bool have_same_race
= false;
334 // if 0 then allowed creating without any characters
335 bool have_req_level_for_heroic
= (req_level_for_heroic
==0);
337 if(!AllowTwoSideAccounts
|| skipCinematics
== 1 || class_
== CLASS_DEATH_KNIGHT
)
339 QueryResult
*result2
= CharacterDatabase
.PQuery("SELECT guid,race,class FROM characters WHERE account = '%u' %s",
340 GetAccountId(), (skipCinematics
== 1 || class_
== CLASS_DEATH_KNIGHT
) ? "" : "LIMIT 1");
343 uint32 team_
= Player::TeamForRace(race_
);
345 Field
* field
= result2
->Fetch();
346 uint8 acc_race
= field
[1].GetUInt32();
348 if(GetSecurity()==SEC_PLAYER
&& class_
== CLASS_DEATH_KNIGHT
)
350 uint8 acc_class
= field
[2].GetUInt32();
351 if(acc_class
== CLASS_DEATH_KNIGHT
)
353 if(heroic_free_slots
> 0)
356 if(heroic_free_slots
==0)
358 data
<< (uint8
)CHAR_CREATE_UNIQUE_CLASS_LIMIT
;
364 if(!have_req_level_for_heroic
)
366 uint32 acc_guid
= field
[0].GetUInt32();
367 uint32 acc_level
= Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL
,acc_guid
);
368 if(acc_level
>= req_level_for_heroic
)
369 have_req_level_for_heroic
= true;
373 // need to check team only for first character
374 // TODO: what to if account already has characters of both races?
375 if (!AllowTwoSideAccounts
)
379 acc_team
= Player::TeamForRace(acc_race
);
381 if(acc_team
!= team_
)
383 data
<< (uint8
)CHAR_CREATE_PVP_TEAMS_VIOLATION
;
390 // search same race for cinematic or same class if need
391 // TODO: check if cinematic already shown? (already logged in?; cinematic field)
392 while ((skipCinematics
== 1 && !have_same_race
) || class_
== CLASS_DEATH_KNIGHT
)
394 if(!result2
->NextRow())
397 field
= result2
->Fetch();
398 acc_race
= field
[1].GetUInt32();
401 have_same_race
= race_
== acc_race
;
403 if(GetSecurity()==SEC_PLAYER
&& class_
== CLASS_DEATH_KNIGHT
)
405 uint8 acc_class
= field
[2].GetUInt32();
406 if(acc_class
== CLASS_DEATH_KNIGHT
)
408 if(heroic_free_slots
> 0)
411 if(heroic_free_slots
==0)
413 data
<< (uint8
)CHAR_CREATE_UNIQUE_CLASS_LIMIT
;
419 if(!have_req_level_for_heroic
)
421 uint32 acc_guid
= field
[0].GetUInt32();
422 uint32 acc_level
= Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL
,acc_guid
);
423 if(acc_level
>= req_level_for_heroic
)
424 have_req_level_for_heroic
= true;
432 if(GetSecurity()==SEC_PLAYER
&& class_
== CLASS_DEATH_KNIGHT
&& !have_req_level_for_heroic
)
434 data
<< (uint8
)CHAR_CREATE_LEVEL_REQUIREMENT
;
439 // extract other data required for player creating
440 uint8 gender
, skin
, face
, hairStyle
, hairColor
, facialHair
, outfitId
;
441 recv_data
>> gender
>> skin
>> face
;
442 recv_data
>> hairStyle
>> hairColor
>> facialHair
>> outfitId
;
444 Player
* pNewChar
= new Player(this);
445 if(!pNewChar
->Create( objmgr
.GenerateLowGuid(HIGHGUID_PLAYER
), name
, race_
, class_
, gender
, skin
, face
, hairStyle
, hairColor
, facialHair
, outfitId
))
447 // Player not create (race/class problem?)
450 data
<< (uint8
)CHAR_CREATE_ERROR
;
456 if(have_same_race
&& skipCinematics
== 1 || skipCinematics
== 2)
457 pNewChar
->setCinematic(1); // not show intro
459 // Player created, save it now
460 pNewChar
->SaveToDB();
463 loginDatabase
.PExecute("DELETE FROM realmcharacters WHERE acctid= '%d' AND realmid = '%d'", GetAccountId(), realmID
);
464 loginDatabase
.PExecute("INSERT INTO realmcharacters (numchars, acctid, realmid) VALUES (%u, %u, %u)", charcount
, GetAccountId(), realmID
);
466 delete pNewChar
; // created only to call SaveToDB()
468 data
<< (uint8
)CHAR_CREATE_SUCCESS
;
471 std::string IP_str
= GetRemoteAddress();
472 sLog
.outBasic("Account: %d (IP: %s) Create Character:[%s]",GetAccountId(),IP_str
.c_str(),name
.c_str());
473 sLog
.outChar("Account: %d (IP: %s) Create Character:[%s]",GetAccountId(),IP_str
.c_str(),name
.c_str());
476 void WorldSession::HandleCharDeleteOpcode( WorldPacket
& recv_data
)
478 CHECK_PACKET_SIZE(recv_data
,8);
483 // can't delete loaded character
484 if(objmgr
.GetPlayer(guid
))
487 uint32 accountId
= 0;
491 if(objmgr
.GetGuildByLeader(guid
))
493 WorldPacket
data(SMSG_CHAR_DELETE
, 1);
494 data
<< (uint8
)CHAR_DELETE_FAILED_GUILD_LEADER
;
499 // is arena team captain
500 if(objmgr
.GetArenaTeamByCaptain(guid
))
502 WorldPacket
data(SMSG_CHAR_DELETE
, 1);
503 data
<< (uint8
)CHAR_DELETE_FAILED_ARENA_CAPTAIN
;
508 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT account,name FROM characters WHERE guid='%u'", GUID_LOPART(guid
));
511 Field
*fields
= result
->Fetch();
512 accountId
= fields
[0].GetUInt32();
513 name
= fields
[1].GetCppString();
517 // prevent deleting other players' characters using cheating tools
518 if(accountId
!= GetAccountId())
521 std::string IP_str
= GetRemoteAddress();
522 sLog
.outBasic("Account: %d (IP: %s) Delete Character:[%s] (guid:%u)",GetAccountId(),IP_str
.c_str(),name
.c_str(),GUID_LOPART(guid
));
523 sLog
.outChar("Account: %d (IP: %s) Delete Character:[%s] (guid: %u)",GetAccountId(),IP_str
.c_str(),name
.c_str(),GUID_LOPART(guid
));
525 if(sLog
.IsOutCharDump()) // optimize GetPlayerDump call
527 std::string dump
= PlayerDumpWriter().GetDump(GUID_LOPART(guid
));
528 sLog
.outCharDump(dump
.c_str(),GetAccountId(),GUID_LOPART(guid
),name
.c_str());
531 Player::DeleteFromDB(guid
, GetAccountId());
533 WorldPacket
data(SMSG_CHAR_DELETE
, 1);
534 data
<< (uint8
)CHAR_DELETE_SUCCESS
;
538 void WorldSession::HandlePlayerLoginOpcode( WorldPacket
& recv_data
)
540 CHECK_PACKET_SIZE(recv_data
,8);
542 if(PlayerLoading() || GetPlayer() != NULL
)
544 sLog
.outError("Player tryes to login again, AccountId = %d",GetAccountId());
548 m_playerLoading
= true;
549 uint64 playerGuid
= 0;
551 DEBUG_LOG( "WORLD: Recvd Player Logon Message" );
553 recv_data
>> playerGuid
;
555 LoginQueryHolder
*holder
= new LoginQueryHolder(GetAccountId(), playerGuid
);
556 if(!holder
->Initialize())
558 delete holder
; // delete all unprocessed queries
559 m_playerLoading
= false;
563 CharacterDatabase
.DelayQueryHolder(&chrHandler
, &CharacterHandler::HandlePlayerLoginCallback
, holder
);
566 void WorldSession::HandlePlayerLogin(LoginQueryHolder
* holder
)
568 uint64 playerGuid
= holder
->GetGuid();
570 Player
* pCurrChar
= new Player(this);
571 pCurrChar
->GetMotionMaster()->Initialize();
573 // "GetAccountId()==db stored account id" checked in LoadFromDB (prevent login not own character using cheating tools)
574 if(!pCurrChar
->LoadFromDB(GUID_LOPART(playerGuid
), holder
))
576 KickPlayer(); // disconnect client, player no set to session and it will not deleted or saved at kick
577 delete pCurrChar
; // delete it manually
578 delete holder
; // delete all unprocessed queries
579 m_playerLoading
= false;
583 SetPlayer(pCurrChar
);
585 pCurrChar
->SendDungeonDifficulty(false);
587 WorldPacket
data( SMSG_LOGIN_VERIFY_WORLD
, 20 );
588 data
<< pCurrChar
->GetMapId();
589 data
<< pCurrChar
->GetPositionX();
590 data
<< pCurrChar
->GetPositionY();
591 data
<< pCurrChar
->GetPositionZ();
592 data
<< pCurrChar
->GetOrientation();
595 data
.Initialize( SMSG_ACCOUNT_DATA_TIMES
, 4+1+8*4 ); // changed in WotLK
596 data
<< uint32(time(NULL
)); // unix time of something
598 for(int i
= 0; i
< NUM_ACCOUNT_DATA_TYPES
; i
++)
599 data
<< uint32(GetAccountData(i
)->Time
); // also unix time
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
= objmgr
.GetGuildById(pCurrChar
->GetGuildId());
660 data
.Initialize(SMSG_GUILD_EVENT
, (2+guild
->GetMOTD().size()+1));
661 data
<< (uint8
)GE_MOTD
;
663 data
<< guild
->GetMOTD();
665 DEBUG_LOG( "WORLD: Sent guild-motd (SMSG_GUILD_EVENT)" );
667 data
.Initialize(SMSG_GUILD_EVENT
, (5+10)); // we guess size
668 data
<<(uint8
)GE_SIGNED_ON
;
670 data
<<pCurrChar
->GetName();
671 data
<<pCurrChar
->GetGUID();
672 guild
->BroadcastPacket(&data
);
673 DEBUG_LOG( "WORLD: Sent guild-signed-on (SMSG_GUILD_EVENT)" );
675 // Increment online members of the guild
676 guild
->IncOnlineMemberCount();
680 // remove wrong guild data
681 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());
682 pCurrChar
->SetInGuild(0);
686 if(!pCurrChar
->isAlive())
687 pCurrChar
->SendCorpseReclaimDelay(true);
689 pCurrChar
->SendInitialPacketsBeforeAddToMap();
691 //Show cinematic at the first time that player login
692 if( !pCurrChar
->getCinematic() )
694 pCurrChar
->setCinematic(1);
696 if(ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(pCurrChar
->getClass()))
698 if(cEntry
->CinematicSequence
)
700 data
.Initialize(SMSG_TRIGGER_CINEMATIC
, 4);
701 data
<< uint32(cEntry
->CinematicSequence
);
704 else if(ChrRacesEntry
const* rEntry
= sChrRacesStore
.LookupEntry(pCurrChar
->getRace()))
706 data
.Initialize(SMSG_TRIGGER_CINEMATIC
, 4);
707 data
<< uint32(rEntry
->CinematicSequence
);
713 if (!pCurrChar
->GetMap()->Add(pCurrChar
))
715 AreaTrigger
const* at
= objmgr
.GetGoBackTrigger(pCurrChar
->GetMapId());
717 pCurrChar
->TeleportTo(at
->target_mapId
, at
->target_X
, at
->target_Y
, at
->target_Z
, pCurrChar
->GetOrientation());
719 pCurrChar
->TeleportTo(pCurrChar
->m_homebindMapId
, pCurrChar
->m_homebindX
, pCurrChar
->m_homebindY
, pCurrChar
->m_homebindZ
, pCurrChar
->GetOrientation());
722 ObjectAccessor::Instance().AddObject(pCurrChar
);
723 //sLog.outDebug("Player %s added to Map.",pCurrChar->GetName());
724 pCurrChar
->GetSocial()->SendSocialList();
726 pCurrChar
->SendInitialPacketsAfterAddToMap();
728 CharacterDatabase
.PExecute("UPDATE characters SET online = 1 WHERE guid = '%u'", pCurrChar
->GetGUIDLow());
729 loginDatabase
.PExecute("UPDATE account SET online = 1 WHERE id = '%u'", GetAccountId());
730 pCurrChar
->SetInGameTime( getMSTime() );
732 // announce group about member online (must be after add to player list to receive announce to self)
733 if(Group
*group
= pCurrChar
->GetGroup())
735 //pCurrChar->groupInfo.group->SendInit(this); // useless
740 sSocialMgr
.SendFriendStatus(pCurrChar
, FRIEND_ONLINE
, pCurrChar
->GetGUIDLow(), true);
742 // Place character in world (and load zone) before some object loading
743 pCurrChar
->LoadCorpse();
745 // setting Ghost+speed if dead
746 if (pCurrChar
->m_deathState
!= ALIVE
)
748 // not blizz like, we must correctly save and load player instead...
749 if(pCurrChar
->getRace() == RACE_NIGHTELF
)
750 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)
751 pCurrChar
->CastSpell(pCurrChar
, 8326, true, 0); // auras SPELL_AURA_GHOST, SPELL_AURA_INCREASE_SPEED(why?), SPELL_AURA_INCREASE_SWIM_SPEED(why?)
753 pCurrChar
->SetMovement(MOVE_WATER_WALK
);
756 if(uint32 sourceNode
= pCurrChar
->m_taxi
.GetTaxiSource())
759 sLog
.outDebug( "WORLD: Restart character %u taxi flight", pCurrChar
->GetGUIDLow() );
761 uint32 MountId
= objmgr
.GetTaxiMount(sourceNode
, pCurrChar
->GetTeam());
762 uint32 path
= pCurrChar
->m_taxi
.GetCurrentTaxiPath();
764 // search appropriate start path node
765 uint32 startNode
= 0;
767 TaxiPathNodeList
const& nodeList
= sTaxiPathNodesByPath
[path
];
769 float distPrev
= MAP_SIZE
*MAP_SIZE
;
771 (nodeList
[0].x
-pCurrChar
->GetPositionX())*(nodeList
[0].x
-pCurrChar
->GetPositionX())+
772 (nodeList
[0].y
-pCurrChar
->GetPositionY())*(nodeList
[0].y
-pCurrChar
->GetPositionY())+
773 (nodeList
[0].z
-pCurrChar
->GetPositionZ())*(nodeList
[0].z
-pCurrChar
->GetPositionZ());
775 for(uint32 i
= 1; i
< nodeList
.size(); ++i
)
777 TaxiPathNode
const& node
= nodeList
[i
];
778 TaxiPathNode
const& prevNode
= nodeList
[i
-1];
780 // skip nodes at another map
781 if(node
.mapid
!= pCurrChar
->GetMapId())
787 (node
.x
-pCurrChar
->GetPositionX())*(node
.x
-pCurrChar
->GetPositionX())+
788 (node
.y
-pCurrChar
->GetPositionY())*(node
.y
-pCurrChar
->GetPositionY())+
789 (node
.z
-pCurrChar
->GetPositionZ())*(node
.z
-pCurrChar
->GetPositionZ());
792 (node
.x
-prevNode
.x
)*(node
.x
-prevNode
.x
)+
793 (node
.y
-prevNode
.y
)*(node
.y
-prevNode
.y
)+
794 (node
.z
-prevNode
.z
)*(node
.z
-prevNode
.z
);
796 if(distNext
+ distPrev
< distNodes
)
803 SendDoFlight( MountId
, path
, startNode
);
806 // Load pet if any and player is alive and not in taxi flight
807 if(pCurrChar
->isAlive() && pCurrChar
->m_taxi
.GetTaxiSource()==0)
808 pCurrChar
->LoadPet();
810 // Set FFA PvP for non GM in non-rest mode
811 if(sWorld
.IsFFAPvPRealm() && !pCurrChar
->isGameMaster() && !pCurrChar
->HasFlag(PLAYER_FLAGS
,PLAYER_FLAGS_RESTING
) )
812 pCurrChar
->SetFlag(PLAYER_FLAGS
,PLAYER_FLAGS_FFA_PVP
);
814 if(pCurrChar
->HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_CONTESTED_PVP
))
815 pCurrChar
->SetContestedPvP();
817 // Apply at_login requests
818 if(pCurrChar
->HasAtLoginFlag(AT_LOGIN_RESET_SPELLS
))
820 pCurrChar
->resetSpells();
821 SendNotification(LANG_RESET_SPELLS
);
824 if(pCurrChar
->HasAtLoginFlag(AT_LOGIN_RESET_TALENTS
))
826 pCurrChar
->resetTalents(true);
827 SendNotification(LANG_RESET_TALENTS
);
830 // show time before shutdown if shutdown planned.
831 if(sWorld
.IsShutdowning())
832 sWorld
.ShutdownMsg(true,pCurrChar
);
834 if(sWorld
.getConfig(CONFIG_ALL_TAXI_PATHS
))
835 pCurrChar
->SetTaxiCheater(true);
837 if(pCurrChar
->isGameMaster())
838 SendNotification(LANG_GM_ON
);
840 std::string IP_str
= GetRemoteAddress();
841 sLog
.outChar("Account: %d (IP: %s) Login Character:[%s] (guid:%u)",
842 GetAccountId(),IP_str
.c_str(),pCurrChar
->GetName() ,pCurrChar
->GetGUIDLow());
844 m_playerLoading
= false;
848 void WorldSession::HandleSetFactionAtWar( WorldPacket
& recv_data
)
850 CHECK_PACKET_SIZE(recv_data
,4+1);
852 DEBUG_LOG( "WORLD: Received CMSG_SET_FACTION_ATWAR" );
857 recv_data
>> repListID
;
860 FactionStateList::iterator itr
= GetPlayer()->m_factions
.find(repListID
);
861 if (itr
== GetPlayer()->m_factions
.end())
864 // always invisible or hidden faction can't change war state
865 if(itr
->second
.Flags
& (FACTION_FLAG_INVISIBLE_FORCED
|FACTION_FLAG_HIDDEN
) )
868 GetPlayer()->SetFactionAtWar(&itr
->second
,flag
);
871 //I think this function is never used :/ I dunno, but i guess this opcode not exists
872 void WorldSession::HandleSetFactionCheat( WorldPacket
& /*recv_data*/ )
874 //CHECK_PACKET_SIZE(recv_data,4+4);
876 //sLog.outDebug("WORLD SESSION: HandleSetFactionCheat");
881 recv_data >> FactionID;
882 recv_data >> Standing;
884 std::list<struct Factions>::iterator itr;
886 for(itr = GetPlayer()->factions.begin(); itr != GetPlayer()->factions.end(); ++itr)
888 if(itr->ReputationListID == FactionID)
890 itr->Standing += Standing;
891 itr->Flags = (itr->Flags | 1);
896 GetPlayer()->UpdateReputation();
899 void WorldSession::HandleMeetingStoneInfo( WorldPacket
& /*recv_data*/ )
901 DEBUG_LOG( "WORLD: Received CMSG_MEETING_STONE_INFO" );
903 WorldPacket
data(SMSG_MEETINGSTONE_SETQUEUE
, 5);
904 data
<< uint32(0) << uint8(6);
908 void WorldSession::HandleTutorialFlag( WorldPacket
& recv_data
)
910 CHECK_PACKET_SIZE(recv_data
,4);
915 uint32 wInt
= (iFlag
/ 32);
918 //sLog.outError("CHEATER? Account:[%d] Guid[%u] tried to send wrong CMSG_TUTORIAL_FLAG", GetAccountId(),GetGUID());
921 uint32 rInt
= (iFlag
% 32);
923 uint32 tutflag
= GetPlayer()->GetTutorialInt( wInt
);
924 tutflag
|= (1 << rInt
);
925 GetPlayer()->SetTutorialInt( wInt
, tutflag
);
927 //sLog.outDebug("Received Tutorial Flag Set {%u}.", iFlag);
930 void WorldSession::HandleTutorialClear( WorldPacket
& /*recv_data*/ )
932 for ( uint32 iI
= 0; iI
< 8; iI
++)
933 GetPlayer()->SetTutorialInt( iI
, 0xFFFFFFFF );
936 void WorldSession::HandleTutorialReset( WorldPacket
& /*recv_data*/ )
938 for ( uint32 iI
= 0; iI
< 8; iI
++)
939 GetPlayer()->SetTutorialInt( iI
, 0x00000000 );
942 void WorldSession::HandleSetWatchedFactionIndexOpcode(WorldPacket
& recv_data
)
944 CHECK_PACKET_SIZE(recv_data
,4);
946 DEBUG_LOG("WORLD: Received CMSG_SET_WATCHED_FACTION");
949 GetPlayer()->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, fact
);
952 void WorldSession::HandleSetWatchedFactionInactiveOpcode(WorldPacket
& recv_data
)
954 CHECK_PACKET_SIZE(recv_data
,4+1);
956 DEBUG_LOG("WORLD: Received CMSG_SET_FACTION_INACTIVE");
959 recv_data
>> replistid
>> inactive
;
961 FactionStateList::iterator itr
= _player
->m_factions
.find(replistid
);
962 if (itr
== _player
->m_factions
.end())
965 _player
->SetFactionInactive(&itr
->second
, inactive
);
968 void WorldSession::HandleToggleHelmOpcode( WorldPacket
& /*recv_data*/ )
970 DEBUG_LOG("CMSG_TOGGLE_HELM for %s", _player
->GetName());
971 _player
->ToggleFlag(PLAYER_FLAGS
, PLAYER_FLAGS_HIDE_HELM
);
974 void WorldSession::HandleToggleCloakOpcode( WorldPacket
& /*recv_data*/ )
976 DEBUG_LOG("CMSG_TOGGLE_CLOAK for %s", _player
->GetName());
977 _player
->ToggleFlag(PLAYER_FLAGS
, PLAYER_FLAGS_HIDE_CLOAK
);
980 void WorldSession::HandleChangePlayerNameOpcode(WorldPacket
& recv_data
)
982 CHECK_PACKET_SIZE(recv_data
, 8+1);
988 recv_data
>> newname
;
990 // prevent character rename to invalid name
991 if(!normalizePlayerName(newname
))
993 WorldPacket
data(SMSG_CHAR_RENAME
, 1);
994 data
<< uint8(CHAR_NAME_NO_NAME
);
999 if(!ObjectMgr::IsValidName(newname
, true))
1001 WorldPacket
data(SMSG_CHAR_RENAME
, 1);
1002 data
<< uint8(CHAR_NAME_INVALID_CHARACTER
);
1003 SendPacket( &data
);
1007 // check name limitations
1008 if(GetSecurity() == SEC_PLAYER
&& objmgr
.IsReservedName(newname
))
1010 WorldPacket
data(SMSG_CHAR_RENAME
, 1);
1011 data
<< uint8(CHAR_NAME_RESERVED
);
1012 SendPacket( &data
);
1016 std::string escaped_newname
= newname
;
1017 CharacterDatabase
.escape_string(escaped_newname
);
1019 // make sure that the character belongs to the current account, that rename at login is enabled
1020 // and that there is no character with the desired new name
1021 CharacterDatabase
.AsyncPQuery(&WorldSession::HandleChangePlayerNameOpcodeCallBack
,
1022 GetAccountId(), newname
,
1023 "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')",
1024 GUID_LOPART(guid
), GetAccountId(), AT_LOGIN_RENAME
, AT_LOGIN_RENAME
, escaped_newname
.c_str()
1028 void WorldSession::HandleChangePlayerNameOpcodeCallBack(QueryResult
*result
, uint32 accountId
, std::string newname
)
1030 WorldSession
* session
= sWorld
.FindSession(accountId
);
1033 if(result
) delete result
;
1039 WorldPacket
data(SMSG_CHAR_RENAME
, 1);
1040 data
<< uint8(CHAR_CREATE_ERROR
);
1041 session
->SendPacket( &data
);
1045 uint32 guidLow
= result
->Fetch()[0].GetUInt32();
1046 uint64 guid
= MAKE_NEW_GUID(guidLow
, 0, HIGHGUID_PLAYER
);
1047 std::string oldname
= result
->Fetch()[1].GetCppString();
1051 CharacterDatabase
.PExecute("UPDATE characters set name = '%s', at_login = at_login & ~ %u WHERE guid ='%u'", newname
.c_str(), uint32(AT_LOGIN_RENAME
), guidLow
);
1052 CharacterDatabase
.PExecute("DELETE FROM character_declinedname WHERE guid ='%u'", guidLow
);
1054 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());
1056 WorldPacket
data(SMSG_CHAR_RENAME
, 1+8+(newname
.size()+1));
1057 data
<< uint8(RESPONSE_SUCCESS
);
1058 data
<< uint64(guid
);
1060 session
->SendPacket(&data
);
1063 void WorldSession::HandleDeclinedPlayerNameOpcode(WorldPacket
& recv_data
)
1067 CHECK_PACKET_SIZE(recv_data
, 8);
1070 // not accept declined names for unsupported languages
1072 if(!objmgr
.GetPlayerNameByGUID(guid
, name
))
1074 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1076 data
<< uint64(guid
);
1082 if(!Utf8toWStr(name
, wname
))
1084 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1086 data
<< uint64(guid
);
1091 if(!isCyrillicCharacter(wname
[0])) // name already stored as only single alphabet using
1093 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1095 data
<< uint64(guid
);
1101 DeclinedName declinedname
;
1103 CHECK_PACKET_SIZE(recv_data
, recv_data
.rpos() + 1);
1106 if(name2
!= name
) // character have different name
1108 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1110 data
<< uint64(guid
);
1115 for(int i
= 0; i
< MAX_DECLINED_NAME_CASES
; ++i
)
1117 CHECK_PACKET_SIZE(recv_data
, recv_data
.rpos() + 1);
1118 recv_data
>> declinedname
.name
[i
];
1119 if(!normalizePlayerName(declinedname
.name
[i
]))
1121 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1123 data
<< uint64(guid
);
1129 if(!ObjectMgr::CheckDeclinedNames(GetMainPartOfName(wname
, 0), declinedname
))
1131 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1133 data
<< uint64(guid
);
1138 for(int i
= 0; i
< MAX_DECLINED_NAME_CASES
; ++i
)
1139 CharacterDatabase
.escape_string(declinedname
.name
[i
]);
1141 CharacterDatabase
.BeginTransaction();
1142 CharacterDatabase
.PExecute("DELETE FROM character_declinedname WHERE guid = '%u'", GUID_LOPART(guid
));
1143 CharacterDatabase
.PExecute("INSERT INTO character_declinedname (guid, genitive, dative, accusative, instrumental, prepositional) VALUES ('%u','%s','%s','%s','%s','%s')",
1144 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());
1145 CharacterDatabase
.CommitTransaction();
1147 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1148 data
<< uint32(0); // OK
1149 data
<< uint64(guid
);
1153 void WorldSession::HandleAlterAppearance( WorldPacket
& recv_data
)
1155 sLog
.outDebug("CMSG_ALTER_APPEARANCE");
1157 CHECK_PACKET_SIZE(recv_data
, 4+4+4);
1159 uint32 Hair
, Color
, FacialHair
;
1160 recv_data
>> Hair
>> Color
>> FacialHair
;
1162 BarberShopStyleEntry
const* bs_hair
= sBarberShopStyleStore
.LookupEntry(Hair
);
1164 if(!bs_hair
|| bs_hair
->type
!= 0 || bs_hair
->race
!= _player
->getRace() || bs_hair
->gender
!= _player
->getGender())
1167 BarberShopStyleEntry
const* bs_facialHair
= sBarberShopStyleStore
.LookupEntry(FacialHair
);
1169 if(!bs_facialHair
|| bs_facialHair
->type
!= 2 || bs_facialHair
->race
!= _player
->getRace() || bs_facialHair
->gender
!= _player
->getGender())
1172 uint32 Cost
= _player
->GetBarberShopCost(bs_hair
->hair_id
, Color
, bs_facialHair
->hair_id
);
1175 // 1,3 - not enough money
1176 // 2 - you have to seat on barber chair
1177 if(_player
->GetMoney() < Cost
)
1179 WorldPacket
data(SMSG_BARBER_SHOP_RESULT
, 4);
1180 data
<< uint32(1); // no money
1186 WorldPacket
data(SMSG_BARBER_SHOP_RESULT
, 4);
1187 data
<< uint32(0); // ok
1191 _player
->SetMoney(_player
->GetMoney() - Cost
); // it isn't free
1193 _player
->SetByteValue(PLAYER_BYTES
, 2, uint8(bs_hair
->hair_id
));
1194 _player
->SetByteValue(PLAYER_BYTES
, 3, uint8(Color
));
1195 _player
->SetByteValue(PLAYER_BYTES_2
, 0, uint8(bs_facialHair
->hair_id
));
1197 _player
->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_VISIT_BARBER_SHOP
, 1);
1199 _player
->SetStandState(0); // stand up
1202 void WorldSession::HandleRemoveGlyph( WorldPacket
& recv_data
)
1204 CHECK_PACKET_SIZE(recv_data
, 4);
1211 sLog
.outDebug("Client sent wrong glyph slot number in opcode CMSG_REMOVE_GLYPH %u", slot
);
1215 if(uint32 glyph
= _player
->GetGlyph(slot
))
1217 if(GlyphPropertiesEntry
const *gp
= sGlyphPropertiesStore
.LookupEntry(glyph
))
1219 _player
->RemoveAurasDueToSpell(gp
->SpellId
);
1220 _player
->SetGlyph(slot
, 0);
1225 void WorldSession::HandleCharCustomize(WorldPacket
& recv_data
)
1227 CHECK_PACKET_SIZE(recv_data
, 8+1);
1230 std::string newname
;
1233 recv_data
>> newname
;
1235 CHECK_PACKET_SIZE(recv_data
, recv_data
.rpos()+1+1+1+1+1+1);
1237 uint8 gender
, skin
, face
, hairStyle
, hairColor
, facialHair
;
1238 recv_data
>> gender
>> skin
>> face
>> hairStyle
>> hairColor
>> facialHair
;
1240 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT at_login FROM characters WHERE guid ='%u'", GUID_LOPART(guid
));
1243 WorldPacket
data(SMSG_CHAR_CUSTOMIZE
, 1);
1244 data
<< uint8(CHAR_CREATE_ERROR
);
1245 SendPacket( &data
);
1249 Field
*fields
= result
->Fetch();
1250 uint32 at_loginFlags
= fields
[0].GetUInt32();
1253 if (!(at_loginFlags
& AT_LOGIN_CUSTOMIZE
))
1255 WorldPacket
data(SMSG_CHAR_CUSTOMIZE
, 1);
1256 data
<< uint8(CHAR_CREATE_ERROR
);
1257 SendPacket( &data
);
1261 // prevent character rename to invalid name
1262 if(!normalizePlayerName(newname
))
1264 WorldPacket
data(SMSG_CHAR_CUSTOMIZE
, 1);
1265 data
<< uint8(CHAR_NAME_NO_NAME
);
1266 SendPacket( &data
);
1270 if(!ObjectMgr::IsValidName(newname
,true))
1272 WorldPacket
data(SMSG_CHAR_CUSTOMIZE
, 1);
1273 data
<< uint8(CHAR_NAME_INVALID_CHARACTER
);
1274 SendPacket( &data
);
1278 // check name limitations
1279 if(GetSecurity() == SEC_PLAYER
&& objmgr
.IsReservedName(newname
))
1281 WorldPacket
data(SMSG_CHAR_CUSTOMIZE
, 1);
1282 data
<< uint8(CHAR_NAME_RESERVED
);
1283 SendPacket( &data
);
1287 if(objmgr
.GetPlayerGUIDByName(newname
)) // character with this name already exist
1289 WorldPacket
data(SMSG_CHAR_CUSTOMIZE
, 1);
1290 data
<< uint8(CHAR_CREATE_NAME_IN_USE
);
1291 SendPacket( &data
);
1295 CharacterDatabase
.escape_string(newname
);
1296 Player::Customize(guid
, gender
, skin
, face
, hairStyle
, hairColor
, facialHair
);
1297 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
));
1298 CharacterDatabase
.PExecute("DELETE FROM character_declinedname WHERE guid ='%u'", GUID_LOPART(guid
));
1300 std::string IP_str
= GetRemoteAddress();
1301 sLog
.outChar("Account: %d (IP: %s), Character guid: %u Customized to: %s", GetAccountId(), IP_str
.c_str(), GUID_LOPART(guid
), newname
.c_str());
1303 WorldPacket
data(SMSG_CHAR_CUSTOMIZE
, 1+8+(newname
.size()+1)+6);
1304 data
<< uint8(RESPONSE_SUCCESS
);
1305 data
<< uint64(guid
);
1307 data
<< uint8(gender
);
1308 data
<< uint8(skin
);
1309 data
<< uint8(face
);
1310 data
<< uint8(hairStyle
);
1311 data
<< uint8(hairColor
);
1312 data
<< uint8(facialHair
);