[7710] Fixed problem with stuck in combat creatures with EventAI. Remove redundent...
[AHbot.git] / src / game / MiscHandler.cpp
blob59097b3c56d12ccbb075ff40da7bd66bb721908e
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 if(GetPlayer()->isAlive()||GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST))
48 return;
50 // the world update order is sessions, players, creatures
51 // the netcode runs in parallel with all of these
52 // creatures can kill players
53 // so if the server is lagging enough the player can
54 // release spirit after he's killed but before he is updated
55 if(GetPlayer()->getDeathState() == JUST_DIED)
57 sLog.outDebug("HandleRepopRequestOpcode: got request after player %s(%d) was killed and before he was updated", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow());
58 GetPlayer()->KillPlayer();
61 //this is spirit release confirm?
62 GetPlayer()->RemovePet(NULL,PET_SAVE_NOT_IN_SLOT, true);
63 GetPlayer()->BuildPlayerRepop();
64 GetPlayer()->RepopAtGraveyard();
67 void WorldSession::HandleWhoOpcode( WorldPacket & recv_data )
69 CHECK_PACKET_SIZE(recv_data,4+4+1+1+4+4+4+4);
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 // recheck
85 CHECK_PACKET_SIZE(recv_data,4+4+(player_name.size()+1)+1+4+4+4+4);
87 recv_data >> guild_name; // guild name, case sensitive...
89 // recheck
90 CHECK_PACKET_SIZE(recv_data,4+4+(player_name.size()+1)+(guild_name.size()+1)+4+4+4+4);
92 recv_data >> racemask; // race mask
93 recv_data >> classmask; // class mask
94 recv_data >> zones_count; // zones count, client limit=10 (2.0.10)
96 if(zones_count > 10)
97 return; // can't be received from real client or broken packet
99 // recheck
100 CHECK_PACKET_SIZE(recv_data,4+4+(player_name.size()+1)+(guild_name.size()+1)+4+4+4+(4*zones_count)+4);
102 for(uint32 i = 0; i < zones_count; i++)
104 uint32 temp;
105 recv_data >> temp; // zone id, 0 if zone is unknown...
106 zoneids[i] = temp;
107 sLog.outDebug("Zone %u: %u", i, zoneids[i]);
110 recv_data >> str_count; // user entered strings count, client limit=4 (checked on 2.0.10)
112 if(str_count > 4)
113 return; // can't be received from real client or broken packet
115 // recheck
116 CHECK_PACKET_SIZE(recv_data,4+4+(player_name.size()+1)+(guild_name.size()+1)+4+4+4+(4*zones_count)+4+(1*str_count));
118 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);
120 std::wstring str[4]; // 4 is client limit
121 for(uint32 i = 0; i < str_count; i++)
123 // recheck (have one more byte)
124 CHECK_PACKET_SIZE(recv_data,recv_data.rpos());
126 std::string temp;
127 recv_data >> temp; // user entered string, it used as universal search pattern(guild+player name)?
129 if(!Utf8toWStr(temp,str[i]))
130 continue;
132 wstrToLower(str[i]);
134 sLog.outDebug("String %u: %s", i, temp.c_str());
137 std::wstring wplayer_name;
138 std::wstring wguild_name;
139 if(!(Utf8toWStr(player_name, wplayer_name) && Utf8toWStr(guild_name, wguild_name)))
140 return;
141 wstrToLower(wplayer_name);
142 wstrToLower(wguild_name);
144 // client send in case not set max level value 100 but mangos support 255 max level,
145 // update it to show GMs with characters after 100 level
146 if(level_max >= MAX_LEVEL)
147 level_max = STRONG_MAX_LEVEL;
149 uint32 team = _player->GetTeam();
150 uint32 security = GetSecurity();
151 bool allowTwoSideWhoList = sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_WHO_LIST);
152 bool gmInWhoList = sWorld.getConfig(CONFIG_GM_IN_WHO_LIST);
154 WorldPacket data( SMSG_WHO, 50 ); // guess size
155 data << clientcount; // clientcount place holder
156 data << clientcount; // clientcount place holder
158 //TODO: Guard Player map
159 HashMapHolder<Player>::MapType& m = ObjectAccessor::Instance().GetPlayers();
160 for(HashMapHolder<Player>::MapType::iterator itr = m.begin(); itr != m.end(); ++itr)
162 if (security == SEC_PLAYER)
164 // player can see member of other team only if CONFIG_ALLOW_TWO_SIDE_WHO_LIST
165 if (itr->second->GetTeam() != team && !allowTwoSideWhoList )
166 continue;
168 // player can see MODERATOR, GAME MASTER, ADMINISTRATOR only if CONFIG_GM_IN_WHO_LIST
169 if ((itr->second->GetSession()->GetSecurity() > SEC_PLAYER && !gmInWhoList))
170 continue;
173 // check if target is globally visible for player
174 if (!(itr->second->IsVisibleGloballyFor(_player)))
175 continue;
177 // check if target's level is in level range
178 uint32 lvl = itr->second->getLevel();
179 if (lvl < level_min || lvl > level_max)
180 continue;
182 // check if class matches classmask
183 uint32 class_ = itr->second->getClass();
184 if (!(classmask & (1 << class_)))
185 continue;
187 // check if race matches racemask
188 uint32 race = itr->second->getRace();
189 if (!(racemask & (1 << race)))
190 continue;
192 uint32 pzoneid = itr->second->GetZoneId();
194 bool z_show = true;
195 for(uint32 i = 0; i < zones_count; i++)
197 if(zoneids[i] == pzoneid)
199 z_show = true;
200 break;
203 z_show = false;
205 if (!z_show)
206 continue;
208 std::string pname = itr->second->GetName();
209 std::wstring wpname;
210 if(!Utf8toWStr(pname,wpname))
211 continue;
212 wstrToLower(wpname);
214 if (!(wplayer_name.empty() || wpname.find(wplayer_name) != std::wstring::npos))
215 continue;
217 std::string gname = objmgr.GetGuildNameById(itr->second->GetGuildId());
218 std::wstring wgname;
219 if(!Utf8toWStr(gname,wgname))
220 continue;
221 wstrToLower(wgname);
223 if (!(wguild_name.empty() || wgname.find(wguild_name) != std::wstring::npos))
224 continue;
226 std::string aname;
227 if(AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(itr->second->GetZoneId()))
228 aname = areaEntry->area_name[GetSessionDbcLocale()];
230 bool s_show = true;
231 for(uint32 i = 0; i < str_count; i++)
233 if (!str[i].empty())
235 if (wgname.find(str[i]) != std::wstring::npos ||
236 wpname.find(str[i]) != std::wstring::npos ||
237 Utf8FitTo(aname, str[i]) )
239 s_show = true;
240 break;
242 s_show = false;
245 if (!s_show)
246 continue;
248 data << pname; // player name
249 data << gname; // guild name
250 data << uint32( lvl ); // player level
251 data << uint32( class_ ); // player class
252 data << uint32( race ); // player race
253 data << uint8(0); // new 2.4.0
254 data << uint32( pzoneid ); // player zone id
256 // 49 is maximum player count sent to client
257 if ((++clientcount) == 49)
258 break;
261 data.put( 0, clientcount ); //insert right count
262 data.put( sizeof(uint32), clientcount ); //insert right count
264 SendPacket(&data);
265 sLog.outDebug( "WORLD: Send SMSG_WHO Message" );
268 void WorldSession::HandleLogoutRequestOpcode( WorldPacket & /*recv_data*/ )
270 sLog.outDebug( "WORLD: Recvd CMSG_LOGOUT_REQUEST Message, security - %u", GetSecurity() );
272 if (uint64 lguid = GetPlayer()->GetLootGUID())
273 DoLootRelease(lguid);
275 //Can not logout if...
276 if( GetPlayer()->isInCombat() || //...is in combat
277 GetPlayer()->duel || //...is in Duel
278 //...is jumping ...is falling
279 GetPlayer()->HasUnitMovementFlag(MOVEMENTFLAG_JUMPING | MOVEMENTFLAG_FALLING))
281 WorldPacket data( SMSG_LOGOUT_RESPONSE, (2+4) ) ;
282 data << (uint8)0xC;
283 data << uint32(0);
284 data << uint8(0);
285 SendPacket( &data );
286 LogoutRequest(0);
287 return;
290 //instant logout in taverns/cities or on taxi or for admins, gm's, mod's if its enabled in mangosd.conf
291 if (GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING) || GetPlayer()->isInFlight() ||
292 GetSecurity() >= sWorld.getConfig(CONFIG_INSTANT_LOGOUT))
294 LogoutPlayer(true);
295 return;
298 // not set flags if player can't free move to prevent lost state at logout cancel
299 if(GetPlayer()->CanFreeMove())
301 GetPlayer()->SetStandState(UNIT_STAND_STATE_SIT);
303 WorldPacket data( SMSG_FORCE_MOVE_ROOT, (8+4) ); // guess size
304 data.append(GetPlayer()->GetPackGUID());
305 data << (uint32)2;
306 SendPacket( &data );
307 GetPlayer()->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
310 WorldPacket data( SMSG_LOGOUT_RESPONSE, 5 );
311 data << uint32(0);
312 data << uint8(0);
313 SendPacket( &data );
314 LogoutRequest(time(NULL));
317 void WorldSession::HandlePlayerLogoutOpcode( WorldPacket & /*recv_data*/ )
319 sLog.outDebug( "WORLD: Recvd CMSG_PLAYER_LOGOUT Message" );
322 void WorldSession::HandleLogoutCancelOpcode( WorldPacket & /*recv_data*/ )
324 sLog.outDebug( "WORLD: Recvd CMSG_LOGOUT_CANCEL Message" );
326 LogoutRequest(0);
328 WorldPacket data( SMSG_LOGOUT_CANCEL_ACK, 0 );
329 SendPacket( &data );
331 // not remove flags if can't free move - its not set in Logout request code.
332 if(GetPlayer()->CanFreeMove())
334 //!we can move again
335 data.Initialize( SMSG_FORCE_MOVE_UNROOT, 8 ); // guess size
336 data.append(GetPlayer()->GetPackGUID());
337 data << uint32(0);
338 SendPacket( &data );
340 //! Stand Up
341 GetPlayer()->SetStandState(UNIT_STAND_STATE_STAND);
343 //! DISABLE_ROTATE
344 GetPlayer()->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
347 sLog.outDebug( "WORLD: sent SMSG_LOGOUT_CANCEL_ACK Message" );
350 void WorldSession::HandleTogglePvP( WorldPacket & recv_data )
352 // this opcode can be used in two ways: Either set explicit new status or toggle old status
353 if(recv_data.size() == 1)
355 bool newPvPStatus;
356 recv_data >> newPvPStatus;
357 GetPlayer()->ApplyModFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP, newPvPStatus);
358 GetPlayer()->ApplyModFlag(PLAYER_FLAGS, PLAYER_FLAGS_PVP_TIMER, !newPvPStatus);
360 else
362 GetPlayer()->ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP);
363 GetPlayer()->ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_PVP_TIMER);
366 if(GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP))
368 if(!GetPlayer()->IsPvP() || GetPlayer()->pvpInfo.endTimer != 0)
369 GetPlayer()->UpdatePvP(true, true);
371 else
373 if(!GetPlayer()->pvpInfo.inHostileArea && GetPlayer()->IsPvP())
374 GetPlayer()->pvpInfo.endTimer = time(NULL); // start toggle-off
378 void WorldSession::HandleZoneUpdateOpcode( WorldPacket & recv_data )
380 CHECK_PACKET_SIZE(recv_data,4);
382 uint32 newZone;
383 recv_data >> newZone;
385 sLog.outDetail("WORLD: Recvd ZONE_UPDATE: %u", newZone);
387 // use server size data
388 uint32 newzone, newarea;
389 GetPlayer()->GetZoneAndAreaId(newzone,newarea);
390 GetPlayer()->UpdateZone(newzone,newarea);
393 void WorldSession::HandleSetTargetOpcode( WorldPacket & recv_data )
395 // When this packet send?
396 CHECK_PACKET_SIZE(recv_data,8);
398 uint64 guid ;
399 recv_data >> guid;
401 _player->SetUInt32Value(UNIT_FIELD_TARGET,guid);
403 // update reputation list if need
404 Unit* unit = ObjectAccessor::GetUnit(*_player, guid );
405 if(!unit)
406 return;
408 if(FactionTemplateEntry const* factionTemplateEntry = sFactionTemplateStore.LookupEntry(unit->getFaction()))
409 _player->GetReputationMgr().SetVisible(factionTemplateEntry);
412 void WorldSession::HandleSetSelectionOpcode( WorldPacket & recv_data )
414 CHECK_PACKET_SIZE(recv_data,8);
416 uint64 guid;
417 recv_data >> guid;
419 _player->SetSelection(guid);
421 // update reputation list if need
422 Unit* unit = ObjectAccessor::GetUnit(*_player, guid );
423 if(!unit)
424 return;
426 if(FactionTemplateEntry const* factionTemplateEntry = sFactionTemplateStore.LookupEntry(unit->getFaction()))
427 _player->GetReputationMgr().SetVisible(factionTemplateEntry);
430 void WorldSession::HandleStandStateChangeOpcode( WorldPacket & recv_data )
432 CHECK_PACKET_SIZE(recv_data,1);
434 sLog.outDebug( "WORLD: Received CMSG_STAND_STATE_CHANGE" );
435 uint8 animstate;
436 recv_data >> animstate;
438 _player->SetStandState(animstate);
441 void WorldSession::HandleFriendListOpcode( WorldPacket & recv_data )
443 CHECK_PACKET_SIZE(recv_data, 4);
444 sLog.outDebug( "WORLD: Received CMSG_CONTACT_LIST" );
445 uint32 unk;
446 recv_data >> unk;
447 sLog.outDebug("unk value is %u", unk);
448 _player->GetSocial()->SendSocialList();
451 void WorldSession::HandleAddFriendOpcode( WorldPacket & recv_data )
453 CHECK_PACKET_SIZE(recv_data, 1+1);
455 sLog.outDebug( "WORLD: Received CMSG_ADD_FRIEND" );
457 std::string friendName = GetMangosString(LANG_FRIEND_IGNORE_UNKNOWN);
458 std::string friendNote;
460 recv_data >> friendName;
462 // recheck
463 CHECK_PACKET_SIZE(recv_data, (friendName.size()+1)+1);
465 recv_data >> friendNote;
467 if(!normalizePlayerName(friendName))
468 return;
470 CharacterDatabase.escape_string(friendName); // prevent SQL injection - normal name don't must changed by this call
472 sLog.outDebug( "WORLD: %s asked to add friend : '%s'",
473 GetPlayer()->GetName(), friendName.c_str() );
475 CharacterDatabase.AsyncPQuery(&WorldSession::HandleAddFriendOpcodeCallBack, GetAccountId(), friendNote, "SELECT guid, race FROM characters WHERE name = '%s'", friendName.c_str());
478 void WorldSession::HandleAddFriendOpcodeCallBack(QueryResult *result, uint32 accountId, std::string friendNote)
480 if(!result)
481 return;
483 uint64 friendGuid = MAKE_NEW_GUID((*result)[0].GetUInt32(), 0, HIGHGUID_PLAYER);
484 uint32 team = Player::TeamForRace((*result)[1].GetUInt8());
486 delete result;
488 WorldSession * session = sWorld.FindSession(accountId);
489 if(!session || !session->GetPlayer())
490 return;
492 FriendsResult friendResult = FRIEND_NOT_FOUND;
493 if(friendGuid)
495 if(friendGuid==session->GetPlayer()->GetGUID())
496 friendResult = FRIEND_SELF;
497 else if(session->GetPlayer()->GetTeam() != team && !sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_ADD_FRIEND) && session->GetSecurity() < SEC_MODERATOR)
498 friendResult = FRIEND_ENEMY;
499 else if(session->GetPlayer()->GetSocial()->HasFriend(GUID_LOPART(friendGuid)))
500 friendResult = FRIEND_ALREADY;
501 else
503 Player* pFriend = ObjectAccessor::FindPlayer(friendGuid);
504 if( pFriend && pFriend->IsInWorld() && pFriend->IsVisibleGloballyFor(session->GetPlayer()))
505 friendResult = FRIEND_ADDED_ONLINE;
506 else
507 friendResult = FRIEND_ADDED_OFFLINE;
509 if(!session->GetPlayer()->GetSocial()->AddToSocialList(GUID_LOPART(friendGuid), false))
511 friendResult = FRIEND_LIST_FULL;
512 sLog.outDebug( "WORLD: %s's friend list is full.", session->GetPlayer()->GetName());
515 session->GetPlayer()->GetSocial()->SetFriendNote(GUID_LOPART(friendGuid), friendNote);
519 sSocialMgr.SendFriendStatus(session->GetPlayer(), friendResult, GUID_LOPART(friendGuid), false);
521 sLog.outDebug( "WORLD: Sent (SMSG_FRIEND_STATUS)" );
524 void WorldSession::HandleDelFriendOpcode( WorldPacket & recv_data )
526 CHECK_PACKET_SIZE(recv_data, 8);
528 uint64 FriendGUID;
530 sLog.outDebug( "WORLD: Received CMSG_DEL_FRIEND" );
532 recv_data >> FriendGUID;
534 _player->GetSocial()->RemoveFromSocialList(GUID_LOPART(FriendGUID), false);
536 sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_REMOVED, GUID_LOPART(FriendGUID), false);
538 sLog.outDebug( "WORLD: Sent motd (SMSG_FRIEND_STATUS)" );
541 void WorldSession::HandleAddIgnoreOpcode( WorldPacket & recv_data )
543 CHECK_PACKET_SIZE(recv_data,1);
545 sLog.outDebug( "WORLD: Received CMSG_ADD_IGNORE" );
547 std::string IgnoreName = GetMangosString(LANG_FRIEND_IGNORE_UNKNOWN);
549 recv_data >> IgnoreName;
551 if(!normalizePlayerName(IgnoreName))
552 return;
554 CharacterDatabase.escape_string(IgnoreName); // prevent SQL injection - normal name don't must changed by this call
556 sLog.outDebug( "WORLD: %s asked to Ignore: '%s'",
557 GetPlayer()->GetName(), IgnoreName.c_str() );
559 CharacterDatabase.AsyncPQuery(&WorldSession::HandleAddIgnoreOpcodeCallBack, GetAccountId(), "SELECT guid FROM characters WHERE name = '%s'", IgnoreName.c_str());
562 void WorldSession::HandleAddIgnoreOpcodeCallBack(QueryResult *result, uint32 accountId)
564 if(!result)
565 return;
567 uint64 IgnoreGuid = MAKE_NEW_GUID((*result)[0].GetUInt32(), 0, HIGHGUID_PLAYER);
569 delete result;
571 WorldSession * session = sWorld.FindSession(accountId);
572 if(!session || !session->GetPlayer())
573 return;
575 FriendsResult ignoreResult = FRIEND_IGNORE_NOT_FOUND;
576 if(IgnoreGuid)
578 if(IgnoreGuid==session->GetPlayer()->GetGUID()) //not add yourself
579 ignoreResult = FRIEND_IGNORE_SELF;
580 else if( session->GetPlayer()->GetSocial()->HasIgnore(GUID_LOPART(IgnoreGuid)) )
581 ignoreResult = FRIEND_IGNORE_ALREADY;
582 else
584 ignoreResult = FRIEND_IGNORE_ADDED;
586 // ignore list full
587 if(!session->GetPlayer()->GetSocial()->AddToSocialList(GUID_LOPART(IgnoreGuid), true))
588 ignoreResult = FRIEND_IGNORE_FULL;
592 sSocialMgr.SendFriendStatus(session->GetPlayer(), ignoreResult, GUID_LOPART(IgnoreGuid), false);
594 sLog.outDebug( "WORLD: Sent (SMSG_FRIEND_STATUS)" );
597 void WorldSession::HandleDelIgnoreOpcode( WorldPacket & recv_data )
599 CHECK_PACKET_SIZE(recv_data, 8);
601 uint64 IgnoreGUID;
603 sLog.outDebug( "WORLD: Received CMSG_DEL_IGNORE" );
605 recv_data >> IgnoreGUID;
607 _player->GetSocial()->RemoveFromSocialList(GUID_LOPART(IgnoreGUID), true);
609 sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_IGNORE_REMOVED, GUID_LOPART(IgnoreGUID), false);
611 sLog.outDebug( "WORLD: Sent motd (SMSG_FRIEND_STATUS)" );
614 void WorldSession::HandleSetFriendNoteOpcode( WorldPacket & recv_data )
616 CHECK_PACKET_SIZE(recv_data, 8+1);
617 uint64 guid;
618 std::string note;
619 recv_data >> guid >> note;
620 _player->GetSocial()->SetFriendNote(guid, note);
623 void WorldSession::HandleBugOpcode( WorldPacket & recv_data )
625 CHECK_PACKET_SIZE(recv_data,4+4+1+4+1);
627 uint32 suggestion, contentlen;
628 std::string content;
629 uint32 typelen;
630 std::string type;
632 recv_data >> suggestion >> contentlen >> content;
634 //recheck
635 CHECK_PACKET_SIZE(recv_data,4+4+(content.size()+1)+4+1);
637 recv_data >> typelen >> type;
639 if( suggestion == 0 )
640 sLog.outDebug( "WORLD: Received CMSG_BUG [Bug Report]" );
641 else
642 sLog.outDebug( "WORLD: Received CMSG_BUG [Suggestion]" );
644 sLog.outDebug( type.c_str( ) );
645 sLog.outDebug( content.c_str( ) );
647 CharacterDatabase.escape_string(type);
648 CharacterDatabase.escape_string(content);
649 CharacterDatabase.PExecute ("INSERT INTO bugreport (type,content) VALUES('%s', '%s')", type.c_str( ), content.c_str( ));
652 void WorldSession::HandleCorpseReclaimOpcode(WorldPacket &recv_data)
654 CHECK_PACKET_SIZE(recv_data,8);
656 sLog.outDetail("WORLD: Received CMSG_RECLAIM_CORPSE");
657 if (GetPlayer()->isAlive())
658 return;
660 // do not allow corpse reclaim in arena
661 if (GetPlayer()->InArena())
662 return;
664 // body not released yet
665 if(!GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST))
666 return;
668 Corpse *corpse = GetPlayer()->GetCorpse();
670 if (!corpse )
671 return;
673 // prevent resurrect before 30-sec delay after body release not finished
674 if(corpse->GetGhostTime() + GetPlayer()->GetCorpseReclaimDelay(corpse->GetType()==CORPSE_RESURRECTABLE_PVP) > time(NULL))
675 return;
677 float dist = corpse->GetDistance2d(GetPlayer());
678 sLog.outDebug("Corpse 2D Distance: \t%f",dist);
679 if (dist > CORPSE_RECLAIM_RADIUS)
680 return;
682 uint64 guid;
683 recv_data >> guid;
685 // resurrect
686 GetPlayer()->ResurrectPlayer(GetPlayer()->InBattleGround() ? 1.0f : 0.5f);
688 // spawn bones
689 GetPlayer()->SpawnCorpseBones();
691 GetPlayer()->SaveToDB();
694 void WorldSession::HandleResurrectResponseOpcode(WorldPacket & recv_data)
696 CHECK_PACKET_SIZE(recv_data,8+1);
698 sLog.outDetail("WORLD: Received CMSG_RESURRECT_RESPONSE");
700 if(GetPlayer()->isAlive())
701 return;
703 uint64 guid;
704 uint8 status;
705 recv_data >> guid;
706 recv_data >> status;
708 if(status == 0)
710 GetPlayer()->clearResurrectRequestData(); // reject
711 return;
714 if(!GetPlayer()->isRessurectRequestedBy(guid))
715 return;
717 GetPlayer()->ResurectUsingRequestData();
718 GetPlayer()->SaveToDB();
721 void WorldSession::HandleAreaTriggerOpcode(WorldPacket & recv_data)
723 CHECK_PACKET_SIZE(recv_data,4);
725 sLog.outDebug("WORLD: Received CMSG_AREATRIGGER");
727 uint32 Trigger_ID;
729 recv_data >> Trigger_ID;
730 sLog.outDebug("Trigger ID:%u",Trigger_ID);
732 if(GetPlayer()->isInFlight())
734 sLog.outDebug("Player '%s' (GUID: %u) in flight, ignore Area Trigger ID:%u",GetPlayer()->GetName(),GetPlayer()->GetGUIDLow(), Trigger_ID);
735 return;
738 AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(Trigger_ID);
739 if(!atEntry)
741 sLog.outDebug("Player '%s' (GUID: %u) send unknown (by DBC) Area Trigger ID:%u",GetPlayer()->GetName(),GetPlayer()->GetGUIDLow(), Trigger_ID);
742 return;
745 if (GetPlayer()->GetMapId()!=atEntry->mapid)
747 sLog.outDebug("Player '%s' (GUID: %u) too far (trigger map: %u player map: %u), ignore Area Trigger ID: %u", GetPlayer()->GetName(), atEntry->mapid, GetPlayer()->GetMapId(), GetPlayer()->GetGUIDLow(), Trigger_ID);
748 return;
751 // delta is safe radius
752 const float delta = 5.0f;
753 // check if player in the range of areatrigger
754 Player* pl = GetPlayer();
756 if (atEntry->radius > 0)
758 // if we have radius check it
759 float dist = pl->GetDistance(atEntry->x,atEntry->y,atEntry->z);
760 if(dist > atEntry->radius + delta)
762 sLog.outDebug("Player '%s' (GUID: %u) too far (radius: %f distance: %f), ignore Area Trigger ID: %u",
763 pl->GetName(), pl->GetGUIDLow(), atEntry->radius, dist, Trigger_ID);
764 return;
767 else
769 // we have only extent
770 float dx = pl->GetPositionX() - atEntry->x;
771 float dy = pl->GetPositionY() - atEntry->y;
772 float dz = pl->GetPositionZ() - atEntry->z;
773 double es = sin(atEntry->box_orientation);
774 double ec = cos(atEntry->box_orientation);
775 // calc rotated vector based on extent axis
776 double rotateDx = dx*ec - dy*es;
777 double rotateDy = dx*es + dy*ec;
779 if( (fabs(rotateDx) > atEntry->box_x/2 + delta) ||
780 (fabs(rotateDy) > atEntry->box_y/2 + delta) ||
781 (fabs(dz) > atEntry->box_z/2 + delta) )
783 sLog.outDebug("Player '%s' (GUID: %u) too far (1/2 box X: %f 1/2 box Y: %f 1/2 box Z: %f rotate dX: %f rotate dY: %f dZ:%f), ignore Area Trigger ID: %u",
784 pl->GetName(), pl->GetGUIDLow(), atEntry->box_x/2, atEntry->box_y/2, atEntry->box_z/2, rotateDx, rotateDy, dz, Trigger_ID);
785 return;
789 if(Script->scriptAreaTrigger(GetPlayer(), atEntry))
790 return;
792 uint32 quest_id = objmgr.GetQuestForAreaTrigger( Trigger_ID );
793 if( quest_id && GetPlayer()->isAlive() && GetPlayer()->IsActiveQuest(quest_id) )
795 Quest const* pQuest = objmgr.GetQuestTemplate(quest_id);
796 if( pQuest )
798 if(GetPlayer()->GetQuestStatus(quest_id) == QUEST_STATUS_INCOMPLETE)
799 GetPlayer()->AreaExploredOrEventHappens( quest_id );
803 if(objmgr.IsTavernAreaTrigger(Trigger_ID))
805 // set resting flag we are in the inn
806 GetPlayer()->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING);
807 GetPlayer()->InnEnter(time(NULL), atEntry->mapid, atEntry->x, atEntry->y, atEntry->z);
808 GetPlayer()->SetRestType(REST_TYPE_IN_TAVERN);
810 if(sWorld.IsFFAPvPRealm())
811 GetPlayer()->RemoveByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP);
813 return;
816 if(GetPlayer()->InBattleGround())
818 BattleGround* bg = GetPlayer()->GetBattleGround();
819 if(bg)
820 if(bg->GetStatus() == STATUS_IN_PROGRESS)
821 bg->HandleAreaTrigger(GetPlayer(), Trigger_ID);
823 return;
826 // NULL if all values default (non teleport trigger)
827 AreaTrigger const* at = objmgr.GetAreaTrigger(Trigger_ID);
828 if(!at)
829 return;
831 if(!GetPlayer()->isGameMaster())
833 uint32 missingLevel = 0;
834 if(GetPlayer()->getLevel() < at->requiredLevel && !sWorld.getConfig(CONFIG_INSTANCE_IGNORE_LEVEL))
835 missingLevel = at->requiredLevel;
837 // must have one or the other, report the first one that's missing
838 uint32 missingItem = 0;
839 if(at->requiredItem)
841 if(!GetPlayer()->HasItemCount(at->requiredItem, 1) &&
842 (!at->requiredItem2 || !GetPlayer()->HasItemCount(at->requiredItem2, 1)))
843 missingItem = at->requiredItem;
845 else if(at->requiredItem2 && !GetPlayer()->HasItemCount(at->requiredItem2, 1))
846 missingItem = at->requiredItem2;
848 uint32 missingKey = 0;
849 if(GetPlayer()->GetDifficulty() == DIFFICULTY_HEROIC)
851 if(at->heroicKey)
853 if(!GetPlayer()->HasItemCount(at->heroicKey, 1) &&
854 (!at->heroicKey2 || !GetPlayer()->HasItemCount(at->heroicKey2, 1)))
855 missingKey = at->heroicKey;
857 else if(at->heroicKey2 && !GetPlayer()->HasItemCount(at->heroicKey2, 1))
858 missingKey = at->heroicKey2;
861 uint32 missingQuest = 0;
862 if(GetPlayer()->GetDifficulty() == DIFFICULTY_HEROIC)
864 if (at->requiredQuestHeroic && !GetPlayer()->GetQuestRewardStatus(at->requiredQuestHeroic))
865 missingQuest = at->requiredQuestHeroic;
867 else
869 if(at->requiredQuest && !GetPlayer()->GetQuestRewardStatus(at->requiredQuest))
870 missingQuest = at->requiredQuest;
873 if(missingLevel || missingItem || missingKey || missingQuest)
875 // TODO: all this is probably wrong
876 if(missingItem)
877 SendAreaTriggerMessage(GetMangosString(LANG_LEVEL_MINREQUIRED_AND_ITEM), at->requiredLevel, objmgr.GetItemPrototype(missingItem)->Name1);
878 else if(missingKey)
879 GetPlayer()->SendTransferAborted(at->target_mapId, TRANSFER_ABORT_DIFFICULTY, DIFFICULTY_HEROIC);
880 else if(missingQuest)
881 SendAreaTriggerMessage(at->requiredFailedText.c_str());
882 else if(missingLevel)
883 SendAreaTriggerMessage(GetMangosString(LANG_LEVEL_MINREQUIRED), missingLevel);
884 return;
888 GetPlayer()->TeleportTo(at->target_mapId,at->target_X,at->target_Y,at->target_Z,at->target_Orientation,TELE_TO_NOT_LEAVE_TRANSPORT);
891 void WorldSession::HandleUpdateAccountData(WorldPacket &recv_data)
893 sLog.outDetail("WORLD: Received CMSG_UPDATE_ACCOUNT_DATA");
895 CHECK_PACKET_SIZE(recv_data, 4+4+4);
897 uint32 type, timestamp, decompressedSize;
898 recv_data >> type >> timestamp >> decompressedSize;
900 sLog.outDebug("UAD: type %u, time %u, decompressedSize %u", type, timestamp, decompressedSize);
902 if(type > NUM_ACCOUNT_DATA_TYPES)
903 return;
905 if(decompressedSize == 0) // erase
907 SetAccountData(type, 0, "");
909 WorldPacket data(SMSG_UPDATE_ACCOUNT_DATA_COMPLETE, 4+4);
910 data << uint32(type);
911 data << uint32(0);
912 SendPacket(&data);
914 return;
917 if(decompressedSize > 0xFFFF)
919 sLog.outError("UAD: Account data packet too big, size %u", decompressedSize);
920 return;
923 ByteBuffer dest;
924 dest.resize(decompressedSize);
926 uLongf realSize = decompressedSize;
927 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)
929 sLog.outError("UAD: Failed to decompress account data");
930 return;
933 std::string adata;
934 dest >> adata;
936 SetAccountData(type, timestamp, adata);
938 WorldPacket data(SMSG_UPDATE_ACCOUNT_DATA_COMPLETE, 4+4);
939 data << uint32(type);
940 data << uint32(0);
941 SendPacket(&data);
944 void WorldSession::HandleRequestAccountData(WorldPacket& recv_data)
946 sLog.outDetail("WORLD: Received CMSG_REQUEST_ACCOUNT_DATA");
948 CHECK_PACKET_SIZE(recv_data, 4);
950 uint32 type;
951 recv_data >> type;
953 sLog.outDebug("RAD: type %u", type);
955 if(type > NUM_ACCOUNT_DATA_TYPES)
956 return;
958 AccountData *adata = GetAccountData(type);
960 uint32 size = adata->Data.size();
962 ByteBuffer dest;
963 dest.resize(size);
965 uLongf destSize = size;
966 if(size && compress(const_cast<uint8*>(dest.contents()), &destSize, (uint8*)adata->Data.c_str(), size) != Z_OK)
968 sLog.outDebug("RAD: Failed to compress account data");
969 return;
972 dest.resize(destSize);
974 WorldPacket data (SMSG_UPDATE_ACCOUNT_DATA, 8+4+4+4+destSize);
975 data << uint64(_player->GetGUID()); // player guid
976 data << uint32(type); // type (0-7)
977 data << uint32(adata->Time); // unix time
978 data << uint32(size); // decompressed length
979 data.append(dest); // compressed data
980 SendPacket(&data);
983 void WorldSession::HandleSetActionButtonOpcode(WorldPacket& recv_data)
985 CHECK_PACKET_SIZE(recv_data,1+2+1+1);
987 sLog.outDebug( "WORLD: Received CMSG_SET_ACTION_BUTTON" );
988 uint8 button, misc, type;
989 uint16 action;
990 recv_data >> button >> action >> misc >> type;
991 sLog.outDetail( "BUTTON: %u ACTION: %u TYPE: %u MISC: %u", button, action, type, misc );
992 if(action==0)
994 sLog.outDetail( "MISC: Remove action from button %u", button );
996 GetPlayer()->removeActionButton(button);
998 else
1000 if(type==ACTION_BUTTON_MACRO || type==ACTION_BUTTON_CMACRO)
1002 sLog.outDetail( "MISC: Added Macro %u into button %u", action, button );
1003 GetPlayer()->addActionButton(button,action,type,misc);
1005 else if(type==ACTION_BUTTON_SPELL)
1007 sLog.outDetail( "MISC: Added Spell %u into button %u", action, button );
1008 GetPlayer()->addActionButton(button,action,type,misc);
1010 else if(type==ACTION_BUTTON_ITEM)
1012 sLog.outDetail( "MISC: Added Item %u into button %u", action, button );
1013 GetPlayer()->addActionButton(button,action,type,misc);
1015 else
1016 sLog.outError( "MISC: Unknown action button type %u for action %u into button %u", type, action, button );
1020 void WorldSession::HandleCompleteCinema( WorldPacket & /*recv_data*/ )
1022 DEBUG_LOG( "WORLD: Player is watching cinema" );
1025 void WorldSession::HandleNextCinematicCamera( WorldPacket & /*recv_data*/ )
1027 DEBUG_LOG( "WORLD: Which movie to play" );
1030 void WorldSession::HandleMoveTimeSkippedOpcode( WorldPacket & /*recv_data*/ )
1032 /* WorldSession::Update( getMSTime() );*/
1033 DEBUG_LOG( "WORLD: Time Lag/Synchronization Resent/Update" );
1036 CHECK_PACKET_SIZE(recv_data,8+4);
1037 uint64 guid;
1038 uint32 time_skipped;
1039 recv_data >> guid;
1040 recv_data >> time_skipped;
1041 sLog.outDebug( "WORLD: CMSG_MOVE_TIME_SKIPPED" );
1043 /// TODO
1044 must be need use in mangos
1045 We substract server Lags to move time ( AntiLags )
1046 for exmaple
1047 GetPlayer()->ModifyLastMoveTime( -int32(time_skipped) );
1051 void WorldSession::HandleFeatherFallAck(WorldPacket &/*recv_data*/)
1053 DEBUG_LOG("WORLD: CMSG_MOVE_FEATHER_FALL_ACK");
1056 void WorldSession::HandleMoveUnRootAck(WorldPacket&/* recv_data*/)
1059 CHECK_PACKET_SIZE(recv_data,8+8+4+4+4+4+4);
1061 sLog.outDebug( "WORLD: CMSG_FORCE_MOVE_UNROOT_ACK" );
1062 recv_data.hexlike();
1063 uint64 guid;
1064 uint64 unknown1;
1065 uint32 unknown2;
1066 float PositionX;
1067 float PositionY;
1068 float PositionZ;
1069 float Orientation;
1071 recv_data >> guid;
1072 recv_data >> unknown1;
1073 recv_data >> unknown2;
1074 recv_data >> PositionX;
1075 recv_data >> PositionY;
1076 recv_data >> PositionZ;
1077 recv_data >> Orientation;
1079 // TODO for later may be we can use for anticheat
1080 DEBUG_LOG("Guid " I64FMTD,guid);
1081 DEBUG_LOG("unknown1 " I64FMTD,unknown1);
1082 DEBUG_LOG("unknown2 %u",unknown2);
1083 DEBUG_LOG("X %f",PositionX);
1084 DEBUG_LOG("Y %f",PositionY);
1085 DEBUG_LOG("Z %f",PositionZ);
1086 DEBUG_LOG("O %f",Orientation);
1090 void WorldSession::HandleMoveRootAck(WorldPacket&/* recv_data*/)
1093 CHECK_PACKET_SIZE(recv_data,8+8+4+4+4+4+4);
1095 sLog.outDebug( "WORLD: CMSG_FORCE_MOVE_ROOT_ACK" );
1096 recv_data.hexlike();
1097 uint64 guid;
1098 uint64 unknown1;
1099 uint32 unknown2;
1100 float PositionX;
1101 float PositionY;
1102 float PositionZ;
1103 float Orientation;
1105 recv_data >> guid;
1106 recv_data >> unknown1;
1107 recv_data >> unknown2;
1108 recv_data >> PositionX;
1109 recv_data >> PositionY;
1110 recv_data >> PositionZ;
1111 recv_data >> Orientation;
1113 // for later may be we can use for anticheat
1114 DEBUG_LOG("Guid " I64FMTD,guid);
1115 DEBUG_LOG("unknown1 " I64FMTD,unknown1);
1116 DEBUG_LOG("unknown1 %u",unknown2);
1117 DEBUG_LOG("X %f",PositionX);
1118 DEBUG_LOG("Y %f",PositionY);
1119 DEBUG_LOG("Z %f",PositionZ);
1120 DEBUG_LOG("O %f",Orientation);
1124 void WorldSession::HandleSetActionBar(WorldPacket& recv_data)
1126 CHECK_PACKET_SIZE(recv_data,1);
1128 uint8 ActionBar;
1130 recv_data >> ActionBar;
1132 if(!GetPlayer()) // ignore until not logged (check needed because STATUS_AUTHED)
1134 if(ActionBar!=0)
1135 sLog.outError("WorldSession::HandleSetActionBar in not logged state with value: %u, ignored",uint32(ActionBar));
1136 return;
1139 GetPlayer()->SetByteValue(PLAYER_FIELD_BYTES, 2, ActionBar);
1142 void WorldSession::HandleWardenDataOpcode(WorldPacket& /*recv_data*/)
1145 CHECK_PACKET_SIZE(recv_data,1);
1147 uint8 tmp;
1148 recv_data >> tmp;
1149 sLog.outDebug("Received opcode CMSG_WARDEN_DATA, not resolve.uint8 = %u",tmp);
1153 void WorldSession::HandlePlayedTime(WorldPacket& /*recv_data*/)
1155 uint32 TotalTimePlayed = GetPlayer()->GetTotalPlayedTime();
1156 uint32 LevelPlayedTime = GetPlayer()->GetLevelPlayedTime();
1158 WorldPacket data(SMSG_PLAYED_TIME, 8);
1159 data << TotalTimePlayed;
1160 data << LevelPlayedTime;
1161 SendPacket(&data);
1164 void WorldSession::HandleInspectOpcode(WorldPacket& recv_data)
1166 CHECK_PACKET_SIZE(recv_data, 8);
1168 uint64 guid;
1169 recv_data >> guid;
1170 DEBUG_LOG("Inspected guid is " I64FMTD, guid);
1172 _player->SetSelection(guid);
1174 Player *plr = objmgr.GetPlayer(guid);
1175 if(!plr) // wrong player
1176 return;
1178 uint32 talent_points = 0x3D;
1179 uint32 guid_size = plr->GetPackGUID().size();
1180 WorldPacket data(SMSG_INSPECT_TALENT, 4+talent_points);
1181 data.append(plr->GetPackGUID());
1182 data << uint32(talent_points);
1184 // fill by 0 talents array
1185 for(uint32 i = 0; i < talent_points; ++i)
1186 data << uint8(0);
1188 if(sWorld.getConfig(CONFIG_TALENTS_INSPECTING) || _player->isGameMaster())
1190 // find class talent tabs (all players have 3 talent tabs)
1191 uint32 const* talentTabIds = GetTalentTabPages(plr->getClass());
1193 uint32 talentTabPos = 0; // pos of first talent rank in tab including all prev tabs
1194 for(uint32 i = 0; i < 3; ++i)
1196 uint32 talentTabId = talentTabIds[i];
1198 // fill by real data
1199 for(uint32 talentId = 0; talentId < sTalentStore.GetNumRows(); ++talentId)
1201 TalentEntry const* talentInfo = sTalentStore.LookupEntry(talentId);
1202 if(!talentInfo)
1203 continue;
1205 // skip another tab talents
1206 if(talentInfo->TalentTab != talentTabId)
1207 continue;
1209 // find talent rank
1210 uint32 curtalent_maxrank = 0;
1211 for(uint32 k = MAX_TALENT_RANK; k > 0; --k)
1213 if(talentInfo->RankID[k-1] && plr->HasSpell(talentInfo->RankID[k-1]))
1215 curtalent_maxrank = k;
1216 break;
1220 // not learned talent
1221 if(!curtalent_maxrank)
1222 continue;
1224 // 1 rank talent bit index
1225 uint32 curtalent_index = talentTabPos + GetTalentInspectBitPosInTab(talentId);
1227 uint32 curtalent_rank_index = curtalent_index+curtalent_maxrank-1;
1229 // slot/offset in 7-bit bytes
1230 uint32 curtalent_rank_slot7 = curtalent_rank_index / 7;
1231 uint32 curtalent_rank_offset7 = curtalent_rank_index % 7;
1233 // rank pos with skipped 8 bit
1234 uint32 curtalent_rank_index2 = curtalent_rank_slot7 * 8 + curtalent_rank_offset7;
1236 // slot/offset in 8-bit bytes with skipped high bit
1237 uint32 curtalent_rank_slot = curtalent_rank_index2 / 8;
1238 uint32 curtalent_rank_offset = curtalent_rank_index2 % 8;
1240 // apply mask
1241 uint32 val = data.read<uint8>(guid_size + 4 + curtalent_rank_slot);
1242 val |= (1 << curtalent_rank_offset);
1243 data.put<uint8>(guid_size + 4 + curtalent_rank_slot, val & 0xFF);
1246 talentTabPos += GetTalentTabInspectBitSize(talentTabId);
1250 SendPacket(&data);
1253 void WorldSession::HandleInspectHonorStatsOpcode(WorldPacket& recv_data)
1255 CHECK_PACKET_SIZE(recv_data, 8);
1257 uint64 guid;
1258 recv_data >> guid;
1260 Player *player = objmgr.GetPlayer(guid);
1262 if(!player)
1264 sLog.outError("InspectHonorStats: WTF, player not found...");
1265 return;
1268 WorldPacket data(MSG_INSPECT_HONOR_STATS, 8+1+4*4);
1269 data << uint64(player->GetGUID());
1270 data << uint8(player->GetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY));
1271 data << uint32(player->GetUInt32Value(PLAYER_FIELD_KILLS));
1272 data << uint32(player->GetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION));
1273 data << uint32(player->GetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION));
1274 data << uint32(player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS));
1275 SendPacket(&data);
1278 void WorldSession::HandleWorldTeleportOpcode(WorldPacket& recv_data)
1280 CHECK_PACKET_SIZE(recv_data,4+4+4+4+4+4);
1282 // write in client console: worldport 469 452 6454 2536 180 or /console worldport 469 452 6454 2536 180
1283 // Received opcode CMSG_WORLD_TELEPORT
1284 // Time is ***, map=469, x=452.000000, y=6454.000000, z=2536.000000, orient=3.141593
1286 //sLog.outDebug("Received opcode CMSG_WORLD_TELEPORT");
1288 if(GetPlayer()->isInFlight())
1290 sLog.outDebug("Player '%s' (GUID: %u) in flight, ignore worldport command.",GetPlayer()->GetName(),GetPlayer()->GetGUIDLow());
1291 return;
1294 uint32 time;
1295 uint32 mapid;
1296 float PositionX;
1297 float PositionY;
1298 float PositionZ;
1299 float Orientation;
1301 recv_data >> time; // time in m.sec.
1302 recv_data >> mapid;
1303 recv_data >> PositionX;
1304 recv_data >> PositionY;
1305 recv_data >> PositionZ;
1306 recv_data >> Orientation; // o (3.141593 = 180 degrees)
1307 DEBUG_LOG("Time %u sec, map=%u, x=%f, y=%f, z=%f, orient=%f", time/1000, mapid, PositionX, PositionY, PositionZ, Orientation);
1309 if (GetSecurity() >= SEC_ADMINISTRATOR)
1310 GetPlayer()->TeleportTo(mapid,PositionX,PositionY,PositionZ,Orientation);
1311 else
1312 SendNotification(LANG_YOU_NOT_HAVE_PERMISSION);
1313 sLog.outDebug("Received worldport command from player %s", GetPlayer()->GetName());
1316 void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data)
1318 CHECK_PACKET_SIZE(recv_data, 1);
1320 sLog.outDebug("Received opcode CMSG_WHOIS");
1321 std::string charname;
1322 recv_data >> charname;
1324 if (GetSecurity() < SEC_ADMINISTRATOR)
1326 SendNotification(LANG_YOU_NOT_HAVE_PERMISSION);
1327 return;
1330 if(charname.empty() || !normalizePlayerName (charname))
1332 SendNotification(LANG_NEED_CHARACTER_NAME);
1333 return;
1336 Player *plr = objmgr.GetPlayer(charname.c_str());
1338 if(!plr)
1340 SendNotification(LANG_PLAYER_NOT_EXIST_OR_OFFLINE, charname.c_str());
1341 return;
1344 uint32 accid = plr->GetSession()->GetAccountId();
1346 QueryResult *result = loginDatabase.PQuery("SELECT username,email,last_ip FROM account WHERE id=%u", accid);
1347 if(!result)
1349 SendNotification(LANG_ACCOUNT_FOR_PLAYER_NOT_FOUND, charname.c_str());
1350 return;
1353 Field *fields = result->Fetch();
1354 std::string acc = fields[0].GetCppString();
1355 if(acc.empty())
1356 acc = "Unknown";
1357 std::string email = fields[1].GetCppString();
1358 if(email.empty())
1359 email = "Unknown";
1360 std::string lastip = fields[2].GetCppString();
1361 if(lastip.empty())
1362 lastip = "Unknown";
1364 std::string msg = charname + "'s " + "account is " + acc + ", e-mail: " + email + ", last ip: " + lastip;
1366 WorldPacket data(SMSG_WHOIS, msg.size()+1);
1367 data << msg;
1368 _player->GetSession()->SendPacket(&data);
1370 delete result;
1372 sLog.outDebug("Received whois command from player %s for character %s", GetPlayer()->GetName(), charname.c_str());
1375 void WorldSession::HandleReportSpamOpcode( WorldPacket & recv_data )
1377 CHECK_PACKET_SIZE(recv_data, 1+8);
1378 sLog.outDebug("WORLD: CMSG_REPORT_SPAM");
1379 recv_data.hexlike();
1381 uint8 spam_type; // 0 - mail, 1 - chat
1382 uint64 spammer_guid;
1383 uint32 unk1, unk2, unk3, unk4 = 0;
1384 std::string description = "";
1385 recv_data >> spam_type; // unk 0x01 const, may be spam type (mail/chat)
1386 recv_data >> spammer_guid; // player guid
1387 switch(spam_type)
1389 case 0:
1390 CHECK_PACKET_SIZE(recv_data, recv_data.rpos()+4+4+4);
1391 recv_data >> unk1; // const 0
1392 recv_data >> unk2; // probably mail id
1393 recv_data >> unk3; // const 0
1394 break;
1395 case 1:
1396 CHECK_PACKET_SIZE(recv_data, recv_data.rpos()+4+4+4+4+1);
1397 recv_data >> unk1; // probably language
1398 recv_data >> unk2; // message type?
1399 recv_data >> unk3; // probably channel id
1400 recv_data >> unk4; // unk random value
1401 recv_data >> description; // spam description string (messagetype, channel name, player name, message)
1402 break;
1405 // NOTE: all chat messages from this spammer automatically ignored by spam reporter until logout in case chat spam.
1406 // if it's mail spam - ALL mails from this spammer automatically removed by client
1408 // Complaint Received message
1409 WorldPacket data(SMSG_COMPLAIN_RESULT, 1);
1410 data << uint8(0);
1411 SendPacket(&data);
1413 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());
1416 void WorldSession::HandleRealmStateRequestOpcode( WorldPacket & recv_data )
1418 CHECK_PACKET_SIZE(recv_data, 4);
1420 sLog.outDebug("CMSG_REALM_SPLIT");
1422 uint32 unk;
1423 std::string split_date = "01/01/01";
1424 recv_data >> unk;
1426 WorldPacket data(SMSG_REALM_SPLIT, 4+4+split_date.size()+1);
1427 data << unk;
1428 data << uint32(0x00000000); // realm split state
1429 // split states:
1430 // 0x0 realm normal
1431 // 0x1 realm split
1432 // 0x2 realm split pending
1433 data << split_date;
1434 SendPacket(&data);
1435 //sLog.outDebug("response sent %u", unk);
1438 void WorldSession::HandleFarSightOpcode( WorldPacket & recv_data )
1440 CHECK_PACKET_SIZE(recv_data, 1);
1442 sLog.outDebug("WORLD: CMSG_FAR_SIGHT");
1443 //recv_data.hexlike();
1445 uint8 unk;
1446 recv_data >> unk;
1448 switch(unk)
1450 case 0:
1451 //WorldPacket data(SMSG_CLEAR_FAR_SIGHT_IMMEDIATE, 0)
1452 //SendPacket(&data);
1453 //_player->SetUInt64Value(PLAYER_FARSIGHT, 0);
1454 sLog.outDebug("Removed FarSight from player %u", _player->GetGUIDLow());
1455 break;
1456 case 1:
1457 sLog.outDebug("Added FarSight " I64FMT " to player %u", _player->GetFarSight(), _player->GetGUIDLow());
1458 break;
1462 void WorldSession::HandleChooseTitleOpcode( WorldPacket & recv_data )
1464 CHECK_PACKET_SIZE(recv_data, 4);
1466 sLog.outDebug("CMSG_SET_TITLE");
1468 int32 title;
1469 recv_data >> title;
1471 // -1 at none
1472 if(title > 0 && title < 128)
1474 if(!GetPlayer()->HasTitle(title))
1475 return;
1477 else
1478 title = 0;
1480 GetPlayer()->SetUInt32Value(PLAYER_CHOSEN_TITLE, title);
1483 void WorldSession::HandleTimeSyncResp( WorldPacket & recv_data )
1485 CHECK_PACKET_SIZE(recv_data, 4+4);
1487 sLog.outDebug("CMSG_TIME_SYNC_RESP");
1489 uint32 counter, time_;
1490 recv_data >> counter >> time_;
1492 // time_ seems always more than getMSTime()
1493 uint32 diff = getMSTimeDiff(getMSTime(),time_);
1495 sLog.outDebug("response sent: counter %u, time %u (HEX: %X), ms. time %u, diff %u", counter, time_, time_, getMSTime(), diff);
1498 void WorldSession::HandleResetInstancesOpcode( WorldPacket & /*recv_data*/ )
1500 sLog.outDebug("WORLD: CMSG_RESET_INSTANCES");
1501 Group *pGroup = _player->GetGroup();
1502 if(pGroup)
1504 if(pGroup->IsLeader(_player->GetGUID()))
1505 pGroup->ResetInstances(INSTANCE_RESET_ALL, _player);
1507 else
1508 _player->ResetInstances(INSTANCE_RESET_ALL);
1511 void WorldSession::HandleDungeonDifficultyOpcode( WorldPacket & recv_data )
1513 CHECK_PACKET_SIZE(recv_data, 4);
1515 sLog.outDebug("MSG_SET_DUNGEON_DIFFICULTY");
1517 uint32 mode;
1518 recv_data >> mode;
1520 if(mode == _player->GetDifficulty())
1521 return;
1523 if(mode > DIFFICULTY_HEROIC)
1525 sLog.outError("WorldSession::HandleDungeonDifficultyOpcode: player %d sent an invalid instance mode %d!", _player->GetGUIDLow(), mode);
1526 return;
1529 // cannot reset while in an instance
1530 Map *map = _player->GetMap();
1531 if(map && map->IsDungeon())
1533 sLog.outError("WorldSession::HandleDungeonDifficultyOpcode: player %d tried to reset the instance while inside!", _player->GetGUIDLow());
1534 return;
1537 if(_player->getLevel() < LEVELREQUIREMENT_HEROIC)
1538 return;
1539 Group *pGroup = _player->GetGroup();
1540 if(pGroup)
1542 if(pGroup->IsLeader(_player->GetGUID()))
1544 // the difficulty is set even if the instances can't be reset
1545 //_player->SendDungeonDifficulty(true);
1546 pGroup->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY, _player);
1547 pGroup->SetDifficulty(mode);
1550 else
1552 _player->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY);
1553 _player->SetDifficulty(mode);
1557 void WorldSession::HandleDismountOpcode( WorldPacket & /*recv_data*/ )
1559 sLog.outDebug("WORLD: CMSG_CANCEL_MOUNT_AURA");
1560 //recv_data.hexlike();
1562 //If player is not mounted, so go out :)
1563 if (!_player->IsMounted()) // not blizz like; no any messages on blizz
1565 ChatHandler(this).SendSysMessage(LANG_CHAR_NON_MOUNTED);
1566 return;
1569 if(_player->isInFlight()) // not blizz like; no any messages on blizz
1571 ChatHandler(this).SendSysMessage(LANG_YOU_IN_FLIGHT);
1572 return;
1575 _player->Unmount();
1576 _player->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
1579 void WorldSession::HandleMoveFlyModeChangeAckOpcode( WorldPacket & recv_data )
1581 CHECK_PACKET_SIZE(recv_data, 8+4+4);
1583 // fly mode on/off
1584 sLog.outDebug("WORLD: CMSG_MOVE_SET_CAN_FLY_ACK");
1585 //recv_data.hexlike();
1587 uint64 guid;
1588 uint32 unk;
1589 uint32 flags;
1591 recv_data >> guid >> unk >> flags;
1593 _player->SetUnitMovementFlags(flags);
1596 25 00 00 00 00 00 00 00 | 00 00 00 00 00 00 80 00
1597 85 4E A9 01 19 BA 7A C3 | 42 0D 70 44 44 B0 A8 42
1598 78 15 94 40 39 03 00 00 | 00 00 80 3F
1599 off:
1600 25 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00
1601 10 FD A9 01 19 BA 7A C3 | 42 0D 70 44 44 B0 A8 42
1602 78 15 94 40 39 03 00 00 | 00 00 00 00
1606 void WorldSession::HandleRequestPetInfoOpcode( WorldPacket & /*recv_data */)
1609 sLog.outDebug("WORLD: CMSG_REQUEST_PET_INFO");
1610 recv_data.hexlike();
1614 void WorldSession::HandleSetTaxiBenchmarkOpcode( WorldPacket & recv_data )
1616 CHECK_PACKET_SIZE(recv_data, 1);
1618 uint8 mode;
1619 recv_data >> mode;
1621 sLog.outDebug("Client used \"/timetest %d\" command", mode);
1624 void WorldSession::HandleSpellClick( WorldPacket & recv_data )
1626 CHECK_PACKET_SIZE(recv_data, 8);
1628 uint64 guid;
1629 recv_data >> guid;
1631 Vehicle *vehicle = ObjectAccessor::GetVehicle(guid);
1633 if(!vehicle)
1634 return;
1636 _player->EnterVehicle(vehicle);
1639 void WorldSession::HandleInspectAchievements( WorldPacket & recv_data )
1641 CHECK_PACKET_SIZE(recv_data, 1);
1642 uint64 guid;
1643 if(!recv_data.readPackGUID(guid))
1644 return;
1646 Player *player = objmgr.GetPlayer(guid);
1647 if(!player)
1648 return;
1650 player->GetAchievementMgr().SendRespondInspectAchievements(_player);