[8483] Implement glyph 43361.
[getmangos.git] / src / game / MiscHandler.cpp
blob954d79a1c5096e2fb136eea0825db8baead23f31
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 "WorldSession.h"
30 #include "Auth/BigNumber.h"
31 #include "Auth/Sha1.h"
32 #include "UpdateData.h"
33 #include "LootMgr.h"
34 #include "Chat.h"
35 #include "ScriptCalls.h"
36 #include <zlib/zlib.h>
37 #include "ObjectAccessor.h"
38 #include "Object.h"
39 #include "BattleGround.h"
40 #include "Pet.h"
41 #include "SocialMgr.h"
43 void WorldSession::HandleRepopRequestOpcode( WorldPacket & recv_data )
45 sLog.outDebug( "WORLD: Recvd CMSG_REPOP_REQUEST Message" );
47 recv_data.read_skip<uint8>();
49 if(GetPlayer()->isAlive()||GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST))
50 return;
52 // the world update order is sessions, players, creatures
53 // the netcode runs in parallel with all of these
54 // creatures can kill players
55 // so if the server is lagging enough the player can
56 // release spirit after he's killed but before he is updated
57 if(GetPlayer()->getDeathState() == JUST_DIED)
59 sLog.outDebug("HandleRepopRequestOpcode: got request after player %s(%d) was killed and before he was updated", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow());
60 GetPlayer()->KillPlayer();
63 //this is spirit release confirm?
64 GetPlayer()->RemovePet(NULL,PET_SAVE_NOT_IN_SLOT, true);
65 GetPlayer()->BuildPlayerRepop();
66 GetPlayer()->RepopAtGraveyard();
69 void WorldSession::HandleWhoOpcode( WorldPacket & recv_data )
71 sLog.outDebug( "WORLD: Recvd CMSG_WHO Message" );
72 //recv_data.hexlike();
74 uint32 clientcount = 0;
76 uint32 level_min, level_max, racemask, classmask, zones_count, str_count;
77 uint32 zoneids[10]; // 10 is client limit
78 std::string player_name, guild_name;
80 recv_data >> level_min; // maximal player level, default 0
81 recv_data >> level_max; // minimal player level, default 100 (MAX_LEVEL)
82 recv_data >> player_name; // player name, case sensitive...
84 recv_data >> guild_name; // guild name, case sensitive...
86 recv_data >> racemask; // race mask
87 recv_data >> classmask; // class mask
88 recv_data >> zones_count; // zones count, client limit=10 (2.0.10)
90 if(zones_count > 10)
91 return; // can't be received from real client or broken packet
93 for(uint32 i = 0; i < zones_count; ++i)
95 uint32 temp;
96 recv_data >> temp; // zone id, 0 if zone is unknown...
97 zoneids[i] = temp;
98 sLog.outDebug("Zone %u: %u", i, zoneids[i]);
101 recv_data >> str_count; // user entered strings count, client limit=4 (checked on 2.0.10)
103 if(str_count > 4)
104 return; // can't be received from real client or broken packet
106 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);
108 std::wstring str[4]; // 4 is client limit
109 for(uint32 i = 0; i < str_count; ++i)
111 std::string temp;
112 recv_data >> temp; // user entered string, it used as universal search pattern(guild+player name)?
114 if(!Utf8toWStr(temp,str[i]))
115 continue;
117 wstrToLower(str[i]);
119 sLog.outDebug("String %u: %s", i, temp.c_str());
122 std::wstring wplayer_name;
123 std::wstring wguild_name;
124 if(!(Utf8toWStr(player_name, wplayer_name) && Utf8toWStr(guild_name, wguild_name)))
125 return;
126 wstrToLower(wplayer_name);
127 wstrToLower(wguild_name);
129 // client send in case not set max level value 100 but mangos support 255 max level,
130 // update it to show GMs with characters after 100 level
131 if(level_max >= MAX_LEVEL)
132 level_max = STRONG_MAX_LEVEL;
134 uint32 team = _player->GetTeam();
135 uint32 security = GetSecurity();
136 bool allowTwoSideWhoList = sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_WHO_LIST);
137 uint32 gmLevelInWhoList = sWorld.getConfig(CONFIG_GM_LEVEL_IN_WHO_LIST);
139 WorldPacket data( SMSG_WHO, 50 ); // guess size
140 data << clientcount; // clientcount place holder
141 data << clientcount; // clientcount place holder
143 //TODO: Guard Player map
144 HashMapHolder<Player>::MapType& m = ObjectAccessor::Instance().GetPlayers();
145 for(HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
147 if (security == SEC_PLAYER)
149 // player can see member of other team only if CONFIG_ALLOW_TWO_SIDE_WHO_LIST
150 if (itr->second->GetTeam() != team && !allowTwoSideWhoList )
151 continue;
153 // player can see MODERATOR, GAME MASTER, ADMINISTRATOR only if CONFIG_GM_IN_WHO_LIST
154 if ((itr->second->GetSession()->GetSecurity() > gmLevelInWhoList))
155 continue;
158 //do not process players which are not in world
159 if(!(itr->second->IsInWorld()))
160 continue;
162 // check if target is globally visible for player
163 if (!(itr->second->IsVisibleGloballyFor(_player)))
164 continue;
166 // check if target's level is in level range
167 uint32 lvl = itr->second->getLevel();
168 if (lvl < level_min || lvl > level_max)
169 continue;
171 // check if class matches classmask
172 uint32 class_ = itr->second->getClass();
173 if (!(classmask & (1 << class_)))
174 continue;
176 // check if race matches racemask
177 uint32 race = itr->second->getRace();
178 if (!(racemask & (1 << race)))
179 continue;
181 uint32 pzoneid = itr->second->GetZoneId();
183 bool z_show = true;
184 for(uint32 i = 0; i < zones_count; ++i)
186 if(zoneids[i] == pzoneid)
188 z_show = true;
189 break;
192 z_show = false;
194 if (!z_show)
195 continue;
197 std::string pname = itr->second->GetName();
198 std::wstring wpname;
199 if(!Utf8toWStr(pname,wpname))
200 continue;
201 wstrToLower(wpname);
203 if (!(wplayer_name.empty() || wpname.find(wplayer_name) != std::wstring::npos))
204 continue;
206 std::string gname = objmgr.GetGuildNameById(itr->second->GetGuildId());
207 std::wstring wgname;
208 if(!Utf8toWStr(gname,wgname))
209 continue;
210 wstrToLower(wgname);
212 if (!(wguild_name.empty() || wgname.find(wguild_name) != std::wstring::npos))
213 continue;
215 std::string aname;
216 if(AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(itr->second->GetZoneId()))
217 aname = areaEntry->area_name[GetSessionDbcLocale()];
219 bool s_show = true;
220 for(uint32 i = 0; i < str_count; ++i)
222 if (!str[i].empty())
224 if (wgname.find(str[i]) != std::wstring::npos ||
225 wpname.find(str[i]) != std::wstring::npos ||
226 Utf8FitTo(aname, str[i]) )
228 s_show = true;
229 break;
231 s_show = false;
234 if (!s_show)
235 continue;
237 data << pname; // player name
238 data << gname; // guild name
239 data << uint32( lvl ); // player level
240 data << uint32( class_ ); // player class
241 data << uint32( race ); // player race
242 data << uint8(0); // new 2.4.0
243 data << uint32( pzoneid ); // player zone id
245 // 49 is maximum player count sent to client
246 if ((++clientcount) == 49)
247 break;
250 data.put( 0, clientcount ); //insert right count
251 data.put( sizeof(uint32), clientcount ); //insert right count
253 SendPacket(&data);
254 sLog.outDebug( "WORLD: Send SMSG_WHO Message" );
257 void WorldSession::HandleLogoutRequestOpcode( WorldPacket & /*recv_data*/ )
259 sLog.outDebug( "WORLD: Recvd CMSG_LOGOUT_REQUEST Message, security - %u", GetSecurity() );
261 if (uint64 lguid = GetPlayer()->GetLootGUID())
262 DoLootRelease(lguid);
264 //Can not logout if...
265 if( GetPlayer()->isInCombat() || //...is in combat
266 GetPlayer()->duel || //...is in Duel
267 //...is jumping ...is falling
268 GetPlayer()->m_movementInfo.HasMovementFlag(MovementFlags(MOVEMENTFLAG_JUMPING | MOVEMENTFLAG_FALLING)))
270 WorldPacket data( SMSG_LOGOUT_RESPONSE, (2+4) ) ;
271 data << (uint8)0xC;
272 data << uint32(0);
273 data << uint8(0);
274 SendPacket( &data );
275 LogoutRequest(0);
276 return;
279 //instant logout in taverns/cities or on taxi or for admins, gm's, mod's if its enabled in mangosd.conf
280 if (GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING) || GetPlayer()->isInFlight() ||
281 GetSecurity() >= sWorld.getConfig(CONFIG_INSTANT_LOGOUT))
283 LogoutPlayer(true);
284 return;
287 // not set flags if player can't free move to prevent lost state at logout cancel
288 if(GetPlayer()->CanFreeMove())
290 GetPlayer()->SetStandState(UNIT_STAND_STATE_SIT);
292 WorldPacket data( SMSG_FORCE_MOVE_ROOT, (8+4) ); // guess size
293 data.append(GetPlayer()->GetPackGUID());
294 data << (uint32)2;
295 SendPacket( &data );
296 GetPlayer()->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
299 WorldPacket data( SMSG_LOGOUT_RESPONSE, 5 );
300 data << uint32(0);
301 data << uint8(0);
302 SendPacket( &data );
303 LogoutRequest(time(NULL));
306 void WorldSession::HandlePlayerLogoutOpcode( WorldPacket & /*recv_data*/ )
308 sLog.outDebug( "WORLD: Recvd CMSG_PLAYER_LOGOUT Message" );
311 void WorldSession::HandleLogoutCancelOpcode( WorldPacket & /*recv_data*/ )
313 sLog.outDebug( "WORLD: Recvd CMSG_LOGOUT_CANCEL Message" );
315 LogoutRequest(0);
317 WorldPacket data( SMSG_LOGOUT_CANCEL_ACK, 0 );
318 SendPacket( &data );
320 // not remove flags if can't free move - its not set in Logout request code.
321 if(GetPlayer()->CanFreeMove())
323 //!we can move again
324 data.Initialize( SMSG_FORCE_MOVE_UNROOT, 8 ); // guess size
325 data.append(GetPlayer()->GetPackGUID());
326 data << uint32(0);
327 SendPacket( &data );
329 //! Stand Up
330 GetPlayer()->SetStandState(UNIT_STAND_STATE_STAND);
332 //! DISABLE_ROTATE
333 GetPlayer()->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
336 sLog.outDebug( "WORLD: sent SMSG_LOGOUT_CANCEL_ACK Message" );
339 void WorldSession::HandleTogglePvP( WorldPacket & recv_data )
341 // this opcode can be used in two ways: Either set explicit new status or toggle old status
342 if(recv_data.size() == 1)
344 bool newPvPStatus;
345 recv_data >> newPvPStatus;
346 GetPlayer()->ApplyModFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP, newPvPStatus);
347 GetPlayer()->ApplyModFlag(PLAYER_FLAGS, PLAYER_FLAGS_PVP_TIMER, !newPvPStatus);
349 else
351 GetPlayer()->ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP);
352 GetPlayer()->ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_PVP_TIMER);
355 if(GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP))
357 if(!GetPlayer()->IsPvP() || GetPlayer()->pvpInfo.endTimer != 0)
358 GetPlayer()->UpdatePvP(true, true);
360 else
362 if(!GetPlayer()->pvpInfo.inHostileArea && GetPlayer()->IsPvP())
363 GetPlayer()->pvpInfo.endTimer = time(NULL); // start toggle-off
367 void WorldSession::HandleZoneUpdateOpcode( WorldPacket & recv_data )
369 uint32 newZone;
370 recv_data >> newZone;
372 sLog.outDetail("WORLD: Recvd ZONE_UPDATE: %u", newZone);
374 // use server size data
375 uint32 newzone, newarea;
376 GetPlayer()->GetZoneAndAreaId(newzone,newarea);
377 GetPlayer()->UpdateZone(newzone,newarea);
380 void WorldSession::HandleSetTargetOpcode( WorldPacket & recv_data )
382 // When this packet send?
383 uint64 guid ;
384 recv_data >> guid;
386 _player->SetUInt32Value(UNIT_FIELD_TARGET,guid);
388 // update reputation list if need
389 Unit* unit = ObjectAccessor::GetUnit(*_player, guid );
390 if(!unit)
391 return;
393 if(FactionTemplateEntry const* factionTemplateEntry = sFactionTemplateStore.LookupEntry(unit->getFaction()))
394 _player->GetReputationMgr().SetVisible(factionTemplateEntry);
397 void WorldSession::HandleSetSelectionOpcode( WorldPacket & recv_data )
399 uint64 guid;
400 recv_data >> guid;
402 _player->SetSelection(guid);
404 // update reputation list if need
405 Unit* unit = ObjectAccessor::GetUnit(*_player, guid );
406 if(!unit)
407 return;
409 if(FactionTemplateEntry const* factionTemplateEntry = sFactionTemplateStore.LookupEntry(unit->getFaction()))
410 _player->GetReputationMgr().SetVisible(factionTemplateEntry);
413 void WorldSession::HandleStandStateChangeOpcode( WorldPacket & recv_data )
415 // sLog.outDebug( "WORLD: Received CMSG_STANDSTATECHANGE" ); -- too many spam in log at lags/debug stop
416 uint32 animstate;
417 recv_data >> animstate;
419 _player->SetStandState(animstate);
422 void WorldSession::HandleContactListOpcode( WorldPacket & recv_data )
424 sLog.outDebug( "WORLD: Received CMSG_CONTACT_LIST" );
425 uint32 unk;
426 recv_data >> unk;
427 sLog.outDebug("unk value is %u", unk);
428 _player->GetSocial()->SendSocialList();
431 void WorldSession::HandleAddFriendOpcode( WorldPacket & recv_data )
433 sLog.outDebug( "WORLD: Received CMSG_ADD_FRIEND" );
435 std::string friendName = GetMangosString(LANG_FRIEND_IGNORE_UNKNOWN);
436 std::string friendNote;
438 recv_data >> friendName;
440 recv_data >> friendNote;
442 if(!normalizePlayerName(friendName))
443 return;
445 CharacterDatabase.escape_string(friendName); // prevent SQL injection - normal name don't must changed by this call
447 sLog.outDebug( "WORLD: %s asked to add friend : '%s'",
448 GetPlayer()->GetName(), friendName.c_str() );
450 CharacterDatabase.AsyncPQuery(&WorldSession::HandleAddFriendOpcodeCallBack, GetAccountId(), friendNote, "SELECT guid, race FROM characters WHERE name = '%s'", friendName.c_str());
453 void WorldSession::HandleAddFriendOpcodeCallBack(QueryResult *result, uint32 accountId, std::string friendNote)
455 if(!result)
456 return;
458 uint64 friendGuid = MAKE_NEW_GUID((*result)[0].GetUInt32(), 0, HIGHGUID_PLAYER);
459 uint32 team = Player::TeamForRace((*result)[1].GetUInt8());
461 delete result;
463 WorldSession * session = sWorld.FindSession(accountId);
464 if(!session || !session->GetPlayer())
465 return;
467 FriendsResult friendResult = FRIEND_NOT_FOUND;
468 if(friendGuid)
470 if(friendGuid==session->GetPlayer()->GetGUID())
471 friendResult = FRIEND_SELF;
472 else if(session->GetPlayer()->GetTeam() != team && !sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_ADD_FRIEND) && session->GetSecurity() < SEC_MODERATOR)
473 friendResult = FRIEND_ENEMY;
474 else if(session->GetPlayer()->GetSocial()->HasFriend(GUID_LOPART(friendGuid)))
475 friendResult = FRIEND_ALREADY;
476 else
478 Player* pFriend = ObjectAccessor::FindPlayer(friendGuid);
479 if( pFriend && pFriend->IsInWorld() && pFriend->IsVisibleGloballyFor(session->GetPlayer()))
480 friendResult = FRIEND_ADDED_ONLINE;
481 else
482 friendResult = FRIEND_ADDED_OFFLINE;
484 if(!session->GetPlayer()->GetSocial()->AddToSocialList(GUID_LOPART(friendGuid), false))
486 friendResult = FRIEND_LIST_FULL;
487 sLog.outDebug( "WORLD: %s's friend list is full.", session->GetPlayer()->GetName());
490 session->GetPlayer()->GetSocial()->SetFriendNote(GUID_LOPART(friendGuid), friendNote);
494 sSocialMgr.SendFriendStatus(session->GetPlayer(), friendResult, GUID_LOPART(friendGuid), false);
496 sLog.outDebug( "WORLD: Sent (SMSG_FRIEND_STATUS)" );
499 void WorldSession::HandleDelFriendOpcode( WorldPacket & recv_data )
501 uint64 FriendGUID;
503 sLog.outDebug( "WORLD: Received CMSG_DEL_FRIEND" );
505 recv_data >> FriendGUID;
507 _player->GetSocial()->RemoveFromSocialList(GUID_LOPART(FriendGUID), false);
509 sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_REMOVED, GUID_LOPART(FriendGUID), false);
511 sLog.outDebug( "WORLD: Sent motd (SMSG_FRIEND_STATUS)" );
514 void WorldSession::HandleAddIgnoreOpcode( WorldPacket & recv_data )
516 sLog.outDebug( "WORLD: Received CMSG_ADD_IGNORE" );
518 std::string IgnoreName = GetMangosString(LANG_FRIEND_IGNORE_UNKNOWN);
520 recv_data >> IgnoreName;
522 if(!normalizePlayerName(IgnoreName))
523 return;
525 CharacterDatabase.escape_string(IgnoreName); // prevent SQL injection - normal name don't must changed by this call
527 sLog.outDebug( "WORLD: %s asked to Ignore: '%s'",
528 GetPlayer()->GetName(), IgnoreName.c_str() );
530 CharacterDatabase.AsyncPQuery(&WorldSession::HandleAddIgnoreOpcodeCallBack, GetAccountId(), "SELECT guid FROM characters WHERE name = '%s'", IgnoreName.c_str());
533 void WorldSession::HandleAddIgnoreOpcodeCallBack(QueryResult *result, uint32 accountId)
535 if(!result)
536 return;
538 uint64 IgnoreGuid = MAKE_NEW_GUID((*result)[0].GetUInt32(), 0, HIGHGUID_PLAYER);
540 delete result;
542 WorldSession * session = sWorld.FindSession(accountId);
543 if(!session || !session->GetPlayer())
544 return;
546 FriendsResult ignoreResult = FRIEND_IGNORE_NOT_FOUND;
547 if(IgnoreGuid)
549 if(IgnoreGuid==session->GetPlayer()->GetGUID()) //not add yourself
550 ignoreResult = FRIEND_IGNORE_SELF;
551 else if( session->GetPlayer()->GetSocial()->HasIgnore(GUID_LOPART(IgnoreGuid)) )
552 ignoreResult = FRIEND_IGNORE_ALREADY;
553 else
555 ignoreResult = FRIEND_IGNORE_ADDED;
557 // ignore list full
558 if(!session->GetPlayer()->GetSocial()->AddToSocialList(GUID_LOPART(IgnoreGuid), true))
559 ignoreResult = FRIEND_IGNORE_FULL;
563 sSocialMgr.SendFriendStatus(session->GetPlayer(), ignoreResult, GUID_LOPART(IgnoreGuid), false);
565 sLog.outDebug( "WORLD: Sent (SMSG_FRIEND_STATUS)" );
568 void WorldSession::HandleDelIgnoreOpcode( WorldPacket & recv_data )
570 uint64 IgnoreGUID;
572 sLog.outDebug( "WORLD: Received CMSG_DEL_IGNORE" );
574 recv_data >> IgnoreGUID;
576 _player->GetSocial()->RemoveFromSocialList(GUID_LOPART(IgnoreGUID), true);
578 sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_IGNORE_REMOVED, GUID_LOPART(IgnoreGUID), false);
580 sLog.outDebug( "WORLD: Sent motd (SMSG_FRIEND_STATUS)" );
583 void WorldSession::HandleSetContactNotesOpcode( WorldPacket & recv_data )
585 sLog.outDebug("CMSG_SET_CONTACT_NOTES");
586 uint64 guid;
587 std::string note;
588 recv_data >> guid >> note;
589 _player->GetSocial()->SetFriendNote(guid, note);
592 void WorldSession::HandleBugOpcode( WorldPacket & recv_data )
594 uint32 suggestion, contentlen;
595 std::string content;
596 uint32 typelen;
597 std::string 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->IsWithinDist(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();
651 GetPlayer()->SaveToDB();
654 void WorldSession::HandleResurrectResponseOpcode(WorldPacket & recv_data)
656 sLog.outDetail("WORLD: Received CMSG_RESURRECT_RESPONSE");
658 if(GetPlayer()->isAlive())
659 return;
661 uint64 guid;
662 uint8 status;
663 recv_data >> guid;
664 recv_data >> status;
666 if(status == 0)
668 GetPlayer()->clearResurrectRequestData(); // reject
669 return;
672 if(!GetPlayer()->isRessurectRequestedBy(guid))
673 return;
675 GetPlayer()->ResurectUsingRequestData();
676 GetPlayer()->SaveToDB();
679 void WorldSession::HandleAreaTriggerOpcode(WorldPacket & recv_data)
681 sLog.outDebug("WORLD: Received CMSG_AREATRIGGER");
683 uint32 Trigger_ID;
685 recv_data >> Trigger_ID;
686 sLog.outDebug("Trigger ID:%u",Trigger_ID);
688 if(GetPlayer()->isInFlight())
690 sLog.outDebug("Player '%s' (GUID: %u) in flight, ignore Area Trigger ID:%u",GetPlayer()->GetName(),GetPlayer()->GetGUIDLow(), Trigger_ID);
691 return;
694 AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(Trigger_ID);
695 if(!atEntry)
697 sLog.outDebug("Player '%s' (GUID: %u) send unknown (by DBC) Area Trigger ID:%u",GetPlayer()->GetName(),GetPlayer()->GetGUIDLow(), Trigger_ID);
698 return;
701 if (GetPlayer()->GetMapId()!=atEntry->mapid)
703 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);
704 return;
707 // delta is safe radius
708 const float delta = 5.0f;
709 // check if player in the range of areatrigger
710 Player* pl = GetPlayer();
712 if (atEntry->radius > 0)
714 // if we have radius check it
715 float dist = pl->GetDistance(atEntry->x,atEntry->y,atEntry->z);
716 if(dist > atEntry->radius + delta)
718 sLog.outDebug("Player '%s' (GUID: %u) too far (radius: %f distance: %f), ignore Area Trigger ID: %u",
719 pl->GetName(), pl->GetGUIDLow(), atEntry->radius, dist, Trigger_ID);
720 return;
723 else
725 // we have only extent
727 // rotate the players position instead of rotating the whole cube, that way we can make a simplified
728 // is-in-cube check and we have to calculate only one point instead of 4
730 // 2PI = 360°, keep in mind that ingame orientation is counter-clockwise
731 double rotation = 2*M_PI-atEntry->box_orientation;
732 double sinVal = sin(rotation);
733 double cosVal = cos(rotation);
735 float playerBoxDistX = pl->GetPositionX() - atEntry->x;
736 float playerBoxDistY = pl->GetPositionY() - atEntry->y;
738 float rotPlayerX = atEntry->x + playerBoxDistX * cosVal - playerBoxDistY*sinVal;
739 float rotPlayerY = atEntry->y + playerBoxDistY * cosVal + playerBoxDistX*sinVal;
741 // box edges are parallel to coordiante axis, so we can treat every dimension independently :D
742 float dz = pl->GetPositionZ() - atEntry->z;
743 float dx = rotPlayerX - atEntry->x;
744 float dy = rotPlayerY - atEntry->y;
745 if( (fabs(dx) > atEntry->box_x/2 + delta) ||
746 (fabs(dy) > atEntry->box_y/2 + delta) ||
747 (fabs(dz) > atEntry->box_z/2 + delta) )
749 sLog.outDebug("Player '%s' (GUID: %u) too far (1/2 box X: %f 1/2 box Y: %f 1/2 box Z: %f rotatedPlayerX: %f rotatedPlayerY: %f dZ:%f), ignore Area Trigger ID: %u",
750 pl->GetName(), pl->GetGUIDLow(), atEntry->box_x/2, atEntry->box_y/2, atEntry->box_z/2, rotPlayerX, rotPlayerY, dz, Trigger_ID);
751 return;
755 if(Script->scriptAreaTrigger(GetPlayer(), atEntry))
756 return;
758 uint32 quest_id = objmgr.GetQuestForAreaTrigger( Trigger_ID );
759 if( quest_id && GetPlayer()->isAlive() && GetPlayer()->IsActiveQuest(quest_id) )
761 Quest const* pQuest = objmgr.GetQuestTemplate(quest_id);
762 if( pQuest )
764 if(GetPlayer()->GetQuestStatus(quest_id) == QUEST_STATUS_INCOMPLETE)
765 GetPlayer()->AreaExploredOrEventHappens( quest_id );
769 if(objmgr.IsTavernAreaTrigger(Trigger_ID))
771 // set resting flag we are in the inn
772 GetPlayer()->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING);
773 GetPlayer()->InnEnter(time(NULL), atEntry->mapid, atEntry->x, atEntry->y, atEntry->z);
774 GetPlayer()->SetRestType(REST_TYPE_IN_TAVERN);
776 if(sWorld.IsFFAPvPRealm())
777 GetPlayer()->RemoveByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP);
779 return;
782 if(GetPlayer()->InBattleGround())
784 BattleGround* bg = GetPlayer()->GetBattleGround();
785 if(bg)
786 if(bg->GetStatus() == STATUS_IN_PROGRESS)
787 bg->HandleAreaTrigger(GetPlayer(), Trigger_ID);
789 return;
792 // NULL if all values default (non teleport trigger)
793 AreaTrigger const* at = objmgr.GetAreaTrigger(Trigger_ID);
794 if(!at)
795 return;
797 if(!GetPlayer()->isGameMaster())
799 uint32 missingLevel = 0;
800 if(GetPlayer()->getLevel() < at->requiredLevel && !sWorld.getConfig(CONFIG_INSTANCE_IGNORE_LEVEL))
801 missingLevel = at->requiredLevel;
803 // must have one or the other, report the first one that's missing
804 uint32 missingItem = 0;
805 if(at->requiredItem)
807 if(!GetPlayer()->HasItemCount(at->requiredItem, 1) &&
808 (!at->requiredItem2 || !GetPlayer()->HasItemCount(at->requiredItem2, 1)))
809 missingItem = at->requiredItem;
811 else if(at->requiredItem2 && !GetPlayer()->HasItemCount(at->requiredItem2, 1))
812 missingItem = at->requiredItem2;
814 uint32 missingKey = 0;
815 if(GetPlayer()->GetDifficulty() == DIFFICULTY_HEROIC)
817 if(at->heroicKey)
819 if(!GetPlayer()->HasItemCount(at->heroicKey, 1) &&
820 (!at->heroicKey2 || !GetPlayer()->HasItemCount(at->heroicKey2, 1)))
821 missingKey = at->heroicKey;
823 else if(at->heroicKey2 && !GetPlayer()->HasItemCount(at->heroicKey2, 1))
824 missingKey = at->heroicKey2;
827 uint32 missingQuest = 0;
828 if(GetPlayer()->GetDifficulty() == DIFFICULTY_HEROIC)
830 if (at->requiredQuestHeroic && !GetPlayer()->GetQuestRewardStatus(at->requiredQuestHeroic))
831 missingQuest = at->requiredQuestHeroic;
833 else
835 if(at->requiredQuest && !GetPlayer()->GetQuestRewardStatus(at->requiredQuest))
836 missingQuest = at->requiredQuest;
839 if(missingLevel || missingItem || missingKey || missingQuest)
841 // TODO: all this is probably wrong
842 if(missingItem)
843 SendAreaTriggerMessage(GetMangosString(LANG_LEVEL_MINREQUIRED_AND_ITEM), at->requiredLevel, objmgr.GetItemPrototype(missingItem)->Name1);
844 else if(missingKey)
845 GetPlayer()->SendTransferAborted(at->target_mapId, TRANSFER_ABORT_DIFFICULTY, DIFFICULTY_HEROIC);
846 else if(missingQuest)
847 SendAreaTriggerMessage(at->requiredFailedText.c_str());
848 else if(missingLevel)
849 SendAreaTriggerMessage(GetMangosString(LANG_LEVEL_MINREQUIRED), missingLevel);
850 return;
854 GetPlayer()->TeleportTo(at->target_mapId,at->target_X,at->target_Y,at->target_Z,at->target_Orientation,TELE_TO_NOT_LEAVE_TRANSPORT);
857 void WorldSession::HandleUpdateAccountData(WorldPacket &recv_data)
859 sLog.outDetail("WORLD: Received CMSG_UPDATE_ACCOUNT_DATA");
861 uint32 type, timestamp, decompressedSize;
862 recv_data >> type >> timestamp >> decompressedSize;
864 sLog.outDebug("UAD: type %u, time %u, decompressedSize %u", type, timestamp, decompressedSize);
866 if(type > NUM_ACCOUNT_DATA_TYPES)
867 return;
869 if(decompressedSize == 0) // erase
871 SetAccountData(AccountDataType(type), 0, "");
873 WorldPacket data(SMSG_UPDATE_ACCOUNT_DATA_COMPLETE, 4+4);
874 data << uint32(type);
875 data << uint32(0);
876 SendPacket(&data);
878 return;
881 if(decompressedSize > 0xFFFF)
883 recv_data.rpos(recv_data.wpos()); // unnneded warning spam in this case
884 sLog.outError("UAD: Account data packet too big, size %u", decompressedSize);
885 return;
888 ByteBuffer dest;
889 dest.resize(decompressedSize);
891 uLongf realSize = decompressedSize;
892 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)
894 recv_data.rpos(recv_data.wpos()); // unnneded warning spam in this case
895 sLog.outError("UAD: Failed to decompress account data");
896 return;
899 recv_data.rpos(recv_data.wpos()); // uncompress read (recv_data.size() - recv_data.rpos())
901 std::string adata;
902 dest >> adata;
904 SetAccountData(AccountDataType(type), timestamp, adata);
906 WorldPacket data(SMSG_UPDATE_ACCOUNT_DATA_COMPLETE, 4+4);
907 data << uint32(type);
908 data << uint32(0);
909 SendPacket(&data);
912 void WorldSession::HandleRequestAccountData(WorldPacket& recv_data)
914 sLog.outDetail("WORLD: Received CMSG_REQUEST_ACCOUNT_DATA");
916 uint32 type;
917 recv_data >> type;
919 sLog.outDebug("RAD: type %u", type);
921 if(type > NUM_ACCOUNT_DATA_TYPES)
922 return;
924 AccountData *adata = GetAccountData(AccountDataType(type));
926 uint32 size = adata->Data.size();
928 uLongf destSize = compressBound(size);
930 ByteBuffer dest;
931 dest.resize(destSize);
933 if(size && compress(const_cast<uint8*>(dest.contents()), &destSize, (uint8*)adata->Data.c_str(), size) != Z_OK)
935 sLog.outDebug("RAD: Failed to compress account data");
936 return;
939 dest.resize(destSize);
941 WorldPacket data (SMSG_UPDATE_ACCOUNT_DATA, 8+4+4+4+destSize);
942 data << uint64(_player->GetGUID()); // player guid
943 data << uint32(type); // type (0-7)
944 data << uint32(adata->Time); // unix time
945 data << uint32(size); // decompressed length
946 data.append(dest); // compressed data
947 SendPacket(&data);
950 void WorldSession::HandleSetActionButtonOpcode(WorldPacket& recv_data)
952 sLog.outDebug( "WORLD: Received CMSG_SET_ACTION_BUTTON" );
953 uint8 button;
954 uint32 packetData;
955 recv_data >> button >> packetData;
957 uint32 action = ACTION_BUTTON_ACTION(packetData);
958 uint8 type = ACTION_BUTTON_TYPE(packetData);
960 sLog.outDetail( "BUTTON: %u ACTION: %u TYPE: %u", button, action, type );
961 if (!packetData)
963 sLog.outDetail( "MISC: Remove action from button %u", button );
964 GetPlayer()->removeActionButton(button);
966 else
968 switch(type)
970 case ACTION_BUTTON_MACRO:
971 case ACTION_BUTTON_CMACRO:
972 sLog.outDetail( "MISC: Added Macro %u into button %u", action, button );
973 break;
974 case ACTION_BUTTON_EQSET:
975 sLog.outDetail( "MISC: Added EquipmentSet %u into button %u", action, button );
976 break;
977 case ACTION_BUTTON_SPELL:
978 sLog.outDetail( "MISC: Added Spell %u into button %u", action, button );
979 break;
980 case ACTION_BUTTON_ITEM:
981 sLog.outDetail( "MISC: Added Item %u into button %u", action, button );
982 break;
983 default:
984 sLog.outError( "MISC: Unknown action button type %u for action %u into button %u", type, action, button );
985 return;
987 GetPlayer()->addActionButton(button,action,type);
991 void WorldSession::HandleCompleteCinematic( WorldPacket & /*recv_data*/ )
993 DEBUG_LOG( "WORLD: Player is watching cinema" );
996 void WorldSession::HandleNextCinematicCamera( WorldPacket & /*recv_data*/ )
998 DEBUG_LOG( "WORLD: Which movie to play" );
1001 void WorldSession::HandleMoveTimeSkippedOpcode( WorldPacket & recv_data )
1003 /* WorldSession::Update( getMSTime() );*/
1004 DEBUG_LOG( "WORLD: Time Lag/Synchronization Resent/Update" );
1006 recv_data.read_skip<uint64>();
1007 recv_data.read_skip<uint32>();
1009 uint64 guid;
1010 uint32 time_skipped;
1011 recv_data >> guid;
1012 recv_data >> time_skipped;
1013 sLog.outDebug( "WORLD: CMSG_MOVE_TIME_SKIPPED" );
1015 /// TODO
1016 must be need use in mangos
1017 We substract server Lags to move time ( AntiLags )
1018 for exmaple
1019 GetPlayer()->ModifyLastMoveTime( -int32(time_skipped) );
1023 void WorldSession::HandleFeatherFallAck(WorldPacket &/*recv_data*/)
1025 DEBUG_LOG("WORLD: CMSG_MOVE_FEATHER_FALL_ACK");
1028 void WorldSession::HandleMoveUnRootAck(WorldPacket& recv_data)
1030 // no used
1031 recv_data.rpos(recv_data.wpos()); // prevent warnings spam
1033 uint64 guid;
1034 recv_data >> guid;
1036 // now can skip not our packet
1037 if(_player->GetGUID() != guid)
1039 recv_data.rpos(recv_data.wpos()); // prevent warnings spam
1040 return;
1043 sLog.outDebug( "WORLD: CMSG_FORCE_MOVE_UNROOT_ACK" );
1045 recv_data.read_skip<uint32>(); // unk
1047 MovementInfo movementInfo;
1048 ReadMovementInfo(recv_data, &movementInfo);
1052 void WorldSession::HandleMoveRootAck(WorldPacket& recv_data)
1054 // no used
1055 recv_data.rpos(recv_data.wpos()); // prevent warnings spam
1057 uint64 guid;
1058 recv_data >> guid;
1060 // now can skip not our packet
1061 if(_player->GetGUID() != guid)
1063 recv_data.rpos(recv_data.wpos()); // prevent warnings spam
1064 return;
1067 sLog.outDebug( "WORLD: CMSG_FORCE_MOVE_ROOT_ACK" );
1069 recv_data.read_skip<uint32>(); // unk
1071 MovementInfo movementInfo;
1072 ReadMovementInfo(recv_data, &movementInfo);
1076 void WorldSession::HandleSetActionBarToggles(WorldPacket& recv_data)
1078 uint8 ActionBar;
1080 recv_data >> ActionBar;
1082 if(!GetPlayer()) // ignore until not logged (check needed because STATUS_AUTHED)
1084 if(ActionBar!=0)
1085 sLog.outError("WorldSession::HandleSetActionBarToggles in not logged state with value: %u, ignored",uint32(ActionBar));
1086 return;
1089 GetPlayer()->SetByteValue(PLAYER_FIELD_BYTES, 2, ActionBar);
1092 void WorldSession::HandleWardenDataOpcode(WorldPacket& recv_data)
1094 recv_data.read_skip<uint8>();
1096 uint8 tmp;
1097 recv_data >> tmp;
1098 sLog.outDebug("Received opcode CMSG_WARDEN_DATA, not resolve.uint8 = %u",tmp);
1102 void WorldSession::HandlePlayedTime(WorldPacket& recv_data)
1104 uint8 unk1;
1105 recv_data >> unk1; // 0 or 1 expected
1107 WorldPacket data(SMSG_PLAYED_TIME, 4 + 4 + 1);
1108 data << uint32(_player->GetTotalPlayedTime());
1109 data << uint32(_player->GetLevelPlayedTime());
1110 data << uint8(unk1); // 0 - will not show in chat frame
1111 SendPacket(&data);
1114 void WorldSession::HandleInspectOpcode(WorldPacket& recv_data)
1116 uint64 guid;
1117 recv_data >> guid;
1118 DEBUG_LOG("Inspected guid is (GUID: %u TypeId: %u)", GUID_LOPART(guid), GuidHigh2TypeId(GUID_HIPART(guid)));
1120 _player->SetSelection(guid);
1122 Player *plr = objmgr.GetPlayer(guid);
1123 if(!plr) // wrong player
1124 return;
1126 WorldPacket data(SMSG_INSPECT_TALENT, 50);
1127 data.append(plr->GetPackGUID());
1129 if(sWorld.getConfig(CONFIG_TALENTS_INSPECTING) || _player->isGameMaster())
1131 plr->BuildPlayerTalentsInfoData(&data);
1132 plr->BuildEnchantmentsInfoData(&data);
1134 else
1136 data << uint32(0); // unspentTalentPoints
1137 data << uint8(0); // talentGroupCount
1138 data << uint8(0); // talentGroupIndex
1139 data << uint32(0); // slotUsedMask
1142 SendPacket(&data);
1145 void WorldSession::HandleInspectHonorStatsOpcode(WorldPacket& recv_data)
1147 uint64 guid;
1148 recv_data >> guid;
1150 Player *player = objmgr.GetPlayer(guid);
1152 if(!player)
1154 sLog.outError("InspectHonorStats: WTF, player not found...");
1155 return;
1158 WorldPacket data(MSG_INSPECT_HONOR_STATS, 8+1+4*4);
1159 data << uint64(player->GetGUID());
1160 data << uint8(player->GetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY));
1161 data << uint32(player->GetUInt32Value(PLAYER_FIELD_KILLS));
1162 data << uint32(player->GetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION));
1163 data << uint32(player->GetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION));
1164 data << uint32(player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS));
1165 SendPacket(&data);
1168 void WorldSession::HandleWorldTeleportOpcode(WorldPacket& recv_data)
1170 // write in client console: worldport 469 452 6454 2536 180 or /console worldport 469 452 6454 2536 180
1171 // Received opcode CMSG_WORLD_TELEPORT
1172 // Time is ***, map=469, x=452.000000, y=6454.000000, z=2536.000000, orient=3.141593
1174 //sLog.outDebug("Received opcode CMSG_WORLD_TELEPORT");
1176 if(GetPlayer()->isInFlight())
1178 sLog.outDebug("Player '%s' (GUID: %u) in flight, ignore worldport command.",GetPlayer()->GetName(),GetPlayer()->GetGUIDLow());
1179 return;
1182 uint32 time;
1183 uint32 mapid;
1184 float PositionX;
1185 float PositionY;
1186 float PositionZ;
1187 float Orientation;
1189 recv_data >> time; // time in m.sec.
1190 recv_data >> mapid;
1191 recv_data >> PositionX;
1192 recv_data >> PositionY;
1193 recv_data >> PositionZ;
1194 recv_data >> Orientation; // o (3.141593 = 180 degrees)
1195 DEBUG_LOG("Time %u sec, map=%u, x=%f, y=%f, z=%f, orient=%f", time/1000, mapid, PositionX, PositionY, PositionZ, Orientation);
1197 if (GetSecurity() >= SEC_ADMINISTRATOR)
1198 GetPlayer()->TeleportTo(mapid,PositionX,PositionY,PositionZ,Orientation);
1199 else
1200 SendNotification(LANG_YOU_NOT_HAVE_PERMISSION);
1201 sLog.outDebug("Received worldport command from player %s", GetPlayer()->GetName());
1204 void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data)
1206 sLog.outDebug("Received opcode CMSG_WHOIS");
1207 std::string charname;
1208 recv_data >> charname;
1210 if (GetSecurity() < SEC_ADMINISTRATOR)
1212 SendNotification(LANG_YOU_NOT_HAVE_PERMISSION);
1213 return;
1216 if(charname.empty() || !normalizePlayerName (charname))
1218 SendNotification(LANG_NEED_CHARACTER_NAME);
1219 return;
1222 Player *plr = objmgr.GetPlayer(charname.c_str());
1224 if(!plr)
1226 SendNotification(LANG_PLAYER_NOT_EXIST_OR_OFFLINE, charname.c_str());
1227 return;
1230 uint32 accid = plr->GetSession()->GetAccountId();
1232 QueryResult *result = loginDatabase.PQuery("SELECT username,email,last_ip FROM account WHERE id=%u", accid);
1233 if(!result)
1235 SendNotification(LANG_ACCOUNT_FOR_PLAYER_NOT_FOUND, charname.c_str());
1236 return;
1239 Field *fields = result->Fetch();
1240 std::string acc = fields[0].GetCppString();
1241 if(acc.empty())
1242 acc = "Unknown";
1243 std::string email = fields[1].GetCppString();
1244 if(email.empty())
1245 email = "Unknown";
1246 std::string lastip = fields[2].GetCppString();
1247 if(lastip.empty())
1248 lastip = "Unknown";
1250 std::string msg = charname + "'s " + "account is " + acc + ", e-mail: " + email + ", last ip: " + lastip;
1252 WorldPacket data(SMSG_WHOIS, msg.size()+1);
1253 data << msg;
1254 _player->GetSession()->SendPacket(&data);
1256 delete result;
1258 sLog.outDebug("Received whois command from player %s for character %s", GetPlayer()->GetName(), charname.c_str());
1261 void WorldSession::HandleComplainOpcode( WorldPacket & recv_data )
1263 sLog.outDebug("WORLD: CMSG_COMPLAIN");
1264 recv_data.hexlike();
1266 uint8 spam_type; // 0 - mail, 1 - chat
1267 uint64 spammer_guid;
1268 uint32 unk1 = 0;
1269 uint32 unk2 = 0;
1270 uint32 unk3 = 0;
1271 uint32 unk4 = 0;
1272 std::string description = "";
1273 recv_data >> spam_type; // unk 0x01 const, may be spam type (mail/chat)
1274 recv_data >> spammer_guid; // player guid
1275 switch(spam_type)
1277 case 0:
1278 recv_data >> unk1; // const 0
1279 recv_data >> unk2; // probably mail id
1280 recv_data >> unk3; // const 0
1281 break;
1282 case 1:
1283 recv_data >> unk1; // probably language
1284 recv_data >> unk2; // message type?
1285 recv_data >> unk3; // probably channel id
1286 recv_data >> unk4; // unk random value
1287 recv_data >> description; // spam description string (messagetype, channel name, player name, message)
1288 break;
1291 // NOTE: all chat messages from this spammer automatically ignored by spam reporter until logout in case chat spam.
1292 // if it's mail spam - ALL mails from this spammer automatically removed by client
1294 // Complaint Received message
1295 WorldPacket data(SMSG_COMPLAIN_RESULT, 1);
1296 data << uint8(0);
1297 SendPacket(&data);
1299 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());
1302 void WorldSession::HandleRealmSplitOpcode( WorldPacket & recv_data )
1304 sLog.outDebug("CMSG_REALM_SPLIT");
1306 uint32 unk;
1307 std::string split_date = "01/01/01";
1308 recv_data >> unk;
1310 WorldPacket data(SMSG_REALM_SPLIT, 4+4+split_date.size()+1);
1311 data << unk;
1312 data << uint32(0x00000000); // realm split state
1313 // split states:
1314 // 0x0 realm normal
1315 // 0x1 realm split
1316 // 0x2 realm split pending
1317 data << split_date;
1318 SendPacket(&data);
1319 //sLog.outDebug("response sent %u", unk);
1322 void WorldSession::HandleFarSightOpcode( WorldPacket & recv_data )
1324 sLog.outDebug("WORLD: CMSG_FAR_SIGHT");
1325 //recv_data.hexlike();
1327 uint8 unk;
1328 recv_data >> unk;
1330 switch(unk)
1332 case 0:
1333 //WorldPacket data(SMSG_CLEAR_FAR_SIGHT_IMMEDIATE, 0)
1334 //SendPacket(&data);
1335 //_player->SetUInt64Value(PLAYER_FARSIGHT, 0);
1336 sLog.outDebug("Removed FarSight from player %u", _player->GetGUIDLow());
1337 break;
1338 case 1:
1339 sLog.outDebug("Added FarSight (GUID:%u TypeId:%u) to player %u", GUID_LOPART(_player->GetFarSight()), GuidHigh2TypeId(GUID_HIPART(_player->GetFarSight())), _player->GetGUIDLow());
1340 break;
1344 void WorldSession::HandleSetTitleOpcode( WorldPacket & recv_data )
1346 sLog.outDebug("CMSG_SET_TITLE");
1348 int32 title;
1349 recv_data >> title;
1351 // -1 at none
1352 if(title > 0 && title < MAX_TITLE_INDEX)
1354 if(!GetPlayer()->HasTitle(title))
1355 return;
1357 else
1358 title = 0;
1360 GetPlayer()->SetUInt32Value(PLAYER_CHOSEN_TITLE, title);
1363 void WorldSession::HandleTimeSyncResp( WorldPacket & recv_data )
1365 sLog.outDebug("CMSG_TIME_SYNC_RESP");
1367 uint32 counter, time_;
1368 recv_data >> counter >> time_;
1370 // time_ seems always more than getMSTime()
1371 uint32 diff = getMSTimeDiff(getMSTime(),time_);
1373 sLog.outDebug("response sent: counter %u, time %u (HEX: %X), ms. time %u, diff %u", counter, time_, time_, getMSTime(), diff);
1376 void WorldSession::HandleResetInstancesOpcode( WorldPacket & /*recv_data*/ )
1378 sLog.outDebug("WORLD: CMSG_RESET_INSTANCES");
1379 Group *pGroup = _player->GetGroup();
1380 if(pGroup)
1382 if(pGroup->IsLeader(_player->GetGUID()))
1383 pGroup->ResetInstances(INSTANCE_RESET_ALL, _player);
1385 else
1386 _player->ResetInstances(INSTANCE_RESET_ALL);
1389 void WorldSession::HandleSetDungeonDifficultyOpcode( WorldPacket & recv_data )
1391 sLog.outDebug("MSG_SET_DUNGEON_DIFFICULTY");
1393 uint32 mode;
1394 recv_data >> mode;
1396 if(mode == _player->GetDifficulty())
1397 return;
1399 if(mode > DIFFICULTY_HEROIC)
1401 sLog.outError("WorldSession::HandleSetDungeonDifficultyOpcode: player %d sent an invalid instance mode %d!", _player->GetGUIDLow(), mode);
1402 return;
1405 // cannot reset while in an instance
1406 Map *map = _player->GetMap();
1407 if(map && map->IsDungeon())
1409 sLog.outError("WorldSession::HandleSetDungeonDifficultyOpcode: player %d tried to reset the instance while inside!", _player->GetGUIDLow());
1410 return;
1413 if(_player->getLevel() < LEVELREQUIREMENT_HEROIC)
1414 return;
1415 Group *pGroup = _player->GetGroup();
1416 if(pGroup)
1418 if(pGroup->IsLeader(_player->GetGUID()))
1420 // the difficulty is set even if the instances can't be reset
1421 //_player->SendDungeonDifficulty(true);
1422 pGroup->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY, _player);
1423 pGroup->SetDifficulty(mode);
1426 else
1428 _player->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY);
1429 _player->SetDifficulty(mode);
1433 void WorldSession::HandleCancelMountAuraOpcode( WorldPacket & /*recv_data*/ )
1435 sLog.outDebug("WORLD: CMSG_CANCEL_MOUNT_AURA");
1436 //recv_data.hexlike();
1438 //If player is not mounted, so go out :)
1439 if (!_player->IsMounted()) // not blizz like; no any messages on blizz
1441 ChatHandler(this).SendSysMessage(LANG_CHAR_NON_MOUNTED);
1442 return;
1445 if(_player->isInFlight()) // not blizz like; no any messages on blizz
1447 ChatHandler(this).SendSysMessage(LANG_YOU_IN_FLIGHT);
1448 return;
1451 _player->Unmount();
1452 _player->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
1455 void WorldSession::HandleMoveSetCanFlyAckOpcode( WorldPacket & recv_data )
1457 // fly mode on/off
1458 sLog.outDebug("WORLD: CMSG_MOVE_SET_CAN_FLY_ACK");
1459 //recv_data.hexlike();
1461 recv_data.read_skip<uint64>(); // guid
1462 recv_data.read_skip<uint32>(); // unk
1464 MovementInfo movementInfo;
1465 ReadMovementInfo(recv_data, &movementInfo);
1467 recv_data.read_skip<uint32>(); // unk2
1469 _player->m_movementInfo.SetMovementFlags(movementInfo.GetMovementFlags());
1472 void WorldSession::HandleRequestPetInfoOpcode( WorldPacket & /*recv_data */)
1475 sLog.outDebug("WORLD: CMSG_REQUEST_PET_INFO");
1476 recv_data.hexlike();
1480 void WorldSession::HandleSetTaxiBenchmarkOpcode( WorldPacket & recv_data )
1482 uint8 mode;
1483 recv_data >> mode;
1485 sLog.outDebug("Client used \"/timetest %d\" command", mode);
1488 void WorldSession::HandleQueryInspectAchievements( WorldPacket & recv_data )
1490 uint64 guid;
1491 if(!recv_data.readPackGUID(guid))
1492 return;
1494 Player *player = objmgr.GetPlayer(guid);
1495 if(!player)
1496 return;
1498 player->GetAchievementMgr().SendRespondInspectAchievements(_player);