[9545] Rename ObjectDefines.h -> ObjectGuid.h
[getmangos.git] / src / game / MiscHandler.cpp
blobd037f016ebeb9acfb41a0bec69e34818834331ef
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.append(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.append(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 if (GetPlayer()->GetMapId() != atEntry->mapid)
700 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);
701 return;
704 // delta is safe radius
705 const float delta = 5.0f;
706 // check if player in the range of areatrigger
707 Player* pl = GetPlayer();
709 if (atEntry->radius > 0)
711 // if we have radius check it
712 float dist = pl->GetDistance(atEntry->x, atEntry->y, atEntry->z);
713 if(dist > atEntry->radius + delta)
715 sLog.outDebug("Player '%s' (GUID: %u) too far (radius: %f distance: %f), ignore Area Trigger ID: %u",
716 pl->GetName(), pl->GetGUIDLow(), atEntry->radius, dist, Trigger_ID);
717 return;
720 else
722 // we have only extent
724 // rotate the players position instead of rotating the whole cube, that way we can make a simplified
725 // is-in-cube check and we have to calculate only one point instead of 4
727 // 2PI = 360°, keep in mind that ingame orientation is counter-clockwise
728 double rotation = 2*M_PI-atEntry->box_orientation;
729 double sinVal = sin(rotation);
730 double cosVal = cos(rotation);
732 float playerBoxDistX = pl->GetPositionX() - atEntry->x;
733 float playerBoxDistY = pl->GetPositionY() - atEntry->y;
735 float rotPlayerX = float(atEntry->x + playerBoxDistX * cosVal - playerBoxDistY*sinVal);
736 float rotPlayerY = float(atEntry->y + playerBoxDistY * cosVal + playerBoxDistX*sinVal);
738 // box edges are parallel to coordiante axis, so we can treat every dimension independently :D
739 float dz = pl->GetPositionZ() - atEntry->z;
740 float dx = rotPlayerX - atEntry->x;
741 float dy = rotPlayerY - atEntry->y;
742 if( (fabs(dx) > atEntry->box_x/2 + delta) ||
743 (fabs(dy) > atEntry->box_y/2 + delta) ||
744 (fabs(dz) > atEntry->box_z/2 + delta) )
746 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",
747 pl->GetName(), pl->GetGUIDLow(), atEntry->box_x/2, atEntry->box_y/2, atEntry->box_z/2, rotPlayerX, rotPlayerY, dz, Trigger_ID);
748 return;
752 if(Script->scriptAreaTrigger(GetPlayer(), atEntry))
753 return;
755 uint32 quest_id = sObjectMgr.GetQuestForAreaTrigger( Trigger_ID );
756 if( quest_id && GetPlayer()->isAlive() && GetPlayer()->IsActiveQuest(quest_id) )
758 Quest const* pQuest = sObjectMgr.GetQuestTemplate(quest_id);
759 if( pQuest )
761 if(GetPlayer()->GetQuestStatus(quest_id) == QUEST_STATUS_INCOMPLETE)
762 GetPlayer()->AreaExploredOrEventHappens( quest_id );
766 if(sObjectMgr.IsTavernAreaTrigger(Trigger_ID))
768 // set resting flag we are in the inn
769 GetPlayer()->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING);
770 GetPlayer()->InnEnter(time(NULL), atEntry->mapid, atEntry->x, atEntry->y, atEntry->z);
771 GetPlayer()->SetRestType(REST_TYPE_IN_TAVERN);
773 if(sWorld.IsFFAPvPRealm())
774 GetPlayer()->SetFFAPvP(false);
776 return;
779 if(GetPlayer()->InBattleGround())
781 BattleGround* bg = GetPlayer()->GetBattleGround();
782 if(bg)
783 bg->HandleAreaTrigger(GetPlayer(), Trigger_ID);
784 return;
787 // NULL if all values default (non teleport trigger)
788 AreaTrigger const* at = sObjectMgr.GetAreaTrigger(Trigger_ID);
789 if(!at)
790 return;
792 if(!GetPlayer()->isGameMaster())
794 uint32 missingLevel = 0;
795 if(GetPlayer()->getLevel() < at->requiredLevel && !sWorld.getConfig(CONFIG_BOOL_INSTANCE_IGNORE_LEVEL))
796 missingLevel = at->requiredLevel;
798 // must have one or the other, report the first one that's missing
799 uint32 missingItem = 0;
800 if(at->requiredItem)
802 if(!GetPlayer()->HasItemCount(at->requiredItem, 1) &&
803 (!at->requiredItem2 || !GetPlayer()->HasItemCount(at->requiredItem2, 1)))
804 missingItem = at->requiredItem;
806 else if(at->requiredItem2 && !GetPlayer()->HasItemCount(at->requiredItem2, 1))
807 missingItem = at->requiredItem2;
809 MapEntry const* mapEntry = sMapStore.LookupEntry(at->target_mapId);
810 if(!mapEntry)
811 return;
813 bool isRegularTargetMap = GetPlayer()->GetDifficulty(mapEntry->IsRaid()) == REGULAR_DIFFICULTY;
815 uint32 missingKey = 0;
816 if (!isRegularTargetMap)
818 if(at->heroicKey)
820 if(!GetPlayer()->HasItemCount(at->heroicKey, 1) &&
821 (!at->heroicKey2 || !GetPlayer()->HasItemCount(at->heroicKey2, 1)))
822 missingKey = at->heroicKey;
824 else if(at->heroicKey2 && !GetPlayer()->HasItemCount(at->heroicKey2, 1))
825 missingKey = at->heroicKey2;
828 uint32 missingQuest = 0;
829 if (!isRegularTargetMap)
831 if (at->requiredQuestHeroic && !GetPlayer()->GetQuestRewardStatus(at->requiredQuestHeroic))
832 missingQuest = at->requiredQuestHeroic;
834 else
836 if(at->requiredQuest && !GetPlayer()->GetQuestRewardStatus(at->requiredQuest))
837 missingQuest = at->requiredQuest;
840 if(missingLevel || missingItem || missingKey || missingQuest)
842 // TODO: all this is probably wrong
843 if(missingItem)
844 SendAreaTriggerMessage(GetMangosString(LANG_LEVEL_MINREQUIRED_AND_ITEM), at->requiredLevel, ObjectMgr::GetItemPrototype(missingItem)->Name1);
845 else if(missingKey)
846 GetPlayer()->SendTransferAborted(at->target_mapId, TRANSFER_ABORT_DIFFICULTY, isRegularTargetMap ? DUNGEON_DIFFICULTY_NORMAL : DUNGEON_DIFFICULTY_HEROIC);
847 else if(missingQuest)
848 SendAreaTriggerMessage("%s", at->requiredFailedText.c_str());
849 else if(missingLevel)
850 SendAreaTriggerMessage(GetMangosString(LANG_LEVEL_MINREQUIRED), missingLevel);
851 return;
855 GetPlayer()->TeleportTo(at->target_mapId, at->target_X, at->target_Y, at->target_Z, at->target_Orientation, TELE_TO_NOT_LEAVE_TRANSPORT);
858 void WorldSession::HandleUpdateAccountData(WorldPacket &recv_data)
860 sLog.outDetail("WORLD: Received CMSG_UPDATE_ACCOUNT_DATA");
862 uint32 type, timestamp, decompressedSize;
863 recv_data >> type >> timestamp >> decompressedSize;
865 sLog.outDebug("UAD: type %u, time %u, decompressedSize %u", type, timestamp, decompressedSize);
867 if(type > NUM_ACCOUNT_DATA_TYPES)
868 return;
870 if(decompressedSize == 0) // erase
872 SetAccountData(AccountDataType(type), 0, "");
874 WorldPacket data(SMSG_UPDATE_ACCOUNT_DATA_COMPLETE, 4+4);
875 data << uint32(type);
876 data << uint32(0);
877 SendPacket(&data);
879 return;
882 if(decompressedSize > 0xFFFF)
884 recv_data.rpos(recv_data.wpos()); // unnneded warning spam in this case
885 sLog.outError("UAD: Account data packet too big, size %u", decompressedSize);
886 return;
889 ByteBuffer dest;
890 dest.resize(decompressedSize);
892 uLongf realSize = decompressedSize;
893 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)
895 recv_data.rpos(recv_data.wpos()); // unneded warning spam in this case
896 sLog.outError("UAD: Failed to decompress account data");
897 return;
900 recv_data.rpos(recv_data.wpos()); // uncompress read (recv_data.size() - recv_data.rpos())
902 std::string adata;
903 dest >> adata;
905 SetAccountData(AccountDataType(type), timestamp, adata);
907 WorldPacket data(SMSG_UPDATE_ACCOUNT_DATA_COMPLETE, 4+4);
908 data << uint32(type);
909 data << uint32(0);
910 SendPacket(&data);
913 void WorldSession::HandleRequestAccountData(WorldPacket& recv_data)
915 sLog.outDetail("WORLD: Received CMSG_REQUEST_ACCOUNT_DATA");
917 uint32 type;
918 recv_data >> type;
920 sLog.outDebug("RAD: type %u", type);
922 if(type > NUM_ACCOUNT_DATA_TYPES)
923 return;
925 AccountData *adata = GetAccountData(AccountDataType(type));
927 uint32 size = adata->Data.size();
929 uLongf destSize = compressBound(size);
931 ByteBuffer dest;
932 dest.resize(destSize);
934 if(size && compress(const_cast<uint8*>(dest.contents()), &destSize, (uint8*)adata->Data.c_str(), size) != Z_OK)
936 sLog.outDebug("RAD: Failed to compress account data");
937 return;
940 dest.resize(destSize);
942 WorldPacket data(SMSG_UPDATE_ACCOUNT_DATA, 8+4+4+4+destSize);
943 data << uint64(_player ? _player->GetGUID() : 0); // player guid
944 data << uint32(type); // type (0-7)
945 data << uint32(adata->Time); // unix time
946 data << uint32(size); // decompressed length
947 data.append(dest); // compressed data
948 SendPacket(&data);
951 void WorldSession::HandleSetActionButtonOpcode(WorldPacket& recv_data)
953 sLog.outDebug( "WORLD: Received CMSG_SET_ACTION_BUTTON" );
954 uint8 button;
955 uint32 packetData;
956 recv_data >> button >> packetData;
958 uint32 action = ACTION_BUTTON_ACTION(packetData);
959 uint8 type = ACTION_BUTTON_TYPE(packetData);
961 sLog.outDetail( "BUTTON: %u ACTION: %u TYPE: %u", button, action, type );
962 if (!packetData)
964 sLog.outDetail( "MISC: Remove action from button %u", button );
965 GetPlayer()->removeActionButton(GetPlayer()->GetActiveSpec(),button);
967 else
969 switch(type)
971 case ACTION_BUTTON_MACRO:
972 case ACTION_BUTTON_CMACRO:
973 sLog.outDetail( "MISC: Added Macro %u into button %u", action, button );
974 break;
975 case ACTION_BUTTON_EQSET:
976 sLog.outDetail( "MISC: Added EquipmentSet %u into button %u", action, button );
977 break;
978 case ACTION_BUTTON_SPELL:
979 sLog.outDetail( "MISC: Added Spell %u into button %u", action, button );
980 break;
981 case ACTION_BUTTON_ITEM:
982 sLog.outDetail( "MISC: Added Item %u into button %u", action, button );
983 break;
984 default:
985 sLog.outError( "MISC: Unknown action button type %u for action %u into button %u", type, action, button );
986 return;
988 GetPlayer()->addActionButton(GetPlayer()->m_activeSpec, button, action, type);
992 void WorldSession::HandleCompleteCinematic( WorldPacket & /*recv_data*/ )
994 DEBUG_LOG( "WORLD: Player is watching cinema" );
997 void WorldSession::HandleNextCinematicCamera( WorldPacket & /*recv_data*/ )
999 DEBUG_LOG( "WORLD: Which movie to play" );
1002 void WorldSession::HandleMoveTimeSkippedOpcode( WorldPacket & recv_data )
1004 /* WorldSession::Update( getMSTime() );*/
1005 DEBUG_LOG( "WORLD: Time Lag/Synchronization Resent/Update" );
1007 uint64 guid;
1008 if(!recv_data.readPackGUID(guid))
1010 recv_data.rpos(recv_data.wpos());
1011 return;
1013 recv_data.read_skip<uint32>();
1015 uint64 guid;
1016 uint32 time_skipped;
1017 recv_data >> guid;
1018 recv_data >> time_skipped;
1019 sLog.outDebug( "WORLD: CMSG_MOVE_TIME_SKIPPED" );
1021 /// TODO
1022 must be need use in mangos
1023 We substract server Lags to move time ( AntiLags )
1024 for exmaple
1025 GetPlayer()->ModifyLastMoveTime( -int32(time_skipped) );
1029 void WorldSession::HandleFeatherFallAck(WorldPacket &recv_data)
1031 DEBUG_LOG("WORLD: CMSG_MOVE_FEATHER_FALL_ACK");
1033 // no used
1034 recv_data.rpos(recv_data.wpos()); // prevent warnings spam
1037 void WorldSession::HandleMoveUnRootAck(WorldPacket& recv_data)
1039 // no used
1040 recv_data.rpos(recv_data.wpos()); // prevent warnings spam
1042 uint64 guid;
1043 recv_data >> guid;
1045 // now can skip not our packet
1046 if(_player->GetGUID() != guid)
1048 recv_data.rpos(recv_data.wpos()); // prevent warnings spam
1049 return;
1052 sLog.outDebug( "WORLD: CMSG_FORCE_MOVE_UNROOT_ACK" );
1054 recv_data.read_skip<uint32>(); // unk
1056 MovementInfo movementInfo;
1057 ReadMovementInfo(recv_data, &movementInfo);
1061 void WorldSession::HandleMoveRootAck(WorldPacket& recv_data)
1063 // no used
1064 recv_data.rpos(recv_data.wpos()); // prevent warnings spam
1066 uint64 guid;
1067 recv_data >> guid;
1069 // now can skip not our packet
1070 if(_player->GetGUID() != guid)
1072 recv_data.rpos(recv_data.wpos()); // prevent warnings spam
1073 return;
1076 sLog.outDebug( "WORLD: CMSG_FORCE_MOVE_ROOT_ACK" );
1078 recv_data.read_skip<uint32>(); // unk
1080 MovementInfo movementInfo;
1081 ReadMovementInfo(recv_data, &movementInfo);
1085 void WorldSession::HandleSetActionBarToggles(WorldPacket& recv_data)
1087 uint8 ActionBar;
1089 recv_data >> ActionBar;
1091 if(!GetPlayer()) // ignore until not logged (check needed because STATUS_AUTHED)
1093 if(ActionBar != 0)
1094 sLog.outError("WorldSession::HandleSetActionBarToggles in not logged state with value: %u, ignored", uint32(ActionBar));
1095 return;
1098 GetPlayer()->SetByteValue(PLAYER_FIELD_BYTES, 2, ActionBar);
1101 void WorldSession::HandleWardenDataOpcode(WorldPacket& recv_data)
1103 recv_data.read_skip<uint8>();
1105 uint8 tmp;
1106 recv_data >> tmp;
1107 sLog.outDebug("Received opcode CMSG_WARDEN_DATA, not resolve.uint8 = %u", tmp);
1111 void WorldSession::HandlePlayedTime(WorldPacket& recv_data)
1113 uint8 unk1;
1114 recv_data >> unk1; // 0 or 1 expected
1116 WorldPacket data(SMSG_PLAYED_TIME, 4 + 4 + 1);
1117 data << uint32(_player->GetTotalPlayedTime());
1118 data << uint32(_player->GetLevelPlayedTime());
1119 data << uint8(unk1); // 0 - will not show in chat frame
1120 SendPacket(&data);
1123 void WorldSession::HandleInspectOpcode(WorldPacket& recv_data)
1125 uint64 guid;
1126 recv_data >> guid;
1127 DEBUG_LOG("Inspected guid is (GUID: %u TypeId: %u)", GUID_LOPART(guid), GuidHigh2TypeId(GUID_HIPART(guid)));
1129 _player->SetSelection(guid);
1131 Player *plr = sObjectMgr.GetPlayer(guid);
1132 if(!plr) // wrong player
1133 return;
1135 WorldPacket data(SMSG_INSPECT_TALENT, 50);
1136 data.append(plr->GetPackGUID());
1138 if(sWorld.getConfig(CONFIG_BOOL_TALENTS_INSPECTING) || _player->isGameMaster())
1140 plr->BuildPlayerTalentsInfoData(&data);
1141 plr->BuildEnchantmentsInfoData(&data);
1143 else
1145 data << uint32(0); // unspentTalentPoints
1146 data << uint8(0); // talentGroupCount
1147 data << uint8(0); // talentGroupIndex
1148 data << uint32(0); // slotUsedMask
1151 SendPacket(&data);
1154 void WorldSession::HandleInspectHonorStatsOpcode(WorldPacket& recv_data)
1156 uint64 guid;
1157 recv_data >> guid;
1159 Player *player = sObjectMgr.GetPlayer(guid);
1161 if(!player)
1163 sLog.outError("InspectHonorStats: WTF, player not found...");
1164 return;
1167 WorldPacket data(MSG_INSPECT_HONOR_STATS, 8+1+4*4);
1168 data << uint64(player->GetGUID());
1169 data << uint8(player->GetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY));
1170 data << uint32(player->GetUInt32Value(PLAYER_FIELD_KILLS));
1171 data << uint32(player->GetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION));
1172 data << uint32(player->GetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION));
1173 data << uint32(player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS));
1174 SendPacket(&data);
1177 void WorldSession::HandleWorldTeleportOpcode(WorldPacket& recv_data)
1179 // write in client console: worldport 469 452 6454 2536 180 or /console worldport 469 452 6454 2536 180
1180 // Received opcode CMSG_WORLD_TELEPORT
1181 // Time is ***, map=469, x=452.000000, y=6454.000000, z=2536.000000, orient=3.141593
1183 uint32 time;
1184 uint32 mapid;
1185 float PositionX;
1186 float PositionY;
1187 float PositionZ;
1188 float Orientation;
1190 recv_data >> time; // time in m.sec.
1191 recv_data >> mapid;
1192 recv_data >> PositionX;
1193 recv_data >> PositionY;
1194 recv_data >> PositionZ;
1195 recv_data >> Orientation; // o (3.141593 = 180 degrees)
1197 //sLog.outDebug("Received opcode CMSG_WORLD_TELEPORT");
1199 if(GetPlayer()->isInFlight())
1201 sLog.outDebug("Player '%s' (GUID: %u) in flight, ignore worldport command.",GetPlayer()->GetName(),GetPlayer()->GetGUIDLow());
1202 return;
1205 DEBUG_LOG("Time %u sec, map=%u, x=%f, y=%f, z=%f, orient=%f", time/1000, mapid, PositionX, PositionY, PositionZ, Orientation);
1207 if (GetSecurity() >= SEC_ADMINISTRATOR)
1208 GetPlayer()->TeleportTo(mapid, PositionX, PositionY, PositionZ, Orientation);
1209 else
1210 SendNotification(LANG_YOU_NOT_HAVE_PERMISSION);
1211 sLog.outDebug("Received worldport command from player %s", GetPlayer()->GetName());
1214 void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data)
1216 sLog.outDebug("Received opcode CMSG_WHOIS");
1217 std::string charname;
1218 recv_data >> charname;
1220 if (GetSecurity() < SEC_ADMINISTRATOR)
1222 SendNotification(LANG_YOU_NOT_HAVE_PERMISSION);
1223 return;
1226 if(charname.empty() || !normalizePlayerName (charname))
1228 SendNotification(LANG_NEED_CHARACTER_NAME);
1229 return;
1232 Player *plr = sObjectMgr.GetPlayer(charname.c_str());
1234 if(!plr)
1236 SendNotification(LANG_PLAYER_NOT_EXIST_OR_OFFLINE, charname.c_str());
1237 return;
1240 uint32 accid = plr->GetSession()->GetAccountId();
1242 QueryResult *result = loginDatabase.PQuery("SELECT username,email,last_ip FROM account WHERE id=%u", accid);
1243 if(!result)
1245 SendNotification(LANG_ACCOUNT_FOR_PLAYER_NOT_FOUND, charname.c_str());
1246 return;
1249 Field *fields = result->Fetch();
1250 std::string acc = fields[0].GetCppString();
1251 if(acc.empty())
1252 acc = "Unknown";
1253 std::string email = fields[1].GetCppString();
1254 if(email.empty())
1255 email = "Unknown";
1256 std::string lastip = fields[2].GetCppString();
1257 if(lastip.empty())
1258 lastip = "Unknown";
1260 std::string msg = charname + "'s " + "account is " + acc + ", e-mail: " + email + ", last ip: " + lastip;
1262 WorldPacket data(SMSG_WHOIS, msg.size()+1);
1263 data << msg;
1264 _player->GetSession()->SendPacket(&data);
1266 delete result;
1268 sLog.outDebug("Received whois command from player %s for character %s", GetPlayer()->GetName(), charname.c_str());
1271 void WorldSession::HandleComplainOpcode( WorldPacket & recv_data )
1273 sLog.outDebug("WORLD: CMSG_COMPLAIN");
1274 recv_data.hexlike();
1276 uint8 spam_type; // 0 - mail, 1 - chat
1277 uint64 spammer_guid;
1278 uint32 unk1 = 0;
1279 uint32 unk2 = 0;
1280 uint32 unk3 = 0;
1281 uint32 unk4 = 0;
1282 std::string description = "";
1283 recv_data >> spam_type; // unk 0x01 const, may be spam type (mail/chat)
1284 recv_data >> spammer_guid; // player guid
1285 switch(spam_type)
1287 case 0:
1288 recv_data >> unk1; // const 0
1289 recv_data >> unk2; // probably mail id
1290 recv_data >> unk3; // const 0
1291 break;
1292 case 1:
1293 recv_data >> unk1; // probably language
1294 recv_data >> unk2; // message type?
1295 recv_data >> unk3; // probably channel id
1296 recv_data >> unk4; // unk random value
1297 recv_data >> description; // spam description string (messagetype, channel name, player name, message)
1298 break;
1301 // NOTE: all chat messages from this spammer automatically ignored by spam reporter until logout in case chat spam.
1302 // if it's mail spam - ALL mails from this spammer automatically removed by client
1304 // Complaint Received message
1305 WorldPacket data(SMSG_COMPLAIN_RESULT, 1);
1306 data << uint8(0);
1307 SendPacket(&data);
1309 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());
1312 void WorldSession::HandleRealmSplitOpcode( WorldPacket & recv_data )
1314 sLog.outDebug("CMSG_REALM_SPLIT");
1316 uint32 unk;
1317 std::string split_date = "01/01/01";
1318 recv_data >> unk;
1320 WorldPacket data(SMSG_REALM_SPLIT, 4+4+split_date.size()+1);
1321 data << unk;
1322 data << uint32(0x00000000); // realm split state
1323 // split states:
1324 // 0x0 realm normal
1325 // 0x1 realm split
1326 // 0x2 realm split pending
1327 data << split_date;
1328 SendPacket(&data);
1329 //sLog.outDebug("response sent %u", unk);
1332 void WorldSession::HandleFarSightOpcode( WorldPacket & recv_data )
1334 sLog.outDebug("WORLD: CMSG_FAR_SIGHT");
1335 //recv_data.hexlike();
1337 uint8 unk;
1338 recv_data >> unk;
1340 switch(unk)
1342 case 0:
1343 //WorldPacket data(SMSG_CLEAR_FAR_SIGHT_IMMEDIATE, 0)
1344 //SendPacket(&data);
1345 //_player->SetUInt64Value(PLAYER_FARSIGHT, 0);
1346 sLog.outDebug("Removed FarSight from player %u", _player->GetGUIDLow());
1347 break;
1348 case 1:
1349 sLog.outDebug("Added FarSight (GUID:%u TypeId:%u) to player %u", GUID_LOPART(_player->GetFarSight()), GuidHigh2TypeId(GUID_HIPART(_player->GetFarSight())), _player->GetGUIDLow());
1350 break;
1354 void WorldSession::HandleSetTitleOpcode( WorldPacket & recv_data )
1356 sLog.outDebug("CMSG_SET_TITLE");
1358 int32 title;
1359 recv_data >> title;
1361 // -1 at none
1362 if(title > 0 && title < MAX_TITLE_INDEX)
1364 if(!GetPlayer()->HasTitle(title))
1365 return;
1367 else
1368 title = 0;
1370 GetPlayer()->SetUInt32Value(PLAYER_CHOSEN_TITLE, title);
1373 void WorldSession::HandleTimeSyncResp( WorldPacket & recv_data )
1375 sLog.outDebug("CMSG_TIME_SYNC_RESP");
1377 uint32 counter, time_;
1378 recv_data >> counter >> time_;
1380 // time_ seems always more than getMSTime()
1381 uint32 diff = getMSTimeDiff(getMSTime(), time_);
1383 sLog.outDebug("response sent: counter %u, time %u (HEX: %X), ms. time %u, diff %u", counter, time_, time_, getMSTime(), diff);
1386 void WorldSession::HandleResetInstancesOpcode( WorldPacket & /*recv_data*/ )
1388 sLog.outDebug("WORLD: CMSG_RESET_INSTANCES");
1390 if(Group *pGroup = _player->GetGroup())
1392 if(pGroup->IsLeader(_player->GetGUID()))
1394 pGroup->ResetInstances(INSTANCE_RESET_ALL, false, _player);
1395 pGroup->ResetInstances(INSTANCE_RESET_ALL, true,_player);
1398 else
1400 _player->ResetInstances(INSTANCE_RESET_ALL, false);
1401 _player->ResetInstances(INSTANCE_RESET_ALL, true);
1405 void WorldSession::HandleSetDungeonDifficultyOpcode( WorldPacket & recv_data )
1407 sLog.outDebug("MSG_SET_DUNGEON_DIFFICULTY");
1409 uint32 mode;
1410 recv_data >> mode;
1412 if(mode >= MAX_DUNGEON_DIFFICULTY)
1414 sLog.outError("WorldSession::HandleSetDungeonDifficultyOpcode: player %d sent an invalid instance mode %d!", _player->GetGUIDLow(), mode);
1415 return;
1418 if(Difficulty(mode) == _player->GetDungeonDifficulty())
1419 return;
1421 // cannot reset while in an instance
1422 Map *map = _player->GetMap();
1423 if(map && map->IsDungeon())
1425 sLog.outError("WorldSession::HandleSetDungeonDifficultyOpcode: player %d tried to reset the instance while inside!", _player->GetGUIDLow());
1426 return;
1429 if(_player->getLevel() < LEVELREQUIREMENT_HEROIC)
1430 return;
1432 if(Group *pGroup = _player->GetGroup())
1434 if(pGroup->IsLeader(_player->GetGUID()))
1436 // the difficulty is set even if the instances can't be reset
1437 //_player->SendDungeonDifficulty(true);
1438 pGroup->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY, false, _player);
1439 pGroup->SetDungeonDifficulty(Difficulty(mode));
1442 else
1444 _player->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY, false);
1445 _player->SetDungeonDifficulty(Difficulty(mode));
1449 void WorldSession::HandleSetRaidDifficultyOpcode( WorldPacket & recv_data )
1451 sLog.outDebug("MSG_SET_RAID_DIFFICULTY");
1453 uint32 mode;
1454 recv_data >> mode;
1456 if(mode >= MAX_RAID_DIFFICULTY)
1458 sLog.outError("WorldSession::HandleSetRaidDifficultyOpcode: player %d sent an invalid instance mode %d!", _player->GetGUIDLow(), mode);
1459 return;
1462 if(Difficulty(mode) == _player->GetRaidDifficulty())
1463 return;
1465 // cannot reset while in an instance
1466 Map *map = _player->GetMap();
1467 if(map && map->IsDungeon())
1469 sLog.outError("WorldSession::HandleSetRaidDifficultyOpcode: player %d tried to reset the instance while inside!", _player->GetGUIDLow());
1470 return;
1473 if(_player->getLevel() < LEVELREQUIREMENT_HEROIC)
1474 return;
1476 if(Group *pGroup = _player->GetGroup())
1478 if(pGroup->IsLeader(_player->GetGUID()))
1480 // the difficulty is set even if the instances can't be reset
1481 //_player->SendDungeonDifficulty(true);
1482 pGroup->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY, true, _player);
1483 pGroup->SetRaidDifficulty(Difficulty(mode));
1486 else
1488 _player->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY, true);
1489 _player->SetRaidDifficulty(Difficulty(mode));
1493 void WorldSession::HandleCancelMountAuraOpcode( WorldPacket & /*recv_data*/ )
1495 sLog.outDebug("WORLD: CMSG_CANCEL_MOUNT_AURA");
1497 //If player is not mounted, so go out :)
1498 if (!_player->IsMounted()) // not blizz like; no any messages on blizz
1500 ChatHandler(this).SendSysMessage(LANG_CHAR_NON_MOUNTED);
1501 return;
1504 if(_player->isInFlight()) // not blizz like; no any messages on blizz
1506 ChatHandler(this).SendSysMessage(LANG_YOU_IN_FLIGHT);
1507 return;
1510 _player->Unmount();
1511 _player->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
1514 void WorldSession::HandleMoveSetCanFlyAckOpcode( WorldPacket & recv_data )
1516 // fly mode on/off
1517 sLog.outDebug("WORLD: CMSG_MOVE_SET_CAN_FLY_ACK");
1518 //recv_data.hexlike();
1520 uint64 guid; // guid - unused
1521 if(!recv_data.readPackGUID(guid))
1522 return;
1524 recv_data.read_skip<uint32>(); // unk
1526 MovementInfo movementInfo(recv_data);
1528 recv_data.read_skip<float>(); // unk2
1530 _player->m_movementInfo.SetMovementFlags(movementInfo.GetMovementFlags());
1533 void WorldSession::HandleRequestPetInfoOpcode( WorldPacket & /*recv_data */)
1536 sLog.outDebug("WORLD: CMSG_REQUEST_PET_INFO");
1537 recv_data.hexlike();
1541 void WorldSession::HandleSetTaxiBenchmarkOpcode( WorldPacket & recv_data )
1543 uint8 mode;
1544 recv_data >> mode;
1546 sLog.outDebug("Client used \"/timetest %d\" command", mode);
1549 void WorldSession::HandleQueryInspectAchievements( WorldPacket & recv_data )
1551 uint64 guid;
1552 if(!recv_data.readPackGUID(guid))
1553 return;
1555 if(Player *player = sObjectMgr.GetPlayer(guid))
1556 player->GetAchievementMgr().SendRespondInspectAchievements(_player);
1559 void WorldSession::HandleWorldStateUITimerUpdate(WorldPacket& /*recv_data*/)
1561 // empty opcode
1562 sLog.outDebug("WORLD: CMSG_WORLD_STATE_UI_TIMER_UPDATE");
1564 WorldPacket data(SMSG_WORLD_STATE_UI_TIMER_UPDATE, 4);
1565 data << uint32(time(NULL));
1566 SendPacket(&data);
1569 void WorldSession::HandleReadyForAccountDataTimes(WorldPacket& /*recv_data*/)
1571 // empty opcode
1572 sLog.outDebug("WORLD: CMSG_READY_FOR_ACCOUNT_DATA_TIMES");
1574 SendAccountDataTimes(GLOBAL_CACHE_MASK);
1577 void WorldSession::HandleHearthandResurrect(WorldPacket & /*recv_data*/)
1579 sLog.outDebug("WORLD: CMSG_HEARTH_AND_RESURRECT");
1581 AreaTableEntry const* atEntry = sAreaStore.LookupEntry(_player->GetAreaId());
1582 if(!atEntry || !(atEntry->flags & AREA_FLAG_CAN_HEARTH_AND_RES))
1583 return;
1585 // Can't use in flight
1586 if (_player->isInFlight())
1587 return;
1589 // Send Everytime
1590 _player->BuildPlayerRepop();
1591 _player->ResurrectPlayer(100);
1592 _player->TeleportToHomebind();