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

Revision 44, 56.4 kB (checked in by yumileroy, 17 years ago)

[svn] * Merge Temp dev SVN with Assembla.
* Changes include:

  • Implementation of w12x's Outdoor PvP and Game Event Systems.
  • Temporary removal of IRC Chat Bot (until infinite loop when disabled is fixed).
  • All mangos -> trinity (to convert your mangos_string table, please run mangos_string_to_trinity_string.sql).
  • Improved Config cleanup.
  • And many more changes.

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