2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "Database/DatabaseEnv.h"
22 #include "Database/DatabaseImpl.h"
23 #include "WorldPacket.h"
28 #include "ObjectMgr.h"
29 #include "WorldSession.h"
30 #include "Auth/BigNumber.h"
31 #include "Auth/Sha1.h"
32 #include "UpdateData.h"
35 #include "ScriptCalls.h"
36 #include <zlib/zlib.h>
37 #include "MapManager.h"
38 #include "ObjectAccessor.h"
40 #include "BattleGround.h"
41 #include "SpellAuras.h"
43 #include "SocialMgr.h"
45 void WorldSession::HandleRepopRequestOpcode( WorldPacket
& /*recv_data*/ )
47 sLog
.outDebug( "WORLD: Recvd CMSG_REPOP_REQUEST Message" );
49 if(GetPlayer()->isAlive()||GetPlayer()->HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_GHOST
))
52 // the world update order is sessions, players, creatures
53 // the netcode runs in parallel with all of these
54 // creatures can kill players
55 // so if the server is lagging enough the player can
56 // release spirit after he's killed but before he is updated
57 if(GetPlayer()->getDeathState() == JUST_DIED
)
59 sLog
.outDebug("HandleRepopRequestOpcode: got request after player %s(%d) was killed and before he was updated", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow());
60 GetPlayer()->KillPlayer();
63 //this is spirit release confirm?
64 GetPlayer()->RemovePet(NULL
,PET_SAVE_NOT_IN_SLOT
, true);
65 GetPlayer()->BuildPlayerRepop();
66 GetPlayer()->RepopAtGraveyard();
69 void WorldSession::HandleWhoOpcode( WorldPacket
& recv_data
)
71 CHECK_PACKET_SIZE(recv_data
,4+4+1+1+4+4+4+4);
73 sLog
.outDebug( "WORLD: Recvd CMSG_WHO Message" );
74 //recv_data.hexlike();
76 uint32 clientcount
= 0;
78 uint32 level_min
, level_max
, racemask
, classmask
, zones_count
, str_count
;
79 uint32 zoneids
[10]; // 10 is client limit
80 std::string player_name
, guild_name
;
82 recv_data
>> level_min
; // maximal player level, default 0
83 recv_data
>> level_max
; // minimal player level, default 100 (MAX_LEVEL)
84 recv_data
>> player_name
; // player name, case sensitive...
87 CHECK_PACKET_SIZE(recv_data
,4+4+(player_name
.size()+1)+1+4+4+4+4);
89 recv_data
>> guild_name
; // guild name, case sensitive...
92 CHECK_PACKET_SIZE(recv_data
,4+4+(player_name
.size()+1)+(guild_name
.size()+1)+4+4+4+4);
94 recv_data
>> racemask
; // race mask
95 recv_data
>> classmask
; // class mask
96 recv_data
>> zones_count
; // zones count, client limit=10 (2.0.10)
99 return; // can't be received from real client or broken packet
102 CHECK_PACKET_SIZE(recv_data
,4+4+(player_name
.size()+1)+(guild_name
.size()+1)+4+4+4+(4*zones_count
)+4);
104 for(uint32 i
= 0; i
< zones_count
; i
++)
107 recv_data
>> temp
; // zone id, 0 if zone is unknown...
109 sLog
.outDebug("Zone %u: %u", i
, zoneids
[i
]);
112 recv_data
>> str_count
; // user entered strings count, client limit=4 (checked on 2.0.10)
115 return; // can't be received from real client or broken packet
118 CHECK_PACKET_SIZE(recv_data
,4+4+(player_name
.size()+1)+(guild_name
.size()+1)+4+4+4+(4*zones_count
)+4+(1*str_count
));
120 sLog
.outDebug("Minlvl %u, maxlvl %u, name %s, guild %s, racemask %u, classmask %u, zones %u, strings %u", level_min
, level_max
, player_name
.c_str(), guild_name
.c_str(), racemask
, classmask
, zones_count
, str_count
);
122 std::wstring str
[4]; // 4 is client limit
123 for(uint32 i
= 0; i
< str_count
; i
++)
125 // recheck (have one more byte)
126 CHECK_PACKET_SIZE(recv_data
,recv_data
.rpos());
129 recv_data
>> temp
; // user entered string, it used as universal search pattern(guild+player name)?
131 if(!Utf8toWStr(temp
,str
[i
]))
136 sLog
.outDebug("String %u: %s", i
, temp
.c_str());
139 std::wstring wplayer_name
;
140 std::wstring wguild_name
;
141 if(!(Utf8toWStr(player_name
, wplayer_name
) && Utf8toWStr(guild_name
, wguild_name
)))
143 wstrToLower(wplayer_name
);
144 wstrToLower(wguild_name
);
146 // client send in case not set max level value 100 but mangos support 255 max level,
147 // update it to show GMs with characters after 100 level
148 if(level_max
>= MAX_LEVEL
)
149 level_max
= STRONG_MAX_LEVEL
;
151 uint32 team
= _player
->GetTeam();
152 uint32 security
= GetSecurity();
153 bool allowTwoSideWhoList
= sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_WHO_LIST
);
154 bool gmInWhoList
= sWorld
.getConfig(CONFIG_GM_IN_WHO_LIST
);
156 WorldPacket
data( SMSG_WHO
, 50 ); // guess size
157 data
<< clientcount
; // clientcount place holder
158 data
<< clientcount
; // clientcount place holder
160 //TODO: Guard Player map
161 HashMapHolder
<Player
>::MapType
& m
= ObjectAccessor::Instance().GetPlayers();
162 for(HashMapHolder
<Player
>::MapType::iterator itr
= m
.begin(); itr
!= m
.end(); ++itr
)
164 if (security
== SEC_PLAYER
)
166 // player can see member of other team only if CONFIG_ALLOW_TWO_SIDE_WHO_LIST
167 if (itr
->second
->GetTeam() != team
&& !allowTwoSideWhoList
)
170 // player can see MODERATOR, GAME MASTER, ADMINISTRATOR only if CONFIG_GM_IN_WHO_LIST
171 if ((itr
->second
->GetSession()->GetSecurity() > SEC_PLAYER
&& !gmInWhoList
))
175 // check if target is globally visible for player
176 if (!(itr
->second
->IsVisibleGloballyFor(_player
)))
179 // check if target's level is in level range
180 uint32 lvl
= itr
->second
->getLevel();
181 if (lvl
< level_min
|| lvl
> level_max
)
184 // check if class matches classmask
185 uint32 class_
= itr
->second
->getClass();
186 if (!(classmask
& (1 << class_
)))
189 // check if race matches racemask
190 uint32 race
= itr
->second
->getRace();
191 if (!(racemask
& (1 << race
)))
194 uint32 pzoneid
= itr
->second
->GetZoneId();
197 for(uint32 i
= 0; i
< zones_count
; i
++)
199 if(zoneids
[i
] == pzoneid
)
210 std::string pname
= itr
->second
->GetName();
212 if(!Utf8toWStr(pname
,wpname
))
216 if (!(wplayer_name
.empty() || wpname
.find(wplayer_name
) != std::wstring::npos
))
219 std::string gname
= objmgr
.GetGuildNameById(itr
->second
->GetGuildId());
221 if(!Utf8toWStr(gname
,wgname
))
225 if (!(wguild_name
.empty() || wgname
.find(wguild_name
) != std::wstring::npos
))
229 if(AreaTableEntry
const* areaEntry
= GetAreaEntryByAreaID(itr
->second
->GetZoneId()))
230 aname
= areaEntry
->area_name
[GetSessionDbcLocale()];
233 for(uint32 i
= 0; i
< str_count
; i
++)
237 if (wgname
.find(str
[i
]) != std::wstring::npos
||
238 wpname
.find(str
[i
]) != std::wstring::npos
||
239 Utf8FitTo(aname
, str
[i
]) )
250 data
<< pname
; // player name
251 data
<< gname
; // guild name
252 data
<< uint32( lvl
); // player level
253 data
<< uint32( class_
); // player class
254 data
<< uint32( race
); // player race
255 data
<< uint8(0); // new 2.4.0
256 data
<< uint32( pzoneid
); // player zone id
258 // 49 is maximum player count sent to client
259 if ((++clientcount
) == 49)
263 data
.put( 0, clientcount
); //insert right count
264 data
.put( sizeof(uint32
), clientcount
); //insert right count
267 sLog
.outDebug( "WORLD: Send SMSG_WHO Message" );
270 void WorldSession::HandleLogoutRequestOpcode( WorldPacket
& /*recv_data*/ )
272 sLog
.outDebug( "WORLD: Recvd CMSG_LOGOUT_REQUEST Message, security - %u", GetSecurity() );
274 if (uint64 lguid
= GetPlayer()->GetLootGUID())
275 DoLootRelease(lguid
);
277 //Can not logout if...
278 if( GetPlayer()->isInCombat() || //...is in combat
279 GetPlayer()->duel
|| //...is in Duel
280 //...is jumping ...is falling
281 GetPlayer()->HasUnitMovementFlag(MOVEMENTFLAG_JUMPING
| MOVEMENTFLAG_FALLING
))
283 WorldPacket
data( SMSG_LOGOUT_RESPONSE
, (2+4) ) ;
292 //instant logout in taverns/cities or on taxi or for admins, gm's, mod's if its enabled in mangosd.conf
293 if (GetPlayer()->HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_RESTING
) || GetPlayer()->isInFlight() ||
294 GetSecurity() >= sWorld
.getConfig(CONFIG_INSTANT_LOGOUT
))
300 // not set flags if player can't free move to prevent lost state at logout cancel
301 if(GetPlayer()->CanFreeMove())
303 GetPlayer()->SetStandState(UNIT_STAND_STATE_SIT
);
305 WorldPacket
data( SMSG_FORCE_MOVE_ROOT
, (8+4) ); // guess size
306 data
.append(GetPlayer()->GetPackGUID());
309 GetPlayer()->SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_STUNNED
);
312 WorldPacket
data( SMSG_LOGOUT_RESPONSE
, 5 );
316 LogoutRequest(time(NULL
));
319 void WorldSession::HandlePlayerLogoutOpcode( WorldPacket
& /*recv_data*/ )
321 sLog
.outDebug( "WORLD: Recvd CMSG_PLAYER_LOGOUT Message" );
324 void WorldSession::HandleLogoutCancelOpcode( WorldPacket
& /*recv_data*/ )
326 sLog
.outDebug( "WORLD: Recvd CMSG_LOGOUT_CANCEL Message" );
330 WorldPacket
data( SMSG_LOGOUT_CANCEL_ACK
, 0 );
333 // not remove flags if can't free move - its not set in Logout request code.
334 if(GetPlayer()->CanFreeMove())
337 data
.Initialize( SMSG_FORCE_MOVE_UNROOT
, 8 ); // guess size
338 data
.append(GetPlayer()->GetPackGUID());
343 GetPlayer()->SetStandState(UNIT_STAND_STATE_STAND
);
346 GetPlayer()->RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_STUNNED
);
349 sLog
.outDebug( "WORLD: sent SMSG_LOGOUT_CANCEL_ACK Message" );
352 void WorldSession::HandleTogglePvP( WorldPacket
& recv_data
)
354 // this opcode can be used in two ways: Either set explicit new status or toggle old status
355 if(recv_data
.size() == 1)
358 recv_data
>> newPvPStatus
;
359 GetPlayer()->ApplyModFlag(PLAYER_FLAGS
, PLAYER_FLAGS_IN_PVP
, newPvPStatus
);
360 GetPlayer()->ApplyModFlag(PLAYER_FLAGS
, PLAYER_FLAGS_PVP_TIMER
, !newPvPStatus
);
364 GetPlayer()->ToggleFlag(PLAYER_FLAGS
, PLAYER_FLAGS_IN_PVP
);
365 GetPlayer()->ToggleFlag(PLAYER_FLAGS
, PLAYER_FLAGS_PVP_TIMER
);
368 if(GetPlayer()->HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_IN_PVP
))
370 if(!GetPlayer()->IsPvP() || GetPlayer()->pvpInfo
.endTimer
!= 0)
371 GetPlayer()->UpdatePvP(true, true);
375 if(!GetPlayer()->pvpInfo
.inHostileArea
&& GetPlayer()->IsPvP())
376 GetPlayer()->pvpInfo
.endTimer
= time(NULL
); // start toggle-off
380 void WorldSession::HandleZoneUpdateOpcode( WorldPacket
& recv_data
)
382 CHECK_PACKET_SIZE(recv_data
,4);
385 recv_data
>> newZone
;
387 sLog
.outDetail("WORLD: Recvd ZONE_UPDATE: %u", newZone
);
389 if(newZone
!= _player
->GetZoneId())
390 GetPlayer()->SendInitWorldStates(); // only if really enters to new zone, not just area change, works strange...
392 GetPlayer()->UpdateZone(newZone
);
395 void WorldSession::HandleSetTargetOpcode( WorldPacket
& recv_data
)
397 // When this packet send?
398 CHECK_PACKET_SIZE(recv_data
,8);
403 _player
->SetUInt32Value(UNIT_FIELD_TARGET
,guid
);
405 // update reputation list if need
406 Unit
* unit
= ObjectAccessor::GetUnit(*_player
, guid
);
410 _player
->SetFactionVisibleForFactionTemplateId(unit
->getFaction());
413 void WorldSession::HandleSetSelectionOpcode( WorldPacket
& recv_data
)
415 CHECK_PACKET_SIZE(recv_data
,8);
420 _player
->SetSelection(guid
);
422 // update reputation list if need
423 Unit
* unit
= ObjectAccessor::GetUnit(*_player
, guid
);
427 _player
->SetFactionVisibleForFactionTemplateId(unit
->getFaction());
430 void WorldSession::HandleStandStateChangeOpcode( WorldPacket
& recv_data
)
432 CHECK_PACKET_SIZE(recv_data
,1);
434 sLog
.outDebug( "WORLD: Received CMSG_STAND_STATE_CHANGE" );
436 recv_data
>> animstate
;
438 _player
->SetStandState(animstate
);
441 void WorldSession::HandleFriendListOpcode( WorldPacket
& recv_data
)
443 CHECK_PACKET_SIZE(recv_data
, 4);
444 sLog
.outDebug( "WORLD: Received CMSG_CONTACT_LIST" );
447 sLog
.outDebug("unk value is %u", unk
);
448 _player
->GetSocial()->SendSocialList();
451 void WorldSession::HandleAddFriendOpcode( WorldPacket
& recv_data
)
453 CHECK_PACKET_SIZE(recv_data
, 1+1);
455 sLog
.outDebug( "WORLD: Received CMSG_ADD_FRIEND" );
457 std::string friendName
= GetMangosString(LANG_FRIEND_IGNORE_UNKNOWN
);
458 std::string friendNote
;
460 recv_data
>> friendName
;
463 CHECK_PACKET_SIZE(recv_data
, (friendName
.size()+1)+1);
465 recv_data
>> friendNote
;
467 if(!normalizePlayerName(friendName
))
470 CharacterDatabase
.escape_string(friendName
); // prevent SQL injection - normal name don't must changed by this call
472 sLog
.outDebug( "WORLD: %s asked to add friend : '%s'",
473 GetPlayer()->GetName(), friendName
.c_str() );
475 CharacterDatabase
.AsyncPQuery(&WorldSession::HandleAddFriendOpcodeCallBack
, GetAccountId(), friendNote
, "SELECT guid, race FROM characters WHERE name = '%s'", friendName
.c_str());
478 void WorldSession::HandleAddFriendOpcodeCallBack(QueryResult
*result
, uint32 accountId
, std::string friendNote
)
483 uint64 friendGuid
= MAKE_NEW_GUID((*result
)[0].GetUInt32(), 0, HIGHGUID_PLAYER
);
484 uint32 team
= Player::TeamForRace((*result
)[1].GetUInt8());
488 WorldSession
* session
= sWorld
.FindSession(accountId
);
489 if(!session
|| !session
->GetPlayer())
492 FriendsResult friendResult
= FRIEND_NOT_FOUND
;
495 if(friendGuid
==session
->GetPlayer()->GetGUID())
496 friendResult
= FRIEND_SELF
;
497 else if(session
->GetPlayer()->GetTeam() != team
&& !sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_ADD_FRIEND
) && session
->GetSecurity() < SEC_MODERATOR
)
498 friendResult
= FRIEND_ENEMY
;
499 else if(session
->GetPlayer()->GetSocial()->HasFriend(GUID_LOPART(friendGuid
)))
500 friendResult
= FRIEND_ALREADY
;
503 Player
* pFriend
= ObjectAccessor::FindPlayer(friendGuid
);
504 if( pFriend
&& pFriend
->IsInWorld() && pFriend
->IsVisibleGloballyFor(session
->GetPlayer()))
505 friendResult
= FRIEND_ADDED_ONLINE
;
507 friendResult
= FRIEND_ADDED_OFFLINE
;
509 if(!session
->GetPlayer()->GetSocial()->AddToSocialList(GUID_LOPART(friendGuid
), false))
511 friendResult
= FRIEND_LIST_FULL
;
512 sLog
.outDebug( "WORLD: %s's friend list is full.", session
->GetPlayer()->GetName());
515 session
->GetPlayer()->GetSocial()->SetFriendNote(GUID_LOPART(friendGuid
), friendNote
);
519 sSocialMgr
.SendFriendStatus(session
->GetPlayer(), friendResult
, GUID_LOPART(friendGuid
), false);
521 sLog
.outDebug( "WORLD: Sent (SMSG_FRIEND_STATUS)" );
524 void WorldSession::HandleDelFriendOpcode( WorldPacket
& recv_data
)
526 CHECK_PACKET_SIZE(recv_data
, 8);
530 sLog
.outDebug( "WORLD: Received CMSG_DEL_FRIEND" );
532 recv_data
>> FriendGUID
;
534 _player
->GetSocial()->RemoveFromSocialList(GUID_LOPART(FriendGUID
), false);
536 sSocialMgr
.SendFriendStatus(GetPlayer(), FRIEND_REMOVED
, GUID_LOPART(FriendGUID
), false);
538 sLog
.outDebug( "WORLD: Sent motd (SMSG_FRIEND_STATUS)" );
541 void WorldSession::HandleAddIgnoreOpcode( WorldPacket
& recv_data
)
543 CHECK_PACKET_SIZE(recv_data
,1);
545 sLog
.outDebug( "WORLD: Received CMSG_ADD_IGNORE" );
547 std::string IgnoreName
= GetMangosString(LANG_FRIEND_IGNORE_UNKNOWN
);
549 recv_data
>> IgnoreName
;
551 if(!normalizePlayerName(IgnoreName
))
554 CharacterDatabase
.escape_string(IgnoreName
); // prevent SQL injection - normal name don't must changed by this call
556 sLog
.outDebug( "WORLD: %s asked to Ignore: '%s'",
557 GetPlayer()->GetName(), IgnoreName
.c_str() );
559 CharacterDatabase
.AsyncPQuery(&WorldSession::HandleAddIgnoreOpcodeCallBack
, GetAccountId(), "SELECT guid FROM characters WHERE name = '%s'", IgnoreName
.c_str());
562 void WorldSession::HandleAddIgnoreOpcodeCallBack(QueryResult
*result
, uint32 accountId
)
567 uint64 IgnoreGuid
= MAKE_NEW_GUID((*result
)[0].GetUInt32(), 0, HIGHGUID_PLAYER
);
571 WorldSession
* session
= sWorld
.FindSession(accountId
);
572 if(!session
|| !session
->GetPlayer())
575 FriendsResult ignoreResult
= FRIEND_IGNORE_NOT_FOUND
;
578 if(IgnoreGuid
==session
->GetPlayer()->GetGUID()) //not add yourself
579 ignoreResult
= FRIEND_IGNORE_SELF
;
580 else if( session
->GetPlayer()->GetSocial()->HasIgnore(GUID_LOPART(IgnoreGuid
)) )
581 ignoreResult
= FRIEND_IGNORE_ALREADY
;
584 ignoreResult
= FRIEND_IGNORE_ADDED
;
587 if(!session
->GetPlayer()->GetSocial()->AddToSocialList(GUID_LOPART(IgnoreGuid
), true))
588 ignoreResult
= FRIEND_IGNORE_FULL
;
592 sSocialMgr
.SendFriendStatus(session
->GetPlayer(), ignoreResult
, GUID_LOPART(IgnoreGuid
), false);
594 sLog
.outDebug( "WORLD: Sent (SMSG_FRIEND_STATUS)" );
597 void WorldSession::HandleDelIgnoreOpcode( WorldPacket
& recv_data
)
599 CHECK_PACKET_SIZE(recv_data
, 8);
603 sLog
.outDebug( "WORLD: Received CMSG_DEL_IGNORE" );
605 recv_data
>> IgnoreGUID
;
607 _player
->GetSocial()->RemoveFromSocialList(GUID_LOPART(IgnoreGUID
), true);
609 sSocialMgr
.SendFriendStatus(GetPlayer(), FRIEND_IGNORE_REMOVED
, GUID_LOPART(IgnoreGUID
), false);
611 sLog
.outDebug( "WORLD: Sent motd (SMSG_FRIEND_STATUS)" );
614 void WorldSession::HandleSetFriendNoteOpcode( WorldPacket
& recv_data
)
616 CHECK_PACKET_SIZE(recv_data
, 8+1);
619 recv_data
>> guid
>> note
;
620 _player
->GetSocial()->SetFriendNote(guid
, note
);
623 void WorldSession::HandleBugOpcode( WorldPacket
& recv_data
)
625 CHECK_PACKET_SIZE(recv_data
,4+4+1+4+1);
627 uint32 suggestion
, contentlen
;
632 recv_data
>> suggestion
>> contentlen
>> content
;
635 CHECK_PACKET_SIZE(recv_data
,4+4+(content
.size()+1)+4+1);
637 recv_data
>> typelen
>> type
;
639 if( suggestion
== 0 )
640 sLog
.outDebug( "WORLD: Received CMSG_BUG [Bug Report]" );
642 sLog
.outDebug( "WORLD: Received CMSG_BUG [Suggestion]" );
644 sLog
.outDebug( type
.c_str( ) );
645 sLog
.outDebug( content
.c_str( ) );
647 CharacterDatabase
.escape_string(type
);
648 CharacterDatabase
.escape_string(content
);
649 CharacterDatabase
.PExecute ("INSERT INTO bugreport (type,content) VALUES('%s', '%s')", type
.c_str( ), content
.c_str( ));
652 void WorldSession::HandleCorpseReclaimOpcode(WorldPacket
&recv_data
)
654 CHECK_PACKET_SIZE(recv_data
,8);
656 sLog
.outDetail("WORLD: Received CMSG_RECLAIM_CORPSE");
657 if (GetPlayer()->isAlive())
660 // do not allow corpse reclaim in arena
661 if (GetPlayer()->InArena())
664 // body not released yet
665 if(!GetPlayer()->HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_GHOST
))
668 Corpse
*corpse
= GetPlayer()->GetCorpse();
673 // prevent resurrect before 30-sec delay after body release not finished
674 if(corpse
->GetGhostTime() + GetPlayer()->GetCorpseReclaimDelay(corpse
->GetType()==CORPSE_RESURRECTABLE_PVP
) > time(NULL
))
677 float dist
= corpse
->GetDistance2d(GetPlayer());
678 sLog
.outDebug("Corpse 2D Distance: \t%f",dist
);
679 if (dist
> CORPSE_RECLAIM_RADIUS
)
686 GetPlayer()->ResurrectPlayer(GetPlayer()->InBattleGround() ? 1.0f
: 0.5f
);
689 GetPlayer()->SpawnCorpseBones();
691 GetPlayer()->SaveToDB();
694 void WorldSession::HandleResurrectResponseOpcode(WorldPacket
& recv_data
)
696 CHECK_PACKET_SIZE(recv_data
,8+1);
698 sLog
.outDetail("WORLD: Received CMSG_RESURRECT_RESPONSE");
700 if(GetPlayer()->isAlive())
710 GetPlayer()->clearResurrectRequestData(); // reject
714 if(!GetPlayer()->isRessurectRequestedBy(guid
))
717 GetPlayer()->ResurectUsingRequestData();
718 GetPlayer()->SaveToDB();
721 void WorldSession::HandleAreaTriggerOpcode(WorldPacket
& recv_data
)
723 CHECK_PACKET_SIZE(recv_data
,4);
725 sLog
.outDebug("WORLD: Received CMSG_AREATRIGGER");
729 recv_data
>> Trigger_ID
;
730 sLog
.outDebug("Trigger ID:%u",Trigger_ID
);
732 if(GetPlayer()->isInFlight())
734 sLog
.outDebug("Player '%s' (GUID: %u) in flight, ignore Area Trigger ID:%u",GetPlayer()->GetName(),GetPlayer()->GetGUIDLow(), Trigger_ID
);
738 AreaTriggerEntry
const* atEntry
= sAreaTriggerStore
.LookupEntry(Trigger_ID
);
741 sLog
.outDebug("Player '%s' (GUID: %u) send unknown (by DBC) Area Trigger ID:%u",GetPlayer()->GetName(),GetPlayer()->GetGUIDLow(), Trigger_ID
);
745 if (GetPlayer()->GetMapId()!=atEntry
->mapid
)
747 sLog
.outDebug("Player '%s' (GUID: %u) too far (trigger map: %u player map: %u), ignore Area Trigger ID: %u", GetPlayer()->GetName(), atEntry
->mapid
, GetPlayer()->GetMapId(), GetPlayer()->GetGUIDLow(), Trigger_ID
);
751 // delta is safe radius
752 const float delta
= 5.0f
;
753 // check if player in the range of areatrigger
754 Player
* pl
= GetPlayer();
756 if (atEntry
->radius
> 0)
758 // if we have radius check it
759 float dist
= pl
->GetDistance(atEntry
->x
,atEntry
->y
,atEntry
->z
);
760 if(dist
> atEntry
->radius
+ delta
)
762 sLog
.outDebug("Player '%s' (GUID: %u) too far (radius: %f distance: %f), ignore Area Trigger ID: %u",
763 pl
->GetName(), pl
->GetGUIDLow(), atEntry
->radius
, dist
, Trigger_ID
);
769 // we have only extent
770 float dx
= pl
->GetPositionX() - atEntry
->x
;
771 float dy
= pl
->GetPositionY() - atEntry
->y
;
772 float dz
= pl
->GetPositionZ() - atEntry
->z
;
773 double es
= sin(atEntry
->box_orientation
);
774 double ec
= cos(atEntry
->box_orientation
);
775 // calc rotated vector based on extent axis
776 double rotateDx
= dx
*ec
- dy
*es
;
777 double rotateDy
= dx
*es
+ dy
*ec
;
779 if( (fabs(rotateDx
) > atEntry
->box_x
/2 + delta
) ||
780 (fabs(rotateDy
) > atEntry
->box_y
/2 + delta
) ||
781 (fabs(dz
) > atEntry
->box_z
/2 + delta
) )
783 sLog
.outDebug("Player '%s' (GUID: %u) too far (1/2 box X: %f 1/2 box Y: %f 1/2 box Z: %f rotate dX: %f rotate dY: %f dZ:%f), ignore Area Trigger ID: %u",
784 pl
->GetName(), pl
->GetGUIDLow(), atEntry
->box_x
/2, atEntry
->box_y
/2, atEntry
->box_z
/2, rotateDx
, rotateDy
, dz
, Trigger_ID
);
789 if(Script
->scriptAreaTrigger(GetPlayer(), atEntry
))
792 uint32 quest_id
= objmgr
.GetQuestForAreaTrigger( Trigger_ID
);
793 if( quest_id
&& GetPlayer()->isAlive() && GetPlayer()->IsActiveQuest(quest_id
) )
795 Quest
const* pQuest
= objmgr
.GetQuestTemplate(quest_id
);
798 if(GetPlayer()->GetQuestStatus(quest_id
) == QUEST_STATUS_INCOMPLETE
)
799 GetPlayer()->AreaExploredOrEventHappens( quest_id
);
803 if(objmgr
.IsTavernAreaTrigger(Trigger_ID
))
805 // set resting flag we are in the inn
806 GetPlayer()->SetFlag(PLAYER_FLAGS
, PLAYER_FLAGS_RESTING
);
807 GetPlayer()->InnEnter(time(NULL
), atEntry
->mapid
, atEntry
->x
, atEntry
->y
, atEntry
->z
);
808 GetPlayer()->SetRestType(REST_TYPE_IN_TAVERN
);
810 if(sWorld
.IsFFAPvPRealm())
811 GetPlayer()->RemoveByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
816 if(GetPlayer()->InBattleGround())
818 BattleGround
* bg
= GetPlayer()->GetBattleGround();
820 if(bg
->GetStatus() == STATUS_IN_PROGRESS
)
821 bg
->HandleAreaTrigger(GetPlayer(), Trigger_ID
);
826 // NULL if all values default (non teleport trigger)
827 AreaTrigger
const* at
= objmgr
.GetAreaTrigger(Trigger_ID
);
831 if(!GetPlayer()->isGameMaster())
833 uint32 missingLevel
= 0;
834 if(GetPlayer()->getLevel() < at
->requiredLevel
&& !sWorld
.getConfig(CONFIG_INSTANCE_IGNORE_LEVEL
))
835 missingLevel
= at
->requiredLevel
;
837 // must have one or the other, report the first one that's missing
838 uint32 missingItem
= 0;
841 if(!GetPlayer()->HasItemCount(at
->requiredItem
, 1) &&
842 (!at
->requiredItem2
|| !GetPlayer()->HasItemCount(at
->requiredItem2
, 1)))
843 missingItem
= at
->requiredItem
;
845 else if(at
->requiredItem2
&& !GetPlayer()->HasItemCount(at
->requiredItem2
, 1))
846 missingItem
= at
->requiredItem2
;
848 uint32 missingKey
= 0;
849 if(GetPlayer()->GetDifficulty() == DIFFICULTY_HEROIC
)
853 if(!GetPlayer()->HasItemCount(at
->heroicKey
, 1) &&
854 (!at
->heroicKey2
|| !GetPlayer()->HasItemCount(at
->heroicKey2
, 1)))
855 missingKey
= at
->heroicKey
;
857 else if(at
->heroicKey2
&& !GetPlayer()->HasItemCount(at
->heroicKey2
, 1))
858 missingKey
= at
->heroicKey2
;
861 uint32 missingQuest
= 0;
862 if(at
->requiredQuest
&& !GetPlayer()->GetQuestRewardStatus(at
->requiredQuest
))
863 missingQuest
= at
->requiredQuest
;
865 if(missingLevel
|| missingItem
|| missingKey
|| missingQuest
)
867 // TODO: all this is probably wrong
869 SendAreaTriggerMessage(GetMangosString(LANG_LEVEL_MINREQUIRED_AND_ITEM
), at
->requiredLevel
, objmgr
.GetItemPrototype(missingItem
)->Name1
);
871 GetPlayer()->SendTransferAborted(at
->target_mapId
, TRANSFER_ABORT_DIFFICULTY
, DIFFICULTY_HEROIC
);
872 else if(missingQuest
)
873 SendAreaTriggerMessage(at
->requiredFailedText
.c_str());
874 else if(missingLevel
)
875 SendAreaTriggerMessage(GetMangosString(LANG_LEVEL_MINREQUIRED
), missingLevel
);
880 GetPlayer()->TeleportTo(at
->target_mapId
,at
->target_X
,at
->target_Y
,at
->target_Z
,at
->target_Orientation
,TELE_TO_NOT_LEAVE_TRANSPORT
);
883 void WorldSession::HandleUpdateAccountData(WorldPacket
&recv_data
)
885 sLog
.outDetail("WORLD: Received CMSG_UPDATE_ACCOUNT_DATA");
887 CHECK_PACKET_SIZE(recv_data
, 4+4+4);
889 uint32 type
, timestamp
, decompressedSize
;
890 recv_data
>> type
>> timestamp
>> decompressedSize
;
892 sLog
.outDebug("UAD: type %u, time %u, decompressedSize %u", type
, timestamp
, decompressedSize
);
894 if(type
> NUM_ACCOUNT_DATA_TYPES
)
897 if(decompressedSize
== 0) // erase
899 SetAccountData(type
, timestamp
, "");
901 WorldPacket
data(SMSG_UPDATE_ACCOUNT_DATA_COMPLETE
, 4+4);
902 data
<< uint32(type
);
909 if(decompressedSize
> 0xFFFF)
911 sLog
.outError("UAD: Account data packet too big, size %u", decompressedSize
);
916 dest
.resize(decompressedSize
);
918 uLongf realSize
= decompressedSize
;
919 if(uncompress(const_cast<uint8
*>(dest
.contents()), &realSize
, const_cast<uint8
*>(recv_data
.contents() + recv_data
.rpos()), recv_data
.size() - recv_data
.rpos()) != Z_OK
)
921 sLog
.outError("UAD: Failed to decompress account data");
928 SetAccountData(type
, timestamp
, adata
);
930 WorldPacket
data(SMSG_UPDATE_ACCOUNT_DATA_COMPLETE
, 4+4);
931 data
<< uint32(type
);
936 void WorldSession::HandleRequestAccountData(WorldPacket
& recv_data
)
938 sLog
.outDetail("WORLD: Received CMSG_REQUEST_ACCOUNT_DATA");
940 CHECK_PACKET_SIZE(recv_data
, 4);
945 sLog
.outDebug("RAD: type %u", type
);
947 if(type
> NUM_ACCOUNT_DATA_TYPES
)
950 AccountData
*adata
= GetAccountData(type
);
952 uint32 size
= adata
->Data
.size();
957 uLongf destSize
= size
;
958 if(size
&& compress(const_cast<uint8
*>(dest
.contents()), &destSize
, (uint8
*)adata
->Data
.c_str(), size
) != Z_OK
)
960 sLog
.outDebug("RAD: Failed to compress account data");
964 dest
.resize(destSize
);
966 WorldPacket
data (SMSG_UPDATE_ACCOUNT_DATA
, 8+4+4+4+destSize
);
967 data
<< uint64(_player
->GetGUID()); // player guid
968 data
<< uint32(type
); // type (0-7)
969 data
<< uint32(adata
->Time
); // unix time
970 data
<< uint32(size
); // decompressed length
971 data
.append(dest
); // compressed data
975 void WorldSession::HandleSetActionButtonOpcode(WorldPacket
& recv_data
)
977 CHECK_PACKET_SIZE(recv_data
,1+2+1+1);
979 sLog
.outDebug( "WORLD: Received CMSG_SET_ACTION_BUTTON" );
980 uint8 button
, misc
, type
;
982 recv_data
>> button
>> action
>> misc
>> type
;
983 sLog
.outDetail( "BUTTON: %u ACTION: %u TYPE: %u MISC: %u", button
, action
, type
, misc
);
986 sLog
.outDetail( "MISC: Remove action from button %u", button
);
988 GetPlayer()->removeActionButton(button
);
992 if(type
==ACTION_BUTTON_MACRO
|| type
==ACTION_BUTTON_CMACRO
)
994 sLog
.outDetail( "MISC: Added Macro %u into button %u", action
, button
);
995 GetPlayer()->addActionButton(button
,action
,type
,misc
);
997 else if(type
==ACTION_BUTTON_SPELL
)
999 sLog
.outDetail( "MISC: Added Action %u into button %u", action
, button
);
1000 GetPlayer()->addActionButton(button
,action
,type
,misc
);
1002 else if(type
==ACTION_BUTTON_ITEM
)
1004 sLog
.outDetail( "MISC: Added Item %u into button %u", action
, button
);
1005 GetPlayer()->addActionButton(button
,action
,type
,misc
);
1008 sLog
.outError( "MISC: Unknown action button type %u for action %u into button %u", type
, action
, button
);
1012 void WorldSession::HandleCompleteCinema( WorldPacket
& /*recv_data*/ )
1014 DEBUG_LOG( "WORLD: Player is watching cinema" );
1017 void WorldSession::HandleNextCinematicCamera( WorldPacket
& /*recv_data*/ )
1019 DEBUG_LOG( "WORLD: Which movie to play" );
1022 void WorldSession::HandleMoveTimeSkippedOpcode( WorldPacket
& /*recv_data*/ )
1024 /* WorldSession::Update( getMSTime() );*/
1025 DEBUG_LOG( "WORLD: Time Lag/Synchronization Resent/Update" );
1028 CHECK_PACKET_SIZE(recv_data,8+4);
1030 uint32 time_skipped;
1032 recv_data >> time_skipped;
1033 sLog.outDebug( "WORLD: CMSG_MOVE_TIME_SKIPPED" );
1036 must be need use in mangos
1037 We substract server Lags to move time ( AntiLags )
1039 GetPlayer()->ModifyLastMoveTime( -int32(time_skipped) );
1043 void WorldSession::HandleFeatherFallAck(WorldPacket
&/*recv_data*/)
1045 DEBUG_LOG("WORLD: CMSG_MOVE_FEATHER_FALL_ACK");
1048 void WorldSession::HandleMoveUnRootAck(WorldPacket
&/* recv_data*/)
1051 CHECK_PACKET_SIZE(recv_data,8+8+4+4+4+4+4);
1053 sLog.outDebug( "WORLD: CMSG_FORCE_MOVE_UNROOT_ACK" );
1054 recv_data.hexlike();
1064 recv_data >> unknown1;
1065 recv_data >> unknown2;
1066 recv_data >> PositionX;
1067 recv_data >> PositionY;
1068 recv_data >> PositionZ;
1069 recv_data >> Orientation;
1071 // TODO for later may be we can use for anticheat
1072 DEBUG_LOG("Guid " I64FMTD,guid);
1073 DEBUG_LOG("unknown1 " I64FMTD,unknown1);
1074 DEBUG_LOG("unknown2 %u",unknown2);
1075 DEBUG_LOG("X %f",PositionX);
1076 DEBUG_LOG("Y %f",PositionY);
1077 DEBUG_LOG("Z %f",PositionZ);
1078 DEBUG_LOG("O %f",Orientation);
1082 void WorldSession::HandleMoveRootAck(WorldPacket
&/* recv_data*/)
1085 CHECK_PACKET_SIZE(recv_data,8+8+4+4+4+4+4);
1087 sLog.outDebug( "WORLD: CMSG_FORCE_MOVE_ROOT_ACK" );
1088 recv_data.hexlike();
1098 recv_data >> unknown1;
1099 recv_data >> unknown2;
1100 recv_data >> PositionX;
1101 recv_data >> PositionY;
1102 recv_data >> PositionZ;
1103 recv_data >> Orientation;
1105 // for later may be we can use for anticheat
1106 DEBUG_LOG("Guid " I64FMTD,guid);
1107 DEBUG_LOG("unknown1 " I64FMTD,unknown1);
1108 DEBUG_LOG("unknown1 %u",unknown2);
1109 DEBUG_LOG("X %f",PositionX);
1110 DEBUG_LOG("Y %f",PositionY);
1111 DEBUG_LOG("Z %f",PositionZ);
1112 DEBUG_LOG("O %f",Orientation);
1116 void WorldSession::HandleMoveTeleportAck(WorldPacket
&/* recv_data*/)
1119 CHECK_PACKET_SIZE(recv_data,8+4);
1121 sLog.outDebug("MSG_MOVE_TELEPORT_ACK");
1126 recv_data >> flags >> time;
1127 DEBUG_LOG("Guid " I64FMTD,guid);
1128 DEBUG_LOG("Flags %u, time %u",flags, time/1000);
1132 void WorldSession::HandleSetActionBar(WorldPacket
& recv_data
)
1134 CHECK_PACKET_SIZE(recv_data
,1);
1138 recv_data
>> ActionBar
;
1140 if(!GetPlayer()) // ignore until not logged (check needed because STATUS_AUTHED)
1143 sLog
.outError("WorldSession::HandleSetActionBar in not logged state with value: %u, ignored",uint32(ActionBar
));
1147 GetPlayer()->SetByteValue(PLAYER_FIELD_BYTES
, 2, ActionBar
);
1150 void WorldSession::HandleWardenDataOpcode(WorldPacket
& /*recv_data*/)
1153 CHECK_PACKET_SIZE(recv_data,1);
1157 sLog.outDebug("Received opcode CMSG_WARDEN_DATA, not resolve.uint8 = %u",tmp);
1161 void WorldSession::HandlePlayedTime(WorldPacket
& /*recv_data*/)
1163 uint32 TotalTimePlayed
= GetPlayer()->GetTotalPlayedTime();
1164 uint32 LevelPlayedTime
= GetPlayer()->GetLevelPlayedTime();
1166 WorldPacket
data(SMSG_PLAYED_TIME
, 8);
1167 data
<< TotalTimePlayed
;
1168 data
<< LevelPlayedTime
;
1172 void WorldSession::HandleInspectOpcode(WorldPacket
& recv_data
)
1174 CHECK_PACKET_SIZE(recv_data
, 8);
1178 DEBUG_LOG("Inspected guid is " I64FMTD
, guid
);
1180 _player
->SetSelection(guid
);
1182 Player
*plr
= objmgr
.GetPlayer(guid
);
1183 if(!plr
) // wrong player
1186 uint32 talent_points
= 0x3D;
1187 uint32 guid_size
= plr
->GetPackGUID().size();
1188 WorldPacket
data(SMSG_INSPECT_TALENT
, 4+talent_points
);
1189 data
.append(plr
->GetPackGUID());
1190 data
<< uint32(talent_points
);
1192 // fill by 0 talents array
1193 for(uint32 i
= 0; i
< talent_points
; ++i
)
1196 if(sWorld
.getConfig(CONFIG_TALENTS_INSPECTING
) || _player
->isGameMaster())
1198 // find class talent tabs (all players have 3 talent tabs)
1199 uint32
const* talentTabIds
= GetTalentTabPages(plr
->getClass());
1201 uint32 talentTabPos
= 0; // pos of first talent rank in tab including all prev tabs
1202 for(uint32 i
= 0; i
< 3; ++i
)
1204 uint32 talentTabId
= talentTabIds
[i
];
1206 // fill by real data
1207 for(uint32 talentId
= 0; talentId
< sTalentStore
.GetNumRows(); ++talentId
)
1209 TalentEntry
const* talentInfo
= sTalentStore
.LookupEntry(talentId
);
1213 // skip another tab talents
1214 if(talentInfo
->TalentTab
!= talentTabId
)
1218 uint32 curtalent_maxrank
= 0;
1219 for(uint32 k
= 5; k
> 0; --k
)
1221 if(talentInfo
->RankID
[k
-1] && plr
->HasSpell(talentInfo
->RankID
[k
-1]))
1223 curtalent_maxrank
= k
;
1228 // not learned talent
1229 if(!curtalent_maxrank
)
1232 // 1 rank talent bit index
1233 uint32 curtalent_index
= talentTabPos
+ GetTalentInspectBitPosInTab(talentId
);
1235 uint32 curtalent_rank_index
= curtalent_index
+curtalent_maxrank
-1;
1237 // slot/offset in 7-bit bytes
1238 uint32 curtalent_rank_slot7
= curtalent_rank_index
/ 7;
1239 uint32 curtalent_rank_offset7
= curtalent_rank_index
% 7;
1241 // rank pos with skipped 8 bit
1242 uint32 curtalent_rank_index2
= curtalent_rank_slot7
* 8 + curtalent_rank_offset7
;
1244 // slot/offset in 8-bit bytes with skipped high bit
1245 uint32 curtalent_rank_slot
= curtalent_rank_index2
/ 8;
1246 uint32 curtalent_rank_offset
= curtalent_rank_index2
% 8;
1249 uint32 val
= data
.read
<uint8
>(guid_size
+ 4 + curtalent_rank_slot
);
1250 val
|= (1 << curtalent_rank_offset
);
1251 data
.put
<uint8
>(guid_size
+ 4 + curtalent_rank_slot
, val
& 0xFF);
1254 talentTabPos
+= GetTalentTabInspectBitSize(talentTabId
);
1261 void WorldSession::HandleInspectHonorStatsOpcode(WorldPacket
& recv_data
)
1263 CHECK_PACKET_SIZE(recv_data
, 8);
1268 Player
*player
= objmgr
.GetPlayer(guid
);
1272 sLog
.outError("InspectHonorStats: WTF, player not found...");
1276 WorldPacket
data(MSG_INSPECT_HONOR_STATS
, 8+1+4*4);
1277 data
<< uint64(player
->GetGUID());
1278 data
<< uint8(player
->GetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
));
1279 data
<< uint32(player
->GetUInt32Value(PLAYER_FIELD_KILLS
));
1280 data
<< uint32(player
->GetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
));
1281 data
<< uint32(player
->GetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
));
1282 data
<< uint32(player
->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
));
1286 void WorldSession::HandleWorldTeleportOpcode(WorldPacket
& recv_data
)
1288 CHECK_PACKET_SIZE(recv_data
,4+4+4+4+4+4);
1290 // write in client console: worldport 469 452 6454 2536 180 or /console worldport 469 452 6454 2536 180
1291 // Received opcode CMSG_WORLD_TELEPORT
1292 // Time is ***, map=469, x=452.000000, y=6454.000000, z=2536.000000, orient=3.141593
1294 //sLog.outDebug("Received opcode CMSG_WORLD_TELEPORT");
1296 if(GetPlayer()->isInFlight())
1298 sLog
.outDebug("Player '%s' (GUID: %u) in flight, ignore worldport command.",GetPlayer()->GetName(),GetPlayer()->GetGUIDLow());
1309 recv_data
>> time
; // time in m.sec.
1311 recv_data
>> PositionX
;
1312 recv_data
>> PositionY
;
1313 recv_data
>> PositionZ
;
1314 recv_data
>> Orientation
; // o (3.141593 = 180 degrees)
1315 DEBUG_LOG("Time %u sec, map=%u, x=%f, y=%f, z=%f, orient=%f", time
/1000, mapid
, PositionX
, PositionY
, PositionZ
, Orientation
);
1317 if (GetSecurity() >= SEC_ADMINISTRATOR
)
1318 GetPlayer()->TeleportTo(mapid
,PositionX
,PositionY
,PositionZ
,Orientation
);
1320 SendNotification(LANG_YOU_NOT_HAVE_PERMISSION
);
1321 sLog
.outDebug("Received worldport command from player %s", GetPlayer()->GetName());
1324 void WorldSession::HandleWhoisOpcode(WorldPacket
& recv_data
)
1326 CHECK_PACKET_SIZE(recv_data
, 1);
1328 sLog
.outDebug("Received opcode CMSG_WHOIS");
1329 std::string charname
;
1330 recv_data
>> charname
;
1332 if (GetSecurity() < SEC_ADMINISTRATOR
)
1334 SendNotification(LANG_YOU_NOT_HAVE_PERMISSION
);
1338 if(charname
.empty() || !normalizePlayerName (charname
))
1340 SendNotification(LANG_NEED_CHARACTER_NAME
);
1344 Player
*plr
= objmgr
.GetPlayer(charname
.c_str());
1348 SendNotification(LANG_PLAYER_NOT_EXIST_OR_OFFLINE
, charname
.c_str());
1352 uint32 accid
= plr
->GetSession()->GetAccountId();
1354 QueryResult
*result
= loginDatabase
.PQuery("SELECT username,email,last_ip FROM account WHERE id=%u", accid
);
1357 SendNotification(LANG_ACCOUNT_FOR_PLAYER_NOT_FOUND
, charname
.c_str());
1361 Field
*fields
= result
->Fetch();
1362 std::string acc
= fields
[0].GetCppString();
1365 std::string email
= fields
[1].GetCppString();
1368 std::string lastip
= fields
[2].GetCppString();
1372 std::string msg
= charname
+ "'s " + "account is " + acc
+ ", e-mail: " + email
+ ", last ip: " + lastip
;
1374 WorldPacket
data(SMSG_WHOIS
, msg
.size()+1);
1376 _player
->GetSession()->SendPacket(&data
);
1380 sLog
.outDebug("Received whois command from player %s for character %s", GetPlayer()->GetName(), charname
.c_str());
1383 void WorldSession::HandleReportSpamOpcode( WorldPacket
& recv_data
)
1385 CHECK_PACKET_SIZE(recv_data
, 1+8);
1386 sLog
.outDebug("WORLD: CMSG_REPORT_SPAM");
1387 recv_data
.hexlike();
1389 uint8 spam_type
; // 0 - mail, 1 - chat
1390 uint64 spammer_guid
;
1391 uint32 unk1
, unk2
, unk3
, unk4
= 0;
1392 std::string description
= "";
1393 recv_data
>> spam_type
; // unk 0x01 const, may be spam type (mail/chat)
1394 recv_data
>> spammer_guid
; // player guid
1398 CHECK_PACKET_SIZE(recv_data
, recv_data
.rpos()+4+4+4);
1399 recv_data
>> unk1
; // const 0
1400 recv_data
>> unk2
; // probably mail id
1401 recv_data
>> unk3
; // const 0
1404 CHECK_PACKET_SIZE(recv_data
, recv_data
.rpos()+4+4+4+4+1);
1405 recv_data
>> unk1
; // probably language
1406 recv_data
>> unk2
; // message type?
1407 recv_data
>> unk3
; // probably channel id
1408 recv_data
>> unk4
; // unk random value
1409 recv_data
>> description
; // spam description string (messagetype, channel name, player name, message)
1413 // NOTE: all chat messages from this spammer automatically ignored by spam reporter until logout in case chat spam.
1414 // if it's mail spam - ALL mails from this spammer automatically removed by client
1416 // Complaint Received message
1417 WorldPacket
data(SMSG_COMPLAIN_RESULT
, 1);
1421 sLog
.outDebug("REPORT SPAM: type %u, guid %u, unk1 %u, unk2 %u, unk3 %u, unk4 %u, message %s", spam_type
, GUID_LOPART(spammer_guid
), unk1
, unk2
, unk3
, unk4
, description
.c_str());
1424 void WorldSession::HandleRealmStateRequestOpcode( WorldPacket
& recv_data
)
1426 CHECK_PACKET_SIZE(recv_data
, 4);
1428 sLog
.outDebug("CMSG_REALM_SPLIT");
1431 std::string split_date
= "01/01/01";
1434 WorldPacket
data(SMSG_REALM_SPLIT
, 4+4+split_date
.size()+1);
1436 data
<< uint32(0x00000000); // realm split state
1440 // 0x2 realm split pending
1443 //sLog.outDebug("response sent %u", unk);
1446 void WorldSession::HandleFarSightOpcode( WorldPacket
& recv_data
)
1448 CHECK_PACKET_SIZE(recv_data
, 1);
1450 sLog
.outDebug("WORLD: CMSG_FAR_SIGHT");
1451 //recv_data.hexlike();
1459 //WorldPacket data(SMSG_CLEAR_FAR_SIGHT_IMMEDIATE, 0)
1460 //SendPacket(&data);
1461 //_player->SetUInt64Value(PLAYER_FARSIGHT, 0);
1462 sLog
.outDebug("Removed FarSight from player %u", _player
->GetGUIDLow());
1465 sLog
.outDebug("Added FarSight " I64FMT
" to player %u", _player
->GetFarSight(), _player
->GetGUIDLow());
1470 void WorldSession::HandleChooseTitleOpcode( WorldPacket
& recv_data
)
1472 CHECK_PACKET_SIZE(recv_data
, 4);
1474 sLog
.outDebug("CMSG_SET_TITLE");
1480 if(title
> 0 && title
< 128)
1482 if(!GetPlayer()->HasTitle(title
))
1488 GetPlayer()->SetUInt32Value(PLAYER_CHOSEN_TITLE
, title
);
1491 void WorldSession::HandleTimeSyncResp( WorldPacket
& recv_data
)
1493 CHECK_PACKET_SIZE(recv_data
, 4+4);
1495 sLog
.outDebug("CMSG_TIME_SYNC_RESP");
1497 uint32 counter
, time_
;
1498 recv_data
>> counter
>> time_
;
1500 // time_ seems always more than getMSTime()
1501 uint32 diff
= getMSTimeDiff(getMSTime(),time_
);
1503 sLog
.outDebug("response sent: counter %u, time %u (HEX: %X), ms. time %u, diff %u", counter
, time_
, time_
, getMSTime(), diff
);
1506 void WorldSession::HandleResetInstancesOpcode( WorldPacket
& /*recv_data*/ )
1508 sLog
.outDebug("WORLD: CMSG_RESET_INSTANCES");
1509 Group
*pGroup
= _player
->GetGroup();
1512 if(pGroup
->IsLeader(_player
->GetGUID()))
1513 pGroup
->ResetInstances(INSTANCE_RESET_ALL
, _player
);
1516 _player
->ResetInstances(INSTANCE_RESET_ALL
);
1519 void WorldSession::HandleDungeonDifficultyOpcode( WorldPacket
& recv_data
)
1521 CHECK_PACKET_SIZE(recv_data
, 4);
1523 sLog
.outDebug("MSG_SET_DUNGEON_DIFFICULTY");
1528 if(mode
== _player
->GetDifficulty())
1531 if(mode
> DIFFICULTY_HEROIC
)
1533 sLog
.outError("WorldSession::HandleDungeonDifficultyOpcode: player %d sent an invalid instance mode %d!", _player
->GetGUIDLow(), mode
);
1537 // cannot reset while in an instance
1538 Map
*map
= _player
->GetMap();
1539 if(map
&& map
->IsDungeon())
1541 sLog
.outError("WorldSession::HandleDungeonDifficultyOpcode: player %d tried to reset the instance while inside!", _player
->GetGUIDLow());
1545 if(_player
->getLevel() < LEVELREQUIREMENT_HEROIC
)
1547 Group
*pGroup
= _player
->GetGroup();
1550 if(pGroup
->IsLeader(_player
->GetGUID()))
1552 // the difficulty is set even if the instances can't be reset
1553 //_player->SendDungeonDifficulty(true);
1554 pGroup
->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY
, _player
);
1555 pGroup
->SetDifficulty(mode
);
1560 _player
->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY
);
1561 _player
->SetDifficulty(mode
);
1565 void WorldSession::HandleDismountOpcode( WorldPacket
& /*recv_data*/ )
1567 sLog
.outDebug("WORLD: CMSG_CANCEL_MOUNT_AURA");
1568 //recv_data.hexlike();
1570 //If player is not mounted, so go out :)
1571 if (!_player
->IsMounted()) // not blizz like; no any messages on blizz
1573 ChatHandler(this).SendSysMessage(LANG_CHAR_NON_MOUNTED
);
1577 if(_player
->isInFlight()) // not blizz like; no any messages on blizz
1579 ChatHandler(this).SendSysMessage(LANG_YOU_IN_FLIGHT
);
1584 _player
->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED
);
1587 void WorldSession::HandleMoveFlyModeChangeAckOpcode( WorldPacket
& recv_data
)
1589 CHECK_PACKET_SIZE(recv_data
, 8+4+4);
1592 sLog
.outDebug("WORLD: CMSG_MOVE_SET_CAN_FLY_ACK");
1593 //recv_data.hexlike();
1599 recv_data
>> guid
>> unk
>> flags
;
1601 _player
->SetUnitMovementFlags(flags
);
1604 25 00 00 00 00 00 00 00 | 00 00 00 00 00 00 80 00
1605 85 4E A9 01 19 BA 7A C3 | 42 0D 70 44 44 B0 A8 42
1606 78 15 94 40 39 03 00 00 | 00 00 80 3F
1608 25 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00
1609 10 FD A9 01 19 BA 7A C3 | 42 0D 70 44 44 B0 A8 42
1610 78 15 94 40 39 03 00 00 | 00 00 00 00
1614 void WorldSession::HandleRequestPetInfoOpcode( WorldPacket
& /*recv_data */)
1617 sLog.outDebug("WORLD: CMSG_REQUEST_PET_INFO");
1618 recv_data.hexlike();
1622 void WorldSession::HandleSetTaxiBenchmarkOpcode( WorldPacket
& recv_data
)
1624 CHECK_PACKET_SIZE(recv_data
, 1);
1629 sLog
.outDebug("Client used \"/timetest %d\" command", mode
);
1632 void WorldSession::HandleSpellClick( WorldPacket
& recv_data
)
1634 CHECK_PACKET_SIZE(recv_data
, 8);
1639 Vehicle
*vehicle
= ObjectAccessor::GetVehicle(guid
);
1644 _player
->EnterVehicle(vehicle
);
1647 void WorldSession::HandleInspectAchievements( WorldPacket
& recv_data
)
1649 CHECK_PACKET_SIZE(recv_data
, 1);
1651 if(!recv_data
.readPackGUID(guid
))
1654 Player
*player
= objmgr
.GetPlayer(guid
);
1658 player
->GetAchievementMgr().SendRespondInspectAchievements(_player
);