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

Revision 139, 56.5 kB (checked in by yumileroy, 17 years ago)

[svn] Spell target selection improvement. Remove most mangos hacks in spell target selection. (work almost done)
Merge mangos svn rev 6744.

Original author: megamage
Date: 2008-10-31 11:04:32-05:00

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