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"
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, 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 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,slot,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_LOADTUTORIALS
, "SELECT tut0,tut1,tut2,tut3,tut4,tut5,tut6,tut7 FROM character_tutorial WHERE account = '%u' AND realmid = '%u'", GetAccountId(), realmID
);
70 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADREPUTATION
, "SELECT faction,standing,flags FROM character_reputation WHERE guid = '%u'", GUID_LOPART(m_guid
));
71 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
));
72 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADACTIONS
, "SELECT button,action,type,misc FROM character_action WHERE guid = '%u' ORDER BY button", GUID_LOPART(m_guid
));
73 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
));
74 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADMAILDATE
, "SELECT MIN(deliver_time) FROM mail WHERE receiver = '%u' AND (checked & 1)=0", GUID_LOPART(m_guid
));
75 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADSOCIALLIST
, "SELECT friend,flags,note FROM character_social WHERE guid = '%u' LIMIT 255", GUID_LOPART(m_guid
));
76 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
));
77 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADSPELLCOOLDOWNS
, "SELECT spell,item,time FROM character_spell_cooldown WHERE guid = '%u'", GUID_LOPART(m_guid
));
78 if(sWorld
.getConfig(CONFIG_DECLINED_NAMES_USED
))
79 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADDECLINEDNAMES
, "SELECT genitive, dative, accusative, instrumental, prepositional FROM character_declinedname WHERE guid = '%u'",GUID_LOPART(m_guid
));
80 // in other case still be dummy query
81 res
&= SetPQuery(PLAYER_LOGIN_QUERY_LOADGUILD
, "SELECT guildid,rank FROM guild_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
));
88 // don't call WorldSession directly
89 // it may get deleted before the query callbacks get executed
90 // instead pass an account id to this handler
91 class CharacterHandler
94 void HandleCharEnumCallback(QueryResult
* result
, uint32 account
)
96 WorldSession
* session
= sWorld
.FindSession(account
);
102 session
->HandleCharEnum(result
);
104 void HandlePlayerLoginCallback(QueryResult
* /*dummy*/, SqlQueryHolder
* holder
)
107 WorldSession
*session
= sWorld
.FindSession(((LoginQueryHolder
*)holder
)->GetAccountId());
113 session
->HandlePlayerLogin((LoginQueryHolder
*)holder
);
117 void WorldSession::HandleCharEnum(QueryResult
* result
)
119 // keys can be non cleared if player open realm list and close it by 'cancel'
120 loginDatabase
.PExecute("UPDATE account SET v = '0', s = '0' WHERE id = '%u'", GetAccountId());
122 WorldPacket
data(SMSG_CHAR_ENUM
, 100); // we guess size
130 Player
*plr
= new Player(this);
133 uint32 guidlow
= (*result
)[0].GetUInt32();
134 sLog
.outDetail("Loading char guid %u from account %u.",guidlow
,GetAccountId());
136 if(plr
->MinimalLoadFromDB( result
, guidlow
))
138 plr
->BuildEnumData( result
, &data
);
142 while( result
->NextRow() );
148 data
.put
<uint8
>(0, num
);
153 void WorldSession::HandleCharEnumOpcode( WorldPacket
& /*recv_data*/ )
155 /// get all the data necessary for loading all characters (along with their pets) on the account
156 CharacterDatabase
.AsyncPQuery(&chrHandler
, &CharacterHandler::HandleCharEnumCallback
, GetAccountId(),
157 !sWorld
.getConfig(CONFIG_DECLINED_NAMES_USED
) ?
158 // ------- Query Without Declined Names --------
160 "SELECT characters.guid, characters.data, characters.name, characters.position_x, characters.position_y, characters.position_z, characters.map, characters.totaltime, characters.leveltime, "
162 "characters.at_login, character_pet.entry, character_pet.modelid, character_pet.level "
163 "FROM characters LEFT JOIN character_pet ON characters.guid=character_pet.owner AND character_pet.slot='0' "
164 "WHERE characters.account = '%u' ORDER BY characters.guid"
166 // --------- Query With Declined Names ---------
168 "SELECT characters.guid, characters.data, characters.name, characters.position_x, characters.position_y, characters.position_z, characters.map, characters.totaltime, characters.leveltime, "
170 "characters.at_login, character_pet.entry, character_pet.modelid, character_pet.level, genitive "
171 "FROM characters LEFT JOIN character_pet ON characters.guid = character_pet.owner AND character_pet.slot='0' "
172 "LEFT JOIN character_declinedname ON characters.guid = character_declinedname.guid "
173 "WHERE characters.account = '%u' ORDER BY characters.guid",
177 void WorldSession::HandleCharCreateOpcode( WorldPacket
& recv_data
)
179 CHECK_PACKET_SIZE(recv_data
,1+1+1+1+1+1+1+1+1+1);
186 // recheck with known string size
187 CHECK_PACKET_SIZE(recv_data
,(name
.size()+1)+1+1+1+1+1+1+1+1+1);
192 WorldPacket
data(SMSG_CHAR_CREATE
, 1); // returned with diff.values in all cases
194 if(GetSecurity() == SEC_PLAYER
)
196 if(uint32 mask
= sWorld
.getConfig(CONFIG_CHARACTERS_CREATING_DISABLED
))
198 bool disabled
= false;
200 uint32 team
= Player::TeamForRace(race_
);
203 case ALLIANCE
: disabled
= mask
& (1<<0); break;
204 case HORDE
: disabled
= mask
& (1<<1); break;
209 data
<< (uint8
)CHAR_CREATE_DISABLED
;
216 ChrClassesEntry
const* classEntry
= sChrClassesStore
.LookupEntry(class_
);
217 ChrRacesEntry
const* raceEntry
= sChrRacesStore
.LookupEntry(race_
);
219 if( !classEntry
|| !raceEntry
)
221 data
<< (uint8
)CHAR_CREATE_FAILED
;
223 sLog
.outError("Class: %u or Race %u not found in DBC (Wrong DBC files?) or Cheater?", class_
, race_
);
227 // prevent character creating Expansion race without Expansion account
228 if (raceEntry
->addon
> Expansion())
230 data
<< (uint8
)CHAR_CREATE_EXPANSION
;
231 sLog
.outError("Expansion %u account:[%d] tried to Create character with expansion %u race (%u)",Expansion(),GetAccountId(),raceEntry
->addon
,race_
);
236 // prevent character creating Expansion class without Expansion account
237 if (classEntry
->addon
> Expansion())
239 data
<< (uint8
)CHAR_CREATE_EXPANSION_CLASS
;
240 sLog
.outError("Expansion %u account:[%d] tried to Create character with expansion %u class (%u)",Expansion(),GetAccountId(),classEntry
->addon
,class_
);
245 // prevent character creating with invalid name
246 if(!normalizePlayerName(name
))
248 data
<< (uint8
)CHAR_NAME_INVALID_CHARACTER
;
250 sLog
.outError("Account:[%d] but tried to Create character with empty [name] ",GetAccountId());
254 // check name limitations
255 if(!ObjectMgr::IsValidName(name
,true))
257 data
<< (uint8
)CHAR_NAME_INVALID_CHARACTER
;
262 if(GetSecurity() == SEC_PLAYER
&& objmgr
.IsReservedName(name
))
264 data
<< (uint8
)CHAR_NAME_RESERVED
;
269 if(objmgr
.GetPlayerGUIDByName(name
))
271 data
<< (uint8
)CHAR_CREATE_NAME_IN_USE
;
276 QueryResult
*resultacct
= loginDatabase
.PQuery("SELECT SUM(numchars) FROM realmcharacters WHERE acctid = '%d'", GetAccountId());
279 Field
*fields
=resultacct
->Fetch();
280 uint32 acctcharcount
= fields
[0].GetUInt32();
283 if (acctcharcount
>= sWorld
.getConfig(CONFIG_CHARACTERS_PER_ACCOUNT
))
285 data
<< (uint8
)CHAR_CREATE_ACCOUNT_LIMIT
;
291 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT COUNT(guid) FROM characters WHERE account = '%d'", GetAccountId());
295 Field
*fields
=result
->Fetch();
296 charcount
= fields
[0].GetUInt8();
299 if (charcount
>= sWorld
.getConfig(CONFIG_CHARACTERS_PER_REALM
))
301 data
<< (uint8
)CHAR_CREATE_SERVER_LIMIT
;
307 bool AllowTwoSideAccounts
= !sWorld
.IsPvPRealm() || sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_ACCOUNTS
) || GetSecurity() > SEC_PLAYER
;
308 uint32 skipCinematics
= sWorld
.getConfig(CONFIG_SKIP_CINEMATICS
);
310 bool have_same_race
= false;
311 if(!AllowTwoSideAccounts
|| skipCinematics
== 1 || class_
== CLASS_DEATH_KNIGHT
)
313 QueryResult
*result2
= CharacterDatabase
.PQuery("SELECT race,class FROM characters WHERE account = '%u' %s",
314 GetAccountId(), (skipCinematics
== 1 || class_
== CLASS_DEATH_KNIGHT
) ? "" : "LIMIT 1");
317 uint32 team_
= Player::TeamForRace(race_
);
319 Field
* field
= result2
->Fetch();
320 uint8 acc_race
= field
[0].GetUInt32();
322 if(class_
== CLASS_DEATH_KNIGHT
)
324 uint8 acc_class
= field
[1].GetUInt32();
325 if(acc_class
== CLASS_DEATH_KNIGHT
)
327 data
<< (uint8
)CHAR_CREATE_UNIQUE_CLASS_LIMIT
;
333 // need to check team only for first character
334 // TODO: what to if account already has characters of both races?
335 if (!AllowTwoSideAccounts
)
339 acc_team
= Player::TeamForRace(acc_race
);
341 if(acc_team
!= team_
)
343 data
<< (uint8
)CHAR_CREATE_PVP_TEAMS_VIOLATION
;
350 // search same race for cinematic or same class if need
351 // TODO: check if cinematic already shown? (already logged in?; cinematic field)
352 while ((skipCinematics
== 1 && !have_same_race
) || class_
== CLASS_DEATH_KNIGHT
)
354 if(!result2
->NextRow())
357 field
= result2
->Fetch();
358 acc_race
= field
[0].GetUInt32();
361 have_same_race
= race_
== acc_race
;
363 if(class_
== CLASS_DEATH_KNIGHT
)
365 uint8 acc_class
= field
[1].GetUInt32();
366 if(acc_class
== CLASS_DEATH_KNIGHT
)
368 data
<< (uint8
)CHAR_CREATE_UNIQUE_CLASS_LIMIT
;
378 // extract other data required for player creating
379 uint8 gender
, skin
, face
, hairStyle
, hairColor
, facialHair
, outfitId
;
380 recv_data
>> gender
>> skin
>> face
;
381 recv_data
>> hairStyle
>> hairColor
>> facialHair
>> outfitId
;
383 Player
* pNewChar
= new Player(this);
384 if(!pNewChar
->Create( objmgr
.GenerateLowGuid(HIGHGUID_PLAYER
), name
, race_
, class_
, gender
, skin
, face
, hairStyle
, hairColor
, facialHair
, outfitId
))
386 // Player not create (race/class problem?)
389 data
<< (uint8
)CHAR_CREATE_ERROR
;
395 if(have_same_race
&& skipCinematics
== 1 || skipCinematics
== 2)
396 pNewChar
->setCinematic(1); // not show intro
398 // Player created, save it now
399 pNewChar
->SaveToDB();
402 loginDatabase
.PExecute("DELETE FROM realmcharacters WHERE acctid= '%d' AND realmid = '%d'", GetAccountId(), realmID
);
403 loginDatabase
.PExecute("INSERT INTO realmcharacters (numchars, acctid, realmid) VALUES (%u, %u, %u)", charcount
, GetAccountId(), realmID
);
405 delete pNewChar
; // created only to call SaveToDB()
407 data
<< (uint8
)CHAR_CREATE_SUCCESS
;
410 std::string IP_str
= GetRemoteAddress();
411 sLog
.outBasic("Account: %d (IP: %s) Create Character:[%s]",GetAccountId(),IP_str
.c_str(),name
.c_str());
412 sLog
.outChar("Account: %d (IP: %s) Create Character:[%s]",GetAccountId(),IP_str
.c_str(),name
.c_str());
415 void WorldSession::HandleCharDeleteOpcode( WorldPacket
& recv_data
)
417 CHECK_PACKET_SIZE(recv_data
,8);
422 // can't delete loaded character
423 if(objmgr
.GetPlayer(guid
))
426 uint32 accountId
= 0;
430 if(objmgr
.GetGuildByLeader(guid
))
432 WorldPacket
data(SMSG_CHAR_DELETE
, 1);
433 data
<< (uint8
)CHAR_DELETE_FAILED_GUILD_LEADER
;
438 // is arena team captain
439 if(objmgr
.GetArenaTeamByCapitan(guid
))
441 WorldPacket
data(SMSG_CHAR_DELETE
, 1);
442 data
<< (uint8
)CHAR_DELETE_FAILED_ARENA_CAPTAIN
;
447 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT account,name FROM characters WHERE guid='%u'", GUID_LOPART(guid
));
450 Field
*fields
= result
->Fetch();
451 accountId
= fields
[0].GetUInt32();
452 name
= fields
[1].GetCppString();
456 // prevent deleting other players' characters using cheating tools
457 if(accountId
!= GetAccountId())
460 std::string IP_str
= GetRemoteAddress();
461 sLog
.outBasic("Account: %d (IP: %s) Delete Character:[%s] (guid:%u)",GetAccountId(),IP_str
.c_str(),name
.c_str(),GUID_LOPART(guid
));
462 sLog
.outChar("Account: %d (IP: %s) Delete Character:[%s] (guid: %u)",GetAccountId(),IP_str
.c_str(),name
.c_str(),GUID_LOPART(guid
));
464 if(sLog
.IsOutCharDump()) // optimize GetPlayerDump call
466 std::string dump
= PlayerDumpWriter().GetDump(GUID_LOPART(guid
));
467 sLog
.outCharDump(dump
.c_str(),GetAccountId(),GUID_LOPART(guid
),name
.c_str());
470 Player::DeleteFromDB(guid
, GetAccountId());
472 WorldPacket
data(SMSG_CHAR_DELETE
, 1);
473 data
<< (uint8
)CHAR_DELETE_SUCCESS
;
477 void WorldSession::HandlePlayerLoginOpcode( WorldPacket
& recv_data
)
479 CHECK_PACKET_SIZE(recv_data
,8);
481 m_playerLoading
= true;
482 uint64 playerGuid
= 0;
484 DEBUG_LOG( "WORLD: Recvd Player Logon Message" );
486 recv_data
>> playerGuid
;
488 LoginQueryHolder
*holder
= new LoginQueryHolder(GetAccountId(), playerGuid
);
489 if(!holder
->Initialize())
491 delete holder
; // delete all unprocessed queries
492 m_playerLoading
= false;
496 CharacterDatabase
.DelayQueryHolder(&chrHandler
, &CharacterHandler::HandlePlayerLoginCallback
, holder
);
499 void WorldSession::HandlePlayerLogin(LoginQueryHolder
* holder
)
501 uint64 playerGuid
= holder
->GetGuid();
503 Player
* pCurrChar
= new Player(this);
504 pCurrChar
->GetMotionMaster()->Initialize();
506 // "GetAccountId()==db stored account id" checked in LoadFromDB (prevent login not own character using cheating tools)
507 if(!pCurrChar
->LoadFromDB(GUID_LOPART(playerGuid
), holder
))
509 KickPlayer(); // disconnect client, player no set to session and it will not deleted or saved at kick
510 delete pCurrChar
; // delete it manually
511 delete holder
; // delete all unprocessed queries
512 m_playerLoading
= false;
516 SetPlayer(pCurrChar
);
518 pCurrChar
->SendDungeonDifficulty(false);
520 WorldPacket
data( SMSG_LOGIN_VERIFY_WORLD
, 20 );
521 data
<< pCurrChar
->GetMapId();
522 data
<< pCurrChar
->GetPositionX();
523 data
<< pCurrChar
->GetPositionY();
524 data
<< pCurrChar
->GetPositionZ();
525 data
<< pCurrChar
->GetOrientation();
528 data
.Initialize( SMSG_ACCOUNT_DATA_TIMES
, 4+1+8*4 ); // changed in WotLK
529 data
<< uint32(time(NULL
)); // unix time of something
531 for(int i
= 0; i
< NUM_ACCOUNT_DATA_TYPES
; i
++)
532 data
<< uint32(GetAccountData(i
)->Time
); // also unix time
535 data
.Initialize(SMSG_FEATURE_SYSTEM_STATUS
, 2); // added in 2.2.0
536 data
<< uint8(2); // unknown value
537 data
<< uint8(0); // enable(1)/disable(0) voice chat interface in client
542 data
.Initialize(SMSG_MOTD
, 50); // new in 2.0.1
546 std::string str_motd
= sWorld
.GetMotd();
547 std::string::size_type pos
, nextpos
;
550 while ( (nextpos
= str_motd
.find('@',pos
)) != std::string::npos
)
554 data
<< str_motd
.substr(pos
,nextpos
-pos
);
560 if (pos
<str_motd
.length())
562 data
<< str_motd
.substr(pos
);
566 data
.put(0, linecount
);
569 DEBUG_LOG( "WORLD: Sent motd (SMSG_MOTD)" );
572 if(pCurrChar
->GetGuildId() != 0)
574 Guild
* guild
= objmgr
.GetGuildById(pCurrChar
->GetGuildId());
577 data
.Initialize(SMSG_GUILD_EVENT
, (2+guild
->GetMOTD().size()+1));
578 data
<< (uint8
)GE_MOTD
;
580 data
<< guild
->GetMOTD();
582 DEBUG_LOG( "WORLD: Sent guild-motd (SMSG_GUILD_EVENT)" );
584 data
.Initialize(SMSG_GUILD_EVENT
, (5+10)); // we guess size
585 data
<<(uint8
)GE_SIGNED_ON
;
587 data
<<pCurrChar
->GetName();
588 data
<<pCurrChar
->GetGUID();
589 guild
->BroadcastPacket(&data
);
590 DEBUG_LOG( "WORLD: Sent guild-signed-on (SMSG_GUILD_EVENT)" );
592 // Increment online members of the guild
593 guild
->IncOnlineMemberCount();
597 // remove wrong guild data
598 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());
599 pCurrChar
->SetUInt32Value(PLAYER_GUILDID
,0);
600 pCurrChar
->SetUInt32ValueInDB(PLAYER_GUILDID
,0,pCurrChar
->GetGUID());
604 if(!pCurrChar
->isAlive())
605 pCurrChar
->SendCorpseReclaimDelay(true);
607 pCurrChar
->SendInitialPacketsBeforeAddToMap();
609 //Show cinematic at the first time that player login
610 if( !pCurrChar
->getCinematic() )
612 pCurrChar
->setCinematic(1);
614 if(ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(pCurrChar
->getClass()))
616 data
.Initialize(SMSG_TRIGGER_CINEMATIC
, 4);
617 data
<< uint32(cEntry
->CinematicSequence
);
620 else if(ChrRacesEntry
const* rEntry
= sChrRacesStore
.LookupEntry(pCurrChar
->getRace()))
622 data
.Initialize(SMSG_TRIGGER_CINEMATIC
, 4);
623 data
<< uint32(rEntry
->CinematicSequence
);
628 //QueryResult *result = CharacterDatabase.PQuery("SELECT guildid,rank FROM guild_member WHERE guid = '%u'",pCurrChar->GetGUIDLow());
629 QueryResult
*resultGuild
= holder
->GetResult(PLAYER_LOGIN_QUERY_LOADGUILD
);
633 Field
*fields
= resultGuild
->Fetch();
634 pCurrChar
->SetInGuild(fields
[0].GetUInt32());
635 pCurrChar
->SetRank(fields
[1].GetUInt32());
638 else if(pCurrChar
->GetGuildId()) // clear guild related fields in case wrong data about non existed membership
640 pCurrChar
->SetInGuild(0);
641 pCurrChar
->SetRank(0);
644 if (!pCurrChar
->GetMap()->Add(pCurrChar
))
646 AreaTrigger
const* at
= objmgr
.GetGoBackTrigger(pCurrChar
->GetMapId());
648 pCurrChar
->TeleportTo(at
->target_mapId
, at
->target_X
, at
->target_Y
, at
->target_Z
, pCurrChar
->GetOrientation());
650 pCurrChar
->TeleportTo(pCurrChar
->m_homebindMapId
, pCurrChar
->m_homebindX
, pCurrChar
->m_homebindY
, pCurrChar
->m_homebindZ
, pCurrChar
->GetOrientation());
653 ObjectAccessor::Instance().AddObject(pCurrChar
);
654 //sLog.outDebug("Player %s added to Map.",pCurrChar->GetName());
655 pCurrChar
->GetSocial()->SendSocialList();
657 pCurrChar
->SendInitialPacketsAfterAddToMap();
659 CharacterDatabase
.PExecute("UPDATE characters SET online = 1 WHERE guid = '%u'", pCurrChar
->GetGUIDLow());
660 loginDatabase
.PExecute("UPDATE account SET online = 1 WHERE id = '%u'", GetAccountId());
661 pCurrChar
->SetInGameTime( getMSTime() );
663 // announce group about member online (must be after add to player list to receive announce to self)
664 if(Group
*group
= pCurrChar
->GetGroup())
666 //pCurrChar->groupInfo.group->SendInit(this); // useless
671 sSocialMgr
.SendFriendStatus(pCurrChar
, FRIEND_ONLINE
, pCurrChar
->GetGUIDLow(), true);
673 // Place character in world (and load zone) before some object loading
674 pCurrChar
->LoadCorpse();
676 // setting Ghost+speed if dead
677 //if ( pCurrChar->m_deathState == DEAD )
678 if (pCurrChar
->m_deathState
!= ALIVE
)
680 // not blizz like, we must correctly save and load player instead...
681 if(pCurrChar
->getRace() == RACE_NIGHTELF
)
682 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)
683 pCurrChar
->CastSpell(pCurrChar
, 8326, true, 0); // auras SPELL_AURA_GHOST, SPELL_AURA_INCREASE_SPEED(why?), SPELL_AURA_INCREASE_SWIM_SPEED(why?)
685 //pCurrChar->SetUInt32Value(UNIT_FIELD_AURA+41, 8326);
686 //pCurrChar->SetUInt32Value(UNIT_FIELD_AURA+42, 20584);
687 //pCurrChar->SetUInt32Value(UNIT_FIELD_AURAFLAGS+6, 238);
688 //pCurrChar->SetUInt32Value(UNIT_FIELD_AURALEVELS+11, 514);
689 //pCurrChar->SetUInt32Value(UNIT_FIELD_AURAAPPLICATIONS+11, 65535);
690 //pCurrChar->SetUInt32Value(UNIT_FIELD_DISPLAYID, 1825);
691 //if (pCurrChar->getRace() == RACE_NIGHTELF)
693 // pCurrChar->SetSpeed(MOVE_RUN, 1.5f*1.2f, true);
694 // pCurrChar->SetSpeed(MOVE_SWIM, 1.5f*1.2f, true);
698 // pCurrChar->SetSpeed(MOVE_RUN, 1.5f, true);
699 // pCurrChar->SetSpeed(MOVE_SWIM, 1.5f, true);
701 pCurrChar
->SetMovement(MOVE_WATER_WALK
);
704 if(uint32 sourceNode
= pCurrChar
->m_taxi
.GetTaxiSource())
707 sLog
.outDebug( "WORLD: Restart character %u taxi flight", pCurrChar
->GetGUIDLow() );
709 uint32 MountId
= objmgr
.GetTaxiMount(sourceNode
, pCurrChar
->GetTeam());
710 uint32 path
= pCurrChar
->m_taxi
.GetCurrentTaxiPath();
712 // search appropriate start path node
713 uint32 startNode
= 0;
715 TaxiPathNodeList
const& nodeList
= sTaxiPathNodesByPath
[path
];
717 float distPrev
= MAP_SIZE
*MAP_SIZE
;
719 (nodeList
[0].x
-pCurrChar
->GetPositionX())*(nodeList
[0].x
-pCurrChar
->GetPositionX())+
720 (nodeList
[0].y
-pCurrChar
->GetPositionY())*(nodeList
[0].y
-pCurrChar
->GetPositionY())+
721 (nodeList
[0].z
-pCurrChar
->GetPositionZ())*(nodeList
[0].z
-pCurrChar
->GetPositionZ());
723 for(uint32 i
= 1; i
< nodeList
.size(); ++i
)
725 TaxiPathNode
const& node
= nodeList
[i
];
726 TaxiPathNode
const& prevNode
= nodeList
[i
-1];
728 // skip nodes at another map
729 if(node
.mapid
!= pCurrChar
->GetMapId())
735 (node
.x
-pCurrChar
->GetPositionX())*(node
.x
-pCurrChar
->GetPositionX())+
736 (node
.y
-pCurrChar
->GetPositionY())*(node
.y
-pCurrChar
->GetPositionY())+
737 (node
.z
-pCurrChar
->GetPositionZ())*(node
.z
-pCurrChar
->GetPositionZ());
740 (node
.x
-prevNode
.x
)*(node
.x
-prevNode
.x
)+
741 (node
.y
-prevNode
.y
)*(node
.y
-prevNode
.y
)+
742 (node
.z
-prevNode
.z
)*(node
.z
-prevNode
.z
);
744 if(distNext
+ distPrev
< distNodes
)
751 SendDoFlight( MountId
, path
, startNode
);
754 // Load pet if any and player is alive and not in taxi flight
755 if(pCurrChar
->isAlive() && pCurrChar
->m_taxi
.GetTaxiSource()==0)
756 pCurrChar
->LoadPet();
758 // Set FFA PvP for non GM in non-rest mode
759 if(sWorld
.IsFFAPvPRealm() && !pCurrChar
->isGameMaster() && !pCurrChar
->HasFlag(PLAYER_FLAGS
,PLAYER_FLAGS_RESTING
) )
760 pCurrChar
->SetFlag(PLAYER_FLAGS
,PLAYER_FLAGS_FFA_PVP
);
762 if(pCurrChar
->HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_CONTESTED_PVP
))
763 pCurrChar
->SetContestedPvP();
765 // Apply at_login requests
766 if(pCurrChar
->HasAtLoginFlag(AT_LOGIN_RESET_SPELLS
))
768 pCurrChar
->resetSpells();
769 SendNotification(LANG_RESET_SPELLS
);
772 if(pCurrChar
->HasAtLoginFlag(AT_LOGIN_RESET_TALENTS
))
774 pCurrChar
->resetTalents(true);
775 SendNotification(LANG_RESET_TALENTS
);
778 // show time before shutdown if shutdown planned.
779 if(sWorld
.IsShutdowning())
780 sWorld
.ShutdownMsg(true,pCurrChar
);
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 m_playerLoading
= false;
793 void WorldSession::HandleSetFactionAtWar( WorldPacket
& recv_data
)
795 CHECK_PACKET_SIZE(recv_data
,4+1);
797 DEBUG_LOG( "WORLD: Received CMSG_SET_FACTION_ATWAR" );
802 recv_data
>> repListID
;
805 FactionStateList::iterator itr
= GetPlayer()->m_factions
.find(repListID
);
806 if (itr
== GetPlayer()->m_factions
.end())
809 // always invisible or hidden faction can't change war state
810 if(itr
->second
.Flags
& (FACTION_FLAG_INVISIBLE_FORCED
|FACTION_FLAG_HIDDEN
) )
813 GetPlayer()->SetFactionAtWar(&itr
->second
,flag
);
816 //I think this function is never used :/ I dunno, but i guess this opcode not exists
817 void WorldSession::HandleSetFactionCheat( WorldPacket
& /*recv_data*/ )
819 //CHECK_PACKET_SIZE(recv_data,4+4);
821 //sLog.outDebug("WORLD SESSION: HandleSetFactionCheat");
826 recv_data >> FactionID;
827 recv_data >> Standing;
829 std::list<struct Factions>::iterator itr;
831 for(itr = GetPlayer()->factions.begin(); itr != GetPlayer()->factions.end(); ++itr)
833 if(itr->ReputationListID == FactionID)
835 itr->Standing += Standing;
836 itr->Flags = (itr->Flags | 1);
841 GetPlayer()->UpdateReputation();
844 void WorldSession::HandleMeetingStoneInfo( WorldPacket
& /*recv_data*/ )
846 DEBUG_LOG( "WORLD: Received CMSG_MEETING_STONE_INFO" );
848 WorldPacket
data(SMSG_MEETINGSTONE_SETQUEUE
, 5);
849 data
<< uint32(0) << uint8(6);
853 void WorldSession::HandleTutorialFlag( WorldPacket
& recv_data
)
855 CHECK_PACKET_SIZE(recv_data
,4);
860 uint32 wInt
= (iFlag
/ 32);
863 //sLog.outError("CHEATER? Account:[%d] Guid[%u] tried to send wrong CMSG_TUTORIAL_FLAG", GetAccountId(),GetGUID());
866 uint32 rInt
= (iFlag
% 32);
868 uint32 tutflag
= GetPlayer()->GetTutorialInt( wInt
);
869 tutflag
|= (1 << rInt
);
870 GetPlayer()->SetTutorialInt( wInt
, tutflag
);
872 //sLog.outDebug("Received Tutorial Flag Set {%u}.", iFlag);
875 void WorldSession::HandleTutorialClear( WorldPacket
& /*recv_data*/ )
877 for ( uint32 iI
= 0; iI
< 8; iI
++)
878 GetPlayer()->SetTutorialInt( iI
, 0xFFFFFFFF );
881 void WorldSession::HandleTutorialReset( WorldPacket
& /*recv_data*/ )
883 for ( uint32 iI
= 0; iI
< 8; iI
++)
884 GetPlayer()->SetTutorialInt( iI
, 0x00000000 );
887 void WorldSession::HandleSetWatchedFactionIndexOpcode(WorldPacket
& recv_data
)
889 CHECK_PACKET_SIZE(recv_data
,4);
891 DEBUG_LOG("WORLD: Received CMSG_SET_WATCHED_FACTION");
894 GetPlayer()->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, fact
);
897 void WorldSession::HandleSetWatchedFactionInactiveOpcode(WorldPacket
& recv_data
)
899 CHECK_PACKET_SIZE(recv_data
,4+1);
901 DEBUG_LOG("WORLD: Received CMSG_SET_FACTION_INACTIVE");
904 recv_data
>> replistid
>> inactive
;
906 FactionStateList::iterator itr
= _player
->m_factions
.find(replistid
);
907 if (itr
== _player
->m_factions
.end())
910 _player
->SetFactionInactive(&itr
->second
, inactive
);
913 void WorldSession::HandleToggleHelmOpcode( WorldPacket
& /*recv_data*/ )
915 DEBUG_LOG("CMSG_TOGGLE_HELM for %s", _player
->GetName());
916 _player
->ToggleFlag(PLAYER_FLAGS
, PLAYER_FLAGS_HIDE_HELM
);
919 void WorldSession::HandleToggleCloakOpcode( WorldPacket
& /*recv_data*/ )
921 DEBUG_LOG("CMSG_TOGGLE_CLOAK for %s", _player
->GetName());
922 _player
->ToggleFlag(PLAYER_FLAGS
, PLAYER_FLAGS_HIDE_CLOAK
);
925 void WorldSession::HandleChangePlayerNameOpcode(WorldPacket
& recv_data
)
927 CHECK_PACKET_SIZE(recv_data
,8+1);
933 CHECK_PACKET_SIZE(recv_data
, 8+1);
936 recv_data
>> newname
;
938 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT at_login FROM characters WHERE guid ='%u'", GUID_LOPART(guid
));
941 uint32 at_loginFlags
;
942 Field
*fields
= result
->Fetch();
943 at_loginFlags
= fields
[0].GetUInt32();
946 if (!(at_loginFlags
& AT_LOGIN_RENAME
))
948 WorldPacket
data(SMSG_CHAR_RENAME
, 1);
949 data
<< (uint8
)CHAR_CREATE_ERROR
;
956 WorldPacket
data(SMSG_CHAR_RENAME
, 1);
957 data
<< (uint8
)CHAR_CREATE_ERROR
;
962 if(!objmgr
.GetPlayerNameByGUID(guid
, oldname
)) // character not exist, because we have no name for this guid
964 WorldPacket
data(SMSG_CHAR_RENAME
, 1);
965 data
<< (uint8
)CHAR_LOGIN_NO_CHARACTER
;
970 // prevent character rename to invalid name
971 if(!normalizePlayerName(newname
))
973 WorldPacket
data(SMSG_CHAR_RENAME
, 1);
974 data
<< (uint8
)CHAR_NAME_NO_NAME
;
979 if(!ObjectMgr::IsValidName(newname
,true))
981 WorldPacket
data(SMSG_CHAR_RENAME
, 1);
982 data
<< (uint8
)CHAR_NAME_INVALID_CHARACTER
;
987 // check name limitations
988 if(GetSecurity() == SEC_PLAYER
&& objmgr
.IsReservedName(newname
))
990 WorldPacket
data(SMSG_CHAR_RENAME
, 1);
991 data
<< (uint8
)CHAR_NAME_RESERVED
;
996 if(objmgr
.GetPlayerGUIDByName(newname
)) // character with this name already exist
998 WorldPacket
data(SMSG_CHAR_RENAME
, 1);
999 data
<< (uint8
)CHAR_CREATE_ERROR
;
1000 SendPacket( &data
);
1004 if(newname
== oldname
) // checked by client
1006 WorldPacket
data(SMSG_CHAR_RENAME
, 1);
1007 data
<< (uint8
)CHAR_NAME_FAILURE
;
1008 SendPacket( &data
);
1012 // we have to check character at_login_flag & AT_LOGIN_RENAME also (fake packets hehe)
1014 CharacterDatabase
.escape_string(newname
);
1015 CharacterDatabase
.PExecute("UPDATE characters set name = '%s', at_login = at_login & ~ %u WHERE guid ='%u'", newname
.c_str(), uint32(AT_LOGIN_RENAME
),GUID_LOPART(guid
));
1016 CharacterDatabase
.PExecute("DELETE FROM character_declinedname WHERE guid ='%u'", GUID_LOPART(guid
));
1018 std::string IP_str
= GetRemoteAddress();
1019 sLog
.outChar("Account: %d (IP: %s) Character:[%s] (guid:%u) Changed name to: %s",GetAccountId(),IP_str
.c_str(),oldname
.c_str(),GUID_LOPART(guid
),newname
.c_str());
1021 WorldPacket
data(SMSG_CHAR_RENAME
,1+8+(newname
.size()+1));
1022 data
<< (uint8
)RESPONSE_SUCCESS
;
1028 void WorldSession::HandleDeclinedPlayerNameOpcode(WorldPacket
& recv_data
)
1032 CHECK_PACKET_SIZE(recv_data
, 8);
1035 // not accept declined names for unsupported languages
1037 if(!objmgr
.GetPlayerNameByGUID(guid
, name
))
1039 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1041 data
<< uint64(guid
);
1047 if(!Utf8toWStr(name
, wname
))
1049 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1051 data
<< uint64(guid
);
1056 if(!isCyrillicCharacter(wname
[0])) // name already stored as only single alphabet using
1058 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1060 data
<< uint64(guid
);
1066 DeclinedName declinedname
;
1068 CHECK_PACKET_SIZE(recv_data
, recv_data
.rpos() + 1);
1071 if(name2
!= name
) // character have different name
1073 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1075 data
<< uint64(guid
);
1080 for(int i
= 0; i
< MAX_DECLINED_NAME_CASES
; ++i
)
1082 CHECK_PACKET_SIZE(recv_data
, recv_data
.rpos() + 1);
1083 recv_data
>> declinedname
.name
[i
];
1084 if(!normalizePlayerName(declinedname
.name
[i
]))
1086 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1088 data
<< uint64(guid
);
1094 if(!ObjectMgr::CheckDeclinedNames(GetMainPartOfName(wname
, 0), declinedname
))
1096 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1098 data
<< uint64(guid
);
1103 for(int i
= 0; i
< MAX_DECLINED_NAME_CASES
; ++i
)
1104 CharacterDatabase
.escape_string(declinedname
.name
[i
]);
1106 CharacterDatabase
.BeginTransaction();
1107 CharacterDatabase
.PExecute("DELETE FROM character_declinedname WHERE guid = '%u'", GUID_LOPART(guid
));
1108 CharacterDatabase
.PExecute("INSERT INTO character_declinedname (guid, genitive, dative, accusative, instrumental, prepositional) VALUES ('%u','%s','%s','%s','%s','%s')",
1109 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());
1110 CharacterDatabase
.CommitTransaction();
1112 WorldPacket
data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT
, 4+8);
1113 data
<< uint32(0); // OK
1114 data
<< uint64(guid
);
1118 void WorldSession::HandleAlterAppearance( WorldPacket
& recv_data
)
1120 sLog
.outDebug("CMSG_ALTER_APPEARANCE");
1122 CHECK_PACKET_SIZE(recv_data
, 4+4+4);
1124 uint32 Hair
, Color
, FacialHair
;
1125 recv_data
>> Hair
>> Color
>> FacialHair
;
1127 BarberShopStyleEntry
const* bs_hair
= sBarberShopStyleStore
.LookupEntry(Hair
);
1129 if(!bs_hair
|| bs_hair
->type
!= 0 || bs_hair
->race
!= _player
->getRace() || bs_hair
->gender
!= _player
->getGender())
1132 BarberShopStyleEntry
const* bs_facialHair
= sBarberShopStyleStore
.LookupEntry(FacialHair
);
1134 if(!bs_facialHair
|| bs_facialHair
->type
!= 2 || bs_facialHair
->race
!= _player
->getRace() || bs_facialHair
->gender
!= _player
->getGender())
1137 uint32 Cost
= _player
->GetBarberShopCost(bs_hair
->hair_id
, Color
, bs_facialHair
->hair_id
);
1140 // 1,3 - not enough money
1141 // 2 - you have to seat on barber chair
1142 if(_player
->GetMoney() < Cost
)
1144 WorldPacket
data(SMSG_BARBER_SHOP_RESULT
, 4);
1145 data
<< uint32(1); // no money
1151 WorldPacket
data(SMSG_BARBER_SHOP_RESULT
, 4);
1152 data
<< uint32(0); // ok
1156 _player
->SetMoney(_player
->GetMoney() - Cost
); // it isn't free
1158 _player
->SetByteValue(PLAYER_BYTES
, 2, uint8(bs_hair
->hair_id
));
1159 _player
->SetByteValue(PLAYER_BYTES
, 3, uint8(Color
));
1160 _player
->SetByteValue(PLAYER_BYTES_2
, 0, uint8(bs_facialHair
->hair_id
));
1162 _player
->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_VISIT_BARBER_SHOP
, 1);
1164 _player
->SetStandState(0); // stand up
1167 void WorldSession::HandleRemoveGlyph( WorldPacket
& recv_data
)
1169 CHECK_PACKET_SIZE(recv_data
, 4);
1176 sLog
.outDebug("Client sent wrong glyph slot number in opcode CMSG_REMOVE_GLYPH %u", slot
);
1180 if(uint32 glyph
= _player
->GetGlyph(slot
))
1182 if(GlyphPropertiesEntry
const *gp
= sGlyphPropertiesStore
.LookupEntry(glyph
))
1184 _player
->RemoveAurasDueToSpell(gp
->SpellId
);
1185 _player
->SetGlyph(slot
, 0);