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

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

[svn] * Added freeze/unfreeze/listfreeze commands patch by toilet1 (I swear I didnt make up the name)
* Fixed a couple of spelling errors in TC conf file

Original author: KingPin?
Date: 2008-10-19 11:42:21-05:00

Line 
1/*
2 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
3 *
4 * Thanks to the original authors: MaNGOS <http://www.mangosproject.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        _player->GetSocial()->AddToSocialList(GUID_LOPART(IgnoreGuid), true);
776    }
777    else if(ignoreResult==FRIEND_IGNORE_ALREADY)
778    {
779        sLog.outDebug( "WORLD: %s Guid Already Ignored.", IgnoreName.c_str() );
780    }
781    else if(ignoreResult==FRIEND_IGNORE_SELF)
782    {
783        sLog.outDebug( "WORLD: %s Guid can't add himself.", IgnoreName.c_str() );
784    }
785    else
786    {
787        sLog.outDebug( "WORLD: %s Guid not found.", IgnoreName.c_str() );
788    }
789
790    sSocialMgr.SendFriendStatus(GetPlayer(), ignoreResult, GUID_LOPART(IgnoreGuid), "", false);
791
792    sLog.outDebug( "WORLD: Sent (SMSG_FRIEND_STATUS)" );
793}
794
795void WorldSession::HandleDelIgnoreOpcode( WorldPacket & recv_data )
796{
797    CHECK_PACKET_SIZE(recv_data, 8);
798
799    uint64 IgnoreGUID;
800
801    sLog.outDebug( "WORLD: Received CMSG_DEL_IGNORE" );
802
803    recv_data >> IgnoreGUID;
804
805    _player->GetSocial()->RemoveFromSocialList(GUID_LOPART(IgnoreGUID), true);
806
807    sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_IGNORE_REMOVED, GUID_LOPART(IgnoreGUID), "", false);
808
809    sLog.outDebug( "WORLD: Sent motd (SMSG_FRIEND_STATUS)" );
810}
811
812void WorldSession::HandleSetFriendNoteOpcode( WorldPacket & recv_data )
813{
814    CHECK_PACKET_SIZE(recv_data, 8+1);
815    uint64 guid;
816    std::string note;
817    recv_data >> guid >> note;
818    _player->GetSocial()->SetFriendNote(guid, note);
819}
820
821void WorldSession::HandleBugOpcode( WorldPacket & recv_data )
822{
823    CHECK_PACKET_SIZE(recv_data,4+4+1+4+1);
824
825    uint32 suggestion, contentlen;
826    std::string content;
827    uint32 typelen;
828    std::string type;
829
830    recv_data >> suggestion >> contentlen >> content;
831
832    //recheck
833    CHECK_PACKET_SIZE(recv_data,4+4+(content.size()+1)+4+1);
834
835    recv_data >> typelen >> type;
836
837    if( suggestion == 0 )
838        sLog.outDebug( "WORLD: Received CMSG_BUG [Bug Report]" );
839    else
840        sLog.outDebug( "WORLD: Received CMSG_BUG [Suggestion]" );
841
842    sLog.outDebug( type.c_str( ) );
843    sLog.outDebug( content.c_str( ) );
844
845    CharacterDatabase.escape_string(type);
846    CharacterDatabase.escape_string(content);
847    CharacterDatabase.PExecute ("INSERT INTO bugreport (type,content) VALUES('%s', '%s')", type.c_str( ), content.c_str( ));
848}
849
850void WorldSession::HandleCorpseReclaimOpcode(WorldPacket &recv_data)
851{
852    CHECK_PACKET_SIZE(recv_data,8);
853
854    sLog.outDetail("WORLD: Received CMSG_RECLAIM_CORPSE");
855    if (GetPlayer()->isAlive())
856        return;
857
858    if (BattleGround * bg = _player->GetBattleGround())
859        if(bg->isArena())
860            return;
861
862    // body not released yet
863    if(!GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST))
864        return;
865
866    Corpse *corpse = GetPlayer()->GetCorpse();
867
868    if (!corpse )
869        return;
870
871    // prevent resurrect before 30-sec delay after body release not finished
872    if(corpse->GetGhostTime() + GetPlayer()->GetCorpseReclaimDelay(corpse->GetType()==CORPSE_RESURRECTABLE_PVP) > time(NULL))
873        return;
874
875    float dist = corpse->GetDistance2d(GetPlayer());
876    sLog.outDebug("Corpse 2D Distance: \t%f",dist);
877    if (dist > CORPSE_RECLAIM_RADIUS)
878        return;
879
880    uint64 guid;
881    recv_data >> guid;
882
883    // resurrect
884    GetPlayer()->ResurrectPlayer(GetPlayer()->InBattleGround() ? 1.0f : 0.5f);
885
886    // spawn bones
887    GetPlayer()->SpawnCorpseBones();
888
889    GetPlayer()->SaveToDB();
890}
891
892void WorldSession::HandleResurrectResponseOpcode(WorldPacket & recv_data)
893{
894    CHECK_PACKET_SIZE(recv_data,8+1);
895
896    sLog.outDetail("WORLD: Received CMSG_RESURRECT_RESPONSE");
897
898    if(GetPlayer()->isAlive())
899        return;
900
901    uint64 guid;
902    uint8 status;
903    recv_data >> guid;
904    recv_data >> status;
905
906    if(status == 0)
907    {
908        GetPlayer()->clearResurrectRequestData();           // reject
909        return;
910    }
911
912    if(!GetPlayer()->isRessurectRequestedBy(guid))
913        return;
914
915    GetPlayer()->ResurectUsingRequestData();
916    GetPlayer()->SaveToDB();
917}
918
919void WorldSession::HandleAreaTriggerOpcode(WorldPacket & recv_data)
920{
921    CHECK_PACKET_SIZE(recv_data,4);
922
923    sLog.outDebug("WORLD: Received CMSG_AREATRIGGER");
924
925    uint32 Trigger_ID;
926
927    recv_data >> Trigger_ID;
928    sLog.outDebug("Trigger ID:%u",Trigger_ID);
929
930    if(GetPlayer()->isInFlight())
931    {
932        sLog.outDebug("Player '%s' (GUID: %u) in flight, ignore Area Trigger ID:%u",GetPlayer()->GetName(),GetPlayer()->GetGUIDLow(), Trigger_ID);
933        return;
934    }
935
936    AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(Trigger_ID);
937    if(!atEntry)
938    {
939        sLog.outDebug("Player '%s' (GUID: %u) send unknown (by DBC) Area Trigger ID:%u",GetPlayer()->GetName(),GetPlayer()->GetGUIDLow(), Trigger_ID);
940        return;
941    }
942
943    if (GetPlayer()->GetMapId()!=atEntry->mapid)
944    {
945        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);
946        return;
947    }
948
949    // delta is safe radius
950    const float delta = 5.0f;
951    // check if player in the range of areatrigger
952    Player* pl = GetPlayer();
953
954    if (atEntry->radius > 0)
955    {
956        // if we have radius check it
957        float dist = pl->GetDistance(atEntry->x,atEntry->y,atEntry->z);
958        if(dist > atEntry->radius + delta)
959        {
960            sLog.outDebug("Player '%s' (GUID: %u) too far (radius: %f distance: %f), ignore Area Trigger ID: %u",
961                pl->GetName(), pl->GetGUIDLow(), atEntry->radius, dist, Trigger_ID);
962            return;
963        }
964    }
965    else
966    {
967        // we have only extent
968        float dx = pl->GetPositionX() - atEntry->x;
969        float dy = pl->GetPositionY() - atEntry->y;
970        float dz = pl->GetPositionZ() - atEntry->z;
971        double es = sin(atEntry->box_orientation);
972        double ec = cos(atEntry->box_orientation);
973        // calc rotated vector based on extent axis
974        double rotateDx = dx*ec - dy*es;
975        double rotateDy = dx*es + dy*ec;
976
977        if( (fabs(rotateDx) > atEntry->box_x/2 + delta) ||
978            (fabs(rotateDy) > atEntry->box_y/2 + delta) ||
979            (fabs(dz) > atEntry->box_z/2 + delta) )
980        {
981            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",
982                pl->GetName(), pl->GetGUIDLow(), atEntry->box_x/2, atEntry->box_y/2, atEntry->box_z/2, rotateDx, rotateDy, dz, Trigger_ID);
983            return;
984        }
985    }
986
987    if(Script->scriptAreaTrigger(GetPlayer(), atEntry))
988        return;
989
990    uint32 quest_id = objmgr.GetQuestForAreaTrigger( Trigger_ID );
991    if( quest_id && GetPlayer()->isAlive() && GetPlayer()->IsActiveQuest(quest_id) )
992    {
993        Quest const* pQuest = objmgr.GetQuestTemplate(quest_id);
994        if( pQuest )
995        {
996            if(GetPlayer()->GetQuestStatus(quest_id) == QUEST_STATUS_INCOMPLETE)
997                GetPlayer()->AreaExploredOrEventHappens( quest_id );
998        }
999    }
1000
1001    if(objmgr.IsTavernAreaTrigger(Trigger_ID))
1002    {
1003        // set resting flag we are in the inn
1004        GetPlayer()->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING);
1005        GetPlayer()->InnEnter(time(NULL), atEntry->mapid, atEntry->x, atEntry->y, atEntry->z);
1006        GetPlayer()->SetRestType(REST_TYPE_IN_TAVERN);
1007
1008        if(sWorld.IsFFAPvPRealm())
1009            GetPlayer()->RemoveFlag(PLAYER_FLAGS,PLAYER_FLAGS_FFA_PVP);
1010
1011        return;
1012    }
1013
1014    if(GetPlayer()->InBattleGround())
1015    {
1016        BattleGround* bg = GetPlayer()->GetBattleGround();
1017        if(bg)
1018            if(bg->GetStatus() == STATUS_IN_PROGRESS)
1019                bg->HandleAreaTrigger(GetPlayer(), Trigger_ID);
1020
1021        return;
1022    }
1023
1024    if(OutdoorPvP * pvp = GetPlayer()->GetOutdoorPvP())
1025    {
1026        if(pvp->HandleAreaTrigger(_player, Trigger_ID))
1027            return;
1028    }
1029
1030    // NULL if all values default (non teleport trigger)
1031    AreaTrigger const* at = objmgr.GetAreaTrigger(Trigger_ID);
1032    if(!at)
1033        return;
1034
1035    if(!GetPlayer()->isGameMaster())
1036    {
1037        uint32 missingLevel = 0;
1038        if(GetPlayer()->getLevel() < at->requiredLevel && !sWorld.getConfig(CONFIG_INSTANCE_IGNORE_LEVEL))
1039            missingLevel = at->requiredLevel;
1040
1041        // must have one or the other, report the first one that's missing
1042        uint32 missingItem = 0;
1043        if(at->requiredItem)
1044        {
1045            if(!GetPlayer()->HasItemCount(at->requiredItem, 1) &&
1046                (!at->requiredItem2 || !GetPlayer()->HasItemCount(at->requiredItem2, 1)))
1047                missingItem = at->requiredItem;
1048        }
1049        else if(at->requiredItem2 && !GetPlayer()->HasItemCount(at->requiredItem2, 1))
1050            missingItem = at->requiredItem2;
1051
1052        uint32 missingKey = 0;
1053        if(GetPlayer()->GetDifficulty() == DIFFICULTY_HEROIC)
1054        {
1055            if(at->heroicKey)
1056            {
1057                if(!GetPlayer()->HasItemCount(at->heroicKey, 1) &&
1058                    (!at->heroicKey2 || !GetPlayer()->HasItemCount(at->heroicKey2, 1)))
1059                    missingKey = at->heroicKey;
1060            }
1061            else if(at->heroicKey2 && !GetPlayer()->HasItemCount(at->heroicKey2, 1))
1062                missingKey = at->heroicKey2;
1063        }
1064
1065        uint32 missingQuest = 0;
1066        if(at->requiredQuest && !GetPlayer()->GetQuestRewardStatus(at->requiredQuest))
1067            missingQuest = at->requiredQuest;
1068
1069        if(missingLevel || missingItem || missingKey || missingQuest)
1070        {
1071            // TODO: all this is probably wrong
1072            if(missingItem)
1073                SendAreaTriggerMessage(GetTrinityString(LANG_LEVEL_MINREQUIRED_AND_ITEM), at->requiredLevel, objmgr.GetItemPrototype(missingItem)->Name1);
1074            else if(missingKey)
1075                GetPlayer()->SendTransferAborted(at->target_mapId, TRANSFER_ABORT_DIFFICULTY2);
1076            else if(missingQuest)
1077                SendAreaTriggerMessage(at->requiredFailedText.c_str());
1078            else if(missingLevel)
1079                SendAreaTriggerMessage(GetTrinityString(LANG_LEVEL_MINREQUIRED), missingLevel);
1080            return;
1081        }
1082    }
1083
1084    GetPlayer()->TeleportTo(at->target_mapId,at->target_X,at->target_Y,at->target_Z,at->target_Orientation,TELE_TO_NOT_LEAVE_TRANSPORT);
1085}
1086
1087void WorldSession::HandleUpdateAccountData(WorldPacket &/*recv_data*/)
1088{
1089    sLog.outDetail("WORLD: Received CMSG_UPDATE_ACCOUNT_DATA");
1090    //recv_data.hexlike();
1091}
1092
1093void WorldSession::HandleRequestAccountData(WorldPacket& /*recv_data*/)
1094{
1095    sLog.outDetail("WORLD: Received CMSG_REQUEST_ACCOUNT_DATA");
1096    //recv_data.hexlike();
1097}
1098
1099void WorldSession::HandleSetActionButtonOpcode(WorldPacket& recv_data)
1100{
1101    CHECK_PACKET_SIZE(recv_data,1+2+1+1);
1102
1103    sLog.outDebug(  "WORLD: Received CMSG_SET_ACTION_BUTTON" );
1104    uint8 button, misc, type;
1105    uint16 action;
1106    recv_data >> button >> action >> misc >> type;
1107    sLog.outDetail( "BUTTON: %u ACTION: %u TYPE: %u MISC: %u", button, action, type, misc );
1108    if(action==0)
1109    {
1110        sLog.outDetail( "MISC: Remove action from button %u", button );
1111
1112        GetPlayer()->removeActionButton(button);
1113    }
1114    else
1115    {
1116        if(type==ACTION_BUTTON_MACRO || type==ACTION_BUTTON_CMACRO)
1117        {
1118            sLog.outDetail( "MISC: Added Macro %u into button %u", action, button );
1119            GetPlayer()->addActionButton(button,action,type,misc);
1120        }
1121        else if(type==ACTION_BUTTON_SPELL)
1122        {
1123            sLog.outDetail( "MISC: Added Action %u into button %u", action, button );
1124            GetPlayer()->addActionButton(button,action,type,misc);
1125        }
1126        else if(type==ACTION_BUTTON_ITEM)
1127        {
1128            sLog.outDetail( "MISC: Added Item %u into button %u", action, button );
1129            GetPlayer()->addActionButton(button,action,type,misc);
1130        }
1131        else
1132            sLog.outError( "MISC: Unknown action button type %u for action %u into button %u", type, action, button );
1133    }
1134}
1135
1136void WorldSession::HandleCompleteCinema( WorldPacket & /*recv_data*/ )
1137{
1138    DEBUG_LOG( "WORLD: Player is watching cinema" );
1139}
1140
1141void WorldSession::HandleNextCinematicCamera( WorldPacket & /*recv_data*/ )
1142{
1143    DEBUG_LOG( "WORLD: Which movie to play" );
1144}
1145
1146void WorldSession::HandleMoveTimeSkippedOpcode( WorldPacket & /*recv_data*/ )
1147{
1148    /*  WorldSession::Update( getMSTime() );*/
1149    DEBUG_LOG( "WORLD: Time Lag/Synchronization Resent/Update" );
1150
1151    /*
1152        CHECK_PACKET_SIZE(recv_data,8+4);
1153        uint64 guid;
1154        uint32 time_skipped;
1155        recv_data >> guid;
1156        recv_data >> time_skipped;
1157        sLog.outDebug( "WORLD: CMSG_MOVE_TIME_SKIPPED" );
1158
1159        /// TODO
1160        must be need use in Trinity
1161        We substract server Lags to move time ( AntiLags )
1162        for exmaple
1163        GetPlayer()->ModifyLastMoveTime( -int32(time_skipped) );
1164    */
1165}
1166
1167void WorldSession::HandleFeatherFallAck(WorldPacket &/*recv_data*/)
1168{
1169    DEBUG_LOG("WORLD: CMSG_MOVE_FEATHER_FALL_ACK");
1170}
1171
1172void WorldSession::HandleMoveUnRootAck(WorldPacket&/* recv_data*/)
1173{
1174    /*
1175        CHECK_PACKET_SIZE(recv_data,8+8+4+4+4+4+4);
1176
1177        sLog.outDebug( "WORLD: CMSG_FORCE_MOVE_UNROOT_ACK" );
1178        recv_data.hexlike();
1179        uint64 guid;
1180        uint64 unknown1;
1181        uint32 unknown2;
1182        float PositionX;
1183        float PositionY;
1184        float PositionZ;
1185        float Orientation;
1186
1187        recv_data >> guid;
1188        recv_data >> unknown1;
1189        recv_data >> unknown2;
1190        recv_data >> PositionX;
1191        recv_data >> PositionY;
1192        recv_data >> PositionZ;
1193        recv_data >> Orientation;
1194
1195        // TODO for later may be we can use for anticheat
1196        DEBUG_LOG("Guid " I64FMTD,guid);
1197        DEBUG_LOG("unknown1 " I64FMTD,unknown1);
1198        DEBUG_LOG("unknown2 %u",unknown2);
1199        DEBUG_LOG("X %f",PositionX);
1200        DEBUG_LOG("Y %f",PositionY);
1201        DEBUG_LOG("Z %f",PositionZ);
1202        DEBUG_LOG("O %f",Orientation);
1203    */
1204}
1205
1206void WorldSession::HandleMoveRootAck(WorldPacket&/* recv_data*/)
1207{
1208    /*
1209        CHECK_PACKET_SIZE(recv_data,8+8+4+4+4+4+4);
1210
1211        sLog.outDebug( "WORLD: CMSG_FORCE_MOVE_ROOT_ACK" );
1212        recv_data.hexlike();
1213        uint64 guid;
1214        uint64 unknown1;
1215        uint32 unknown2;
1216        float PositionX;
1217        float PositionY;
1218        float PositionZ;
1219        float Orientation;
1220
1221        recv_data >> guid;
1222        recv_data >> unknown1;
1223        recv_data >> unknown2;
1224        recv_data >> PositionX;
1225        recv_data >> PositionY;
1226        recv_data >> PositionZ;
1227        recv_data >> Orientation;
1228
1229        // for later may be we can use for anticheat
1230        DEBUG_LOG("Guid " I64FMTD,guid);
1231        DEBUG_LOG("unknown1 " I64FMTD,unknown1);
1232        DEBUG_LOG("unknown1 %u",unknown2);
1233        DEBUG_LOG("X %f",PositionX);
1234        DEBUG_LOG("Y %f",PositionY);
1235        DEBUG_LOG("Z %f",PositionZ);
1236        DEBUG_LOG("O %f",Orientation);
1237    */
1238}
1239
1240void WorldSession::HandleMoveTeleportAck(WorldPacket&/* recv_data*/)
1241{
1242    /*
1243        CHECK_PACKET_SIZE(recv_data,8+4);
1244
1245        sLog.outDebug("MSG_MOVE_TELEPORT_ACK");
1246        uint64 guid;
1247        uint32 flags, time;
1248
1249        recv_data >> guid;
1250        recv_data >> flags >> time;
1251        DEBUG_LOG("Guid " I64FMTD,guid);
1252        DEBUG_LOG("Flags %u, time %u",flags, time/1000);
1253    */
1254}
1255
1256void WorldSession::HandleSetActionBar(WorldPacket& recv_data)
1257{
1258    CHECK_PACKET_SIZE(recv_data,1);
1259
1260    uint8 ActionBar;
1261
1262    recv_data >> ActionBar;
1263
1264    if(!GetPlayer())                                        // ignore until not logged (check needed because STATUS_AUTHED)
1265    {
1266        if(ActionBar!=0)
1267            sLog.outError("WorldSession::HandleSetActionBar in not logged state with value: %u, ignored",uint32(ActionBar));
1268        return;
1269    }
1270
1271    GetPlayer()->SetByteValue(PLAYER_FIELD_BYTES, 2, ActionBar);
1272}
1273
1274void WorldSession::HandleWardenDataOpcode(WorldPacket& /*recv_data*/)
1275{
1276    /*
1277        CHECK_PACKET_SIZE(recv_data,1);
1278
1279        uint8 tmp;
1280        recv_data >> tmp;
1281        sLog.outDebug("Received opcode CMSG_WARDEN_DATA, not resolve.uint8 = %u",tmp);
1282    */
1283}
1284
1285void WorldSession::HandlePlayedTime(WorldPacket& /*recv_data*/)
1286{
1287    uint32 TotalTimePlayed = GetPlayer()->GetTotalPlayedTime();
1288    uint32 LevelPlayedTime = GetPlayer()->GetLevelPlayedTime();
1289
1290    WorldPacket data(SMSG_PLAYED_TIME, 8);
1291    data << TotalTimePlayed;
1292    data << LevelPlayedTime;
1293    SendPacket(&data);
1294}
1295
1296void WorldSession::HandleInspectOpcode(WorldPacket& recv_data)
1297{
1298    CHECK_PACKET_SIZE(recv_data, 8);
1299
1300    uint64 guid;
1301    recv_data >> guid;
1302    DEBUG_LOG("Inspected guid is " I64FMTD, guid);
1303
1304    _player->SetSelection(guid);
1305
1306    Player *plr = objmgr.GetPlayer(guid);
1307    if(!plr)                                                // wrong player
1308        return;
1309
1310    uint32 talent_points = 0x3D;
1311    uint32 guid_size = plr->GetPackGUID().size();
1312    WorldPacket data(SMSG_INSPECT_TALENT, 4+talent_points);
1313    data.append(plr->GetPackGUID());
1314    data << uint32(talent_points);
1315
1316    // fill by 0 talents array
1317    for(uint32 i = 0; i < talent_points; ++i)
1318        data << uint8(0);
1319
1320    if(sWorld.getConfig(CONFIG_TALENTS_INSPECTING) || _player->isGameMaster())
1321    {
1322        // find class talent tabs (all players have 3 talent tabs)
1323        uint32 const* talentTabIds = GetTalentTabPages(plr->getClass());
1324
1325        uint32 talentTabPos = 0;                            // pos of first talent rank in tab including all prev tabs
1326        for(uint32 i = 0; i < 3; ++i)
1327        {
1328            uint32 talentTabId = talentTabIds[i];
1329
1330            // fill by real data
1331            for(uint32 talentId = 0; talentId < sTalentStore.GetNumRows(); ++talentId)
1332            {
1333                TalentEntry const* talentInfo = sTalentStore.LookupEntry(talentId);
1334                if(!talentInfo)
1335                    continue;
1336
1337                // skip another tab talents
1338                if(talentInfo->TalentTab != talentTabId)
1339                    continue;
1340
1341                // find talent rank
1342                uint32 curtalent_maxrank = 0;
1343                for(uint32 k = 5; k > 0; --k)
1344                {
1345                    if(talentInfo->RankID[k-1] && plr->HasSpell(talentInfo->RankID[k-1]))
1346                    {
1347                        curtalent_maxrank = k;
1348                        break;
1349                    }
1350                }
1351
1352                // not learned talent
1353                if(!curtalent_maxrank)
1354                    continue;
1355
1356                // 1 rank talent bit index
1357                uint32 curtalent_index = talentTabPos + GetTalentInspectBitPosInTab(talentId);
1358
1359                uint32 curtalent_rank_index = curtalent_index+curtalent_maxrank-1;
1360
1361                // slot/offset in 7-bit bytes
1362                uint32 curtalent_rank_slot7   = curtalent_rank_index / 7;
1363                uint32 curtalent_rank_offset7 = curtalent_rank_index % 7;
1364
1365                // rank pos with skipped 8 bit
1366                uint32 curtalent_rank_index2 = curtalent_rank_slot7 * 8 + curtalent_rank_offset7;
1367
1368                // slot/offset in 8-bit bytes with skipped high bit
1369                uint32 curtalent_rank_slot = curtalent_rank_index2 / 8;
1370                uint32 curtalent_rank_offset =  curtalent_rank_index2 % 8;
1371
1372                // apply mask
1373                uint32 val = data.read<uint8>(guid_size + 4 + curtalent_rank_slot);
1374                val |= (1 << curtalent_rank_offset);
1375                data.put<uint8>(guid_size + 4 + curtalent_rank_slot, val & 0xFF);
1376            }
1377
1378            talentTabPos += GetTalentTabInspectBitSize(talentTabId);
1379        }
1380    }
1381
1382    SendPacket(&data);
1383}
1384
1385void WorldSession::HandleInspectHonorStatsOpcode(WorldPacket& recv_data)
1386{
1387    CHECK_PACKET_SIZE(recv_data, 8);
1388
1389    uint64 guid;
1390    recv_data >> guid;
1391
1392    Player *player = objmgr.GetPlayer(guid);
1393
1394    if(!player)
1395    {
1396        sLog.outError("InspectHonorStats: WTF, player not found...");
1397        return;
1398    }
1399
1400    WorldPacket data(MSG_INSPECT_HONOR_STATS, 8+1+4*4);
1401    data << uint64(player->GetGUID());
1402    data << uint8(player->GetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY));
1403    data << uint32(player->GetUInt32Value(PLAYER_FIELD_KILLS));
1404    data << uint32(player->GetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION));
1405    data << uint32(player->GetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION));
1406    data << uint32(player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS));
1407    SendPacket(&data);
1408}
1409
1410void WorldSession::HandleWorldTeleportOpcode(WorldPacket& recv_data)
1411{
1412    CHECK_PACKET_SIZE(recv_data,4+4+4+4+4+4);
1413
1414    // write in client console: worldport 469 452 6454 2536 180 or /console worldport 469 452 6454 2536 180
1415    // Received opcode CMSG_WORLD_TELEPORT
1416    // Time is ***, map=469, x=452.000000, y=6454.000000, z=2536.000000, orient=3.141593
1417
1418    //sLog.outDebug("Received opcode CMSG_WORLD_TELEPORT");
1419
1420    if(GetPlayer()->isInFlight())
1421    {
1422        sLog.outDebug("Player '%s' (GUID: %u) in flight, ignore worldport command.",GetPlayer()->GetName(),GetPlayer()->GetGUIDLow());
1423        return;
1424    }
1425
1426    uint32 time;
1427    uint32 mapid;
1428    float PositionX;
1429    float PositionY;
1430    float PositionZ;
1431    float Orientation;
1432
1433    recv_data >> time;                                      // time in m.sec.
1434    recv_data >> mapid;
1435    recv_data >> PositionX;
1436    recv_data >> PositionY;
1437    recv_data >> PositionZ;
1438    recv_data >> Orientation;                               // o (3.141593 = 180 degrees)
1439    DEBUG_LOG("Time %u sec, map=%u, x=%f, y=%f, z=%f, orient=%f", time/1000, mapid, PositionX, PositionY, PositionZ, Orientation);
1440
1441    if (GetSecurity() >= SEC_ADMINISTRATOR)
1442        GetPlayer()->TeleportTo(mapid,PositionX,PositionY,PositionZ,Orientation);
1443    else
1444        SendNotification(LANG_YOU_NOT_HAVE_PERMISSION);
1445    sLog.outDebug("Received worldport command from player %s", GetPlayer()->GetName());
1446}
1447
1448void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data)
1449{
1450    CHECK_PACKET_SIZE(recv_data, 1);
1451
1452    sLog.outDebug("Received opcode CMSG_WHOIS");
1453    std::string charname;
1454    recv_data >> charname;
1455
1456    if (GetSecurity() < SEC_ADMINISTRATOR)
1457    {
1458        SendNotification(LANG_YOU_NOT_HAVE_PERMISSION);
1459        return;
1460    }
1461
1462    if(charname.empty())
1463    {
1464        SendNotification(LANG_NEED_CHARACTER_NAME);
1465        return;
1466    }
1467
1468    Player *plr = objmgr.GetPlayer(charname.c_str());
1469
1470    if(!plr)
1471    {
1472        SendNotification(LANG_PLAYER_NOT_EXIST_OR_OFFLINE, charname.c_str());
1473        return;
1474    }
1475
1476    uint32 accid = plr->GetSession()->GetAccountId();
1477
1478    QueryResult *result = loginDatabase.PQuery("SELECT username,email,last_ip FROM account WHERE id=%u", accid);
1479    if(!result)
1480    {
1481        SendNotification(LANG_ACCOUNT_FOR_PLAYER_NOT_FOUND, charname.c_str());
1482        return;
1483    }
1484
1485    Field *fields = result->Fetch();
1486    std::string acc = fields[0].GetCppString();
1487    if(acc.empty())
1488        acc = "Unknown";
1489    std::string email = fields[1].GetCppString();
1490    if(email.empty())
1491        email = "Unknown";
1492    std::string lastip = fields[2].GetCppString();
1493    if(lastip.empty())
1494        lastip = "Unknown";
1495
1496    std::string msg = charname + "'s " + "account is " + acc + ", e-mail: " + email + ", last ip: " + lastip;
1497
1498    WorldPacket data(SMSG_WHOIS, msg.size()+1);
1499    data << msg;
1500    _player->GetSession()->SendPacket(&data);
1501
1502    delete result;
1503
1504    sLog.outDebug("Received whois command from player %s for character %s", GetPlayer()->GetName(), charname.c_str());
1505}
1506
1507void WorldSession::HandleReportSpamOpcode( WorldPacket & recv_data )
1508{
1509    CHECK_PACKET_SIZE(recv_data, 1+8);
1510    sLog.outDebug("WORLD: CMSG_REPORT_SPAM");
1511    recv_data.hexlike();
1512
1513    uint8 spam_type;                                        // 0 - mail, 1 - chat
1514    uint64 spammer_guid;
1515    uint32 unk1, unk2, unk3, unk4 = 0;
1516    std::string description = "";
1517    recv_data >> spam_type;                                 // unk 0x01 const, may be spam type (mail/chat)
1518    recv_data >> spammer_guid;                              // player guid
1519    switch(spam_type)
1520    {
1521        case 0:
1522            CHECK_PACKET_SIZE(recv_data, recv_data.rpos()+4+4+4);
1523            recv_data >> unk1;                              // const 0
1524            recv_data >> unk2;                              // probably mail id
1525            recv_data >> unk3;                              // const 0
1526            break;
1527        case 1:
1528            CHECK_PACKET_SIZE(recv_data, recv_data.rpos()+4+4+4+4+1);
1529            recv_data >> unk1;                              // probably language
1530            recv_data >> unk2;                              // message type?
1531            recv_data >> unk3;                              // probably channel id
1532            recv_data >> unk4;                              // unk random value
1533            recv_data >> description;                       // spam description string (messagetype, channel name, player name, message)
1534            break;
1535    }
1536
1537    // NOTE: all chat messages from this spammer automatically ignored by spam reporter until logout in case chat spam.
1538    // if it's mail spam - ALL mails from this spammer automatically removed by client
1539
1540    // Complaint Received message
1541    WorldPacket data(SMSG_COMPLAIN_RESULT, 1);
1542    data << uint8(0);
1543    SendPacket(&data);
1544
1545    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());
1546}
1547
1548void WorldSession::HandleRealmStateRequestOpcode( WorldPacket & recv_data )
1549{
1550    CHECK_PACKET_SIZE(recv_data, 4);
1551
1552    sLog.outDebug("CMSG_REALM_SPLIT");
1553
1554    uint32 unk;
1555    std::string split_date = "01/01/01";
1556    recv_data >> unk;
1557
1558    WorldPacket data(SMSG_REALM_SPLIT, 4+4+split_date.size()+1);
1559    data << unk;
1560    data << uint32(0x00000000);                             // realm split state
1561    // split states:
1562    // 0x0 realm normal
1563    // 0x1 realm split
1564    // 0x2 realm split pending
1565    data << split_date;
1566    SendPacket(&data);
1567    //sLog.outDebug("response sent %u", unk);
1568}
1569
1570void WorldSession::HandleFarSightOpcode( WorldPacket & recv_data )
1571{
1572    CHECK_PACKET_SIZE(recv_data, 1);
1573
1574    sLog.outDebug("WORLD: CMSG_FAR_SIGHT");
1575    //recv_data.hexlike();
1576
1577    uint8 unk;
1578    recv_data >> unk;
1579
1580    switch(unk)
1581    {
1582        case 0:
1583            //WorldPacket data(SMSG_CLEAR_FAR_SIGHT_IMMEDIATE, 0)
1584            //SendPacket(&data);
1585            //_player->SetUInt64Value(PLAYER_FARSIGHT, 0);
1586            sLog.outDebug("Removed FarSight from player %u", _player->GetGUIDLow());
1587            break;
1588        case 1:
1589            sLog.outDebug("Added FarSight " I64FMTD " to player %u", _player->GetUInt64Value(PLAYER_FARSIGHT), _player->GetGUIDLow());
1590            break;
1591    }
1592}
1593
1594void WorldSession::HandleChooseTitleOpcode( WorldPacket & recv_data )
1595{
1596    CHECK_PACKET_SIZE(recv_data, 4);
1597
1598    sLog.outDebug("CMSG_SET_TITLE");
1599
1600    int32 title;
1601    recv_data >> title;
1602
1603    // -1 at none
1604    if(title > 0 && title < 64)
1605    {
1606       if(!GetPlayer()->HasFlag64(PLAYER__FIELD_KNOWN_TITLES,uint64(1) << title))
1607            return;
1608    }
1609    else
1610        title = 0;
1611
1612    GetPlayer()->SetUInt32Value(PLAYER_CHOSEN_TITLE, title);
1613}
1614
1615void WorldSession::HandleAllowMoveAckOpcode( WorldPacket & recv_data )
1616{
1617    CHECK_PACKET_SIZE(recv_data, 4+4);
1618
1619    sLog.outDebug("CMSG_ALLOW_MOVE_ACK");
1620
1621    uint32 counter, time_;
1622    recv_data >> counter >> time_;
1623
1624    // time_ seems always more than getMSTime()
1625    uint32 diff = getMSTimeDiff(getMSTime(),time_);
1626
1627    sLog.outDebug("response sent: counter %u, time %u (HEX: %X), ms. time %u, diff %u", counter, time_, time_, getMSTime(), diff);
1628}
1629
1630void WorldSession::HandleResetInstancesOpcode( WorldPacket & /*recv_data*/ )
1631{
1632    sLog.outDebug("WORLD: CMSG_RESET_INSTANCES");
1633    Group *pGroup = _player->GetGroup();
1634    if(pGroup)
1635    {
1636        if(pGroup->IsLeader(_player->GetGUID()))
1637            pGroup->ResetInstances(INSTANCE_RESET_ALL, _player);
1638    }
1639    else
1640        _player->ResetInstances(INSTANCE_RESET_ALL);
1641}
1642
1643void WorldSession::HandleDungeonDifficultyOpcode( WorldPacket & recv_data )
1644{
1645    CHECK_PACKET_SIZE(recv_data, 4);
1646
1647    sLog.outDebug("MSG_SET_DUNGEON_DIFFICULTY");
1648
1649    uint32 mode;
1650    recv_data >> mode;
1651
1652    if(mode == _player->GetDifficulty())
1653        return;
1654
1655    if(mode > DIFFICULTY_HEROIC)
1656    {
1657        sLog.outError("WorldSession::HandleDungeonDifficultyOpcode: player %d sent an invalid instance mode %d!", _player->GetGUIDLow(), mode);
1658        return;
1659    }
1660
1661    // cannot reset while in an instance
1662    Map *map = _player->GetMap();
1663    if(map && map->IsDungeon())
1664    {
1665        sLog.outError("WorldSession::HandleDungeonDifficultyOpcode: player %d tried to reset the instance while inside!", _player->GetGUIDLow());
1666        return;
1667    }
1668
1669    if(_player->getLevel() < LEVELREQUIREMENT_HEROIC)
1670        return;
1671    Group *pGroup = _player->GetGroup();
1672    if(pGroup)
1673    {
1674        if(pGroup->IsLeader(_player->GetGUID()))
1675        {
1676            // the difficulty is set even if the instances can't be reset
1677            //_player->SendDungeonDifficulty(true);
1678            pGroup->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY, _player);
1679            pGroup->SetDifficulty(mode);
1680        }
1681    }
1682    else
1683    {
1684        _player->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY);
1685        _player->SetDifficulty(mode);
1686    }
1687}
1688
1689void WorldSession::HandleNewUnknownOpcode( WorldPacket & recv_data )
1690{
1691    sLog.outDebug("New Unknown Opcode %u", recv_data.GetOpcode());
1692    recv_data.hexlike();
1693    /*
1694    New Unknown Opcode 837
1695    STORAGE_SIZE: 60
1696    02 00 00 00 00 00 00 00 | 00 00 00 00 01 20 00 00
1697    89 EB 33 01 71 5C 24 C4 | 15 03 35 45 74 47 8B 42
1698    BA B8 1B 40 00 00 00 00 | 00 00 00 00 77 66 42 BF
1699    23 91 26 3F 00 00 60 41 | 00 00 00 00
1700
1701    New Unknown Opcode 837
1702    STORAGE_SIZE: 44
1703    02 00 00 00 00 00 00 00 | 00 00 00 00 00 00 80 00
1704    7B 80 34 01 84 EA 2B C4 | 5F A1 36 45 C9 39 1C 42
1705    BA B8 1B 40 CE 06 00 00 | 00 00 80 3F
1706    */
1707}
1708
1709void WorldSession::HandleDismountOpcode( WorldPacket & /*recv_data*/ )
1710{
1711    sLog.outDebug("WORLD: CMSG_CANCEL_MOUNT_AURA");
1712    //recv_data.hexlike();
1713
1714    //If player is not mounted, so go out :)
1715    if (!_player->IsMounted())                              // not blizz like; no any messages on blizz
1716    {
1717        ChatHandler(this).SendSysMessage(LANG_CHAR_NON_MOUNTED);
1718        return;
1719    }
1720
1721    if(_player->isInFlight())                               // not blizz like; no any messages on blizz
1722    {
1723        ChatHandler(this).SendSysMessage(LANG_YOU_IN_FLIGHT);
1724        return;
1725    }
1726
1727    _player->Unmount();
1728    _player->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
1729}
1730
1731void WorldSession::HandleMoveFlyModeChangeAckOpcode( WorldPacket & recv_data )
1732{
1733    CHECK_PACKET_SIZE(recv_data, 8+4+4);
1734
1735    // fly mode on/off
1736    sLog.outDebug("WORLD: CMSG_MOVE_SET_CAN_FLY_ACK");
1737    //recv_data.hexlike();
1738
1739    uint64 guid;
1740    uint32 unk;
1741    uint32 flags;
1742
1743    recv_data >> guid >> unk >> flags;
1744
1745    _player->SetUnitMovementFlags(flags);
1746    /*
1747    on:
1748    25 00 00 00 00 00 00 00 | 00 00 00 00 00 00 80 00
1749    85 4E A9 01 19 BA 7A C3 | 42 0D 70 44 44 B0 A8 42
1750    78 15 94 40 39 03 00 00 | 00 00 80 3F
1751    off:
1752    25 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00
1753    10 FD A9 01 19 BA 7A C3 | 42 0D 70 44 44 B0 A8 42
1754    78 15 94 40 39 03 00 00 | 00 00 00 00
1755    */
1756}
1757
1758void WorldSession::HandleRequestPetInfoOpcode( WorldPacket & /*recv_data */)
1759{
1760    /*
1761        sLog.outDebug("WORLD: CMSG_REQUEST_PET_INFO");
1762        recv_data.hexlike();
1763    */
1764}
1765
1766void WorldSession::HandleSetTaxiBenchmarkOpcode( WorldPacket & recv_data )
1767{
1768    CHECK_PACKET_SIZE(recv_data, 1);
1769
1770    uint8 mode;
1771    recv_data >> mode;
1772
1773    sLog.outDebug("Client used \"/timetest %d\" command", mode);
1774}
Note: See TracBrowser for help on using the browser.