[9636] Move item real-time/in-game duration counting flag to new extraflags field.
[getmangos.git] / src / game / MiscHandler.cpp
blobd9589305d6ad792f19394d1ae2fd096965552792
1 /*
2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Common.h"
20 #include "Language.h"
21 #include "Database/DatabaseEnv.h"
22 #include "Database/DatabaseImpl.h"
23 #include "WorldPacket.h"
24 #include "Opcodes.h"
25 #include "Log.h"
26 #include "Player.h"
27 #include "World.h"
28 #include "ObjectMgr.h"
29 #include "ObjectGuid.h"
30 #include "WorldSession.h"
31 #include "Auth/BigNumber.h"
32 #include "Auth/Sha1.h"
33 #include "UpdateData.h"
34 #include "LootMgr.h"
35 #include "Chat.h"
36 #include "ScriptCalls.h"
37 #include <zlib/zlib.h>
38 #include "ObjectAccessor.h"
39 #include "Object.h"
40 #include "BattleGround.h"
41 #include "Pet.h"
42 #include "SocialMgr.h"
43 #include "DBCEnums.h"
45 void WorldSession::HandleRepopRequestOpcode( WorldPacket & recv_data )
47 sLog.outDebug( "WORLD: Recvd CMSG_REPOP_REQUEST Message" );
49 recv_data.read_skip<uint8>();
51 if(GetPlayer()->isAlive() || GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST))
52 return;
54 // the world update order is sessions, players, creatures
55 // the netcode runs in parallel with all of these
56 // creatures can kill players
57 // so if the server is lagging enough the player can
58 // release spirit after he's killed but before he is updated
59 if(GetPlayer()->getDeathState() == JUST_DIED)
61 sLog.outDebug("HandleRepopRequestOpcode: got request after player %s(%d) was killed and before he was updated", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow());
62 GetPlayer()->KillPlayer();
65 //this is spirit release confirm?
66 GetPlayer()->RemovePet(NULL,PET_SAVE_NOT_IN_SLOT, true);
67 GetPlayer()->BuildPlayerRepop();
68 GetPlayer()->RepopAtGraveyard();
71 void WorldSession::HandleWhoOpcode( WorldPacket & recv_data )
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...
86 recv_data >> guild_name; // guild name, case sensitive...
88 recv_data >> racemask; // race mask
89 recv_data >> classmask; // class mask
90 recv_data >> zones_count; // zones count, client limit=10 (2.0.10)
92 if(zones_count > 10)
93 return; // can't be received from real client or broken packet
95 for(uint32 i = 0; i < zones_count; ++i)
97 uint32 temp;
98 recv_data >> temp; // zone id, 0 if zone is unknown...
99 zoneids[i] = temp;
100 sLog.outDebug("Zone %u: %u", i, zoneids[i]);
103 recv_data >> str_count; // user entered strings count, client limit=4 (checked on 2.0.10)
105 if(str_count > 4)
106 return; // can't be received from real client or broken packet
108 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);
110 std::wstring str[4]; // 4 is client limit
111 for(uint32 i = 0; i < str_count; ++i)
113 std::string temp;
114 recv_data >> temp; // user entered string, it used as universal search pattern(guild+player name)?
116 if(!Utf8toWStr(temp,str[i]))
117 continue;
119 wstrToLower(str[i]);
121 sLog.outDebug("String %u: %s", i, temp.c_str());
124 std::wstring wplayer_name;
125 std::wstring wguild_name;
126 if(!(Utf8toWStr(player_name, wplayer_name) && Utf8toWStr(guild_name, wguild_name)))
127 return;
128 wstrToLower(wplayer_name);
129 wstrToLower(wguild_name);
131 // client send in case not set max level value 100 but mangos support 255 max level,
132 // update it to show GMs with characters after 100 level
133 if(level_max >= MAX_LEVEL)
134 level_max = STRONG_MAX_LEVEL;
136 uint32 team = _player->GetTeam();
137 uint32 security = GetSecurity();
138 bool allowTwoSideWhoList = sWorld.getConfig(CONFIG_BOOL_ALLOW_TWO_SIDE_WHO_LIST);
139 AccountTypes gmLevelInWhoList = (AccountTypes)sWorld.getConfig(CONFIG_UINT32_GM_LEVEL_IN_WHO_LIST);
141 WorldPacket data( SMSG_WHO, 50 ); // guess size
142 data << clientcount; // clientcount place holder
143 data << clientcount; // clientcount place holder
145 //TODO: Guard Player map
146 HashMapHolder<Player>::MapType& m = sObjectAccessor.GetPlayers();
147 for(HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
149 if (security == SEC_PLAYER)
151 // player can see member of other team only if CONFIG_BOOL_ALLOW_TWO_SIDE_WHO_LIST
152 if (itr->second->GetTeam() != team && !allowTwoSideWhoList )
153 continue;
155 // player can see MODERATOR, GAME MASTER, ADMINISTRATOR only if CONFIG_GM_IN_WHO_LIST
156 if (itr->second->GetSession()->GetSecurity() > gmLevelInWhoList)
157 continue;
160 //do not process players which are not in world
161 if(!(itr->second->IsInWorld()))
162 continue;
164 // check if target is globally visible for player
165 if (!(itr->second->IsVisibleGloballyFor(_player)))
166 continue;
168 // check if target's level is in level range
169 uint32 lvl = itr->second->getLevel();
170 if (lvl < level_min || lvl > level_max)
171 continue;
173 // check if class matches classmask
174 uint32 class_ = itr->second->getClass();
175 if (!(classmask & (1 << class_)))
176 continue;
178 // check if race matches racemask
179 uint32 race = itr->second->getRace();
180 if (!(racemask & (1 << race)))
181 continue;
183 uint32 pzoneid = itr->second->GetZoneId();
185 bool z_show = true;
186 for(uint32 i = 0; i < zones_count; ++i)
188 if(zoneids[i] == pzoneid)
190 z_show = true;
191 break;
194 z_show = false;
196 if (!z_show)
197 continue;
199 std::string pname = itr->second->GetName();
200 std::wstring wpname;
201 if(!Utf8toWStr(pname,wpname))
202 continue;
203 wstrToLower(wpname);
205 if (!(wplayer_name.empty() || wpname.find(wplayer_name) != std::wstring::npos))
206 continue;
208 std::string gname = sObjectMgr.GetGuildNameById(itr->second->GetGuildId());
209 std::wstring wgname;
210 if(!Utf8toWStr(gname,wgname))
211 continue;
212 wstrToLower(wgname);
214 if (!(wguild_name.empty() || wgname.find(wguild_name) != std::wstring::npos))
215 continue;
217 std::string aname;
218 if(AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(itr->second->GetZoneId()))
219 aname = areaEntry->area_name[GetSessionDbcLocale()];
221 bool s_show = true;
222 for(uint32 i = 0; i < str_count; ++i)
224 if (!str[i].empty())
226 if (wgname.find(str[i]) != std::wstring::npos ||
227 wpname.find(str[i]) != std::wstring::npos ||
228 Utf8FitTo(aname, str[i]) )
230 s_show = true;
231 break;
233 s_show = false;
236 if (!s_show)
237 continue;
239 data << pname; // player name
240 data << gname; // guild name
241 data << uint32( lvl ); // player level
242 data << uint32( class_ ); // player class
243 data << uint32( race ); // player race
244 data << uint8(0); // new 2.4.0
245 data << uint32( pzoneid ); // player zone id
247 // 49 is maximum player count sent to client
248 if ((++clientcount) == 49)
249 break;
252 data.put( 0, clientcount ); // insert right count
253 data.put( sizeof(uint32), clientcount ); // insert right count
255 SendPacket(&data);
256 sLog.outDebug( "WORLD: Send SMSG_WHO Message" );
259 void WorldSession::HandleLogoutRequestOpcode( WorldPacket & /*recv_data*/ )
261 sLog.outDebug( "WORLD: Recvd CMSG_LOGOUT_REQUEST Message, security - %u", GetSecurity() );
263 if (uint64 lguid = GetPlayer()->GetLootGUID())
264 DoLootRelease(lguid);
266 //Can not logout if...
267 if( GetPlayer()->isInCombat() || //...is in combat
268 GetPlayer()->duel || //...is in Duel
269 //...is jumping ...is falling
270 GetPlayer()->m_movementInfo.HasMovementFlag(MovementFlags(MOVEFLAG_FALLING | MOVEFLAG_FALLINGFAR)))
272 WorldPacket data( SMSG_LOGOUT_RESPONSE, (2+4) ) ;
273 data << (uint8)0xC;
274 data << uint32(0);
275 data << uint8(0);
276 SendPacket( &data );
277 LogoutRequest(0);
278 return;
281 //instant logout in taverns/cities or on taxi or for admins, gm's, mod's if its enabled in mangosd.conf
282 if (GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING) || GetPlayer()->isInFlight() ||
283 GetSecurity() >= (AccountTypes)sWorld.getConfig(CONFIG_UINT32_INSTANT_LOGOUT))
285 LogoutPlayer(true);
286 return;
289 // not set flags if player can't free move to prevent lost state at logout cancel
290 if(GetPlayer()->CanFreeMove())
292 GetPlayer()->SetStandState(UNIT_STAND_STATE_SIT);
294 WorldPacket data( SMSG_FORCE_MOVE_ROOT, (8+4) ); // guess size
295 data << GetPlayer()->GetPackGUID();
296 data << (uint32)2;
297 SendPacket( &data );
298 GetPlayer()->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
301 WorldPacket data( SMSG_LOGOUT_RESPONSE, 5 );
302 data << uint32(0);
303 data << uint8(0);
304 SendPacket( &data );
305 LogoutRequest(time(NULL));
308 void WorldSession::HandlePlayerLogoutOpcode( WorldPacket & /*recv_data*/ )
310 sLog.outDebug( "WORLD: Recvd CMSG_PLAYER_LOGOUT Message" );
313 void WorldSession::HandleLogoutCancelOpcode( WorldPacket & /*recv_data*/ )
315 sLog.outDebug( "WORLD: Recvd CMSG_LOGOUT_CANCEL Message" );
317 LogoutRequest(0);
319 WorldPacket data( SMSG_LOGOUT_CANCEL_ACK, 0 );
320 SendPacket( &data );
322 // not remove flags if can't free move - its not set in Logout request code.
323 if(GetPlayer()->CanFreeMove())
325 //!we can move again
326 data.Initialize( SMSG_FORCE_MOVE_UNROOT, 8 ); // guess size
327 data << GetPlayer()->GetPackGUID();
328 data << uint32(0);
329 SendPacket( &data );
331 //! Stand Up
332 GetPlayer()->SetStandState(UNIT_STAND_STATE_STAND);
334 //! DISABLE_ROTATE
335 GetPlayer()->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
338 sLog.outDebug( "WORLD: sent SMSG_LOGOUT_CANCEL_ACK Message" );
341 void WorldSession::HandleTogglePvP( WorldPacket & recv_data )
343 // this opcode can be used in two ways: Either set explicit new status or toggle old status
344 if(recv_data.size() == 1)
346 bool newPvPStatus;
347 recv_data >> newPvPStatus;
348 GetPlayer()->ApplyModFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP, newPvPStatus);
349 GetPlayer()->ApplyModFlag(PLAYER_FLAGS, PLAYER_FLAGS_PVP_TIMER, !newPvPStatus);
351 else
353 GetPlayer()->ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP);
354 GetPlayer()->ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_PVP_TIMER);
357 if(GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP))
359 if(!GetPlayer()->IsPvP() || GetPlayer()->pvpInfo.endTimer != 0)
360 GetPlayer()->UpdatePvP(true, true);
362 else
364 if(!GetPlayer()->pvpInfo.inHostileArea && GetPlayer()->IsPvP())
365 GetPlayer()->pvpInfo.endTimer = time(NULL); // start toggle-off
369 void WorldSession::HandleZoneUpdateOpcode( WorldPacket & recv_data )
371 uint32 newZone;
372 recv_data >> newZone;
374 sLog.outDetail("WORLD: Recvd ZONE_UPDATE: %u", newZone);
376 // use server size data
377 uint32 newzone, newarea;
378 GetPlayer()->GetZoneAndAreaId(newzone, newarea);
379 GetPlayer()->UpdateZone(newzone, newarea);
382 void WorldSession::HandleSetTargetOpcode( WorldPacket & recv_data )
384 // When this packet send?
385 uint64 guid ;
386 recv_data >> guid;
388 _player->SetTargetGUID(guid);
390 // update reputation list if need
391 Unit* unit = ObjectAccessor::GetUnit(*_player, guid );
392 if(!unit)
393 return;
395 if(FactionTemplateEntry const* factionTemplateEntry = sFactionTemplateStore.LookupEntry(unit->getFaction()))
396 _player->GetReputationMgr().SetVisible(factionTemplateEntry);
399 void WorldSession::HandleSetSelectionOpcode( WorldPacket & recv_data )
401 uint64 guid;
402 recv_data >> guid;
404 _player->SetSelection(guid);
406 // update reputation list if need
407 Unit* unit = ObjectAccessor::GetUnit(*_player, guid );
408 if(!unit)
409 return;
411 if(FactionTemplateEntry const* factionTemplateEntry = sFactionTemplateStore.LookupEntry(unit->getFaction()))
412 _player->GetReputationMgr().SetVisible(factionTemplateEntry);
415 void WorldSession::HandleStandStateChangeOpcode( WorldPacket & recv_data )
417 // sLog.outDebug( "WORLD: Received CMSG_STANDSTATECHANGE" ); -- too many spam in log at lags/debug stop
418 uint32 animstate;
419 recv_data >> animstate;
421 _player->SetStandState(animstate);
424 void WorldSession::HandleContactListOpcode( WorldPacket & recv_data )
426 sLog.outDebug( "WORLD: Received CMSG_CONTACT_LIST" );
427 uint32 unk;
428 recv_data >> unk;
429 sLog.outDebug("unk value is %u", unk);
430 _player->GetSocial()->SendSocialList();
433 void WorldSession::HandleAddFriendOpcode( WorldPacket & recv_data )
435 sLog.outDebug( "WORLD: Received CMSG_ADD_FRIEND" );
437 std::string friendName = GetMangosString(LANG_FRIEND_IGNORE_UNKNOWN);
438 std::string friendNote;
440 recv_data >> friendName;
442 recv_data >> friendNote;
444 if(!normalizePlayerName(friendName))
445 return;
447 CharacterDatabase.escape_string(friendName); // prevent SQL injection - normal name don't must changed by this call
449 sLog.outDebug( "WORLD: %s asked to add friend : '%s'",
450 GetPlayer()->GetName(), friendName.c_str() );
452 CharacterDatabase.AsyncPQuery(&WorldSession::HandleAddFriendOpcodeCallBack, GetAccountId(), friendNote, "SELECT guid, race FROM characters WHERE name = '%s'", friendName.c_str());
455 void WorldSession::HandleAddFriendOpcodeCallBack(QueryResult *result, uint32 accountId, std::string friendNote)
457 if(!result)
458 return;
460 uint64 friendGuid = MAKE_NEW_GUID((*result)[0].GetUInt32(), 0, HIGHGUID_PLAYER);
461 uint32 team = Player::TeamForRace((*result)[1].GetUInt8());
463 delete result;
465 WorldSession * session = sWorld.FindSession(accountId);
466 if(!session || !session->GetPlayer())
467 return;
469 FriendsResult friendResult = FRIEND_NOT_FOUND;
470 if(friendGuid)
472 if(friendGuid==session->GetPlayer()->GetGUID())
473 friendResult = FRIEND_SELF;
474 else if(session->GetPlayer()->GetTeam() != team && !sWorld.getConfig(CONFIG_BOOL_ALLOW_TWO_SIDE_ADD_FRIEND) && session->GetSecurity() < SEC_MODERATOR)
475 friendResult = FRIEND_ENEMY;
476 else if(session->GetPlayer()->GetSocial()->HasFriend(GUID_LOPART(friendGuid)))
477 friendResult = FRIEND_ALREADY;
478 else
480 Player* pFriend = ObjectAccessor::FindPlayer(friendGuid);
481 if( pFriend && pFriend->IsInWorld() && pFriend->IsVisibleGloballyFor(session->GetPlayer()))
482 friendResult = FRIEND_ADDED_ONLINE;
483 else
484 friendResult = FRIEND_ADDED_OFFLINE;
486 if(!session->GetPlayer()->GetSocial()->AddToSocialList(GUID_LOPART(friendGuid), false))
488 friendResult = FRIEND_LIST_FULL;
489 sLog.outDebug( "WORLD: %s's friend list is full.", session->GetPlayer()->GetName());
492 session->GetPlayer()->GetSocial()->SetFriendNote(GUID_LOPART(friendGuid), friendNote);
496 sSocialMgr.SendFriendStatus(session->GetPlayer(), friendResult, GUID_LOPART(friendGuid), false);
498 sLog.outDebug( "WORLD: Sent (SMSG_FRIEND_STATUS)" );
501 void WorldSession::HandleDelFriendOpcode( WorldPacket & recv_data )
503 uint64 FriendGUID;
505 sLog.outDebug( "WORLD: Received CMSG_DEL_FRIEND" );
507 recv_data >> FriendGUID;
509 _player->GetSocial()->RemoveFromSocialList(GUID_LOPART(FriendGUID), false);
511 sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_REMOVED, GUID_LOPART(FriendGUID), false);
513 sLog.outDebug( "WORLD: Sent motd (SMSG_FRIEND_STATUS)" );
516 void WorldSession::HandleAddIgnoreOpcode( WorldPacket & recv_data )
518 sLog.outDebug( "WORLD: Received CMSG_ADD_IGNORE" );
520 std::string IgnoreName = GetMangosString(LANG_FRIEND_IGNORE_UNKNOWN);
522 recv_data >> IgnoreName;
524 if(!normalizePlayerName(IgnoreName))
525 return;
527 CharacterDatabase.escape_string(IgnoreName); // prevent SQL injection - normal name don't must changed by this call
529 sLog.outDebug( "WORLD: %s asked to Ignore: '%s'",
530 GetPlayer()->GetName(), IgnoreName.c_str() );
532 CharacterDatabase.AsyncPQuery(&WorldSession::HandleAddIgnoreOpcodeCallBack, GetAccountId(), "SELECT guid FROM characters WHERE name = '%s'", IgnoreName.c_str());
535 void WorldSession::HandleAddIgnoreOpcodeCallBack(QueryResult *result, uint32 accountId)
537 if(!result)
538 return;
540 uint64 IgnoreGuid = MAKE_NEW_GUID((*result)[0].GetUInt32(), 0, HIGHGUID_PLAYER);
542 delete result;
544 WorldSession * session = sWorld.FindSession(accountId);
545 if(!session || !session->GetPlayer())
546 return;
548 FriendsResult ignoreResult = FRIEND_IGNORE_NOT_FOUND;
549 if(IgnoreGuid)
551 if(IgnoreGuid == session->GetPlayer()->GetGUID()) //not add yourself
552 ignoreResult = FRIEND_IGNORE_SELF;
553 else if( session->GetPlayer()->GetSocial()->HasIgnore(GUID_LOPART(IgnoreGuid)) )
554 ignoreResult = FRIEND_IGNORE_ALREADY;
555 else
557 ignoreResult = FRIEND_IGNORE_ADDED;
559 // ignore list full
560 if(!session->GetPlayer()->GetSocial()->AddToSocialList(GUID_LOPART(IgnoreGuid), true))
561 ignoreResult = FRIEND_IGNORE_FULL;
565 sSocialMgr.SendFriendStatus(session->GetPlayer(), ignoreResult, GUID_LOPART(IgnoreGuid), false);
567 sLog.outDebug( "WORLD: Sent (SMSG_FRIEND_STATUS)" );
570 void WorldSession::HandleDelIgnoreOpcode( WorldPacket & recv_data )
572 uint64 IgnoreGUID;
574 sLog.outDebug( "WORLD: Received CMSG_DEL_IGNORE" );
576 recv_data >> IgnoreGUID;
578 _player->GetSocial()->RemoveFromSocialList(GUID_LOPART(IgnoreGUID), true);
580 sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_IGNORE_REMOVED, GUID_LOPART(IgnoreGUID), false);
582 sLog.outDebug( "WORLD: Sent motd (SMSG_FRIEND_STATUS)" );
585 void WorldSession::HandleSetContactNotesOpcode( WorldPacket & recv_data )
587 sLog.outDebug("CMSG_SET_CONTACT_NOTES");
588 uint64 guid;
589 std::string note;
590 recv_data >> guid >> note;
591 _player->GetSocial()->SetFriendNote(GUID_LOPART(guid), note);
594 void WorldSession::HandleBugOpcode( WorldPacket & recv_data )
596 uint32 suggestion, contentlen, typelen;
597 std::string content, type;
599 recv_data >> suggestion >> contentlen >> content;
601 recv_data >> typelen >> type;
603 if( suggestion == 0 )
604 sLog.outDebug( "WORLD: Received CMSG_BUG [Bug Report]" );
605 else
606 sLog.outDebug( "WORLD: Received CMSG_BUG [Suggestion]" );
608 sLog.outDebug("%s", type.c_str() );
609 sLog.outDebug("%s", content.c_str() );
611 CharacterDatabase.escape_string(type);
612 CharacterDatabase.escape_string(content);
613 CharacterDatabase.PExecute ("INSERT INTO bugreport (type,content) VALUES('%s', '%s')", type.c_str( ), content.c_str( ));
616 void WorldSession::HandleReclaimCorpseOpcode(WorldPacket &recv_data)
618 sLog.outDetail("WORLD: Received CMSG_RECLAIM_CORPSE");
619 if (GetPlayer()->isAlive())
620 return;
622 // do not allow corpse reclaim in arena
623 if (GetPlayer()->InArena())
624 return;
626 // body not released yet
627 if(!GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST))
628 return;
630 Corpse *corpse = GetPlayer()->GetCorpse();
632 if (!corpse )
633 return;
635 // prevent resurrect before 30-sec delay after body release not finished
636 if(corpse->GetGhostTime() + GetPlayer()->GetCorpseReclaimDelay(corpse->GetType()==CORPSE_RESURRECTABLE_PVP) > time(NULL))
637 return;
639 if (!corpse->IsWithinDistInMap(GetPlayer(), CORPSE_RECLAIM_RADIUS, true))
640 return;
642 uint64 guid;
643 recv_data >> guid;
645 // resurrect
646 GetPlayer()->ResurrectPlayer(GetPlayer()->InBattleGround() ? 1.0f : 0.5f);
648 // spawn bones
649 GetPlayer()->SpawnCorpseBones();
652 void WorldSession::HandleResurrectResponseOpcode(WorldPacket & recv_data)
654 sLog.outDetail("WORLD: Received CMSG_RESURRECT_RESPONSE");
656 if(GetPlayer()->isAlive())
657 return;
659 uint64 guid;
660 uint8 status;
661 recv_data >> guid;
662 recv_data >> status;
664 if(status == 0)
666 GetPlayer()->clearResurrectRequestData(); // reject
667 return;
670 if(!GetPlayer()->isRessurectRequestedBy(guid))
671 return;
673 GetPlayer()->ResurectUsingRequestData(); // will call spawncorpsebones
676 void WorldSession::HandleAreaTriggerOpcode(WorldPacket & recv_data)
678 sLog.outDebug("WORLD: Received CMSG_AREATRIGGER");
680 uint32 Trigger_ID;
682 recv_data >> Trigger_ID;
683 sLog.outDebug("Trigger ID: %u", Trigger_ID);
685 if(GetPlayer()->isInFlight())
687 sLog.outDebug("Player '%s' (GUID: %u) in flight, ignore Area Trigger ID: %u", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow(), Trigger_ID);
688 return;
691 AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(Trigger_ID);
692 if(!atEntry)
694 sLog.outDebug("Player '%s' (GUID: %u) send unknown (by DBC) Area Trigger ID: %u", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow(), Trigger_ID);
695 return;
698 // delta is safe radius
699 const float delta = 5.0f;
700 // check if player in the range of areatrigger
701 Player* pl = GetPlayer();
703 if (!IsPointInAreaTriggerZone(atEntry, pl->GetMapId(), pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), delta))
705 sLog.outDebug("Player '%s' (GUID: %u) too far, ignore Area Trigger ID: %u", pl->GetName(), pl->GetGUIDLow(), Trigger_ID);
706 return;
709 if(Script->scriptAreaTrigger(pl, atEntry))
710 return;
712 uint32 quest_id = sObjectMgr.GetQuestForAreaTrigger( Trigger_ID );
713 if( quest_id && pl->isAlive() && pl->IsActiveQuest(quest_id) )
715 Quest const* pQuest = sObjectMgr.GetQuestTemplate(quest_id);
716 if( pQuest )
718 if(pl->GetQuestStatus(quest_id) == QUEST_STATUS_INCOMPLETE)
719 pl->AreaExploredOrEventHappens( quest_id );
723 // enter to tavern, not overwrite city rest
724 if(sObjectMgr.IsTavernAreaTrigger(Trigger_ID) && pl->GetRestType() != REST_TYPE_IN_CITY)
726 // set resting flag we are in the inn
727 pl->SetRestType(REST_TYPE_IN_TAVERN, Trigger_ID);
728 return;
731 if(pl->InBattleGround())
733 if (BattleGround* bg = pl->GetBattleGround())
734 bg->HandleAreaTrigger(pl, Trigger_ID);
735 return;
738 // NULL if all values default (non teleport trigger)
739 AreaTrigger const* at = sObjectMgr.GetAreaTrigger(Trigger_ID);
740 if(!at)
741 return;
743 if(!GetPlayer()->isGameMaster())
745 uint32 missingLevel = 0;
746 if(GetPlayer()->getLevel() < at->requiredLevel && !sWorld.getConfig(CONFIG_BOOL_INSTANCE_IGNORE_LEVEL))
747 missingLevel = at->requiredLevel;
749 // must have one or the other, report the first one that's missing
750 uint32 missingItem = 0;
751 if(at->requiredItem)
753 if(!GetPlayer()->HasItemCount(at->requiredItem, 1) &&
754 (!at->requiredItem2 || !GetPlayer()->HasItemCount(at->requiredItem2, 1)))
755 missingItem = at->requiredItem;
757 else if(at->requiredItem2 && !GetPlayer()->HasItemCount(at->requiredItem2, 1))
758 missingItem = at->requiredItem2;
760 MapEntry const* mapEntry = sMapStore.LookupEntry(at->target_mapId);
761 if(!mapEntry)
762 return;
764 bool isRegularTargetMap = GetPlayer()->GetDifficulty(mapEntry->IsRaid()) == REGULAR_DIFFICULTY;
766 uint32 missingKey = 0;
767 if (!isRegularTargetMap)
769 if(at->heroicKey)
771 if(!GetPlayer()->HasItemCount(at->heroicKey, 1) &&
772 (!at->heroicKey2 || !GetPlayer()->HasItemCount(at->heroicKey2, 1)))
773 missingKey = at->heroicKey;
775 else if(at->heroicKey2 && !GetPlayer()->HasItemCount(at->heroicKey2, 1))
776 missingKey = at->heroicKey2;
779 uint32 missingQuest = 0;
780 if (!isRegularTargetMap)
782 if (at->requiredQuestHeroic && !GetPlayer()->GetQuestRewardStatus(at->requiredQuestHeroic))
783 missingQuest = at->requiredQuestHeroic;
785 else
787 if(at->requiredQuest && !GetPlayer()->GetQuestRewardStatus(at->requiredQuest))
788 missingQuest = at->requiredQuest;
791 if(missingLevel || missingItem || missingKey || missingQuest)
793 // TODO: all this is probably wrong
794 if(missingItem)
795 SendAreaTriggerMessage(GetMangosString(LANG_LEVEL_MINREQUIRED_AND_ITEM), at->requiredLevel, ObjectMgr::GetItemPrototype(missingItem)->Name1);
796 else if(missingKey)
797 GetPlayer()->SendTransferAborted(at->target_mapId, TRANSFER_ABORT_DIFFICULTY, isRegularTargetMap ? DUNGEON_DIFFICULTY_NORMAL : DUNGEON_DIFFICULTY_HEROIC);
798 else if(missingQuest)
799 SendAreaTriggerMessage("%s", at->requiredFailedText.c_str());
800 else if(missingLevel)
801 SendAreaTriggerMessage(GetMangosString(LANG_LEVEL_MINREQUIRED), missingLevel);
802 return;
806 GetPlayer()->TeleportTo(at->target_mapId, at->target_X, at->target_Y, at->target_Z, at->target_Orientation, TELE_TO_NOT_LEAVE_TRANSPORT);
809 void WorldSession::HandleUpdateAccountData(WorldPacket &recv_data)
811 sLog.outDetail("WORLD: Received CMSG_UPDATE_ACCOUNT_DATA");
813 uint32 type, timestamp, decompressedSize;
814 recv_data >> type >> timestamp >> decompressedSize;
816 sLog.outDebug("UAD: type %u, time %u, decompressedSize %u", type, timestamp, decompressedSize);
818 if(type > NUM_ACCOUNT_DATA_TYPES)
819 return;
821 if(decompressedSize == 0) // erase
823 SetAccountData(AccountDataType(type), 0, "");
825 WorldPacket data(SMSG_UPDATE_ACCOUNT_DATA_COMPLETE, 4+4);
826 data << uint32(type);
827 data << uint32(0);
828 SendPacket(&data);
830 return;
833 if(decompressedSize > 0xFFFF)
835 recv_data.rpos(recv_data.wpos()); // unnneded warning spam in this case
836 sLog.outError("UAD: Account data packet too big, size %u", decompressedSize);
837 return;
840 ByteBuffer dest;
841 dest.resize(decompressedSize);
843 uLongf realSize = decompressedSize;
844 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)
846 recv_data.rpos(recv_data.wpos()); // unneded warning spam in this case
847 sLog.outError("UAD: Failed to decompress account data");
848 return;
851 recv_data.rpos(recv_data.wpos()); // uncompress read (recv_data.size() - recv_data.rpos())
853 std::string adata;
854 dest >> adata;
856 SetAccountData(AccountDataType(type), timestamp, adata);
858 WorldPacket data(SMSG_UPDATE_ACCOUNT_DATA_COMPLETE, 4+4);
859 data << uint32(type);
860 data << uint32(0);
861 SendPacket(&data);
864 void WorldSession::HandleRequestAccountData(WorldPacket& recv_data)
866 sLog.outDetail("WORLD: Received CMSG_REQUEST_ACCOUNT_DATA");
868 uint32 type;
869 recv_data >> type;
871 sLog.outDebug("RAD: type %u", type);
873 if(type > NUM_ACCOUNT_DATA_TYPES)
874 return;
876 AccountData *adata = GetAccountData(AccountDataType(type));
878 uint32 size = adata->Data.size();
880 uLongf destSize = compressBound(size);
882 ByteBuffer dest;
883 dest.resize(destSize);
885 if(size && compress(const_cast<uint8*>(dest.contents()), &destSize, (uint8*)adata->Data.c_str(), size) != Z_OK)
887 sLog.outDebug("RAD: Failed to compress account data");
888 return;
891 dest.resize(destSize);
893 WorldPacket data(SMSG_UPDATE_ACCOUNT_DATA, 8+4+4+4+destSize);
894 data << uint64(_player ? _player->GetGUID() : 0); // player guid
895 data << uint32(type); // type (0-7)
896 data << uint32(adata->Time); // unix time
897 data << uint32(size); // decompressed length
898 data.append(dest); // compressed data
899 SendPacket(&data);
902 void WorldSession::HandleSetActionButtonOpcode(WorldPacket& recv_data)
904 sLog.outDebug( "WORLD: Received CMSG_SET_ACTION_BUTTON" );
905 uint8 button;
906 uint32 packetData;
907 recv_data >> button >> packetData;
909 uint32 action = ACTION_BUTTON_ACTION(packetData);
910 uint8 type = ACTION_BUTTON_TYPE(packetData);
912 sLog.outDetail( "BUTTON: %u ACTION: %u TYPE: %u", button, action, type );
913 if (!packetData)
915 sLog.outDetail( "MISC: Remove action from button %u", button );
916 GetPlayer()->removeActionButton(GetPlayer()->GetActiveSpec(),button);
918 else
920 switch(type)
922 case ACTION_BUTTON_MACRO:
923 case ACTION_BUTTON_CMACRO:
924 sLog.outDetail( "MISC: Added Macro %u into button %u", action, button );
925 break;
926 case ACTION_BUTTON_EQSET:
927 sLog.outDetail( "MISC: Added EquipmentSet %u into button %u", action, button );
928 break;
929 case ACTION_BUTTON_SPELL:
930 sLog.outDetail( "MISC: Added Spell %u into button %u", action, button );
931 break;
932 case ACTION_BUTTON_ITEM:
933 sLog.outDetail( "MISC: Added Item %u into button %u", action, button );
934 break;
935 default:
936 sLog.outError( "MISC: Unknown action button type %u for action %u into button %u", type, action, button );
937 return;
939 GetPlayer()->addActionButton(GetPlayer()->m_activeSpec, button, action, type);
943 void WorldSession::HandleCompleteCinematic( WorldPacket & /*recv_data*/ )
945 DEBUG_LOG( "WORLD: Player is watching cinema" );
948 void WorldSession::HandleNextCinematicCamera( WorldPacket & /*recv_data*/ )
950 DEBUG_LOG( "WORLD: Which movie to play" );
953 void WorldSession::HandleMoveTimeSkippedOpcode( WorldPacket & recv_data )
955 /* WorldSession::Update( getMSTime() );*/
956 DEBUG_LOG( "WORLD: Time Lag/Synchronization Resent/Update" );
958 ObjectGuid guid;
960 recv_data >> guid.ReadAsPacked();
961 recv_data >> Unused<uint32>();
964 uint64 guid;
965 uint32 time_skipped;
966 recv_data >> guid;
967 recv_data >> time_skipped;
968 sLog.outDebug( "WORLD: CMSG_MOVE_TIME_SKIPPED" );
970 /// TODO
971 must be need use in mangos
972 We substract server Lags to move time ( AntiLags )
973 for exmaple
974 GetPlayer()->ModifyLastMoveTime( -int32(time_skipped) );
978 void WorldSession::HandleFeatherFallAck(WorldPacket &recv_data)
980 DEBUG_LOG("WORLD: CMSG_MOVE_FEATHER_FALL_ACK");
982 // no used
983 recv_data.rpos(recv_data.wpos()); // prevent warnings spam
986 void WorldSession::HandleMoveUnRootAck(WorldPacket& recv_data)
988 // no used
989 recv_data.rpos(recv_data.wpos()); // prevent warnings spam
991 uint64 guid;
992 recv_data >> guid;
994 // now can skip not our packet
995 if(_player->GetGUID() != guid)
997 recv_data.rpos(recv_data.wpos()); // prevent warnings spam
998 return;
1001 sLog.outDebug( "WORLD: CMSG_FORCE_MOVE_UNROOT_ACK" );
1003 recv_data.read_skip<uint32>(); // unk
1005 MovementInfo movementInfo;
1006 ReadMovementInfo(recv_data, &movementInfo);
1010 void WorldSession::HandleMoveRootAck(WorldPacket& recv_data)
1012 // no used
1013 recv_data.rpos(recv_data.wpos()); // prevent warnings spam
1015 uint64 guid;
1016 recv_data >> guid;
1018 // now can skip not our packet
1019 if(_player->GetGUID() != guid)
1021 recv_data.rpos(recv_data.wpos()); // prevent warnings spam
1022 return;
1025 sLog.outDebug( "WORLD: CMSG_FORCE_MOVE_ROOT_ACK" );
1027 recv_data.read_skip<uint32>(); // unk
1029 MovementInfo movementInfo;
1030 ReadMovementInfo(recv_data, &movementInfo);
1034 void WorldSession::HandleSetActionBarToggles(WorldPacket& recv_data)
1036 uint8 ActionBar;
1038 recv_data >> ActionBar;
1040 if(!GetPlayer()) // ignore until not logged (check needed because STATUS_AUTHED)
1042 if(ActionBar != 0)
1043 sLog.outError("WorldSession::HandleSetActionBarToggles in not logged state with value: %u, ignored", uint32(ActionBar));
1044 return;
1047 GetPlayer()->SetByteValue(PLAYER_FIELD_BYTES, 2, ActionBar);
1050 void WorldSession::HandleWardenDataOpcode(WorldPacket& recv_data)
1052 recv_data.read_skip<uint8>();
1054 uint8 tmp;
1055 recv_data >> tmp;
1056 sLog.outDebug("Received opcode CMSG_WARDEN_DATA, not resolve.uint8 = %u", tmp);
1060 void WorldSession::HandlePlayedTime(WorldPacket& recv_data)
1062 uint8 unk1;
1063 recv_data >> unk1; // 0 or 1 expected
1065 WorldPacket data(SMSG_PLAYED_TIME, 4 + 4 + 1);
1066 data << uint32(_player->GetTotalPlayedTime());
1067 data << uint32(_player->GetLevelPlayedTime());
1068 data << uint8(unk1); // 0 - will not show in chat frame
1069 SendPacket(&data);
1072 void WorldSession::HandleInspectOpcode(WorldPacket& recv_data)
1074 uint64 guid;
1075 recv_data >> guid;
1076 DEBUG_LOG("Inspected guid is (GUID: %u TypeId: %u)", GUID_LOPART(guid), GuidHigh2TypeId(GUID_HIPART(guid)));
1078 _player->SetSelection(guid);
1080 Player *plr = sObjectMgr.GetPlayer(guid);
1081 if(!plr) // wrong player
1082 return;
1084 WorldPacket data(SMSG_INSPECT_TALENT, 50);
1085 data << plr->GetPackGUID();
1087 if(sWorld.getConfig(CONFIG_BOOL_TALENTS_INSPECTING) || _player->isGameMaster())
1089 plr->BuildPlayerTalentsInfoData(&data);
1090 plr->BuildEnchantmentsInfoData(&data);
1092 else
1094 data << uint32(0); // unspentTalentPoints
1095 data << uint8(0); // talentGroupCount
1096 data << uint8(0); // talentGroupIndex
1097 data << uint32(0); // slotUsedMask
1100 SendPacket(&data);
1103 void WorldSession::HandleInspectHonorStatsOpcode(WorldPacket& recv_data)
1105 uint64 guid;
1106 recv_data >> guid;
1108 Player *player = sObjectMgr.GetPlayer(guid);
1110 if(!player)
1112 sLog.outError("InspectHonorStats: WTF, player not found...");
1113 return;
1116 WorldPacket data(MSG_INSPECT_HONOR_STATS, 8+1+4*4);
1117 data << uint64(player->GetGUID());
1118 data << uint8(player->GetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY));
1119 data << uint32(player->GetUInt32Value(PLAYER_FIELD_KILLS));
1120 data << uint32(player->GetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION));
1121 data << uint32(player->GetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION));
1122 data << uint32(player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS));
1123 SendPacket(&data);
1126 void WorldSession::HandleWorldTeleportOpcode(WorldPacket& recv_data)
1128 // write in client console: worldport 469 452 6454 2536 180 or /console worldport 469 452 6454 2536 180
1129 // Received opcode CMSG_WORLD_TELEPORT
1130 // Time is ***, map=469, x=452.000000, y=6454.000000, z=2536.000000, orient=3.141593
1132 uint32 time;
1133 uint32 mapid;
1134 float PositionX;
1135 float PositionY;
1136 float PositionZ;
1137 float Orientation;
1139 recv_data >> time; // time in m.sec.
1140 recv_data >> mapid;
1141 recv_data >> PositionX;
1142 recv_data >> PositionY;
1143 recv_data >> PositionZ;
1144 recv_data >> Orientation; // o (3.141593 = 180 degrees)
1146 //sLog.outDebug("Received opcode CMSG_WORLD_TELEPORT");
1148 if(GetPlayer()->isInFlight())
1150 sLog.outDebug("Player '%s' (GUID: %u) in flight, ignore worldport command.",GetPlayer()->GetName(),GetPlayer()->GetGUIDLow());
1151 return;
1154 DEBUG_LOG("Time %u sec, map=%u, x=%f, y=%f, z=%f, orient=%f", time/1000, mapid, PositionX, PositionY, PositionZ, Orientation);
1156 if (GetSecurity() >= SEC_ADMINISTRATOR)
1157 GetPlayer()->TeleportTo(mapid, PositionX, PositionY, PositionZ, Orientation);
1158 else
1159 SendNotification(LANG_YOU_NOT_HAVE_PERMISSION);
1160 sLog.outDebug("Received worldport command from player %s", GetPlayer()->GetName());
1163 void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data)
1165 sLog.outDebug("Received opcode CMSG_WHOIS");
1166 std::string charname;
1167 recv_data >> charname;
1169 if (GetSecurity() < SEC_ADMINISTRATOR)
1171 SendNotification(LANG_YOU_NOT_HAVE_PERMISSION);
1172 return;
1175 if(charname.empty() || !normalizePlayerName (charname))
1177 SendNotification(LANG_NEED_CHARACTER_NAME);
1178 return;
1181 Player *plr = sObjectMgr.GetPlayer(charname.c_str());
1183 if(!plr)
1185 SendNotification(LANG_PLAYER_NOT_EXIST_OR_OFFLINE, charname.c_str());
1186 return;
1189 uint32 accid = plr->GetSession()->GetAccountId();
1191 QueryResult *result = loginDatabase.PQuery("SELECT username,email,last_ip FROM account WHERE id=%u", accid);
1192 if(!result)
1194 SendNotification(LANG_ACCOUNT_FOR_PLAYER_NOT_FOUND, charname.c_str());
1195 return;
1198 Field *fields = result->Fetch();
1199 std::string acc = fields[0].GetCppString();
1200 if(acc.empty())
1201 acc = "Unknown";
1202 std::string email = fields[1].GetCppString();
1203 if(email.empty())
1204 email = "Unknown";
1205 std::string lastip = fields[2].GetCppString();
1206 if(lastip.empty())
1207 lastip = "Unknown";
1209 std::string msg = charname + "'s " + "account is " + acc + ", e-mail: " + email + ", last ip: " + lastip;
1211 WorldPacket data(SMSG_WHOIS, msg.size()+1);
1212 data << msg;
1213 _player->GetSession()->SendPacket(&data);
1215 delete result;
1217 sLog.outDebug("Received whois command from player %s for character %s", GetPlayer()->GetName(), charname.c_str());
1220 void WorldSession::HandleComplainOpcode( WorldPacket & recv_data )
1222 sLog.outDebug("WORLD: CMSG_COMPLAIN");
1223 recv_data.hexlike();
1225 uint8 spam_type; // 0 - mail, 1 - chat
1226 uint64 spammer_guid;
1227 uint32 unk1 = 0;
1228 uint32 unk2 = 0;
1229 uint32 unk3 = 0;
1230 uint32 unk4 = 0;
1231 std::string description = "";
1232 recv_data >> spam_type; // unk 0x01 const, may be spam type (mail/chat)
1233 recv_data >> spammer_guid; // player guid
1234 switch(spam_type)
1236 case 0:
1237 recv_data >> unk1; // const 0
1238 recv_data >> unk2; // probably mail id
1239 recv_data >> unk3; // const 0
1240 break;
1241 case 1:
1242 recv_data >> unk1; // probably language
1243 recv_data >> unk2; // message type?
1244 recv_data >> unk3; // probably channel id
1245 recv_data >> unk4; // unk random value
1246 recv_data >> description; // spam description string (messagetype, channel name, player name, message)
1247 break;
1250 // NOTE: all chat messages from this spammer automatically ignored by spam reporter until logout in case chat spam.
1251 // if it's mail spam - ALL mails from this spammer automatically removed by client
1253 // Complaint Received message
1254 WorldPacket data(SMSG_COMPLAIN_RESULT, 1);
1255 data << uint8(0);
1256 SendPacket(&data);
1258 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());
1261 void WorldSession::HandleRealmSplitOpcode( WorldPacket & recv_data )
1263 sLog.outDebug("CMSG_REALM_SPLIT");
1265 uint32 unk;
1266 std::string split_date = "01/01/01";
1267 recv_data >> unk;
1269 WorldPacket data(SMSG_REALM_SPLIT, 4+4+split_date.size()+1);
1270 data << unk;
1271 data << uint32(0x00000000); // realm split state
1272 // split states:
1273 // 0x0 realm normal
1274 // 0x1 realm split
1275 // 0x2 realm split pending
1276 data << split_date;
1277 SendPacket(&data);
1278 //sLog.outDebug("response sent %u", unk);
1281 void WorldSession::HandleFarSightOpcode( WorldPacket & recv_data )
1283 sLog.outDebug("WORLD: CMSG_FAR_SIGHT");
1284 //recv_data.hexlike();
1286 uint8 unk;
1287 recv_data >> unk;
1289 switch(unk)
1291 case 0:
1292 //WorldPacket data(SMSG_CLEAR_FAR_SIGHT_IMMEDIATE, 0)
1293 //SendPacket(&data);
1294 //_player->SetUInt64Value(PLAYER_FARSIGHT, 0);
1295 sLog.outDebug("Removed FarSight from player %u", _player->GetGUIDLow());
1296 break;
1297 case 1:
1298 sLog.outDebug("Added FarSight (GUID:%u TypeId:%u) to player %u", GUID_LOPART(_player->GetFarSight()), GuidHigh2TypeId(GUID_HIPART(_player->GetFarSight())), _player->GetGUIDLow());
1299 break;
1303 void WorldSession::HandleSetTitleOpcode( WorldPacket & recv_data )
1305 sLog.outDebug("CMSG_SET_TITLE");
1307 int32 title;
1308 recv_data >> title;
1310 // -1 at none
1311 if(title > 0 && title < MAX_TITLE_INDEX)
1313 if(!GetPlayer()->HasTitle(title))
1314 return;
1316 else
1317 title = 0;
1319 GetPlayer()->SetUInt32Value(PLAYER_CHOSEN_TITLE, title);
1322 void WorldSession::HandleTimeSyncResp( WorldPacket & recv_data )
1324 sLog.outDebug("CMSG_TIME_SYNC_RESP");
1326 uint32 counter, time_;
1327 recv_data >> counter >> time_;
1329 // time_ seems always more than getMSTime()
1330 uint32 diff = getMSTimeDiff(getMSTime(), time_);
1332 sLog.outDebug("response sent: counter %u, time %u (HEX: %X), ms. time %u, diff %u", counter, time_, time_, getMSTime(), diff);
1335 void WorldSession::HandleResetInstancesOpcode( WorldPacket & /*recv_data*/ )
1337 sLog.outDebug("WORLD: CMSG_RESET_INSTANCES");
1339 if(Group *pGroup = _player->GetGroup())
1341 if(pGroup->IsLeader(_player->GetGUID()))
1343 pGroup->ResetInstances(INSTANCE_RESET_ALL, false, _player);
1344 pGroup->ResetInstances(INSTANCE_RESET_ALL, true,_player);
1347 else
1349 _player->ResetInstances(INSTANCE_RESET_ALL, false);
1350 _player->ResetInstances(INSTANCE_RESET_ALL, true);
1354 void WorldSession::HandleSetDungeonDifficultyOpcode( WorldPacket & recv_data )
1356 sLog.outDebug("MSG_SET_DUNGEON_DIFFICULTY");
1358 uint32 mode;
1359 recv_data >> mode;
1361 if(mode >= MAX_DUNGEON_DIFFICULTY)
1363 sLog.outError("WorldSession::HandleSetDungeonDifficultyOpcode: player %d sent an invalid instance mode %d!", _player->GetGUIDLow(), mode);
1364 return;
1367 if(Difficulty(mode) == _player->GetDungeonDifficulty())
1368 return;
1370 // cannot reset while in an instance
1371 Map *map = _player->GetMap();
1372 if(map && map->IsDungeon())
1374 sLog.outError("WorldSession::HandleSetDungeonDifficultyOpcode: player %d tried to reset the instance while inside!", _player->GetGUIDLow());
1375 return;
1378 if(_player->getLevel() < LEVELREQUIREMENT_HEROIC)
1379 return;
1381 if(Group *pGroup = _player->GetGroup())
1383 if(pGroup->IsLeader(_player->GetGUID()))
1385 // the difficulty is set even if the instances can't be reset
1386 //_player->SendDungeonDifficulty(true);
1387 pGroup->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY, false, _player);
1388 pGroup->SetDungeonDifficulty(Difficulty(mode));
1391 else
1393 _player->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY, false);
1394 _player->SetDungeonDifficulty(Difficulty(mode));
1398 void WorldSession::HandleSetRaidDifficultyOpcode( WorldPacket & recv_data )
1400 sLog.outDebug("MSG_SET_RAID_DIFFICULTY");
1402 uint32 mode;
1403 recv_data >> mode;
1405 if(mode >= MAX_RAID_DIFFICULTY)
1407 sLog.outError("WorldSession::HandleSetRaidDifficultyOpcode: player %d sent an invalid instance mode %d!", _player->GetGUIDLow(), mode);
1408 return;
1411 if(Difficulty(mode) == _player->GetRaidDifficulty())
1412 return;
1414 // cannot reset while in an instance
1415 Map *map = _player->GetMap();
1416 if(map && map->IsDungeon())
1418 sLog.outError("WorldSession::HandleSetRaidDifficultyOpcode: player %d tried to reset the instance while inside!", _player->GetGUIDLow());
1419 return;
1422 if(_player->getLevel() < LEVELREQUIREMENT_HEROIC)
1423 return;
1425 if(Group *pGroup = _player->GetGroup())
1427 if(pGroup->IsLeader(_player->GetGUID()))
1429 // the difficulty is set even if the instances can't be reset
1430 //_player->SendDungeonDifficulty(true);
1431 pGroup->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY, true, _player);
1432 pGroup->SetRaidDifficulty(Difficulty(mode));
1435 else
1437 _player->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY, true);
1438 _player->SetRaidDifficulty(Difficulty(mode));
1442 void WorldSession::HandleCancelMountAuraOpcode( WorldPacket & /*recv_data*/ )
1444 sLog.outDebug("WORLD: CMSG_CANCEL_MOUNT_AURA");
1446 //If player is not mounted, so go out :)
1447 if (!_player->IsMounted()) // not blizz like; no any messages on blizz
1449 ChatHandler(this).SendSysMessage(LANG_CHAR_NON_MOUNTED);
1450 return;
1453 if(_player->isInFlight()) // not blizz like; no any messages on blizz
1455 ChatHandler(this).SendSysMessage(LANG_YOU_IN_FLIGHT);
1456 return;
1459 _player->Unmount();
1460 _player->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
1463 void WorldSession::HandleMoveSetCanFlyAckOpcode( WorldPacket & recv_data )
1465 // fly mode on/off
1466 sLog.outDebug("WORLD: CMSG_MOVE_SET_CAN_FLY_ACK");
1467 //recv_data.hexlike();
1469 ObjectGuid guid; // guid - unused
1470 MovementInfo movementInfo;
1472 recv_data >> guid.ReadAsPacked();
1473 recv_data >> Unused<uint32>(); // unk
1474 recv_data >> movementInfo;
1475 recv_data >> Unused<float>(); // unk2
1477 _player->m_movementInfo.SetMovementFlags(movementInfo.GetMovementFlags());
1480 void WorldSession::HandleRequestPetInfoOpcode( WorldPacket & /*recv_data */)
1483 sLog.outDebug("WORLD: CMSG_REQUEST_PET_INFO");
1484 recv_data.hexlike();
1488 void WorldSession::HandleSetTaxiBenchmarkOpcode( WorldPacket & recv_data )
1490 uint8 mode;
1491 recv_data >> mode;
1493 sLog.outDebug("Client used \"/timetest %d\" command", mode);
1496 void WorldSession::HandleQueryInspectAchievements( WorldPacket & recv_data )
1498 ObjectGuid guid;
1500 recv_data >> guid.ReadAsPacked();
1502 if(Player *player = sObjectMgr.GetPlayer(guid))
1503 player->GetAchievementMgr().SendRespondInspectAchievements(_player);
1506 void WorldSession::HandleWorldStateUITimerUpdate(WorldPacket& /*recv_data*/)
1508 // empty opcode
1509 sLog.outDebug("WORLD: CMSG_WORLD_STATE_UI_TIMER_UPDATE");
1511 WorldPacket data(SMSG_WORLD_STATE_UI_TIMER_UPDATE, 4);
1512 data << uint32(time(NULL));
1513 SendPacket(&data);
1516 void WorldSession::HandleReadyForAccountDataTimes(WorldPacket& /*recv_data*/)
1518 // empty opcode
1519 sLog.outDebug("WORLD: CMSG_READY_FOR_ACCOUNT_DATA_TIMES");
1521 SendAccountDataTimes(GLOBAL_CACHE_MASK);
1524 void WorldSession::HandleHearthandResurrect(WorldPacket & /*recv_data*/)
1526 sLog.outDebug("WORLD: CMSG_HEARTH_AND_RESURRECT");
1528 AreaTableEntry const* atEntry = sAreaStore.LookupEntry(_player->GetAreaId());
1529 if(!atEntry || !(atEntry->flags & AREA_FLAG_CAN_HEARTH_AND_RES))
1530 return;
1532 // Can't use in flight
1533 if (_player->isInFlight())
1534 return;
1536 // Send Everytime
1537 _player->BuildPlayerRepop();
1538 _player->ResurrectPlayer(100);
1539 _player->TeleportToHomebind();