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
21 #include "Database/DatabaseEnv.h"
22 #include "WorldPacket.h"
27 #include "ObjectMgr.h"
28 #include "WorldSession.h"
29 #include "Auth/BigNumber.h"
30 #include "Auth/Sha1.h"
31 #include "UpdateData.h"
34 #include "ScriptCalls.h"
35 #include <zlib/zlib.h>
36 #include "MapManager.h"
37 #include "ObjectAccessor.h"
39 #include "BattleGround.h"
40 #include "SpellAuras.h"
42 #include "SocialMgr.h"
44 void WorldSession::HandleRepopRequestOpcode( WorldPacket
& /*recv_data*/ )
46 sLog
.outDebug( "WORLD: Recvd CMSG_REPOP_REQUEST Message" );
48 if(GetPlayer()->isAlive()||GetPlayer()->HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_GHOST
))
51 // the world update order is sessions, players, creatures
52 // the netcode runs in parallel with all of these
53 // creatures can kill players
54 // so if the server is lagging enough the player can
55 // release spirit after he's killed but before he is updated
56 if(GetPlayer()->getDeathState() == JUST_DIED
)
58 sLog
.outDebug("HandleRepopRequestOpcode: got request after player %s(%d) was killed and before he was updated", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow());
59 GetPlayer()->KillPlayer();
62 //this is spirit release confirm?
63 GetPlayer()->RemovePet(NULL
,PET_SAVE_NOT_IN_SLOT
, true);
64 GetPlayer()->BuildPlayerRepop();
65 GetPlayer()->RepopAtGraveyard();
68 void WorldSession::HandleWhoOpcode( WorldPacket
& recv_data
)
70 CHECK_PACKET_SIZE(recv_data
,4+4+1+1+4+4+4+4);
72 sLog
.outDebug( "WORLD: Recvd CMSG_WHO Message" );
73 //recv_data.hexlike();
75 uint32 clientcount
= 0;
77 uint32 level_min
, level_max
, racemask
, classmask
, zones_count
, str_count
;
78 uint32 zoneids
[10]; // 10 is client limit
79 std::string player_name
, guild_name
;
81 recv_data
>> level_min
; // maximal player level, default 0
82 recv_data
>> level_max
; // minimal player level, default 100
83 recv_data
>> player_name
; // player name, case sensitive...
86 CHECK_PACKET_SIZE(recv_data
,4+4+(player_name
.size()+1)+1+4+4+4+4);
88 recv_data
>> guild_name
; // guild name, case sensitive...
91 CHECK_PACKET_SIZE(recv_data
,4+4+(player_name
.size()+1)+(guild_name
.size()+1)+4+4+4+4);
93 recv_data
>> racemask
; // race mask
94 recv_data
>> classmask
; // class mask
95 recv_data
>> zones_count
; // zones count, client limit=10 (2.0.10)
98 return; // can't be received from real client or broken packet
101 CHECK_PACKET_SIZE(recv_data
,4+4+(player_name
.size()+1)+(guild_name
.size()+1)+4+4+4+(4*zones_count
)+4);
103 for(uint32 i
= 0; i
< zones_count
; i
++)
106 recv_data
>> temp
; // zone id, 0 if zone is unknown...
108 sLog
.outDebug("Zone %u: %u", i
, zoneids
[i
]);
111 recv_data
>> str_count
; // user entered strings count, client limit=4 (checked on 2.0.10)
114 return; // can't be received from real client or broken packet
117 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
));
119 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
);
121 std::wstring str
[4]; // 4 is client limit
122 for(uint32 i
= 0; i
< str_count
; i
++)
124 // recheck (have one more byte)
125 CHECK_PACKET_SIZE(recv_data
,recv_data
.rpos());
128 recv_data
>> temp
; // user entered string, it used as universal search pattern(guild+player name)?
130 if(!Utf8toWStr(temp
,str
[i
]))
135 sLog
.outDebug("String %u: %s", i
, str
[i
].c_str());
138 std::wstring wplayer_name
;
139 std::wstring wguild_name
;
140 if(!(Utf8toWStr(player_name
, wplayer_name
) && Utf8toWStr(guild_name
, wguild_name
)))
142 wstrToLower(wplayer_name
);
143 wstrToLower(wguild_name
);
145 // client send in case not set max level value 100 but mangos support 255 max level,
146 // update it to show GMs with characters after 100 level
150 uint32 team
= _player
->GetTeam();
151 uint32 security
= GetSecurity();
152 bool allowTwoSideWhoList
= sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_WHO_LIST
);
153 bool gmInWhoList
= sWorld
.getConfig(CONFIG_GM_IN_WHO_LIST
);
155 WorldPacket
data( SMSG_WHO
, 50 ); // guess size
156 data
<< clientcount
; // clientcount place holder
157 data
<< clientcount
; // clientcount place holder
159 //TODO: Guard Player map
160 HashMapHolder
<Player
>::MapType
& m
= ObjectAccessor::Instance().GetPlayers();
161 for(HashMapHolder
<Player
>::MapType::iterator itr
= m
.begin(); itr
!= m
.end(); ++itr
)
163 if (security
== SEC_PLAYER
)
165 // player can see member of other team only if CONFIG_ALLOW_TWO_SIDE_WHO_LIST
166 if (itr
->second
->GetTeam() != team
&& !allowTwoSideWhoList
)
169 // player can see MODERATOR, GAME MASTER, ADMINISTRATOR only if CONFIG_GM_IN_WHO_LIST
170 if ((itr
->second
->GetSession()->GetSecurity() > SEC_PLAYER
&& !gmInWhoList
))
174 // check if target is globally visible for player
175 if (!(itr
->second
->IsVisibleGloballyFor(_player
)))
178 // check if target's level is in level range
179 uint32 lvl
= itr
->second
->getLevel();
180 if (lvl
< level_min
|| lvl
> level_max
)
183 // check if class matches classmask
184 uint32 class_
= itr
->second
->getClass();
185 if (!(classmask
& (1 << class_
)))
188 // check if race matches racemask
189 uint32 race
= itr
->second
->getRace();
190 if (!(racemask
& (1 << race
)))
193 uint32 pzoneid
= itr
->second
->GetZoneId();
196 for(uint32 i
= 0; i
< zones_count
; i
++)
198 if(zoneids
[i
] == pzoneid
)
209 std::string pname
= itr
->second
->GetName();
211 if(!Utf8toWStr(pname
,wpname
))
215 if (!(wplayer_name
.empty() || wpname
.find(wplayer_name
) != std::wstring::npos
))
218 std::string gname
= objmgr
.GetGuildNameById(itr
->second
->GetGuildId());
220 if(!Utf8toWStr(gname
,wgname
))
224 if (!(wguild_name
.empty() || wgname
.find(wguild_name
) != std::wstring::npos
))
228 if(AreaTableEntry
const* areaEntry
= GetAreaEntryByAreaID(itr
->second
->GetZoneId()))
229 aname
= areaEntry
->area_name
[GetSessionDbcLocale()];
232 for(uint32 i
= 0; i
< str_count
; i
++)
236 if (wgname
.find(str
[i
]) != std::wstring::npos
||
237 wpname
.find(str
[i
]) != std::wstring::npos
||
238 Utf8FitTo(aname
, str
[i
]) )
249 data
<< pname
; // player name
250 data
<< gname
; // guild name
251 data
<< uint32( lvl
); // player level
252 data
<< uint32( class_
); // player class
253 data
<< uint32( race
); // player race
254 data
<< uint8(0); // new 2.4.0
255 data
<< uint32( pzoneid
); // player zone id
257 // 49 is maximum player count sent to client
258 if ((++clientcount
) == 49)
262 data
.put( 0, clientcount
); //insert right count
263 data
.put( sizeof(uint32
), clientcount
); //insert right count
266 sLog
.outDebug( "WORLD: Send SMSG_WHO Message" );
269 void WorldSession::HandleLogoutRequestOpcode( WorldPacket
& /*recv_data*/ )
271 sLog
.outDebug( "WORLD: Recvd CMSG_LOGOUT_REQUEST Message, security - %u", GetSecurity() );
273 if (uint64 lguid
= GetPlayer()->GetLootGUID())
274 DoLootRelease(lguid
);
276 //instant logout for admins, gm's, mod's
277 if( GetSecurity() > SEC_PLAYER
)
283 //Can not logout if...
284 if( GetPlayer()->isInCombat() || //...is in combat
285 GetPlayer()->duel
|| //...is in Duel
286 //...is jumping ...is falling
287 GetPlayer()->HasUnitMovementFlag(MOVEMENTFLAG_JUMPING
| MOVEMENTFLAG_FALLING
))
289 WorldPacket
data( SMSG_LOGOUT_RESPONSE
, (2+4) ) ;
298 //instant logout in taverns/cities or on taxi
299 if(GetPlayer()->HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_RESTING
) || GetPlayer()->isInFlight())
305 // not set flags if player can't free move to prevent lost state at logout cancel
306 if(GetPlayer()->CanFreeMove())
308 GetPlayer()->SetStandState(PLAYER_STATE_SIT
);
310 WorldPacket
data( SMSG_FORCE_MOVE_ROOT
, (8+4) ); // guess size
311 data
.append(GetPlayer()->GetPackGUID());
314 GetPlayer()->SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_STUNNED
);
317 WorldPacket
data( SMSG_LOGOUT_RESPONSE
, 5 );
321 LogoutRequest(time(NULL
));
324 void WorldSession::HandlePlayerLogoutOpcode( WorldPacket
& /*recv_data*/ )
326 sLog
.outDebug( "WORLD: Recvd CMSG_PLAYER_LOGOUT Message" );
329 void WorldSession::HandleLogoutCancelOpcode( WorldPacket
& /*recv_data*/ )
331 sLog
.outDebug( "WORLD: Recvd CMSG_LOGOUT_CANCEL Message" );
335 WorldPacket
data( SMSG_LOGOUT_CANCEL_ACK
, 0 );
338 // not remove flags if can't free move - its not set in Logout request code.
339 if(GetPlayer()->CanFreeMove())
342 data
.Initialize( SMSG_FORCE_MOVE_UNROOT
, 8 ); // guess size
343 data
.append(GetPlayer()->GetPackGUID());
348 GetPlayer()->SetStandState(PLAYER_STATE_NONE
);
351 GetPlayer()->RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_STUNNED
);
354 sLog
.outDebug( "WORLD: sent SMSG_LOGOUT_CANCEL_ACK Message" );
357 void WorldSession::SendGMTicketGetTicket(uint32 status
, char const* text
)
359 int len
= text
? strlen(text
) : 0;
360 WorldPacket
data( SMSG_GMTICKET_GETTICKET
, (4+len
+1+4+2+4+4) );
361 data
<< uint32(status
); // standard 0x0A, 0x06 if text present
364 data
<< text
; // ticket text
365 data
<< uint8(0x7); // ticket category
366 data
<< float(0); // time from ticket creation?
367 data
<< float(0); // const
368 data
<< float(0); // const
369 data
<< uint8(0); // const
370 data
<< uint8(0); // const
375 void WorldSession::HandleGMTicketGetTicketOpcode( WorldPacket
& /*recv_data*/ )
377 WorldPacket
data( SMSG_QUERY_TIME_RESPONSE
, 4+4 );
378 data
<< (uint32
)time(NULL
);
384 guid
= GetPlayer()->GetGUID();
386 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT COUNT(ticket_id) FROM character_ticket WHERE guid = '%u'", GUID_LOPART(guid
));
391 fields
= result
->Fetch();
392 cnt
= fields
[0].GetUInt32();
397 QueryResult
*result2
= CharacterDatabase
.PQuery("SELECT ticket_text FROM character_ticket WHERE guid = '%u'", GUID_LOPART(guid
));
400 Field
*fields2
= result2
->Fetch();
401 SendGMTicketGetTicket(0x06,fields2
[0].GetString());
406 SendGMTicketGetTicket(0x0A,0);
410 void WorldSession::HandleGMTicketUpdateTextOpcode( WorldPacket
& recv_data
)
412 CHECK_PACKET_SIZE(recv_data
,1);
414 std::string ticketText
;
415 recv_data
>> ticketText
;
417 CharacterDatabase
.escape_string(ticketText
);
418 CharacterDatabase
.PExecute("UPDATE character_ticket SET ticket_text = '%s' WHERE guid = '%u'", ticketText
.c_str(), _player
->GetGUIDLow());
421 void WorldSession::HandleGMTicketDeleteOpcode( WorldPacket
& /*recv_data*/ )
423 uint32 guid
= GetPlayer()->GetGUIDLow();
425 CharacterDatabase
.PExecute("DELETE FROM character_ticket WHERE guid = '%u' LIMIT 1",guid
);
427 WorldPacket
data( SMSG_GMTICKET_DELETETICKET
, 4 );
431 SendGMTicketGetTicket(0x0A, 0);
434 void WorldSession::HandleGMTicketCreateOpcode( WorldPacket
& recv_data
)
436 CHECK_PACKET_SIZE(recv_data
, 4*4+1+2*4);
440 std::string ticketText
= "";
443 recv_data
>> map
>> x
>> y
>> z
; // last check 2.4.3
444 recv_data
>> ticketText
;
447 CHECK_PACKET_SIZE(recv_data
,4*4+(ticketText
.size()+1)+2*4);
449 recv_data
>> unk1
>> unk2
;
450 // note: the packet might contain more data, but the exact structure of that is unknown
452 sLog
.outDebug("TicketCreate: map %u, x %f, y %f, z %f, text %s, unk1 %u, unk2 %u", map
, x
, y
, z
, ticketText
.c_str(), unk1
, unk2
);
454 CharacterDatabase
.escape_string(ticketText
);
456 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT COUNT(*) FROM character_ticket WHERE guid = '%u'", _player
->GetGUIDLow());
461 Field
*fields
= result
->Fetch();
462 cnt
= fields
[0].GetUInt32();
467 WorldPacket
data( SMSG_GMTICKET_CREATE
, 4 );
473 CharacterDatabase
.PExecute("INSERT INTO character_ticket (guid,ticket_text) VALUES ('%u', '%s')", _player
->GetGUIDLow(), ticketText
.c_str());
475 WorldPacket
data( SMSG_QUERY_TIME_RESPONSE
, 4+4 );
476 data
<< (uint32
)time(NULL
);
480 data
.Initialize( SMSG_GMTICKET_CREATE
, 4 );
483 DEBUG_LOG("update the ticket\n");
485 //TODO: Guard player map
486 HashMapHolder
<Player
>::MapType
&m
= ObjectAccessor::Instance().GetPlayers();
487 for(HashMapHolder
<Player
>::MapType::iterator itr
= m
.begin(); itr
!= m
.end(); ++itr
)
489 if(itr
->second
->GetSession()->GetSecurity() >= SEC_GAMEMASTER
&& itr
->second
->isAcceptTickets())
490 ChatHandler(itr
->second
).PSendSysMessage(LANG_COMMAND_TICKETNEW
,GetPlayer()->GetName());
496 void WorldSession::HandleGMTicketSystemStatusOpcode( WorldPacket
& /*recv_data*/ )
498 WorldPacket
data( SMSG_GMTICKET_SYSTEMSTATUS
,4 );
499 data
<< uint32(1); // we can also disable ticket system by sending 0 value
504 void WorldSession::HandleGMSurveySubmit( WorldPacket
& recv_data
)
506 // GM survey is shown after SMSG_GM_TICKET_STATUS_UPDATE with status = 3
507 CHECK_PACKET_SIZE(recv_data
,4+4);
509 recv_data
>> x
; // answer range? (6 = 0-5?)
510 sLog
.outDebug("SURVEY: X = %u", x
);
513 memset(result
, 0, sizeof(result
));
514 for( int i
= 0; i
< 10; ++i
)
516 CHECK_PACKET_SIZE(recv_data
,recv_data
.rpos()+4);
518 recv_data
>> questionID
; // GMSurveyQuestions.dbc
522 CHECK_PACKET_SIZE(recv_data
,recv_data
.rpos()+1+1);
524 std::string unk_text
;
525 recv_data
>> value
; // answer
526 recv_data
>> unk_text
; // always empty?
529 sLog
.outDebug("SURVEY: ID %u, value %u, text %s", questionID
, value
, unk_text
.c_str());
532 CHECK_PACKET_SIZE(recv_data
,recv_data
.rpos()+1);
534 recv_data
>> comment
; // addional comment
535 sLog
.outDebug("SURVEY: comment %s", comment
.c_str());
537 // TODO: chart this data in some way
540 void WorldSession::HandleTogglePvP( WorldPacket
& recv_data
)
542 // this opcode can be used in two ways: Either set explicit new status or toggle old status
543 if(recv_data
.size() == 1)
546 recv_data
>> newPvPStatus
;
547 GetPlayer()->ApplyModFlag(PLAYER_FLAGS
, PLAYER_FLAGS_IN_PVP
, newPvPStatus
);
548 GetPlayer()->ApplyModFlag(PLAYER_FLAGS
, PLAYER_FLAGS_PVP
, !newPvPStatus
);
552 GetPlayer()->ToggleFlag(PLAYER_FLAGS
, PLAYER_FLAGS_IN_PVP
);
553 GetPlayer()->ToggleFlag(PLAYER_FLAGS
, PLAYER_FLAGS_PVP
);
556 if(GetPlayer()->HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_IN_PVP
))
558 if(!GetPlayer()->IsPvP() || GetPlayer()->pvpInfo
.endTimer
!= 0)
559 GetPlayer()->UpdatePvP(true, true);
563 if(!GetPlayer()->pvpInfo
.inHostileArea
&& GetPlayer()->IsPvP())
564 GetPlayer()->pvpInfo
.endTimer
= time(NULL
); // start toggle-off
568 void WorldSession::HandleZoneUpdateOpcode( WorldPacket
& recv_data
)
570 CHECK_PACKET_SIZE(recv_data
,4);
573 recv_data
>> newZone
;
575 sLog
.outDetail("WORLD: Recvd ZONE_UPDATE: %u", newZone
);
577 if(newZone
!= _player
->GetZoneId())
578 GetPlayer()->SendInitWorldStates(); // only if really enters to new zone, not just area change, works strange...
580 GetPlayer()->UpdateZone(newZone
);
583 void WorldSession::HandleSetTargetOpcode( WorldPacket
& recv_data
)
585 // When this packet send?
586 CHECK_PACKET_SIZE(recv_data
,8);
591 _player
->SetUInt32Value(UNIT_FIELD_TARGET
,guid
);
593 // update reputation list if need
594 Unit
* unit
= ObjectAccessor::GetUnit(*_player
, guid
);
598 _player
->SetFactionVisibleForFactionTemplateId(unit
->getFaction());
601 void WorldSession::HandleSetSelectionOpcode( WorldPacket
& recv_data
)
603 CHECK_PACKET_SIZE(recv_data
,8);
608 _player
->SetSelection(guid
);
610 // update reputation list if need
611 Unit
* unit
= ObjectAccessor::GetUnit(*_player
, guid
);
615 _player
->SetFactionVisibleForFactionTemplateId(unit
->getFaction());
618 void WorldSession::HandleStandStateChangeOpcode( WorldPacket
& recv_data
)
620 CHECK_PACKET_SIZE(recv_data
,1);
622 sLog
.outDebug( "WORLD: Received CMSG_STAND_STATE_CHANGE" );
624 recv_data
>> animstate
;
626 _player
->SetStandState(animstate
);
629 void WorldSession::HandleFriendListOpcode( WorldPacket
& recv_data
)
631 CHECK_PACKET_SIZE(recv_data
, 4);
632 sLog
.outDebug( "WORLD: Received CMSG_CONTACT_LIST" );
635 sLog
.outDebug("unk value is %u", unk
);
636 _player
->GetSocial()->SendSocialList();
639 void WorldSession::HandleAddFriendOpcode( WorldPacket
& recv_data
)
641 CHECK_PACKET_SIZE(recv_data
, 1+1);
643 sLog
.outDebug( "WORLD: Received CMSG_ADD_FRIEND" );
645 std::string friendName
= GetMangosString(LANG_FRIEND_IGNORE_UNKNOWN
);
646 std::string friendNote
;
647 FriendsResult friendResult
= FRIEND_NOT_FOUND
;
648 Player
*pFriend
= NULL
;
649 uint64 friendGuid
= 0;
651 recv_data
>> friendName
;
654 CHECK_PACKET_SIZE(recv_data
, (friendName
.size()+1)+1);
656 recv_data
>> friendNote
;
658 if(!normalizePlayerName(friendName
))
661 CharacterDatabase
.escape_string(friendName
); // prevent SQL injection - normal name don't must changed by this call
663 sLog
.outDebug( "WORLD: %s asked to add friend : '%s'",
664 GetPlayer()->GetName(), friendName
.c_str() );
666 friendGuid
= objmgr
.GetPlayerGUIDByName(friendName
);
670 pFriend
= ObjectAccessor::FindPlayer(friendGuid
);
671 if(pFriend
==GetPlayer())
672 friendResult
= FRIEND_SELF
;
673 else if(GetPlayer()->GetTeam()!=objmgr
.GetPlayerTeamByGUID(friendGuid
) && !sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_ADD_FRIEND
) && GetSecurity() < SEC_MODERATOR
)
674 friendResult
= FRIEND_ENEMY
;
675 else if(GetPlayer()->GetSocial()->HasFriend(GUID_LOPART(friendGuid
)))
676 friendResult
= FRIEND_ALREADY
;
679 if (friendGuid
&& friendResult
==FRIEND_NOT_FOUND
)
681 if( pFriend
&& pFriend
->IsInWorld() && pFriend
->IsVisibleGloballyFor(GetPlayer()))
682 friendResult
= FRIEND_ADDED_ONLINE
;
684 friendResult
= FRIEND_ADDED_OFFLINE
;
686 if(!_player
->GetSocial()->AddToSocialList(GUID_LOPART(friendGuid
), false))
688 friendResult
= FRIEND_LIST_FULL
;
689 sLog
.outDebug( "WORLD: %s's friend list is full.", GetPlayer()->GetName());
692 _player
->GetSocial()->SetFriendNote(GUID_LOPART(friendGuid
), friendNote
);
694 sLog
.outDebug( "WORLD: %s Guid found '%u'.", friendName
.c_str(), GUID_LOPART(friendGuid
));
696 else if(friendResult
==FRIEND_ALREADY
)
698 sLog
.outDebug( "WORLD: %s Guid Already a Friend.", friendName
.c_str() );
700 else if(friendResult
==FRIEND_SELF
)
702 sLog
.outDebug( "WORLD: %s Guid can't add himself.", friendName
.c_str() );
706 sLog
.outDebug( "WORLD: %s Guid not found.", friendName
.c_str() );
709 sSocialMgr
.SendFriendStatus(GetPlayer(), friendResult
, GUID_LOPART(friendGuid
), friendName
, false);
711 sLog
.outDebug( "WORLD: Sent (SMSG_FRIEND_STATUS)" );
714 void WorldSession::HandleDelFriendOpcode( WorldPacket
& recv_data
)
716 CHECK_PACKET_SIZE(recv_data
, 8);
720 sLog
.outDebug( "WORLD: Received CMSG_DEL_FRIEND" );
722 recv_data
>> FriendGUID
;
724 _player
->GetSocial()->RemoveFromSocialList(GUID_LOPART(FriendGUID
), false);
726 sSocialMgr
.SendFriendStatus(GetPlayer(), FRIEND_REMOVED
, GUID_LOPART(FriendGUID
), "", false);
728 sLog
.outDebug( "WORLD: Sent motd (SMSG_FRIEND_STATUS)" );
731 void WorldSession::HandleAddIgnoreOpcode( WorldPacket
& recv_data
)
733 CHECK_PACKET_SIZE(recv_data
,1);
735 sLog
.outDebug( "WORLD: Received CMSG_ADD_IGNORE" );
737 std::string IgnoreName
= GetMangosString(LANG_FRIEND_IGNORE_UNKNOWN
);
738 FriendsResult ignoreResult
= FRIEND_IGNORE_NOT_FOUND
;
739 uint64 IgnoreGuid
= 0;
741 recv_data
>> IgnoreName
;
743 if(!normalizePlayerName(IgnoreName
))
746 CharacterDatabase
.escape_string(IgnoreName
); // prevent SQL injection - normal name don't must changed by this call
748 sLog
.outDebug( "WORLD: %s asked to Ignore: '%s'",
749 GetPlayer()->GetName(), IgnoreName
.c_str() );
751 IgnoreGuid
= objmgr
.GetPlayerGUIDByName(IgnoreName
);
755 if(IgnoreGuid
==GetPlayer()->GetGUID())
756 ignoreResult
= FRIEND_IGNORE_SELF
;
759 if( GetPlayer()->GetSocial()->HasIgnore(GUID_LOPART(IgnoreGuid
)) )
760 ignoreResult
= FRIEND_IGNORE_ALREADY
;
764 if (IgnoreGuid
&& ignoreResult
== FRIEND_IGNORE_NOT_FOUND
)
766 ignoreResult
= FRIEND_IGNORE_ADDED
;
768 if(!_player
->GetSocial()->AddToSocialList(GUID_LOPART(IgnoreGuid
), true))
769 ignoreResult
= FRIEND_IGNORE_FULL
;
771 else if(ignoreResult
==FRIEND_IGNORE_ALREADY
)
773 sLog
.outDebug( "WORLD: %s Guid Already Ignored.", IgnoreName
.c_str() );
775 else if(ignoreResult
==FRIEND_IGNORE_SELF
)
777 sLog
.outDebug( "WORLD: %s Guid can't add himself.", IgnoreName
.c_str() );
781 sLog
.outDebug( "WORLD: %s Guid not found.", IgnoreName
.c_str() );
784 sSocialMgr
.SendFriendStatus(GetPlayer(), ignoreResult
, GUID_LOPART(IgnoreGuid
), "", false);
786 sLog
.outDebug( "WORLD: Sent (SMSG_FRIEND_STATUS)" );
789 void WorldSession::HandleDelIgnoreOpcode( WorldPacket
& recv_data
)
791 CHECK_PACKET_SIZE(recv_data
, 8);
795 sLog
.outDebug( "WORLD: Received CMSG_DEL_IGNORE" );
797 recv_data
>> IgnoreGUID
;
799 _player
->GetSocial()->RemoveFromSocialList(GUID_LOPART(IgnoreGUID
), true);
801 sSocialMgr
.SendFriendStatus(GetPlayer(), FRIEND_IGNORE_REMOVED
, GUID_LOPART(IgnoreGUID
), "", false);
803 sLog
.outDebug( "WORLD: Sent motd (SMSG_FRIEND_STATUS)" );
806 void WorldSession::HandleSetFriendNoteOpcode( WorldPacket
& recv_data
)
808 CHECK_PACKET_SIZE(recv_data
, 8+1);
811 recv_data
>> guid
>> note
;
812 _player
->GetSocial()->SetFriendNote(guid
, note
);
815 void WorldSession::HandleBugOpcode( WorldPacket
& recv_data
)
817 CHECK_PACKET_SIZE(recv_data
,4+4+1+4+1);
819 uint32 suggestion
, contentlen
;
824 recv_data
>> suggestion
>> contentlen
>> content
;
827 CHECK_PACKET_SIZE(recv_data
,4+4+(content
.size()+1)+4+1);
829 recv_data
>> typelen
>> type
;
831 if( suggestion
== 0 )
832 sLog
.outDebug( "WORLD: Received CMSG_BUG [Bug Report]" );
834 sLog
.outDebug( "WORLD: Received CMSG_BUG [Suggestion]" );
836 sLog
.outDebug( type
.c_str( ) );
837 sLog
.outDebug( content
.c_str( ) );
839 CharacterDatabase
.escape_string(type
);
840 CharacterDatabase
.escape_string(content
);
841 CharacterDatabase
.PExecute ("INSERT INTO bugreport (type,content) VALUES('%s', '%s')", type
.c_str( ), content
.c_str( ));
844 void WorldSession::HandleCorpseReclaimOpcode(WorldPacket
&recv_data
)
846 CHECK_PACKET_SIZE(recv_data
,8);
848 sLog
.outDetail("WORLD: Received CMSG_RECLAIM_CORPSE");
849 if (GetPlayer()->isAlive())
852 // body not released yet
853 if(!GetPlayer()->HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_GHOST
))
856 Corpse
*corpse
= GetPlayer()->GetCorpse();
861 // prevent resurrect before 30-sec delay after body release not finished
862 if(corpse
->GetGhostTime() + GetPlayer()->GetCorpseReclaimDelay(corpse
->GetType()==CORPSE_RESURRECTABLE_PVP
) > time(NULL
))
865 float dist
= corpse
->GetDistance2d(GetPlayer());
866 sLog
.outDebug("Corpse 2D Distance: \t%f",dist
);
867 if (dist
> CORPSE_RECLAIM_RADIUS
)
874 GetPlayer()->ResurrectPlayer(GetPlayer()->InBattleGround() ? 1.0f
: 0.5f
);
877 GetPlayer()->SpawnCorpseBones();
879 GetPlayer()->SaveToDB();
882 void WorldSession::HandleResurrectResponseOpcode(WorldPacket
& recv_data
)
884 CHECK_PACKET_SIZE(recv_data
,8+1);
886 sLog
.outDetail("WORLD: Received CMSG_RESURRECT_RESPONSE");
888 if(GetPlayer()->isAlive())
898 GetPlayer()->clearResurrectRequestData(); // reject
902 if(!GetPlayer()->isRessurectRequestedBy(guid
))
905 GetPlayer()->ResurectUsingRequestData();
906 GetPlayer()->SaveToDB();
909 void WorldSession::HandleAreaTriggerOpcode(WorldPacket
& recv_data
)
911 CHECK_PACKET_SIZE(recv_data
,4);
913 sLog
.outDebug("WORLD: Received CMSG_AREATRIGGER");
917 recv_data
>> Trigger_ID
;
918 sLog
.outDebug("Trigger ID:%u",Trigger_ID
);
920 if(GetPlayer()->isInFlight())
922 sLog
.outDebug("Player '%s' (GUID: %u) in flight, ignore Area Trigger ID:%u",GetPlayer()->GetName(),GetPlayer()->GetGUIDLow(), Trigger_ID
);
926 AreaTriggerEntry
const* atEntry
= sAreaTriggerStore
.LookupEntry(Trigger_ID
);
929 sLog
.outDebug("Player '%s' (GUID: %u) send unknown (by DBC) Area Trigger ID:%u",GetPlayer()->GetName(),GetPlayer()->GetGUIDLow(), Trigger_ID
);
933 if (GetPlayer()->GetMapId()!=atEntry
->mapid
)
935 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
);
939 // delta is safe radius
940 const float delta
= 5.0f
;
941 // check if player in the range of areatrigger
942 Player
* pl
= GetPlayer();
944 if (atEntry
->radius
> 0)
946 // if we have radius check it
947 float dist
= pl
->GetDistance(atEntry
->x
,atEntry
->y
,atEntry
->z
);
948 if(dist
> atEntry
->radius
+ delta
)
950 sLog
.outDebug("Player '%s' (GUID: %u) too far (radius: %f distance: %f), ignore Area Trigger ID: %u",
951 pl
->GetName(), pl
->GetGUIDLow(), atEntry
->radius
, dist
, Trigger_ID
);
957 // we have only extent
958 float dx
= pl
->GetPositionX() - atEntry
->x
;
959 float dy
= pl
->GetPositionY() - atEntry
->y
;
960 float dz
= pl
->GetPositionZ() - atEntry
->z
;
961 double es
= sin(atEntry
->box_orientation
);
962 double ec
= cos(atEntry
->box_orientation
);
963 // calc rotated vector based on extent axis
964 double rotateDx
= dx
*ec
- dy
*es
;
965 double rotateDy
= dx
*es
+ dy
*ec
;
967 if( (fabs(rotateDx
) > atEntry
->box_x
/2 + delta
) ||
968 (fabs(rotateDy
) > atEntry
->box_y
/2 + delta
) ||
969 (fabs(dz
) > atEntry
->box_z
/2 + delta
) )
971 sLog
.outDebug("Player '%s' (GUID: %u) too far (1/2 box X: %f 1/2 box Y: %u 1/2 box Z: %u rotate dX: %f rotate dY: %f dZ:%f), ignore Area Trigger ID: %u",
972 pl
->GetName(), pl
->GetGUIDLow(), atEntry
->box_x
/2, atEntry
->box_y
/2, atEntry
->box_z
/2, rotateDx
, rotateDy
, dz
, Trigger_ID
);
977 if(Script
->scriptAreaTrigger(GetPlayer(), atEntry
))
980 uint32 quest_id
= objmgr
.GetQuestForAreaTrigger( Trigger_ID
);
981 if( quest_id
&& GetPlayer()->isAlive() && GetPlayer()->IsActiveQuest(quest_id
) )
983 Quest
const* pQuest
= objmgr
.GetQuestTemplate(quest_id
);
986 if(GetPlayer()->GetQuestStatus(quest_id
) == QUEST_STATUS_INCOMPLETE
)
987 GetPlayer()->AreaExploredOrEventHappens( quest_id
);
991 if(objmgr
.IsTavernAreaTrigger(Trigger_ID
))
993 // set resting flag we are in the inn
994 GetPlayer()->SetFlag(PLAYER_FLAGS
, PLAYER_FLAGS_RESTING
);
995 GetPlayer()->InnEnter(time(NULL
), atEntry
->mapid
, atEntry
->x
, atEntry
->y
, atEntry
->z
);
996 GetPlayer()->SetRestType(REST_TYPE_IN_TAVERN
);
998 if(sWorld
.IsFFAPvPRealm())
999 GetPlayer()->RemoveFlag(PLAYER_FLAGS
,PLAYER_FLAGS_FFA_PVP
);
1004 if(GetPlayer()->InBattleGround())
1006 BattleGround
* bg
= GetPlayer()->GetBattleGround();
1008 if(bg
->GetStatus() == STATUS_IN_PROGRESS
)
1009 bg
->HandleAreaTrigger(GetPlayer(), Trigger_ID
);
1014 // NULL if all values default (non teleport trigger)
1015 AreaTrigger
const* at
= objmgr
.GetAreaTrigger(Trigger_ID
);
1019 if(!GetPlayer()->isGameMaster())
1021 uint32 missingLevel
= 0;
1022 if(GetPlayer()->getLevel() < at
->requiredLevel
&& !sWorld
.getConfig(CONFIG_INSTANCE_IGNORE_LEVEL
))
1023 missingLevel
= at
->requiredLevel
;
1025 // must have one or the other, report the first one that's missing
1026 uint32 missingItem
= 0;
1027 if(at
->requiredItem
)
1029 if(!GetPlayer()->HasItemCount(at
->requiredItem
, 1) &&
1030 (!at
->requiredItem2
|| !GetPlayer()->HasItemCount(at
->requiredItem2
, 1)))
1031 missingItem
= at
->requiredItem
;
1033 else if(at
->requiredItem2
&& !GetPlayer()->HasItemCount(at
->requiredItem2
, 1))
1034 missingItem
= at
->requiredItem2
;
1036 uint32 missingKey
= 0;
1037 if(GetPlayer()->GetDifficulty() == DIFFICULTY_HEROIC
)
1041 if(!GetPlayer()->HasItemCount(at
->heroicKey
, 1) &&
1042 (!at
->heroicKey2
|| !GetPlayer()->HasItemCount(at
->heroicKey2
, 1)))
1043 missingKey
= at
->heroicKey
;
1045 else if(at
->heroicKey2
&& !GetPlayer()->HasItemCount(at
->heroicKey2
, 1))
1046 missingKey
= at
->heroicKey2
;
1049 uint32 missingQuest
= 0;
1050 if(at
->requiredQuest
&& !GetPlayer()->GetQuestRewardStatus(at
->requiredQuest
))
1051 missingQuest
= at
->requiredQuest
;
1053 if(missingLevel
|| missingItem
|| missingKey
|| missingQuest
)
1055 // TODO: all this is probably wrong
1057 SendAreaTriggerMessage(GetMangosString(LANG_LEVEL_MINREQUIRED_AND_ITEM
), at
->requiredLevel
, objmgr
.GetItemPrototype(missingItem
)->Name1
);
1059 GetPlayer()->SendTransferAborted(at
->target_mapId
, TRANSFER_ABORT_DIFFICULTY
, DIFFICULTY_HEROIC
);
1060 else if(missingQuest
)
1061 SendAreaTriggerMessage(at
->requiredFailedText
.c_str());
1062 else if(missingLevel
)
1063 SendAreaTriggerMessage(GetMangosString(LANG_LEVEL_MINREQUIRED
), missingLevel
);
1068 GetPlayer()->TeleportTo(at
->target_mapId
,at
->target_X
,at
->target_Y
,at
->target_Z
,at
->target_Orientation
,TELE_TO_NOT_LEAVE_TRANSPORT
);
1071 void WorldSession::HandleUpdateAccountData(WorldPacket
&recv_data
)
1073 sLog
.outDetail("WORLD: Received CMSG_UPDATE_ACCOUNT_DATA");
1075 CHECK_PACKET_SIZE(recv_data
, 4+4+4);
1077 uint32 type
, timestamp
, decompressedSize
;
1078 recv_data
>> type
>> timestamp
>> decompressedSize
;
1080 if(type
> NUM_ACCOUNT_DATA_TYPES
)
1083 if(decompressedSize
== 0) // erase
1085 SetAccountData(type
, timestamp
, "");
1087 WorldPacket
data(SMSG_UPDATE_ACCOUNT_DATA_COMPLETE
, 4+4);
1088 data
<< uint32(type
);
1095 if(decompressedSize
> 0xFFFF)
1097 sLog
.outError("UAD: Account data packet too big, size %u", decompressedSize
);
1102 dest
.resize(decompressedSize
);
1104 uLongf realSize
= decompressedSize
;
1105 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
)
1107 sLog
.outError("UAD: Failed to decompress account data");
1114 SetAccountData(type
, timestamp
, adata
);
1116 WorldPacket
data(SMSG_UPDATE_ACCOUNT_DATA_COMPLETE
, 4+4);
1117 data
<< uint32(type
);
1122 void WorldSession::HandleRequestAccountData(WorldPacket
& recv_data
)
1124 sLog
.outDetail("WORLD: Received CMSG_REQUEST_ACCOUNT_DATA");
1126 CHECK_PACKET_SIZE(recv_data
, 4);
1131 if(type
> NUM_ACCOUNT_DATA_TYPES
)
1134 AccountData
*adata
= GetAccountData(type
);
1136 uint32 size
= adata
->Data
.size();
1141 uLongf destSize
= size
;
1142 if(compress(const_cast<uint8
*>(dest
.contents()), &destSize
, (uint8
*)adata
->Data
.c_str(), size
) != Z_OK
)
1144 sLog
.outDebug("RAD: Failed to compress account data");
1148 dest
.resize(destSize
);
1150 WorldPacket
data (SMSG_UPDATE_ACCOUNT_DATA
, 8+4+4+4+destSize
);
1151 data
<< uint64(_player
->GetGUID()); // player guid
1152 data
<< uint32(type
); // type (0-7)
1153 data
<< uint32(adata
->Time
); // unix time
1154 data
<< uint32(size
); // decompressed length
1155 data
.append(dest
); // compressed data
1159 void WorldSession::HandleSetActionButtonOpcode(WorldPacket
& recv_data
)
1161 CHECK_PACKET_SIZE(recv_data
,1+2+1+1);
1163 sLog
.outDebug( "WORLD: Received CMSG_SET_ACTION_BUTTON" );
1164 uint8 button
, misc
, type
;
1166 recv_data
>> button
>> action
>> misc
>> type
;
1167 sLog
.outDetail( "BUTTON: %u ACTION: %u TYPE: %u MISC: %u", button
, action
, type
, misc
);
1170 sLog
.outDetail( "MISC: Remove action from button %u", button
);
1172 GetPlayer()->removeActionButton(button
);
1176 if(type
==ACTION_BUTTON_MACRO
|| type
==ACTION_BUTTON_CMACRO
)
1178 sLog
.outDetail( "MISC: Added Macro %u into button %u", action
, button
);
1179 GetPlayer()->addActionButton(button
,action
,type
,misc
);
1181 else if(type
==ACTION_BUTTON_SPELL
)
1183 sLog
.outDetail( "MISC: Added Action %u into button %u", action
, button
);
1184 GetPlayer()->addActionButton(button
,action
,type
,misc
);
1186 else if(type
==ACTION_BUTTON_ITEM
)
1188 sLog
.outDetail( "MISC: Added Item %u into button %u", action
, button
);
1189 GetPlayer()->addActionButton(button
,action
,type
,misc
);
1192 sLog
.outError( "MISC: Unknown action button type %u for action %u into button %u", type
, action
, button
);
1196 void WorldSession::HandleCompleteCinema( WorldPacket
& /*recv_data*/ )
1198 DEBUG_LOG( "WORLD: Player is watching cinema" );
1201 void WorldSession::HandleNextCinematicCamera( WorldPacket
& /*recv_data*/ )
1203 DEBUG_LOG( "WORLD: Which movie to play" );
1206 void WorldSession::HandleMoveTimeSkippedOpcode( WorldPacket
& /*recv_data*/ )
1208 /* WorldSession::Update( getMSTime() );*/
1209 DEBUG_LOG( "WORLD: Time Lag/Synchronization Resent/Update" );
1212 CHECK_PACKET_SIZE(recv_data,8+4);
1214 uint32 time_skipped;
1216 recv_data >> time_skipped;
1217 sLog.outDebug( "WORLD: CMSG_MOVE_TIME_SKIPPED" );
1220 must be need use in mangos
1221 We substract server Lags to move time ( AntiLags )
1223 GetPlayer()->ModifyLastMoveTime( -int32(time_skipped) );
1227 void WorldSession::HandleFeatherFallAck(WorldPacket
&/*recv_data*/)
1229 DEBUG_LOG("WORLD: CMSG_MOVE_FEATHER_FALL_ACK");
1232 void WorldSession::HandleMoveUnRootAck(WorldPacket
&/* recv_data*/)
1235 CHECK_PACKET_SIZE(recv_data,8+8+4+4+4+4+4);
1237 sLog.outDebug( "WORLD: CMSG_FORCE_MOVE_UNROOT_ACK" );
1238 recv_data.hexlike();
1248 recv_data >> unknown1;
1249 recv_data >> unknown2;
1250 recv_data >> PositionX;
1251 recv_data >> PositionY;
1252 recv_data >> PositionZ;
1253 recv_data >> Orientation;
1255 // TODO for later may be we can use for anticheat
1256 DEBUG_LOG("Guid " I64FMTD,guid);
1257 DEBUG_LOG("unknown1 " I64FMTD,unknown1);
1258 DEBUG_LOG("unknown2 %u",unknown2);
1259 DEBUG_LOG("X %f",PositionX);
1260 DEBUG_LOG("Y %f",PositionY);
1261 DEBUG_LOG("Z %f",PositionZ);
1262 DEBUG_LOG("O %f",Orientation);
1266 void WorldSession::HandleMoveRootAck(WorldPacket
&/* recv_data*/)
1269 CHECK_PACKET_SIZE(recv_data,8+8+4+4+4+4+4);
1271 sLog.outDebug( "WORLD: CMSG_FORCE_MOVE_ROOT_ACK" );
1272 recv_data.hexlike();
1282 recv_data >> unknown1;
1283 recv_data >> unknown2;
1284 recv_data >> PositionX;
1285 recv_data >> PositionY;
1286 recv_data >> PositionZ;
1287 recv_data >> Orientation;
1289 // for later may be we can use for anticheat
1290 DEBUG_LOG("Guid " I64FMTD,guid);
1291 DEBUG_LOG("unknown1 " I64FMTD,unknown1);
1292 DEBUG_LOG("unknown1 %u",unknown2);
1293 DEBUG_LOG("X %f",PositionX);
1294 DEBUG_LOG("Y %f",PositionY);
1295 DEBUG_LOG("Z %f",PositionZ);
1296 DEBUG_LOG("O %f",Orientation);
1300 void WorldSession::HandleMoveTeleportAck(WorldPacket
&/* recv_data*/)
1303 CHECK_PACKET_SIZE(recv_data,8+4);
1305 sLog.outDebug("MSG_MOVE_TELEPORT_ACK");
1310 recv_data >> flags >> time;
1311 DEBUG_LOG("Guid " I64FMTD,guid);
1312 DEBUG_LOG("Flags %u, time %u",flags, time/1000);
1316 void WorldSession::HandleSetActionBar(WorldPacket
& recv_data
)
1318 CHECK_PACKET_SIZE(recv_data
,1);
1322 recv_data
>> ActionBar
;
1324 if(!GetPlayer()) // ignore until not logged (check needed because STATUS_AUTHED)
1327 sLog
.outError("WorldSession::HandleSetActionBar in not logged state with value: %u, ignored",uint32(ActionBar
));
1331 GetPlayer()->SetByteValue(PLAYER_FIELD_BYTES
, 2, ActionBar
);
1334 void WorldSession::HandleWardenDataOpcode(WorldPacket
& /*recv_data*/)
1337 CHECK_PACKET_SIZE(recv_data,1);
1341 sLog.outDebug("Received opcode CMSG_WARDEN_DATA, not resolve.uint8 = %u",tmp);
1345 void WorldSession::HandlePlayedTime(WorldPacket
& /*recv_data*/)
1347 uint32 TotalTimePlayed
= GetPlayer()->GetTotalPlayedTime();
1348 uint32 LevelPlayedTime
= GetPlayer()->GetLevelPlayedTime();
1350 WorldPacket
data(SMSG_PLAYED_TIME
, 8);
1351 data
<< TotalTimePlayed
;
1352 data
<< LevelPlayedTime
;
1356 void WorldSession::HandleInspectOpcode(WorldPacket
& recv_data
)
1358 CHECK_PACKET_SIZE(recv_data
, 8);
1362 DEBUG_LOG("Inspected guid is " I64FMTD
, guid
);
1364 _player
->SetSelection(guid
);
1366 Player
*plr
= objmgr
.GetPlayer(guid
);
1367 if(!plr
) // wrong player
1370 uint32 talent_points
= 0x3D;
1371 uint32 guid_size
= plr
->GetPackGUID().size();
1372 WorldPacket
data(SMSG_INSPECT_TALENT
, 4+talent_points
);
1373 data
.append(plr
->GetPackGUID());
1374 data
<< uint32(talent_points
);
1376 // fill by 0 talents array
1377 for(uint32 i
= 0; i
< talent_points
; ++i
)
1380 if(sWorld
.getConfig(CONFIG_TALENTS_INSPECTING
) || _player
->isGameMaster())
1382 // find class talent tabs (all players have 3 talent tabs)
1383 uint32
const* talentTabIds
= GetTalentTabPages(plr
->getClass());
1385 uint32 talentTabPos
= 0; // pos of first talent rank in tab including all prev tabs
1386 for(uint32 i
= 0; i
< 3; ++i
)
1388 uint32 talentTabId
= talentTabIds
[i
];
1390 // fill by real data
1391 for(uint32 talentId
= 0; talentId
< sTalentStore
.GetNumRows(); ++talentId
)
1393 TalentEntry
const* talentInfo
= sTalentStore
.LookupEntry(talentId
);
1397 // skip another tab talents
1398 if(talentInfo
->TalentTab
!= talentTabId
)
1402 uint32 curtalent_maxrank
= 0;
1403 for(uint32 k
= 5; k
> 0; --k
)
1405 if(talentInfo
->RankID
[k
-1] && plr
->HasSpell(talentInfo
->RankID
[k
-1]))
1407 curtalent_maxrank
= k
;
1412 // not learned talent
1413 if(!curtalent_maxrank
)
1416 // 1 rank talent bit index
1417 uint32 curtalent_index
= talentTabPos
+ GetTalentInspectBitPosInTab(talentId
);
1419 uint32 curtalent_rank_index
= curtalent_index
+curtalent_maxrank
-1;
1421 // slot/offset in 7-bit bytes
1422 uint32 curtalent_rank_slot7
= curtalent_rank_index
/ 7;
1423 uint32 curtalent_rank_offset7
= curtalent_rank_index
% 7;
1425 // rank pos with skipped 8 bit
1426 uint32 curtalent_rank_index2
= curtalent_rank_slot7
* 8 + curtalent_rank_offset7
;
1428 // slot/offset in 8-bit bytes with skipped high bit
1429 uint32 curtalent_rank_slot
= curtalent_rank_index2
/ 8;
1430 uint32 curtalent_rank_offset
= curtalent_rank_index2
% 8;
1433 uint32 val
= data
.read
<uint8
>(guid_size
+ 4 + curtalent_rank_slot
);
1434 val
|= (1 << curtalent_rank_offset
);
1435 data
.put
<uint8
>(guid_size
+ 4 + curtalent_rank_slot
, val
& 0xFF);
1438 talentTabPos
+= GetTalentTabInspectBitSize(talentTabId
);
1445 void WorldSession::HandleInspectHonorStatsOpcode(WorldPacket
& recv_data
)
1447 CHECK_PACKET_SIZE(recv_data
, 8);
1452 Player
*player
= objmgr
.GetPlayer(guid
);
1456 sLog
.outError("InspectHonorStats: WTF, player not found...");
1460 WorldPacket
data(MSG_INSPECT_HONOR_STATS
, 8+1+4*4);
1461 data
<< uint64(player
->GetGUID());
1462 data
<< uint8(player
->GetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
));
1463 data
<< uint32(player
->GetUInt32Value(PLAYER_FIELD_KILLS
));
1464 data
<< uint32(player
->GetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
));
1465 data
<< uint32(player
->GetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
));
1466 data
<< uint32(player
->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
));
1470 void WorldSession::HandleWorldTeleportOpcode(WorldPacket
& recv_data
)
1472 CHECK_PACKET_SIZE(recv_data
,4+4+4+4+4+4);
1474 // write in client console: worldport 469 452 6454 2536 180 or /console worldport 469 452 6454 2536 180
1475 // Received opcode CMSG_WORLD_TELEPORT
1476 // Time is ***, map=469, x=452.000000, y=6454.000000, z=2536.000000, orient=3.141593
1478 //sLog.outDebug("Received opcode CMSG_WORLD_TELEPORT");
1480 if(GetPlayer()->isInFlight())
1482 sLog
.outDebug("Player '%s' (GUID: %u) in flight, ignore worldport command.",GetPlayer()->GetName(),GetPlayer()->GetGUIDLow());
1493 recv_data
>> time
; // time in m.sec.
1495 recv_data
>> PositionX
;
1496 recv_data
>> PositionY
;
1497 recv_data
>> PositionZ
;
1498 recv_data
>> Orientation
; // o (3.141593 = 180 degrees)
1499 DEBUG_LOG("Time %u sec, map=%u, x=%f, y=%f, z=%f, orient=%f", time
/1000, mapid
, PositionX
, PositionY
, PositionZ
, Orientation
);
1501 if (GetSecurity() >= SEC_ADMINISTRATOR
)
1502 GetPlayer()->TeleportTo(mapid
,PositionX
,PositionY
,PositionZ
,Orientation
);
1504 SendNotification(LANG_YOU_NOT_HAVE_PERMISSION
);
1505 sLog
.outDebug("Received worldport command from player %s", GetPlayer()->GetName());
1508 void WorldSession::HandleWhoisOpcode(WorldPacket
& recv_data
)
1510 CHECK_PACKET_SIZE(recv_data
, 1);
1512 sLog
.outDebug("Received opcode CMSG_WHOIS");
1513 std::string charname
;
1514 recv_data
>> charname
;
1516 if (GetSecurity() < SEC_ADMINISTRATOR
)
1518 SendNotification(LANG_YOU_NOT_HAVE_PERMISSION
);
1522 if(charname
.empty())
1524 SendNotification(LANG_NEED_CHARACTER_NAME
);
1528 Player
*plr
= objmgr
.GetPlayer(charname
.c_str());
1532 SendNotification(LANG_PLAYER_NOT_EXIST_OR_OFFLINE
, charname
.c_str());
1536 uint32 accid
= plr
->GetSession()->GetAccountId();
1538 QueryResult
*result
= loginDatabase
.PQuery("SELECT username,email,last_ip FROM account WHERE id=%u", accid
);
1541 SendNotification(LANG_ACCOUNT_FOR_PLAYER_NOT_FOUND
, charname
.c_str());
1545 Field
*fields
= result
->Fetch();
1546 std::string acc
= fields
[0].GetCppString();
1549 std::string email
= fields
[1].GetCppString();
1552 std::string lastip
= fields
[2].GetCppString();
1556 std::string msg
= charname
+ "'s " + "account is " + acc
+ ", e-mail: " + email
+ ", last ip: " + lastip
;
1558 WorldPacket
data(SMSG_WHOIS
, msg
.size()+1);
1560 _player
->GetSession()->SendPacket(&data
);
1564 sLog
.outDebug("Received whois command from player %s for character %s", GetPlayer()->GetName(), charname
.c_str());
1567 void WorldSession::HandleReportSpamOpcode( WorldPacket
& recv_data
)
1569 CHECK_PACKET_SIZE(recv_data
, 1+8);
1570 sLog
.outDebug("WORLD: CMSG_REPORT_SPAM");
1571 recv_data
.hexlike();
1573 uint8 spam_type
; // 0 - mail, 1 - chat
1574 uint64 spammer_guid
;
1575 uint32 unk1
, unk2
, unk3
, unk4
= 0;
1576 std::string description
= "";
1577 recv_data
>> spam_type
; // unk 0x01 const, may be spam type (mail/chat)
1578 recv_data
>> spammer_guid
; // player guid
1582 CHECK_PACKET_SIZE(recv_data
, recv_data
.rpos()+4+4+4);
1583 recv_data
>> unk1
; // const 0
1584 recv_data
>> unk2
; // probably mail id
1585 recv_data
>> unk3
; // const 0
1588 CHECK_PACKET_SIZE(recv_data
, recv_data
.rpos()+4+4+4+4+1);
1589 recv_data
>> unk1
; // probably language
1590 recv_data
>> unk2
; // message type?
1591 recv_data
>> unk3
; // probably channel id
1592 recv_data
>> unk4
; // unk random value
1593 recv_data
>> description
; // spam description string (messagetype, channel name, player name, message)
1597 // NOTE: all chat messages from this spammer automatically ignored by spam reporter until logout in case chat spam.
1598 // if it's mail spam - ALL mails from this spammer automatically removed by client
1600 // Complaint Received message
1601 WorldPacket
data(SMSG_COMPLAIN_RESULT
, 1);
1605 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());
1608 void WorldSession::HandleRealmStateRequestOpcode( WorldPacket
& recv_data
)
1610 CHECK_PACKET_SIZE(recv_data
, 4);
1612 sLog
.outDebug("CMSG_REALM_SPLIT");
1615 std::string split_date
= "01/01/01";
1618 WorldPacket
data(SMSG_REALM_SPLIT
, 4+4+split_date
.size()+1);
1620 data
<< uint32(0x00000000); // realm split state
1624 // 0x2 realm split pending
1627 //sLog.outDebug("response sent %u", unk);
1630 void WorldSession::HandleFarSightOpcode( WorldPacket
& recv_data
)
1632 CHECK_PACKET_SIZE(recv_data
, 1);
1634 sLog
.outDebug("WORLD: CMSG_FAR_SIGHT");
1635 //recv_data.hexlike();
1643 //WorldPacket data(SMSG_CLEAR_FAR_SIGHT_IMMEDIATE, 0)
1644 //SendPacket(&data);
1645 //_player->SetUInt64Value(PLAYER_FARSIGHT, 0);
1646 sLog
.outDebug("Removed FarSight from player %u", _player
->GetGUIDLow());
1649 sLog
.outDebug("Added FarSight " I64FMTD
" to player %u", _player
->GetUInt64Value(PLAYER_FARSIGHT
), _player
->GetGUIDLow());
1654 void WorldSession::HandleChooseTitleOpcode( WorldPacket
& recv_data
)
1656 CHECK_PACKET_SIZE(recv_data
, 4);
1658 sLog
.outDebug("CMSG_SET_TITLE");
1664 if(title
> 0 && title
< 64)
1666 if(!GetPlayer()->HasFlag64(PLAYER__FIELD_KNOWN_TITLES
,uint64(1) << title
))
1672 GetPlayer()->SetUInt32Value(PLAYER_CHOSEN_TITLE
, title
);
1675 void WorldSession::HandleAllowMoveAckOpcode( WorldPacket
& recv_data
)
1677 CHECK_PACKET_SIZE(recv_data
, 4+4);
1679 sLog
.outDebug("CMSG_ALLOW_MOVE_ACK");
1681 uint32 counter
, time_
;
1682 recv_data
>> counter
>> time_
;
1684 // time_ seems always more than getMSTime()
1685 uint32 diff
= getMSTimeDiff(getMSTime(),time_
);
1687 sLog
.outDebug("response sent: counter %u, time %u (HEX: %X), ms. time %u, diff %u", counter
, time_
, time_
, getMSTime(), diff
);
1690 void WorldSession::HandleResetInstancesOpcode( WorldPacket
& /*recv_data*/ )
1692 sLog
.outDebug("WORLD: CMSG_RESET_INSTANCES");
1693 Group
*pGroup
= _player
->GetGroup();
1696 if(pGroup
->IsLeader(_player
->GetGUID()))
1697 pGroup
->ResetInstances(INSTANCE_RESET_ALL
, _player
);
1700 _player
->ResetInstances(INSTANCE_RESET_ALL
);
1703 void WorldSession::HandleDungeonDifficultyOpcode( WorldPacket
& recv_data
)
1705 CHECK_PACKET_SIZE(recv_data
, 4);
1707 sLog
.outDebug("MSG_SET_DUNGEON_DIFFICULTY");
1712 if(mode
== _player
->GetDifficulty())
1715 if(mode
> DIFFICULTY_HEROIC
)
1717 sLog
.outError("WorldSession::HandleDungeonDifficultyOpcode: player %d sent an invalid instance mode %d!", _player
->GetGUIDLow(), mode
);
1721 // cannot reset while in an instance
1722 Map
*map
= _player
->GetMap();
1723 if(map
&& map
->IsDungeon())
1725 sLog
.outError("WorldSession::HandleDungeonDifficultyOpcode: player %d tried to reset the instance while inside!", _player
->GetGUIDLow());
1729 if(_player
->getLevel() < LEVELREQUIREMENT_HEROIC
)
1731 Group
*pGroup
= _player
->GetGroup();
1734 if(pGroup
->IsLeader(_player
->GetGUID()))
1736 // the difficulty is set even if the instances can't be reset
1737 //_player->SendDungeonDifficulty(true);
1738 pGroup
->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY
, _player
);
1739 pGroup
->SetDifficulty(mode
);
1744 _player
->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY
);
1745 _player
->SetDifficulty(mode
);
1749 void WorldSession::HandleNewUnknownOpcode( WorldPacket
& recv_data
)
1751 sLog
.outDebug("New Unknown Opcode %u", recv_data
.GetOpcode());
1752 recv_data
.hexlike();
1754 New Unknown Opcode 837
1756 02 00 00 00 00 00 00 00 | 00 00 00 00 01 20 00 00
1757 89 EB 33 01 71 5C 24 C4 | 15 03 35 45 74 47 8B 42
1758 BA B8 1B 40 00 00 00 00 | 00 00 00 00 77 66 42 BF
1759 23 91 26 3F 00 00 60 41 | 00 00 00 00
1761 New Unknown Opcode 837
1763 02 00 00 00 00 00 00 00 | 00 00 00 00 00 00 80 00
1764 7B 80 34 01 84 EA 2B C4 | 5F A1 36 45 C9 39 1C 42
1765 BA B8 1B 40 CE 06 00 00 | 00 00 80 3F
1769 void WorldSession::HandleDismountOpcode( WorldPacket
& /*recv_data*/ )
1771 sLog
.outDebug("WORLD: CMSG_CANCEL_MOUNT_AURA");
1772 //recv_data.hexlike();
1774 //If player is not mounted, so go out :)
1775 if (!_player
->IsMounted()) // not blizz like; no any messages on blizz
1777 ChatHandler(this).SendSysMessage(LANG_CHAR_NON_MOUNTED
);
1781 if(_player
->isInFlight()) // not blizz like; no any messages on blizz
1783 ChatHandler(this).SendSysMessage(LANG_YOU_IN_FLIGHT
);
1788 _player
->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED
);
1791 void WorldSession::HandleMoveFlyModeChangeAckOpcode( WorldPacket
& recv_data
)
1793 CHECK_PACKET_SIZE(recv_data
, 8+4+4);
1796 sLog
.outDebug("WORLD: CMSG_MOVE_SET_CAN_FLY_ACK");
1797 //recv_data.hexlike();
1803 recv_data
>> guid
>> unk
>> flags
;
1805 _player
->SetUnitMovementFlags(flags
);
1808 25 00 00 00 00 00 00 00 | 00 00 00 00 00 00 80 00
1809 85 4E A9 01 19 BA 7A C3 | 42 0D 70 44 44 B0 A8 42
1810 78 15 94 40 39 03 00 00 | 00 00 80 3F
1812 25 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00
1813 10 FD A9 01 19 BA 7A C3 | 42 0D 70 44 44 B0 A8 42
1814 78 15 94 40 39 03 00 00 | 00 00 00 00
1818 void WorldSession::HandleRequestPetInfoOpcode( WorldPacket
& /*recv_data */)
1821 sLog.outDebug("WORLD: CMSG_REQUEST_PET_INFO");
1822 recv_data.hexlike();
1826 void WorldSession::HandleSetTaxiBenchmarkOpcode( WorldPacket
& recv_data
)
1828 CHECK_PACKET_SIZE(recv_data
, 1);
1833 sLog
.outDebug("Client used \"/timetest %d\" command", mode
);
1836 void WorldSession::HandleSpellClick( WorldPacket
& recv_data
)
1838 CHECK_PACKET_SIZE(recv_data
, 8);
1843 Unit
*vehicle
= ObjectAccessor::GetUnit(*_player
, guid
);
1848 _player
->SetClientControl(vehicle
, 1);
1849 _player
->CastSpell(_player
, 43768, true);
1850 _player
->SetUInt64Value(UNIT_FIELD_CHARM
, guid
);
1851 _player
->SetUInt64Value(PLAYER_FARSIGHT
, guid
);