root/trunk/src/game/MiscHandler.cpp @ 2

Revision 2, 56.1 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#include "Common.h"
20#include "Language.h"
21#include "Database/DatabaseEnv.h"
22#include "WorldPacket.h"
23#include "Opcodes.h"
24#include "Log.h"
25#include "Player.h"
26#include "World.h"
27#include "ObjectMgr.h"
28#include "WorldSession.h"
29#include "Auth/BigNumber.h"
30#include "Auth/Sha1.h"
31#include "UpdateData.h"
32#include "LootMgr.h"
33#include "Chat.h"
34#include "ScriptCalls.h"
35#include <zlib/zlib.h>
36#include "MapManager.h"
37#include "ObjectAccessor.h"
38#include "Object.h"
39#include "BattleGround.h"
40#include "SpellAuras.h"
41#include "Pet.h"
42#include "SocialMgr.h"
43
44void WorldSession::HandleRepopRequestOpcode( WorldPacket & /*recv_data*/ )
45{
46    sLog.outDebug( "WORLD: Recvd CMSG_REPOP_REQUEST Message" );
47
48    if(GetPlayer()->isAlive()||GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST))
49        return;
50
51    // the world update order is sessions, players, creatures
52    // the netcode runs in parallel with all of these
53    // creatures can kill players
54    // so if the server is lagging enough the player can
55    // release spirit after he's killed but before he is updated
56    if(GetPlayer()->getDeathState() == JUST_DIED)
57    {
58        sLog.outDebug("HandleRepopRequestOpcode: got request after player %s(%d) was killed and before he was updated", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow());
59        GetPlayer()->KillPlayer();
60    }
61
62    //this is spirit release confirm?
63    GetPlayer()->RemovePet(NULL,PET_SAVE_NOT_IN_SLOT, true);
64    GetPlayer()->BuildPlayerRepop();
65    GetPlayer()->RepopAtGraveyard();
66}
67
68void WorldSession::HandleWhoOpcode( WorldPacket & recv_data )
69{
70    CHECK_PACKET_SIZE(recv_data,4+4+1+1+4+4+4+4);
71
72    sLog.outDebug( "WORLD: Recvd CMSG_WHO Message" );
73    //recv_data.hexlike();
74
75    uint32 clientcount = 0;
76
77    uint32 level_min, level_max, racemask, classmask, zones_count, str_count;
78    uint32 zoneids[10];                                     // 10 is client limit
79    std::string player_name, guild_name;
80
81    recv_data >> level_min;                                 // maximal player level, default 0
82    recv_data >> level_max;                                 // minimal player level, default 100
83    recv_data >> player_name;                               // player name, case sensitive...
84
85    // recheck
86    CHECK_PACKET_SIZE(recv_data,4+4+(player_name.size()+1)+1+4+4+4+4);
87
88    recv_data >> guild_name;                                // guild name, case sensitive...
89
90    // recheck
91    CHECK_PACKET_SIZE(recv_data,4+4+(player_name.size()+1)+(guild_name.size()+1)+4+4+4+4);
92
93    recv_data >> racemask;                                  // race mask
94    recv_data >> classmask;                                 // class mask
95    recv_data >> zones_count;                               // zones count, client limit=10 (2.0.10)
96
97    if(zones_count > 10)
98        return;                                             // can't be received from real client or broken packet
99
100    // recheck
101    CHECK_PACKET_SIZE(recv_data,4+4+(player_name.size()+1)+(guild_name.size()+1)+4+4+4+(4*zones_count)+4);
102
103    for(uint32 i = 0; i < zones_count; i++)
104    {
105        uint32 temp;
106        recv_data >> temp;                                  // zone id, 0 if zone is unknown...
107        zoneids[i] = temp;
108        sLog.outDebug("Zone %u: %u", i, zoneids[i]);
109    }
110
111    recv_data >> str_count;                                 // user entered strings count, client limit=4 (checked on 2.0.10)
112
113    if(str_count > 4)
114        return;                                             // can't be received from real client or broken packet
115
116    // recheck
117    CHECK_PACKET_SIZE(recv_data,4+4+(player_name.size()+1)+(guild_name.size()+1)+4+4+4+(4*zones_count)+4+(1*str_count));
118
119    sLog.outDebug("Minlvl %u, maxlvl %u, name %s, guild %s, racemask %u, classmask %u, zones %u, strings %u", level_min, level_max, player_name.c_str(), guild_name.c_str(), racemask, classmask, zones_count, str_count);
120
121    std::wstring str[4];                                    // 4 is client limit
122    for(uint32 i = 0; i < str_count; i++)
123    {
124        // recheck (have one more byte)
125        CHECK_PACKET_SIZE(recv_data,recv_data.rpos());
126
127        std::string temp;
128        recv_data >> temp;                                  // user entered string, it used as universal search pattern(guild+player name)?
129
130        if(!Utf8toWStr(temp,str[i]))
131            continue;
132
133        wstrToLower(str[i]);
134
135        sLog.outDebug("String %u: %s", i, str[i].c_str());
136    }
137
138    std::wstring wplayer_name;
139    std::wstring wguild_name;
140    if(!(Utf8toWStr(player_name, wplayer_name) && Utf8toWStr(guild_name, wguild_name)))
141        return;
142    wstrToLower(wplayer_name);
143    wstrToLower(wguild_name);
144
145    // client send in case not set max level value 100 but mangos support 255 max level,
146    // update it to show GMs with characters after 100 level
147    if(level_max >= 100)
148        level_max = 255;
149
150    uint32 team = _player->GetTeam();
151    uint32 security = GetSecurity();
152    bool allowTwoSideWhoList = sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_WHO_LIST);
153    bool gmInWhoList         = sWorld.getConfig(CONFIG_GM_IN_WHO_LIST);
154
155    WorldPacket data( SMSG_WHO, 50 );                       // guess size
156    data << clientcount;                                    // clientcount place holder
157    data << clientcount;                                    // clientcount place holder
158
159    //TODO: Guard Player map
160    HashMapHolder<Player>::MapType& m = ObjectAccessor::Instance().GetPlayers();
161    for(HashMapHolder<Player>::MapType::iterator itr = m.begin(); itr != m.end(); ++itr)
162    {
163        if (security == SEC_PLAYER)
164        {
165            // player can see member of other team only if CONFIG_ALLOW_TWO_SIDE_WHO_LIST
166            if (itr->second->GetTeam() != team && !allowTwoSideWhoList )
167                continue;
168
169            // player can see MODERATOR, GAME MASTER, ADMINISTRATOR only if CONFIG_GM_IN_WHO_LIST
170            if ((itr->second->GetSession()->GetSecurity() > SEC_PLAYER && !gmInWhoList))
171                continue;
172        }
173
174        // check if target is globally visible for player
175        if (!(itr->second->IsVisibleGloballyFor(_player)))
176            continue;
177
178        // check if target's level is in level range
179        uint32 lvl = itr->second->getLevel();
180        if (lvl < level_min || lvl > level_max)
181            continue;
182
183        // check if class matches classmask
184        uint32 class_ = itr->second->getClass();
185        if (!(classmask & (1 << class_)))
186            continue;
187
188        // check if race matches racemask
189        uint32 race = itr->second->getRace();
190        if (!(racemask & (1 << race)))
191            continue;
192
193        uint32 pzoneid = itr->second->GetZoneId();
194
195        bool z_show = true;
196        for(uint32 i = 0; i < zones_count; i++)
197        {
198            if(zoneids[i] == pzoneid)
199            {
200                z_show = true;
201                break;
202            }
203
204            z_show = false;
205        }
206        if (!z_show)
207            continue;
208
209        std::string pname = itr->second->GetName();
210        std::wstring wpname;
211        if(!Utf8toWStr(pname,wpname))
212            continue;
213        wstrToLower(wpname);
214
215        if (!(wplayer_name.empty() || wpname.find(wplayer_name) != std::wstring::npos))
216            continue;
217
218        std::string gname = objmgr.GetGuildNameById(itr->second->GetGuildId());
219        std::wstring wgname;
220        if(!Utf8toWStr(gname,wgname))
221            continue;
222        wstrToLower(wgname);
223
224        if (!(wguild_name.empty() || wgname.find(wguild_name) != std::wstring::npos))
225            continue;
226
227        std::string aname;
228        if(AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(itr->second->GetZoneId()))
229            aname = areaEntry->area_name[GetSessionDbcLocale()];
230
231        bool s_show = true;
232        for(uint32 i = 0; i < str_count; i++)
233        {
234            if (!str[i].empty())
235            {
236                if (wgname.find(str[i]) != std::wstring::npos ||
237                    wpname.find(str[i]) != std::wstring::npos ||
238                    Utf8FitTo(aname, str[i]) )
239                {
240                    s_show = true;
241                    break;
242                }
243                s_show = false;
244            }
245        }
246        if (!s_show)
247            continue;
248
249        data << pname;                                      // player name
250        data << gname;                                      // guild name
251        data << uint32( lvl );                              // player level
252        data << uint32( class_ );                           // player class
253        data << uint32( race );                             // player race
254        data << uint8(0);                                   // new 2.4.0
255        data << uint32( pzoneid );                          // player zone id
256
257        // 49 is maximum player count sent to client
258        if ((++clientcount) == 49)
259            break;
260    }
261
262    data.put( 0,              clientcount );                //insert right count
263    data.put( sizeof(uint32), clientcount );                //insert right count
264
265    SendPacket(&data);
266    sLog.outDebug( "WORLD: Send SMSG_WHO Message" );
267}
268
269void WorldSession::HandleLogoutRequestOpcode( WorldPacket & /*recv_data*/ )
270{
271    sLog.outDebug( "WORLD: Recvd CMSG_LOGOUT_REQUEST Message, security - %u", GetSecurity() );
272
273    if (uint64 lguid = GetPlayer()->GetLootGUID())
274        DoLootRelease(lguid);
275
276    //instant logout for admins, gm's, mod's
277    if( GetSecurity() > SEC_PLAYER )
278    {
279        LogoutPlayer(true);
280        return;
281    }
282
283    //Can not logout if...
284    if( GetPlayer()->isInCombat() ||                        //...is in combat
285        GetPlayer()->duel         ||                        //...is in Duel
286                                                            //...is jumping ...is falling
287        GetPlayer()->HasUnitMovementFlag(MOVEMENTFLAG_JUMPING | MOVEMENTFLAG_FALLING))
288    {
289        WorldPacket data( SMSG_LOGOUT_RESPONSE, (2+4) ) ;
290        data << (uint8)0xC;
291        data << uint32(0);
292        data << uint8(0);
293        SendPacket( &data );
294        LogoutRequest(0);
295        return;
296    }
297
298    //instant logout in taverns/cities or on taxi
299    if(GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING) || GetPlayer()->isInFlight())
300    {
301        LogoutPlayer(true);
302        return;
303    }
304
305    // not set flags if player can't free move to prevent lost state at logout cancel
306    if(GetPlayer()->CanFreeMove())
307    {
308        GetPlayer()->SetStandState(PLAYER_STATE_SIT);
309
310        WorldPacket data( SMSG_FORCE_MOVE_ROOT, (8+4) );    // guess size
311        data.append(GetPlayer()->GetPackGUID());
312        data << (uint32)2;
313        SendPacket( &data );
314        GetPlayer()->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_ROTATE);
315    }
316
317    WorldPacket data( SMSG_LOGOUT_RESPONSE, 5 );
318    data << uint32(0);
319    data << uint8(0);
320    SendPacket( &data );
321    LogoutRequest(time(NULL));
322}
323
324void WorldSession::HandlePlayerLogoutOpcode( WorldPacket & /*recv_data*/ )
325{
326    sLog.outDebug( "WORLD: Recvd CMSG_PLAYER_LOGOUT Message" );
327}
328
329void WorldSession::HandleLogoutCancelOpcode( WorldPacket & /*recv_data*/ )
330{
331    sLog.outDebug( "WORLD: Recvd CMSG_LOGOUT_CANCEL Message" );
332
333    LogoutRequest(0);
334
335    WorldPacket data( SMSG_LOGOUT_CANCEL_ACK, 0 );
336    SendPacket( &data );
337
338    // not remove flags if can't free move - its not set in Logout request code.
339    if(GetPlayer()->CanFreeMove())
340    {
341        //!we can move again
342        data.Initialize( SMSG_FORCE_MOVE_UNROOT, 8 );       // guess size
343        data.append(GetPlayer()->GetPackGUID());
344        data << uint32(0);
345        SendPacket( &data );
346
347        //! Stand Up
348        GetPlayer()->SetStandState(PLAYER_STATE_NONE);
349
350        //! DISABLE_ROTATE
351        GetPlayer()->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_ROTATE);
352    }
353
354    sLog.outDebug( "WORLD: sent SMSG_LOGOUT_CANCEL_ACK Message" );
355}
356
357void WorldSession::SendGMTicketGetTicket(uint32 status, char const* text)
358{
359    int len = text ? strlen(text) : 0;
360    WorldPacket data( SMSG_GMTICKET_GETTICKET, (4+len+1+4+2+4+4) );
361    data << uint32(status);                                 // standard 0x0A, 0x06 if text present
362    if(status == 6)
363    {
364        data << text;                                       // ticket text
365        data << uint8(0x7);                                 // ticket category
366        data << float(0);                                   // time from ticket creation?
367        data << float(0);                                   // const
368        data << float(0);                                   // const
369        data << uint8(0);                                   // const
370        data << uint8(0);                                   // const
371    }
372    SendPacket( &data );
373}
374
375void WorldSession::HandleGMTicketGetTicketOpcode( WorldPacket & /*recv_data*/ )
376{
377    WorldPacket data( SMSG_QUERY_TIME_RESPONSE, 4+4 );
378    data << (uint32)time(NULL);
379    data << (uint32)0;
380    SendPacket( &data );
381
382    uint64 guid;
383    Field *fields;
384    guid = GetPlayer()->GetGUID();
385
386    QueryResult *result = CharacterDatabase.PQuery("SELECT COUNT(ticket_id) FROM character_ticket WHERE guid = '%u'", GUID_LOPART(guid));
387
388    if (result)
389    {
390        int cnt;
391        fields = result->Fetch();
392        cnt = fields[0].GetUInt32();
393        delete result;
394
395        if ( cnt > 0 )
396        {
397            QueryResult *result2 = CharacterDatabase.PQuery("SELECT ticket_text FROM character_ticket WHERE guid = '%u'", GUID_LOPART(guid));
398            if(result2)
399            {
400                Field *fields2 = result2->Fetch();
401                SendGMTicketGetTicket(0x06,fields2[0].GetString());
402                delete result2;
403            }
404        }
405        else
406            SendGMTicketGetTicket(0x0A,0);
407    }
408}
409
410void WorldSession::HandleGMTicketUpdateTextOpcode( WorldPacket & recv_data )
411{
412    CHECK_PACKET_SIZE(recv_data,1);
413
414    std::string ticketText;
415    recv_data >> ticketText;
416
417    CharacterDatabase.escape_string(ticketText);
418    CharacterDatabase.PExecute("UPDATE character_ticket SET ticket_text = '%s' WHERE guid = '%u'", ticketText.c_str(), _player->GetGUIDLow());
419}
420
421void WorldSession::HandleGMTicketDeleteOpcode( WorldPacket & /*recv_data*/ )
422{
423    uint32 guid = GetPlayer()->GetGUIDLow();
424
425    CharacterDatabase.PExecute("DELETE FROM character_ticket WHERE guid = '%u' LIMIT 1",guid);
426
427    WorldPacket data( SMSG_GMTICKET_DELETETICKET, 4 );
428    data << uint32(9);
429    SendPacket( &data );
430
431    SendGMTicketGetTicket(0x0A, 0);
432}
433
434void WorldSession::HandleGMTicketCreateOpcode( WorldPacket & recv_data )
435{
436    CHECK_PACKET_SIZE(recv_data, 4*4+1+2*4);
437
438    uint32 map;
439    float x, y, z;
440    std::string ticketText = "";
441    uint32 unk1, unk2;
442
443    recv_data >> map >> x >> y >> z;                        // last check 2.4.3
444    recv_data >> ticketText;
445
446    // recheck
447    CHECK_PACKET_SIZE(recv_data,4*4+(ticketText.size()+1)+2*4);
448
449    recv_data >> unk1 >> unk2;
450    // note: the packet might contain more data, but the exact structure of that is unknown
451
452    sLog.outDebug("TicketCreate: map %u, x %f, y %f, z %f, text %s, unk1 %u, unk2 %u", map, x, y, z, ticketText.c_str(), unk1, unk2);
453
454    CharacterDatabase.escape_string(ticketText);
455
456    QueryResult *result = CharacterDatabase.PQuery("SELECT COUNT(*) FROM character_ticket WHERE guid = '%u'", _player->GetGUIDLow());
457
458    if (result)
459    {
460        int cnt;
461        Field *fields = result->Fetch();
462        cnt = fields[0].GetUInt32();
463        delete result;
464
465        if ( cnt > 0 )
466        {
467            WorldPacket data( SMSG_GMTICKET_CREATE, 4 );
468            data << uint32(1);
469            SendPacket( &data );
470        }
471        else
472        {
473            CharacterDatabase.PExecute("INSERT INTO character_ticket (guid,ticket_text) VALUES ('%u', '%s')", _player->GetGUIDLow(), ticketText.c_str());
474
475            WorldPacket data( SMSG_QUERY_TIME_RESPONSE, 4+4 );
476            data << (uint32)time(NULL);
477            data << (uint32)0;
478            SendPacket( &data );
479
480            data.Initialize( SMSG_GMTICKET_CREATE, 4 );
481            data << uint32(2);
482            SendPacket( &data );
483            DEBUG_LOG("update the ticket\n");
484
485            //TODO: Guard player map
486            HashMapHolder<Player>::MapType &m = ObjectAccessor::Instance().GetPlayers();
487            for(HashMapHolder<Player>::MapType::iterator itr = m.begin(); itr != m.end(); ++itr)
488            {
489                if(itr->second->GetSession()->GetSecurity() >= SEC_GAMEMASTER && itr->second->isAcceptTickets())
490                    ChatHandler(itr->second).PSendSysMessage(LANG_COMMAND_TICKETNEW,GetPlayer()->GetName());
491            }
492        }
493    }
494}
495
496void WorldSession::HandleGMTicketSystemStatusOpcode( WorldPacket & /*recv_data*/ )
497{
498    WorldPacket data( SMSG_GMTICKET_SYSTEMSTATUS,4 );
499    data << uint32(1);                                      // we can also disable ticket system by sending 0 value
500
501    SendPacket( &data );
502}
503
504void WorldSession::HandleGMSurveySubmit( WorldPacket & recv_data)
505{
506    // GM survey is shown after SMSG_GM_TICKET_STATUS_UPDATE with status = 3
507    CHECK_PACKET_SIZE(recv_data,4+4);
508    uint32 x;
509    recv_data >> x;                                         // answer range? (6 = 0-5?)
510    sLog.outDebug("SURVEY: X = %u", x);
511
512    uint8 result[10];
513    memset(result, 0, sizeof(result));
514    for( int i = 0; i < 10; ++i)
515    {
516        CHECK_PACKET_SIZE(recv_data,recv_data.rpos()+4);
517        uint32 questionID;
518        recv_data >> questionID;                            // GMSurveyQuestions.dbc
519        if (!questionID)
520            break;
521
522        CHECK_PACKET_SIZE(recv_data,recv_data.rpos()+1+1);
523        uint8 value;
524        std::string unk_text;
525        recv_data >> value;                                 // answer
526        recv_data >> unk_text;                              // always empty?
527
528        result[i] = value;
529        sLog.outDebug("SURVEY: ID %u, value %u, text %s", questionID, value, unk_text.c_str());
530    }
531
532    CHECK_PACKET_SIZE(recv_data,recv_data.rpos()+1);
533    std::string comment;
534    recv_data >> comment;                                   // addional comment
535    sLog.outDebug("SURVEY: comment %s", comment.c_str());
536
537    // TODO: chart this data in some way
538}
539
540void WorldSession::HandleTogglePvP( WorldPacket & recv_data )
541{
542    // this opcode can be used in two ways: Either set explicit new status or toggle old status
543    if(recv_data.size() == 1)
544    {
545        bool newPvPStatus;
546        recv_data >> newPvPStatus;
547        GetPlayer()->ApplyModFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP, newPvPStatus);
548    }
549    else
550    {
551        GetPlayer()->ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP);
552    }
553
554    if(GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP))
555    {
556        if(!GetPlayer()->IsPvP() || GetPlayer()->pvpInfo.endTimer != 0)
557            GetPlayer()->UpdatePvP(true, true);
558    }
559    else
560    {
561        if(!GetPlayer()->pvpInfo.inHostileArea && GetPlayer()->IsPvP())
562            GetPlayer()->pvpInfo.endTimer = time(NULL);     // start toggle-off
563    }
564}
565
566void WorldSession::HandleZoneUpdateOpcode( WorldPacket & recv_data )
567{
568    CHECK_PACKET_SIZE(recv_data,4);
569
570    uint32 newZone;
571    recv_data >> newZone;
572
573    sLog.outDetail("WORLD: Recvd ZONE_UPDATE: %u", newZone);
574
575    if(newZone != _player->GetZoneId())
576        GetPlayer()->SendInitWorldStates();                 // only if really enters to new zone, not just area change, works strange...
577
578    GetPlayer()->UpdateZone(newZone);
579}
580
581void WorldSession::HandleSetTargetOpcode( WorldPacket & recv_data )
582{
583    // When this packet send?
584    CHECK_PACKET_SIZE(recv_data,8);
585
586    uint64 guid ;
587    recv_data >> guid;
588
589    _player->SetUInt32Value(UNIT_FIELD_TARGET,guid);
590
591    // update reputation list if need
592    Unit* unit = ObjectAccessor::GetUnit(*_player, guid );
593    if(!unit)
594        return;
595
596    _player->SetFactionVisibleForFactionTemplateId(unit->getFaction());
597}
598
599void WorldSession::HandleSetSelectionOpcode( WorldPacket & recv_data )
600{
601    CHECK_PACKET_SIZE(recv_data,8);
602
603    uint64 guid;
604    recv_data >> guid;
605
606    _player->SetSelection(guid);
607
608    // update reputation list if need
609    Unit* unit = ObjectAccessor::GetUnit(*_player, guid );
610    if(!unit)
611        return;
612
613    _player->SetFactionVisibleForFactionTemplateId(unit->getFaction());
614}
615
616void WorldSession::HandleStandStateChangeOpcode( WorldPacket & recv_data )
617{
618    CHECK_PACKET_SIZE(recv_data,1);
619
620    sLog.outDebug( "WORLD: Received CMSG_STAND_STATE_CHANGE"  );
621    uint8 animstate;
622    recv_data >> animstate;
623
624    _player->SetStandState(animstate);
625}
626
627void WorldSession::HandleFriendListOpcode( WorldPacket & recv_data )
628{
629    CHECK_PACKET_SIZE(recv_data, 4);
630    sLog.outDebug( "WORLD: Received CMSG_CONTACT_LIST" );
631    uint32 unk;
632    recv_data >> unk;
633    sLog.outDebug("unk value is %u", unk);
634    _player->GetSocial()->SendSocialList();
635}
636
637void WorldSession::HandleAddFriendOpcode( WorldPacket & recv_data )
638{
639    CHECK_PACKET_SIZE(recv_data, 1+1);
640
641    sLog.outDebug( "WORLD: Received CMSG_ADD_FRIEND" );
642
643    std::string friendName  = GetMangosString(LANG_FRIEND_IGNORE_UNKNOWN);
644    std::string friendNote;
645    FriendsResult friendResult = FRIEND_NOT_FOUND;
646    Player *pFriend     = NULL;
647    uint64 friendGuid   = 0;
648
649    recv_data >> friendName;
650
651    // recheck
652    CHECK_PACKET_SIZE(recv_data, (friendName.size()+1)+1);
653
654    recv_data >> friendNote;
655
656    if(!normalizePlayerName(friendName))
657        return;
658
659    CharacterDatabase.escape_string(friendName);            // prevent SQL injection - normal name don't must changed by this call
660
661    sLog.outDebug( "WORLD: %s asked to add friend : '%s'",
662        GetPlayer()->GetName(), friendName.c_str() );
663
664    friendGuid = objmgr.GetPlayerGUIDByName(friendName);
665
666    if(friendGuid)
667    {
668        pFriend = ObjectAccessor::FindPlayer(friendGuid);
669        if(pFriend==GetPlayer())
670            friendResult = FRIEND_SELF;
671        else if(GetPlayer()->GetTeam()!=objmgr.GetPlayerTeamByGUID(friendGuid) && !sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_ADD_FRIEND) && GetSecurity() < SEC_MODERATOR)
672            friendResult = FRIEND_ENEMY;
673        else if(GetPlayer()->GetSocial()->HasFriend(GUID_LOPART(friendGuid)))
674            friendResult = FRIEND_ALREADY;
675    }
676
677    if (friendGuid && friendResult==FRIEND_NOT_FOUND)
678    {
679        if( pFriend && pFriend->IsInWorld() && pFriend->IsVisibleGloballyFor(GetPlayer()))
680            friendResult = FRIEND_ADDED_ONLINE;
681        else
682            friendResult = FRIEND_ADDED_OFFLINE;
683
684        if(!_player->GetSocial()->AddToSocialList(GUID_LOPART(friendGuid), false))
685        {
686            friendResult = FRIEND_LIST_FULL;
687            sLog.outDebug( "WORLD: %s's friend list is full.", GetPlayer()->GetName());
688        }
689
690        _player->GetSocial()->SetFriendNote(GUID_LOPART(friendGuid), friendNote);
691
692        sLog.outDebug( "WORLD: %s Guid found '%u'.", friendName.c_str(), GUID_LOPART(friendGuid));
693    }
694    else if(friendResult==FRIEND_ALREADY)
695    {
696        sLog.outDebug( "WORLD: %s Guid Already a Friend.", friendName.c_str() );
697    }
698    else if(friendResult==FRIEND_SELF)
699    {
700        sLog.outDebug( "WORLD: %s Guid can't add himself.", friendName.c_str() );
701    }
702    else
703    {
704        sLog.outDebug( "WORLD: %s Guid not found.", friendName.c_str() );
705    }
706
707    sSocialMgr.SendFriendStatus(GetPlayer(), friendResult, GUID_LOPART(friendGuid), friendName, false);
708
709    sLog.outDebug( "WORLD: Sent (SMSG_FRIEND_STATUS)" );
710}
711
712void WorldSession::HandleDelFriendOpcode( WorldPacket & recv_data )
713{
714    CHECK_PACKET_SIZE(recv_data, 8);
715
716    uint64 FriendGUID;
717
718    sLog.outDebug( "WORLD: Received CMSG_DEL_FRIEND" );
719
720    recv_data >> FriendGUID;
721
722    _player->GetSocial()->RemoveFromSocialList(GUID_LOPART(FriendGUID), false);
723
724    sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_REMOVED, GUID_LOPART(FriendGUID), "", false);
725
726    sLog.outDebug( "WORLD: Sent motd (SMSG_FRIEND_STATUS)" );
727}
728
729void WorldSession::HandleAddIgnoreOpcode( WorldPacket & recv_data )
730{
731    CHECK_PACKET_SIZE(recv_data,1);
732
733    sLog.outDebug( "WORLD: Received CMSG_ADD_IGNORE" );
734
735    std::string IgnoreName = GetMangosString(LANG_FRIEND_IGNORE_UNKNOWN);
736    FriendsResult ignoreResult = FRIEND_IGNORE_NOT_FOUND;
737    uint64 IgnoreGuid = 0;
738
739    recv_data >> IgnoreName;
740
741    if(!normalizePlayerName(IgnoreName))
742        return;
743
744    CharacterDatabase.escape_string(IgnoreName);            // prevent SQL injection - normal name don't must changed by this call
745
746    sLog.outDebug( "WORLD: %s asked to Ignore: '%s'",
747        GetPlayer()->GetName(), IgnoreName.c_str() );
748
749    IgnoreGuid = objmgr.GetPlayerGUIDByName(IgnoreName);
750
751    if(IgnoreGuid)
752    {
753        if(IgnoreGuid==GetPlayer()->GetGUID())
754            ignoreResult = FRIEND_IGNORE_SELF;
755        else
756        {
757            if( GetPlayer()->GetSocial()->HasIgnore(GUID_LOPART(IgnoreGuid)) )
758                ignoreResult = FRIEND_IGNORE_ALREADY;
759        }
760    }
761
762    if (IgnoreGuid && ignoreResult == FRIEND_IGNORE_NOT_FOUND)
763    {
764        ignoreResult = FRIEND_IGNORE_ADDED;
765
766        _player->GetSocial()->AddToSocialList(GUID_LOPART(IgnoreGuid), true);
767    }
768    else if(ignoreResult==FRIEND_IGNORE_ALREADY)
769    {
770        sLog.outDebug( "WORLD: %s Guid Already Ignored.", IgnoreName.c_str() );
771    }
772    else if(ignoreResult==FRIEND_IGNORE_SELF)
773    {
774        sLog.outDebug( "WORLD: %s Guid can't add himself.", IgnoreName.c_str() );
775    }
776    else
777    {
778        sLog.outDebug( "WORLD: %s Guid not found.", IgnoreName.c_str() );
779    }
780
781    sSocialMgr.SendFriendStatus(GetPlayer(), ignoreResult, GUID_LOPART(IgnoreGuid), "", false);
782
783    sLog.outDebug( "WORLD: Sent (SMSG_FRIEND_STATUS)" );
784}
785
786void WorldSession::HandleDelIgnoreOpcode( WorldPacket & recv_data )
787{
788    CHECK_PACKET_SIZE(recv_data, 8);
789
790    uint64 IgnoreGUID;
791
792    sLog.outDebug( "WORLD: Received CMSG_DEL_IGNORE" );
793
794    recv_data >> IgnoreGUID;
795
796    _player->GetSocial()->RemoveFromSocialList(GUID_LOPART(IgnoreGUID), true);
797
798    sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_IGNORE_REMOVED, GUID_LOPART(IgnoreGUID), "", false);
799
800    sLog.outDebug( "WORLD: Sent motd (SMSG_FRIEND_STATUS)" );
801}
802
803void WorldSession::HandleSetFriendNoteOpcode( WorldPacket & recv_data )
804{
805    CHECK_PACKET_SIZE(recv_data, 8+1);
806    uint64 guid;
807    std::string note;
808    recv_data >> guid >> note;
809    _player->GetSocial()->SetFriendNote(guid, note);
810}
811
812void WorldSession::HandleBugOpcode( WorldPacket & recv_data )
813{
814    CHECK_PACKET_SIZE(recv_data,4+4+1+4+1);
815
816    uint32 suggestion, contentlen;
817    std::string content;
818    uint32 typelen;
819    std::string type;
820
821    recv_data >> suggestion >> contentlen >> content;
822
823    //recheck
824    CHECK_PACKET_SIZE(recv_data,4+4+(content.size()+1)+4+1);
825
826    recv_data >> typelen >> type;
827
828    if( suggestion == 0 )
829        sLog.outDebug( "WORLD: Received CMSG_BUG [Bug Report]" );
830    else
831        sLog.outDebug( "WORLD: Received CMSG_BUG [Suggestion]" );
832
833    sLog.outDebug( type.c_str( ) );
834    sLog.outDebug( content.c_str( ) );
835
836    CharacterDatabase.escape_string(type);
837    CharacterDatabase.escape_string(content);
838    CharacterDatabase.PExecute ("INSERT INTO bugreport (type,content) VALUES('%s', '%s')", type.c_str( ), content.c_str( ));
839}
840
841void WorldSession::HandleCorpseReclaimOpcode(WorldPacket &recv_data)
842{
843    CHECK_PACKET_SIZE(recv_data,8);
844
845    sLog.outDetail("WORLD: Received CMSG_RECLAIM_CORPSE");
846    if (GetPlayer()->isAlive())
847        return;
848
849    // body not released yet
850    if(!GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST))
851        return;
852
853    Corpse *corpse = GetPlayer()->GetCorpse();
854
855    if (!corpse )
856        return;
857
858    // prevent resurrect before 30-sec delay after body release not finished
859    if(corpse->GetGhostTime() + GetPlayer()->GetCorpseReclaimDelay(corpse->GetType()==CORPSE_RESURRECTABLE_PVP) > time(NULL))
860        return;
861
862    float dist = corpse->GetDistance2d(GetPlayer());
863    sLog.outDebug("Corpse 2D Distance: \t%f",dist);
864    if (dist > CORPSE_RECLAIM_RADIUS)
865        return;
866
867    uint64 guid;
868    recv_data >> guid;
869
870    // resurrect
871    GetPlayer()->ResurrectPlayer(GetPlayer()->InBattleGround() ? 1.0f : 0.5f);
872
873    // spawn bones
874    GetPlayer()->SpawnCorpseBones();
875
876    GetPlayer()->SaveToDB();
877}
878
879void WorldSession::HandleResurrectResponseOpcode(WorldPacket & recv_data)
880{
881    CHECK_PACKET_SIZE(recv_data,8+1);
882
883    sLog.outDetail("WORLD: Received CMSG_RESURRECT_RESPONSE");
884
885    if(GetPlayer()->isAlive())
886        return;
887
888    uint64 guid;
889    uint8 status;
890    recv_data >> guid;
891    recv_data >> status;
892
893    if(status == 0)
894    {
895        GetPlayer()->clearResurrectRequestData();           // reject
896        return;
897    }
898
899    if(!GetPlayer()->isRessurectRequestedBy(guid))
900        return;
901
902    GetPlayer()->ResurectUsingRequestData();
903    GetPlayer()->SaveToDB();
904}
905
906void WorldSession::HandleAreaTriggerOpcode(WorldPacket & recv_data)
907{
908    CHECK_PACKET_SIZE(recv_data,4);
909
910    sLog.outDebug("WORLD: Received CMSG_AREATRIGGER");
911
912    uint32 Trigger_ID;
913
914    recv_data >> Trigger_ID;
915    sLog.outDebug("Trigger ID:%u",Trigger_ID);
916
917    if(GetPlayer()->isInFlight())
918    {
919        sLog.outDebug("Player '%s' (GUID: %u) in flight, ignore Area Trigger ID:%u",GetPlayer()->GetName(),GetPlayer()->GetGUIDLow(), Trigger_ID);
920        return;
921    }
922
923    AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(Trigger_ID);
924    if(!atEntry)
925    {
926        sLog.outDebug("Player '%s' (GUID: %u) send unknown (by DBC) Area Trigger ID:%u",GetPlayer()->GetName(),GetPlayer()->GetGUIDLow(), Trigger_ID);
927        return;
928    }
929
930    if (GetPlayer()->GetMapId()!=atEntry->mapid)
931    {
932        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);
933        return;
934    }
935
936    // delta is safe radius
937    const float delta = 5.0f;
938    // check if player in the range of areatrigger
939    Player* pl = GetPlayer();
940
941    if (atEntry->radius > 0)
942    {
943        // if we have radius check it
944        float dist = pl->GetDistance(atEntry->x,atEntry->y,atEntry->z);
945        if(dist > atEntry->radius + delta)
946        {
947            sLog.outDebug("Player '%s' (GUID: %u) too far (radius: %f distance: %f), ignore Area Trigger ID: %u",
948                pl->GetName(), pl->GetGUIDLow(), atEntry->radius, dist, Trigger_ID);
949            return;
950        }
951    }
952    else
953    {
954        // we have only extent
955        float dx = pl->GetPositionX() - atEntry->x;
956        float dy = pl->GetPositionY() - atEntry->y;
957        float dz = pl->GetPositionZ() - atEntry->z;
958        double es = sin(atEntry->box_orientation);
959        double ec = cos(atEntry->box_orientation);
960        // calc rotated vector based on extent axis
961        double rotateDx = dx*ec - dy*es;
962        double rotateDy = dx*es + dy*ec;
963
964        if( (fabs(rotateDx) > atEntry->box_x/2 + delta) ||
965            (fabs(rotateDy) > atEntry->box_y/2 + delta) ||
966            (fabs(dz) > atEntry->box_z/2 + delta) )
967        {
968            sLog.outDebug("Player '%s' (GUID: %u) too far (1/2 box X: %f 1/2 box Y: %u 1/2 box Z: %u rotate dX: %f rotate dY: %f dZ:%f), ignore Area Trigger ID: %u",
969                pl->GetName(), pl->GetGUIDLow(), atEntry->box_x/2, atEntry->box_y/2, atEntry->box_z/2, rotateDx, rotateDy, dz, Trigger_ID);
970            return;
971        }
972    }
973
974    if(Script->scriptAreaTrigger(GetPlayer(), atEntry))
975        return;
976
977    uint32 quest_id = objmgr.GetQuestForAreaTrigger( Trigger_ID );
978    if( quest_id && GetPlayer()->isAlive() && GetPlayer()->IsActiveQuest(quest_id) )
979    {
980        Quest const* pQuest = objmgr.GetQuestTemplate(quest_id);
981        if( pQuest )
982        {
983            if(GetPlayer()->GetQuestStatus(quest_id) == QUEST_STATUS_INCOMPLETE)
984                GetPlayer()->AreaExploredOrEventHappens( quest_id );
985        }
986    }
987
988    if(objmgr.IsTavernAreaTrigger(Trigger_ID))
989    {
990        // set resting flag we are in the inn
991        GetPlayer()->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING);
992        GetPlayer()->InnEnter(time(NULL), atEntry->mapid, atEntry->x, atEntry->y, atEntry->z);
993        GetPlayer()->SetRestType(REST_TYPE_IN_TAVERN);
994
995        if(sWorld.IsFFAPvPRealm())
996            GetPlayer()->RemoveFlag(PLAYER_FLAGS,PLAYER_FLAGS_FFA_PVP);
997
998        return;
999    }
1000
1001    if(GetPlayer()->InBattleGround())
1002    {
1003        BattleGround* bg = GetPlayer()->GetBattleGround();
1004        if(bg)
1005            if(bg->GetStatus() == STATUS_IN_PROGRESS)
1006                bg->HandleAreaTrigger(GetPlayer(), Trigger_ID);
1007
1008        return;
1009    }
1010
1011    // NULL if all values default (non teleport trigger)
1012    AreaTrigger const* at = objmgr.GetAreaTrigger(Trigger_ID);
1013    if(!at)
1014        return;
1015
1016    if(!GetPlayer()->isGameMaster())
1017    {
1018        uint32 missingLevel = 0;
1019        if(GetPlayer()->getLevel() < at->requiredLevel && !sWorld.getConfig(CONFIG_INSTANCE_IGNORE_LEVEL))
1020            missingLevel = at->requiredLevel;
1021
1022        // must have one or the other, report the first one that's missing
1023        uint32 missingItem = 0;
1024        if(at->requiredItem)
1025        {
1026            if(!GetPlayer()->HasItemCount(at->requiredItem, 1) &&
1027                (!at->requiredItem2 || !GetPlayer()->HasItemCount(at->requiredItem2, 1)))
1028                missingItem = at->requiredItem;
1029        }
1030        else if(at->requiredItem2 && !GetPlayer()->HasItemCount(at->requiredItem2, 1))
1031            missingItem = at->requiredItem2;
1032
1033        uint32 missingKey = 0;
1034        if(GetPlayer()->GetDifficulty() == DIFFICULTY_HEROIC)
1035        {
1036            if(at->heroicKey)
1037            {
1038                if(!GetPlayer()->HasItemCount(at->heroicKey, 1) &&
1039                    (!at->heroicKey2 || !GetPlayer()->HasItemCount(at->heroicKey2, 1)))
1040                    missingKey = at->heroicKey;
1041            }
1042            else if(at->heroicKey2 && !GetPlayer()->HasItemCount(at->heroicKey2, 1))
1043                missingKey = at->heroicKey2;
1044        }
1045
1046        uint32 missingQuest = 0;
1047        if(at->requiredQuest && !GetPlayer()->GetQuestRewardStatus(at->requiredQuest))
1048            missingQuest = at->requiredQuest;
1049
1050        if(missingLevel || missingItem || missingKey || missingQuest)
1051        {
1052            // TODO: all this is probably wrong
1053            if(missingItem)
1054                SendAreaTriggerMessage(GetMangosString(LANG_LEVEL_MINREQUIRED_AND_ITEM), at->requiredLevel, objmgr.GetItemPrototype(missingItem)->Name1);
1055            else if(missingKey)
1056                GetPlayer()->SendTransferAborted(at->target_mapId, TRANSFER_ABORT_DIFFICULTY2);
1057            else if(missingQuest)
1058                SendAreaTriggerMessage(at->requiredFailedText.c_str());
1059            else if(missingLevel)
1060                SendAreaTriggerMessage(GetMangosString(LANG_LEVEL_MINREQUIRED), missingLevel);
1061            return;
1062        }
1063    }
1064
1065    GetPlayer()->TeleportTo(at->target_mapId,at->target_X,at->target_Y,at->target_Z,at->target_Orientation,TELE_TO_NOT_LEAVE_TRANSPORT);
1066}
1067
1068void WorldSession::HandleUpdateAccountData(WorldPacket &/*recv_data*/)
1069{
1070    sLog.outDetail("WORLD: Received CMSG_UPDATE_ACCOUNT_DATA");
1071    //recv_data.hexlike();
1072}
1073
1074void WorldSession::HandleRequestAccountData(WorldPacket& /*recv_data*/)
1075{
1076    sLog.outDetail("WORLD: Received CMSG_REQUEST_ACCOUNT_DATA");
1077    //recv_data.hexlike();
1078}
1079
1080void WorldSession::HandleSetActionButtonOpcode(WorldPacket& recv_data)
1081{
1082    CHECK_PACKET_SIZE(recv_data,1+2+1+1);
1083
1084    sLog.outDebug(  "WORLD: Received CMSG_SET_ACTION_BUTTON" );
1085    uint8 button, misc, type;
1086    uint16 action;
1087    recv_data >> button >> action >> misc >> type;
1088    sLog.outDetail( "BUTTON: %u ACTION: %u TYPE: %u MISC: %u", button, action, type, misc );
1089    if(action==0)
1090    {
1091        sLog.outDetail( "MISC: Remove action from button %u", button );
1092
1093        GetPlayer()->removeActionButton(button);
1094    }
1095    else
1096    {
1097        if(type==ACTION_BUTTON_MACRO || type==ACTION_BUTTON_CMACRO)
1098        {
1099            sLog.outDetail( "MISC: Added Macro %u into button %u", action, button );
1100            GetPlayer()->addActionButton(button,action,type,misc);
1101        }
1102        else if(type==ACTION_BUTTON_SPELL)
1103        {
1104            sLog.outDetail( "MISC: Added Action %u into button %u", action, button );
1105            GetPlayer()->addActionButton(button,action,type,misc);
1106        }
1107        else if(type==ACTION_BUTTON_ITEM)
1108        {
1109            sLog.outDetail( "MISC: Added Item %u into button %u", action, button );
1110            GetPlayer()->addActionButton(button,action,type,misc);
1111        }
1112        else
1113            sLog.outError( "MISC: Unknown action button type %u for action %u into button %u", type, action, button );
1114    }
1115}
1116
1117void WorldSession::HandleCompleteCinema( WorldPacket & /*recv_data*/ )
1118{
1119    DEBUG_LOG( "WORLD: Player is watching cinema" );
1120}
1121
1122void WorldSession::HandleNextCinematicCamera( WorldPacket & /*recv_data*/ )
1123{
1124    DEBUG_LOG( "WORLD: Which movie to play" );
1125}
1126
1127void WorldSession::HandleMoveTimeSkippedOpcode( WorldPacket & /*recv_data*/ )
1128{
1129    /*  WorldSession::Update( getMSTime() );*/
1130    DEBUG_LOG( "WORLD: Time Lag/Synchronization Resent/Update" );
1131
1132    /*
1133        CHECK_PACKET_SIZE(recv_data,8+4);
1134        uint64 guid;
1135        uint32 time_skipped;
1136        recv_data >> guid;
1137        recv_data >> time_skipped;
1138        sLog.outDebug( "WORLD: CMSG_MOVE_TIME_SKIPPED" );
1139
1140        /// TODO
1141        must be need use in mangos
1142        We substract server Lags to move time ( AntiLags )
1143        for exmaple
1144        GetPlayer()->ModifyLastMoveTime( -int32(time_skipped) );
1145    */
1146}
1147
1148void WorldSession::HandleFeatherFallAck(WorldPacket &/*recv_data*/)
1149{
1150    DEBUG_LOG("WORLD: CMSG_MOVE_FEATHER_FALL_ACK");
1151}
1152
1153void WorldSession::HandleMoveUnRootAck(WorldPacket&/* recv_data*/)
1154{
1155    /*
1156        CHECK_PACKET_SIZE(recv_data,8+8+4+4+4+4+4);
1157
1158        sLog.outDebug( "WORLD: CMSG_FORCE_MOVE_UNROOT_ACK" );
1159        recv_data.hexlike();
1160        uint64 guid;
1161        uint64 unknown1;
1162        uint32 unknown2;
1163        float PositionX;
1164        float PositionY;
1165        float PositionZ;
1166        float Orientation;
1167
1168        recv_data >> guid;
1169        recv_data >> unknown1;
1170        recv_data >> unknown2;
1171        recv_data >> PositionX;
1172        recv_data >> PositionY;
1173        recv_data >> PositionZ;
1174        recv_data >> Orientation;
1175
1176        // TODO for later may be we can use for anticheat
1177        DEBUG_LOG("Guid " I64FMTD,guid);
1178        DEBUG_LOG("unknown1 " I64FMTD,unknown1);
1179        DEBUG_LOG("unknown2 %u",unknown2);
1180        DEBUG_LOG("X %f",PositionX);
1181        DEBUG_LOG("Y %f",PositionY);
1182        DEBUG_LOG("Z %f",PositionZ);
1183        DEBUG_LOG("O %f",Orientation);
1184    */
1185}
1186
1187void WorldSession::HandleMoveRootAck(WorldPacket&/* recv_data*/)
1188{
1189    /*
1190        CHECK_PACKET_SIZE(recv_data,8+8+4+4+4+4+4);
1191
1192        sLog.outDebug( "WORLD: CMSG_FORCE_MOVE_ROOT_ACK" );
1193        recv_data.hexlike();
1194        uint64 guid;
1195        uint64 unknown1;
1196        uint32 unknown2;
1197        float PositionX;
1198        float PositionY;
1199        float PositionZ;
1200        float Orientation;
1201
1202        recv_data >> guid;
1203        recv_data >> unknown1;
1204        recv_data >> unknown2;
1205        recv_data >> PositionX;
1206        recv_data >> PositionY;
1207        recv_data >> PositionZ;
1208        recv_data >> Orientation;
1209
1210        // for later may be we can use for anticheat
1211        DEBUG_LOG("Guid " I64FMTD,guid);
1212        DEBUG_LOG("unknown1 " I64FMTD,unknown1);
1213        DEBUG_LOG("unknown1 %u",unknown2);
1214        DEBUG_LOG("X %f",PositionX);
1215        DEBUG_LOG("Y %f",PositionY);
1216        DEBUG_LOG("Z %f",PositionZ);
1217        DEBUG_LOG("O %f",Orientation);
1218    */
1219}
1220
1221void WorldSession::HandleMoveTeleportAck(WorldPacket&/* recv_data*/)
1222{
1223    /*
1224        CHECK_PACKET_SIZE(recv_data,8+4);
1225
1226        sLog.outDebug("MSG_MOVE_TELEPORT_ACK");
1227        uint64 guid;
1228        uint32 flags, time;
1229
1230        recv_data >> guid;
1231        recv_data >> flags >> time;
1232        DEBUG_LOG("Guid " I64FMTD,guid);
1233        DEBUG_LOG("Flags %u, time %u",flags, time/1000);
1234    */
1235}
1236
1237void WorldSession::HandleSetActionBar(WorldPacket& recv_data)
1238{
1239    CHECK_PACKET_SIZE(recv_data,1);
1240
1241    uint8 ActionBar;
1242
1243    recv_data >> ActionBar;
1244
1245    if(!GetPlayer())                                        // ignore until not logged (check needed because STATUS_AUTHED)
1246    {
1247        if(ActionBar!=0)
1248            sLog.outError("WorldSession::HandleSetActionBar in not logged state with value: %u, ignored",uint32(ActionBar));
1249        return;
1250    }
1251
1252    GetPlayer()->SetByteValue(PLAYER_FIELD_BYTES, 2, ActionBar);
1253}
1254
1255void WorldSession::HandleWardenDataOpcode(WorldPacket& /*recv_data*/)
1256{
1257    /*
1258        CHECK_PACKET_SIZE(recv_data,1);
1259
1260        uint8 tmp;
1261        recv_data >> tmp;
1262        sLog.outDebug("Received opcode CMSG_WARDEN_DATA, not resolve.uint8 = %u",tmp);
1263    */
1264}
1265
1266void WorldSession::HandlePlayedTime(WorldPacket& /*recv_data*/)
1267{
1268    uint32 TotalTimePlayed = GetPlayer()->GetTotalPlayedTime();
1269    uint32 LevelPlayedTime = GetPlayer()->GetLevelPlayedTime();
1270
1271    WorldPacket data(SMSG_PLAYED_TIME, 8);
1272    data << TotalTimePlayed;
1273    data << LevelPlayedTime;
1274    SendPacket(&data);
1275}
1276
1277void WorldSession::HandleInspectOpcode(WorldPacket& recv_data)
1278{
1279    CHECK_PACKET_SIZE(recv_data, 8);
1280
1281    uint64 guid;
1282    recv_data >> guid;
1283    DEBUG_LOG("Inspected guid is " I64FMTD, guid);
1284
1285    _player->SetSelection(guid);
1286
1287    Player *plr = objmgr.GetPlayer(guid);
1288    if(!plr)                                                // wrong player
1289        return;
1290
1291    uint32 talent_points = 0x3D;
1292    uint32 guid_size = plr->GetPackGUID().size();
1293    WorldPacket data(SMSG_INSPECT_TALENT, 4+talent_points);
1294    data.append(plr->GetPackGUID());
1295    data << uint32(talent_points);
1296
1297    // fill by 0 talents array
1298    for(uint32 i = 0; i < talent_points; ++i)
1299        data << uint8(0);
1300
1301    if(sWorld.getConfig(CONFIG_TALENTS_INSPECTING) || _player->isGameMaster())
1302    {
1303        // find class talent tabs (all players have 3 talent tabs)
1304        uint32 const* talentTabIds = GetTalentTabPages(plr->getClass());
1305
1306        uint32 talentTabPos = 0;                            // pos of first talent rank in tab including all prev tabs
1307        for(uint32 i = 0; i < 3; ++i)
1308        {
1309            uint32 talentTabId = talentTabIds[i];
1310
1311            // fill by real data
1312            for(uint32 talentId = 0; talentId < sTalentStore.GetNumRows(); ++talentId)
1313            {
1314                TalentEntry const* talentInfo = sTalentStore.LookupEntry(talentId);
1315                if(!talentInfo)
1316                    continue;
1317
1318                // skip another tab talents
1319                if(talentInfo->TalentTab != talentTabId)
1320                    continue;
1321
1322                // find talent rank
1323                uint32 curtalent_maxrank = 0;
1324                for(uint32 k = 5; k > 0; --k)
1325                {
1326                    if(talentInfo->RankID[k-1] && plr->HasSpell(talentInfo->RankID[k-1]))
1327                    {
1328                        curtalent_maxrank = k;
1329                        break;
1330                    }
1331                }
1332
1333                // not learned talent
1334                if(!curtalent_maxrank)
1335                    continue;
1336
1337                // 1 rank talent bit index
1338                uint32 curtalent_index = talentTabPos + GetTalentInspectBitPosInTab(talentId);
1339
1340                uint32 curtalent_rank_index = curtalent_index+curtalent_maxrank-1;
1341
1342                // slot/offset in 7-bit bytes
1343                uint32 curtalent_rank_slot7   = curtalent_rank_index / 7;
1344                uint32 curtalent_rank_offset7 = curtalent_rank_index % 7;
1345
1346                // rank pos with skipped 8 bit
1347                uint32 curtalent_rank_index2 = curtalent_rank_slot7 * 8 + curtalent_rank_offset7;
1348
1349                // slot/offset in 8-bit bytes with skipped high bit
1350                uint32 curtalent_rank_slot = curtalent_rank_index2 / 8;
1351                uint32 curtalent_rank_offset =  curtalent_rank_index2 % 8;
1352
1353                // apply mask
1354                uint32 val = data.read<uint8>(guid_size + 4 + curtalent_rank_slot);
1355                val |= (1 << curtalent_rank_offset);
1356                data.put<uint8>(guid_size + 4 + curtalent_rank_slot, val & 0xFF);
1357            }
1358
1359            talentTabPos += GetTalentTabInspectBitSize(talentTabId);
1360        }
1361    }
1362
1363    SendPacket(&data);
1364}
1365
1366void WorldSession::HandleInspectHonorStatsOpcode(WorldPacket& recv_data)
1367{
1368    CHECK_PACKET_SIZE(recv_data, 8);
1369
1370    uint64 guid;
1371    recv_data >> guid;
1372
1373    Player *player = objmgr.GetPlayer(guid);
1374
1375    if(!player)
1376    {
1377        sLog.outError("InspectHonorStats: WTF, player not found...");
1378        return;
1379    }
1380
1381    WorldPacket data(MSG_INSPECT_HONOR_STATS, 8+1+4*4);
1382    data << uint64(player->GetGUID());
1383    data << uint8(player->GetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY));
1384    data << uint32(player->GetUInt32Value(PLAYER_FIELD_KILLS));
1385    data << uint32(player->GetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION));
1386    data << uint32(player->GetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION));
1387    data << uint32(player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS));
1388    SendPacket(&data);
1389}
1390
1391void WorldSession::HandleWorldTeleportOpcode(WorldPacket& recv_data)
1392{
1393    CHECK_PACKET_SIZE(recv_data,4+4+4+4+4+4);
1394
1395    // write in client console: worldport 469 452 6454 2536 180 or /console worldport 469 452 6454 2536 180
1396    // Received opcode CMSG_WORLD_TELEPORT
1397    // Time is ***, map=469, x=452.000000, y=6454.000000, z=2536.000000, orient=3.141593
1398
1399    //sLog.outDebug("Received opcode CMSG_WORLD_TELEPORT");
1400
1401    if(GetPlayer()->isInFlight())
1402    {
1403        sLog.outDebug("Player '%s' (GUID: %u) in flight, ignore worldport command.",GetPlayer()->GetName(),GetPlayer()->GetGUIDLow());
1404        return;
1405    }
1406
1407    uint32 time;
1408    uint32 mapid;
1409    float PositionX;
1410    float PositionY;
1411    float PositionZ;
1412    float Orientation;
1413
1414    recv_data >> time;                                      // time in m.sec.
1415    recv_data >> mapid;
1416    recv_data >> PositionX;
1417    recv_data >> PositionY;
1418    recv_data >> PositionZ;
1419    recv_data >> Orientation;                               // o (3.141593 = 180 degrees)
1420    DEBUG_LOG("Time %u sec, map=%u, x=%f, y=%f, z=%f, orient=%f", time/1000, mapid, PositionX, PositionY, PositionZ, Orientation);
1421
1422    if (GetSecurity() >= SEC_ADMINISTRATOR)
1423        GetPlayer()->TeleportTo(mapid,PositionX,PositionY,PositionZ,Orientation);
1424    else
1425        SendNotification("You do not have permission to perform that function");
1426    sLog.outDebug("Received worldport command from player %s", GetPlayer()->GetName());
1427}
1428
1429void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data)
1430{
1431    CHECK_PACKET_SIZE(recv_data, 1);
1432
1433    sLog.outDebug("Received opcode CMSG_WHOIS");
1434    std::string charname, acc, email, lastip, msg;
1435    recv_data >> charname;
1436
1437    if (GetSecurity() < SEC_ADMINISTRATOR)
1438    {
1439        SendNotification("You do not have permission to perform that function");
1440        return;
1441    }
1442
1443    if(charname.empty())
1444    {
1445        SendNotification("Please provide character name");
1446        return;
1447    }
1448
1449    uint32 accid;
1450    Field *fields;
1451
1452    Player *plr = objmgr.GetPlayer(charname.c_str());
1453
1454    if(plr)
1455        accid = plr->GetSession()->GetAccountId();
1456    else
1457    {
1458        SendNotification("Player %s not found or offline", charname.c_str());
1459        return;
1460    }
1461
1462    if(!accid)
1463    {
1464        SendNotification("Account for character %s not found", charname.c_str());
1465        return;
1466    }
1467
1468    QueryResult *result = loginDatabase.PQuery("SELECT username,email,last_ip FROM account WHERE id=%u", accid);
1469    if(result)
1470    {
1471        fields = result->Fetch();
1472        acc = fields[0].GetCppString();
1473        if(acc.empty())
1474            acc = "Unknown";
1475        email = fields[1].GetCppString();
1476        if(email.empty())
1477            email = "Unknown";
1478        lastip = fields[2].GetCppString();
1479        if(lastip.empty())
1480            lastip = "Unknown";
1481        msg = charname + "'s " + "account is " + acc + ", e-mail: " + email + ", last ip: " + lastip;
1482
1483        WorldPacket data(SMSG_WHOIS, msg.size()+1);
1484        data << msg;
1485        _player->GetSession()->SendPacket(&data);
1486    }
1487    else
1488        SendNotification("Account for character %s not found", charname.c_str());
1489
1490    delete result;
1491    sLog.outDebug("Received whois command from player %s for character %s", GetPlayer()->GetName(), charname.c_str());
1492}
1493
1494void WorldSession::HandleReportSpamOpcode( WorldPacket & recv_data )
1495{
1496    CHECK_PACKET_SIZE(recv_data, 1+8);
1497    sLog.outDebug("WORLD: CMSG_REPORT_SPAM");
1498    recv_data.hexlike();
1499
1500    uint8 spam_type;                                        // 0 - mail, 1 - chat
1501    uint64 spammer_guid;
1502    uint32 unk1, unk2, unk3, unk4 = 0;
1503    std::string description = "";
1504    recv_data >> spam_type;                                 // unk 0x01 const, may be spam type (mail/chat)
1505    recv_data >> spammer_guid;                              // player guid
1506    switch(spam_type)
1507    {
1508        case 0:
1509            CHECK_PACKET_SIZE(recv_data, recv_data.rpos()+4+4+4);
1510            recv_data >> unk1;                              // const 0
1511            recv_data >> unk2;                              // probably mail id
1512            recv_data >> unk3;                              // const 0
1513            break;
1514        case 1:
1515            CHECK_PACKET_SIZE(recv_data, recv_data.rpos()+4+4+4+4+1);
1516            recv_data >> unk1;                              // probably language
1517            recv_data >> unk2;                              // message type?
1518            recv_data >> unk3;                              // probably channel id
1519            recv_data >> unk4;                              // unk random value
1520            recv_data >> description;                       // spam description string (messagetype, channel name, player name, message)
1521            break;
1522    }
1523
1524    // NOTE: all chat messages from this spammer automatically ignored by spam reporter until logout in case chat spam.
1525    // if it's mail spam - ALL mails from this spammer automatically removed by client
1526
1527    // Complaint Received message
1528    WorldPacket data(SMSG_COMPLAIN_RESULT, 1);
1529    data << uint8(0);
1530    SendPacket(&data);
1531
1532    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());
1533}
1534
1535void WorldSession::HandleRealmStateRequestOpcode( WorldPacket & recv_data )
1536{
1537    CHECK_PACKET_SIZE(recv_data, 4);
1538
1539    sLog.outDebug("CMSG_REALM_SPLIT");
1540
1541    uint32 unk;
1542    std::string split_date = "01/01/01";
1543    recv_data >> unk;
1544
1545    WorldPacket data(SMSG_REALM_SPLIT, 4+4+split_date.size()+1);
1546    data << unk;
1547    data << uint32(0x00000000);                             // realm split state
1548    // split states:
1549    // 0x0 realm normal
1550    // 0x1 realm split
1551    // 0x2 realm split pending
1552    data << split_date;
1553    SendPacket(&data);
1554    //sLog.outDebug("response sent %u", unk);
1555}
1556
1557void WorldSession::HandleFarSightOpcode( WorldPacket & recv_data )
1558{
1559    CHECK_PACKET_SIZE(recv_data, 1);
1560
1561    sLog.outDebug("WORLD: CMSG_FAR_SIGHT");
1562    //recv_data.hexlike();
1563
1564    uint8 unk;
1565    recv_data >> unk;
1566
1567    switch(unk)
1568    {
1569        case 0:
1570            //WorldPacket data(SMSG_CLEAR_FAR_SIGHT_IMMEDIATE, 0)
1571            //SendPacket(&data);
1572            //_player->SetUInt64Value(PLAYER_FARSIGHT, 0);
1573            sLog.outDebug("Removed FarSight from player %u", _player->GetGUIDLow());
1574            break;
1575        case 1:
1576            sLog.outDebug("Added FarSight " I64FMTD " to player %u", _player->GetUInt64Value(PLAYER_FARSIGHT), _player->GetGUIDLow());
1577            break;
1578    }
1579}
1580
1581void WorldSession::HandleChooseTitleOpcode( WorldPacket & recv_data )
1582{
1583    CHECK_PACKET_SIZE(recv_data, 4);
1584
1585    sLog.outDebug("CMSG_SET_TITLE");
1586
1587    int32 title;
1588    recv_data >> title;
1589
1590    // -1 at none
1591    if(title > 0 && title < 64)
1592    {
1593       if(!GetPlayer()->HasFlag64(PLAYER__FIELD_KNOWN_TITLES,uint64(1) << title))
1594            return;
1595    }
1596    else
1597        title = 0;
1598
1599    GetPlayer()->SetUInt32Value(PLAYER_CHOSEN_TITLE, title);
1600}
1601
1602void WorldSession::HandleAllowMoveAckOpcode( WorldPacket & recv_data )
1603{
1604    CHECK_PACKET_SIZE(recv_data, 4+4);
1605
1606    sLog.outDebug("CMSG_ALLOW_MOVE_ACK");
1607
1608    uint32 counter, time_;
1609    recv_data >> counter >> time_;
1610
1611    // time_ seems always more than getMSTime()
1612    uint32 diff = getMSTimeDiff(getMSTime(),time_);
1613
1614    sLog.outDebug("response sent: counter %u, time %u (HEX: %X), ms. time %u, diff %u", counter, time_, time_, getMSTime(), diff);
1615}
1616
1617void WorldSession::HandleResetInstancesOpcode( WorldPacket & /*recv_data*/ )
1618{
1619    sLog.outDebug("WORLD: CMSG_RESET_INSTANCES");
1620    Group *pGroup = _player->GetGroup();
1621    if(pGroup)
1622    {
1623        if(pGroup->IsLeader(_player->GetGUID()))
1624            pGroup->ResetInstances(INSTANCE_RESET_ALL, _player);
1625    }
1626    else
1627        _player->ResetInstances(INSTANCE_RESET_ALL);
1628}
1629
1630void WorldSession::HandleDungeonDifficultyOpcode( WorldPacket & recv_data )
1631{
1632    CHECK_PACKET_SIZE(recv_data, 4);
1633
1634    sLog.outDebug("MSG_SET_DUNGEON_DIFFICULTY");
1635
1636    uint32 mode;
1637    recv_data >> mode;
1638
1639    if(mode == _player->GetDifficulty())
1640        return;
1641
1642    if(mode > DIFFICULTY_HEROIC)
1643    {
1644        sLog.outError("WorldSession::HandleDungeonDifficultyOpcode: player %d sent an invalid instance mode %d!", _player->GetGUIDLow(), mode);
1645        return;
1646    }
1647
1648    // cannot reset while in an instance
1649    Map *map = _player->GetMap();
1650    if(map && map->IsDungeon())
1651    {
1652        sLog.outError("WorldSession::HandleDungeonDifficultyOpcode: player %d tried to reset the instance while inside!", _player->GetGUIDLow());
1653        return;
1654    }
1655
1656    if(_player->getLevel() < LEVELREQUIREMENT_HEROIC)
1657        return;
1658    Group *pGroup = _player->GetGroup();
1659    if(pGroup)
1660    {
1661        if(pGroup->IsLeader(_player->GetGUID()))
1662        {
1663            // the difficulty is set even if the instances can't be reset
1664            //_player->SendDungeonDifficulty(true);
1665            pGroup->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY, _player);
1666            pGroup->SetDifficulty(mode);
1667        }
1668    }
1669    else
1670    {
1671        _player->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY);
1672        _player->SetDifficulty(mode);
1673    }
1674}
1675
1676void WorldSession::HandleNewUnknownOpcode( WorldPacket & recv_data )
1677{
1678    sLog.outDebug("New Unknown Opcode %u", recv_data.GetOpcode());
1679    recv_data.hexlike();
1680    /*
1681    New Unknown Opcode 837
1682    STORAGE_SIZE: 60
1683    02 00 00 00 00 00 00 00 | 00 00 00 00 01 20 00 00
1684    89 EB 33 01 71 5C 24 C4 | 15 03 35 45 74 47 8B 42
1685    BA B8 1B 40 00 00 00 00 | 00 00 00 00 77 66 42 BF
1686    23 91 26 3F 00 00 60 41 | 00 00 00 00
1687
1688    New Unknown Opcode 837
1689    STORAGE_SIZE: 44
1690    02 00 00 00 00 00 00 00 | 00 00 00 00 00 00 80 00
1691    7B 80 34 01 84 EA 2B C4 | 5F A1 36 45 C9 39 1C 42
1692    BA B8 1B 40 CE 06 00 00 | 00 00 80 3F
1693    */
1694}
1695
1696void WorldSession::HandleDismountOpcode( WorldPacket & /*recv_data*/ )
1697{
1698    sLog.outDebug("WORLD: CMSG_CANCEL_MOUNT_AURA");
1699    //recv_data.hexlike();
1700
1701    //If player is not mounted, so go out :)
1702    if (!_player->IsMounted())                              // not blizz like; no any messages on blizz
1703    {
1704        ChatHandler(this).SendSysMessage(LANG_CHAR_NON_MOUNTED);
1705        return;
1706    }
1707
1708    if(_player->isInFlight())                               // not blizz like; no any messages on blizz
1709    {
1710        ChatHandler(this).SendSysMessage(LANG_YOU_IN_FLIGHT);
1711        return;
1712    }
1713
1714    _player->Unmount();
1715    _player->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
1716}
1717
1718void WorldSession::HandleMoveFlyModeChangeAckOpcode( WorldPacket & recv_data )
1719{
1720    CHECK_PACKET_SIZE(recv_data, 8+4+4);
1721
1722    // fly mode on/off
1723    sLog.outDebug("WORLD: CMSG_MOVE_SET_CAN_FLY_ACK");
1724    //recv_data.hexlike();
1725
1726    uint64 guid;
1727    uint32 unk;
1728    uint32 flags;
1729
1730    recv_data >> guid >> unk >> flags;
1731
1732    _player->SetUnitMovementFlags(flags);
1733    /*
1734    on:
1735    25 00 00 00 00 00 00 00 | 00 00 00 00 00 00 80 00
1736    85 4E A9 01 19 BA 7A C3 | 42 0D 70 44 44 B0 A8 42
1737    78 15 94 40 39 03 00 00 | 00 00 80 3F
1738    off:
1739    25 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00
1740    10 FD A9 01 19 BA 7A C3 | 42 0D 70 44 44 B0 A8 42
1741    78 15 94 40 39 03 00 00 | 00 00 00 00
1742    */
1743}
1744
1745void WorldSession::HandleRequestPetInfoOpcode( WorldPacket & /*recv_data */)
1746{
1747    /*
1748        sLog.outDebug("WORLD: CMSG_REQUEST_PET_INFO");
1749        recv_data.hexlike();
1750    */
1751}
1752
1753void WorldSession::HandleSetTaxiBenchmarkOpcode( WorldPacket & recv_data )
1754{
1755    CHECK_PACKET_SIZE(recv_data, 1);
1756
1757    uint8 mode;
1758    recv_data >> mode;
1759
1760    sLog.outDebug("Client used \"/timetest %d\" command", mode);
1761}
Note: See TracBrowser for help on using the browser.