root/trunk/src/game/GroupHandler.cpp @ 157

Revision 132, 26.4 kB (checked in by yumileroy, 17 years ago)

[svn] * Added npc follow, waterwalk, repairitems commands. Patch by dythzer
* Prevent adding more than 5 people to raid - Apoc
* fixed typo from one of our previous commits.
* Fixed two strings in core, thanx to warhead for patch.

Original author: KingPin?
Date: 2008-10-29 17:09:32-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include "Common.h"
22#include "Database/DatabaseEnv.h"
23#include "Opcodes.h"
24#include "Log.h"
25#include "WorldPacket.h"
26#include "WorldSession.h"
27#include "World.h"
28#include "ObjectMgr.h"
29#include "Player.h"
30#include "Group.h"
31#include "ObjectAccessor.h"
32#include "MapManager.h"
33#include "SocialMgr.h"
34#include "Util.h"
35
36/* differeces from off:
37    -you can uninvite yourself - is is useful
38    -you can accept invitation even if leader went offline
39*/
40/* todo:
41    -group_destroyed msg is sent but not shown
42    -reduce xp gaining when in raid group
43    -quest sharing has to be corrected
44    -FIX sending PartyMemberStats
45*/
46
47void WorldSession::SendPartyResult(PartyOperation operation, std::string member, PartyResult res)
48{
49    WorldPacket data(SMSG_PARTY_COMMAND_RESULT, (8+member.size()+1));
50    data << (uint32)operation;
51    data << member;
52    data << (uint32)res;
53
54    SendPacket( &data );
55}
56
57void WorldSession::HandleGroupInviteOpcode( WorldPacket & recv_data )
58{
59    std::string membername;
60    recv_data >> membername;
61
62    if(_player->InBattleGround())
63    {
64        SendPartyResult(PARTY_OP_INVITE, membername, PARTY_RESULT_INVITE_RESTRICTED);
65        return;
66    }
67
68    // attempt add selected player
69
70    // cheating
71    if(!normalizePlayerName(membername))
72    {
73        SendPartyResult(PARTY_OP_INVITE, membername, PARTY_RESULT_CANT_FIND_TARGET);
74        return;
75    }
76
77    Player *player = objmgr.GetPlayer(membername.c_str());
78
79    // no player
80    if(!player)
81    {
82        SendPartyResult(PARTY_OP_INVITE, membername, PARTY_RESULT_CANT_FIND_TARGET);
83        return;
84    }
85
86    // can't group with
87    if(!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP) && GetPlayer()->GetTeam() != player->GetTeam())
88    {
89        SendPartyResult(PARTY_OP_INVITE, membername, PARTY_RESULT_TARGET_UNFRIENDLY);
90        return;
91    }
92    if(GetPlayer()->GetInstanceId() != 0 && player->GetInstanceId() != 0 && GetPlayer()->GetInstanceId() != player->GetInstanceId() && GetPlayer()->GetMapId() == player->GetMapId())
93    {
94        SendPartyResult(PARTY_OP_INVITE, membername, PARTY_RESULT_NOT_IN_YOUR_INSTANCE);
95        return;
96    }
97    // just ignore us
98    if(player->GetInstanceId() != 0 && player->GetDifficulty() != GetPlayer()->GetDifficulty())
99    {
100        SendPartyResult(PARTY_OP_INVITE, membername, PARTY_RESULT_TARGET_IGNORE_YOU);
101        return;
102    }
103
104    if(player->GetSocial()->HasIgnore(GetPlayer()->GetGUIDLow()))
105    {
106        SendPartyResult(PARTY_OP_INVITE, membername, PARTY_RESULT_TARGET_IGNORE_YOU);
107        return;
108    }
109
110    // player already in another group or invited
111    if(player->GetGroup() || player->GetGroupInvite() )
112    {
113        SendPartyResult(PARTY_OP_INVITE, membername, PARTY_RESULT_ALREADY_IN_GROUP);
114        return;
115    }
116
117    Group *group = GetPlayer()->GetGroup();
118
119    if(group)
120    {
121        // not have permissions for invite
122        if(!group->IsLeader(GetPlayer()->GetGUID()) && !group->IsAssistant(GetPlayer()->GetGUID()))
123        {
124            SendPartyResult(PARTY_OP_INVITE, "", PARTY_RESULT_YOU_NOT_LEADER);
125            return;
126        }
127
128        // not have place
129        if(group->IsFull())
130        {
131            SendPartyResult(PARTY_OP_INVITE, "", PARTY_RESULT_PARTY_FULL);
132            return;
133        }
134    }
135
136    // ok, but group not exist, start a new group
137    // but don't create and save the group to the DB until
138    // at least one person joins
139    if(!group)
140    {
141        group = new Group;
142        // new group: if can't add then delete
143        if(!group->AddLeaderInvite(GetPlayer()))
144        {
145            delete group;
146            return;
147        }
148        if(!group->AddInvite(player))
149        {
150            delete group;
151            return;
152        }
153    }
154    else
155    {
156        // already existed group: if can't add then just leave
157        if(!group->AddInvite(player))
158        {
159            return;
160        }
161    }
162
163    // ok, we do it
164    WorldPacket data(SMSG_GROUP_INVITE, 10);                // guess size
165    data << GetPlayer()->GetName();
166    player->GetSession()->SendPacket(&data);
167
168    SendPartyResult(PARTY_OP_INVITE, membername, PARTY_RESULT_OK);
169}
170
171void WorldSession::HandleGroupAcceptOpcode( WorldPacket & /*recv_data*/ )
172{
173    Group *group = GetPlayer()->GetGroupInvite();
174    if (!group) return;
175
176    if(group->GetLeaderGUID() == GetPlayer()->GetGUID())
177    {
178        sLog.outError("HandleGroupAcceptOpcode: player %s(%d) tried to accept an invite to his own group", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow());
179        return;
180    }
181
182    // remove in from ivites in any case
183    group->RemoveInvite(GetPlayer());
184
185    /** error handling **/
186    /********************/
187
188    // not have place
189    if(group->IsFull())
190    {
191        SendPartyResult(PARTY_OP_INVITE, "", PARTY_RESULT_PARTY_FULL);
192        return;
193    }
194
195    Player* leader = objmgr.GetPlayer(group->GetLeaderGUID());
196
197    if(leader && leader->InBattleGround())
198    {
199        SendPartyResult(PARTY_OP_INVITE, "", PARTY_RESULT_INVITE_RESTRICTED);
200        return;
201    }
202
203    // forming a new group, create it
204    if(!group->IsCreated())
205    {
206        if(leader) group->RemoveInvite(leader);
207        group->Create(group->GetLeaderGUID(), group->GetLeaderName());
208        objmgr.AddGroup(group);
209    }
210
211    // everything's fine, do it
212    if(!group->AddMember(GetPlayer()->GetGUID(), GetPlayer()->GetName()))
213        return;
214
215    uint8 subgroup = group->GetMemberGroup(GetPlayer()->GetGUID());
216
217    GetPlayer()->SetGroup(group, subgroup);
218}
219
220void WorldSession::HandleGroupDeclineOpcode( WorldPacket & /*recv_data*/ )
221{
222    Group  *group  = GetPlayer()->GetGroupInvite();
223    if (!group) return;
224
225    Player *leader = objmgr.GetPlayer(group->GetLeaderGUID());
226
227    /** error handling **/
228    if(!leader || !leader->GetSession())
229        return;
230    /********************/
231
232    // everything's fine, do it
233    if(!group->IsCreated())
234    {
235        // note: this means that if you invite more than one person
236        // and one of them declines before the first one accepts
237        // all invites will be cleared
238        // fixme: is that ok ?
239        group->RemoveAllInvites();
240        delete group;
241    }
242
243    GetPlayer()->SetGroupInvite(NULL);
244
245    WorldPacket data( SMSG_GROUP_DECLINE, 10 );             // guess size
246    data << GetPlayer()->GetName();
247    leader->GetSession()->SendPacket( &data );
248}
249
250void WorldSession::HandleGroupUninviteGuidOpcode(WorldPacket & recv_data)
251{
252    CHECK_PACKET_SIZE(recv_data,8);
253
254    uint64 guid;
255    recv_data >> guid;
256
257    if(_player->InBattleGround())
258    {
259        SendPartyResult(PARTY_OP_INVITE, "", PARTY_RESULT_INVITE_RESTRICTED);
260        return;
261    }
262
263    std::string membername;
264    if(!objmgr.GetPlayerNameByGUID(guid, membername))
265        return;                                             // not found
266
267    HandleGroupUninvite(guid, membername);
268}
269
270void WorldSession::HandleGroupUninviteNameOpcode(WorldPacket & recv_data)
271{
272    CHECK_PACKET_SIZE(recv_data,1);
273
274    std::string membername;
275    recv_data >> membername;
276
277    if(_player->InBattleGround())
278    {
279        SendPartyResult(PARTY_OP_INVITE, membername, PARTY_RESULT_INVITE_RESTRICTED);
280        return;
281    }
282
283    // player not found
284    if(!normalizePlayerName(membername))
285        return;
286
287    uint64 guid = objmgr.GetPlayerGUIDByName(membername);
288
289    // player not found
290    if(!guid)
291        return;
292
293    HandleGroupUninvite(guid, membername);
294}
295
296void WorldSession::HandleGroupUninvite(uint64 guid, std::string name)
297{
298    Group *group = GetPlayer()->GetGroup();
299    if(!group)
300        return;
301
302    if(_player->InBattleGround())
303    {
304        SendPartyResult(PARTY_OP_INVITE, "", PARTY_RESULT_INVITE_RESTRICTED);
305        return;
306    }
307
308    Player *player = objmgr.GetPlayer(guid);
309
310    /** error handling **/
311    if(!group->IsLeader(GetPlayer()->GetGUID()) && !group->IsAssistant(GetPlayer()->GetGUID()))
312    {
313        SendPartyResult(PARTY_OP_LEAVE, "", PARTY_RESULT_YOU_NOT_LEADER);
314        return;
315    }
316
317    if(!group->IsMember(guid) && (player && player->GetGroupInvite() != group))
318    {
319        SendPartyResult(PARTY_OP_LEAVE, name, PARTY_RESULT_NOT_IN_YOUR_PARTY);
320        return;
321    }
322
323    if(guid == GetPlayer()->GetGUID())
324    {
325        sLog.outError("WorldSession::HandleGroupUninvite: leader %s(%d) tried to uninvite himself from the group.", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow());
326        return;
327    }
328    /********************/
329
330    // everything's fine, do it
331
332    if(player && player->GetGroupInvite())                  // uninvite invitee
333        player->UninviteFromGroup();
334    else                                                    // uninvite member
335        Player::RemoveFromGroup(group,guid);
336}
337
338void WorldSession::HandleGroupSetLeaderOpcode( WorldPacket & recv_data )
339{
340    CHECK_PACKET_SIZE(recv_data,8);
341
342    Group *group = GetPlayer()->GetGroup();
343    if(!group)
344        return;
345
346    uint64 guid;
347    recv_data >> guid;
348
349    Player *player = objmgr.GetPlayer(guid);
350
351    /** error handling **/
352    if (!player || !group->IsLeader(GetPlayer()->GetGUID()) || player->GetGroup() != group)
353        return;
354    /********************/
355
356    // everything's fine, do it
357    group->ChangeLeader(guid);
358}
359
360void WorldSession::HandleGroupLeaveOpcode( WorldPacket & /*recv_data*/ )
361{
362    if(!GetPlayer()->GetGroup())
363        return;
364
365    if(_player->InBattleGround())
366    {
367        SendPartyResult(PARTY_OP_INVITE, "", PARTY_RESULT_INVITE_RESTRICTED);
368        return;
369    }
370
371    /** error handling **/
372    /********************/
373
374    // everything's fine, do it
375    SendPartyResult(PARTY_OP_LEAVE, GetPlayer()->GetName(), PARTY_RESULT_OK);
376
377    GetPlayer()->RemoveFromGroup();
378}
379
380void WorldSession::HandleLootMethodOpcode( WorldPacket & recv_data )
381{
382    CHECK_PACKET_SIZE(recv_data,4+8+4);
383
384    Group *group = GetPlayer()->GetGroup();
385    if(!group)
386        return;
387
388    uint32 lootMethod;
389    uint64 lootMaster;
390    uint32 lootThreshold;
391    recv_data >> lootMethod >> lootMaster >> lootThreshold;
392
393    /** error handling **/
394    if(!group->IsLeader(GetPlayer()->GetGUID()))
395        return;
396    /********************/
397
398    // everything's fine, do it
399    group->SetLootMethod((LootMethod)lootMethod);
400    group->SetLooterGuid(lootMaster);
401    group->SetLootThreshold((ItemQualities)lootThreshold);
402    group->SendUpdate();
403}
404
405void WorldSession::HandleLootRoll( WorldPacket &recv_data )
406{
407    CHECK_PACKET_SIZE(recv_data,8+4+1);
408
409    if(!GetPlayer()->GetGroup())
410        return;
411
412    uint64 Guid;
413    uint32 NumberOfPlayers;
414    uint8  Choise;
415    recv_data >> Guid;                                      //guid of the item rolled
416    recv_data >> NumberOfPlayers;
417    recv_data >> Choise;                                    //0: pass, 1: need, 2: greed
418
419    //sLog.outDebug("WORLD RECIEVE CMSG_LOOT_ROLL, From:%u, Numberofplayers:%u, Choise:%u", (uint32)Guid, NumberOfPlayers, Choise);
420
421    Group* group = GetPlayer()->GetGroup();
422    if(!group)
423        return;
424
425    // everything's fine, do it
426    group->CountRollVote(GetPlayer()->GetGUID(), Guid, NumberOfPlayers, Choise);
427}
428
429void WorldSession::HandleMinimapPingOpcode(WorldPacket& recv_data)
430{
431    CHECK_PACKET_SIZE(recv_data,4+4);
432
433    if(!GetPlayer()->GetGroup())
434        return;
435
436    float x, y;
437    recv_data >> x;
438    recv_data >> y;
439
440    //sLog.outDebug("Received opcode MSG_MINIMAP_PING X: %f, Y: %f", x, y);
441
442    /** error handling **/
443    /********************/
444
445    // everything's fine, do it
446    WorldPacket data(MSG_MINIMAP_PING, (8+4+4));
447    data << GetPlayer()->GetGUID();
448    data << x;
449    data << y;
450    GetPlayer()->GetGroup()->BroadcastPacket(&data, -1, GetPlayer()->GetGUID());
451}
452
453void WorldSession::HandleRandomRollOpcode(WorldPacket& recv_data)
454{
455    CHECK_PACKET_SIZE(recv_data,4+4);
456
457    uint32 minimum, maximum, roll;
458    recv_data >> minimum;
459    recv_data >> maximum;
460
461    /** error handling **/
462    if(minimum > maximum || maximum > 10000)                // < 32768 for urand call
463        return;
464    /********************/
465
466    // everything's fine, do it
467    roll = urand(minimum, maximum);
468
469    //sLog.outDebug("ROLL: MIN: %u, MAX: %u, ROLL: %u", minimum, maximum, roll);
470
471    WorldPacket data(MSG_RANDOM_ROLL, 4+4+4+8);
472    data << minimum;
473    data << maximum;
474    data << roll;
475    data << GetPlayer()->GetGUID();
476    if(GetPlayer()->GetGroup())
477        GetPlayer()->GetGroup()->BroadcastPacket(&data);
478    else
479        SendPacket(&data);
480}
481
482void WorldSession::HandleRaidIconTargetOpcode( WorldPacket & recv_data )
483{
484    CHECK_PACKET_SIZE(recv_data,1);
485
486    Group *group = GetPlayer()->GetGroup();
487    if(!group)
488        return;
489
490    uint8  x;
491    recv_data >> x;
492
493    /** error handling **/
494    /********************/
495
496    // everything's fine, do it
497    if(x == 0xFF)                                           // target icon request
498    {
499        group->SendTargetIconList(this);
500    }
501    else                                                    // target icon update
502    {
503        // recheck
504        CHECK_PACKET_SIZE(recv_data,1+8);
505
506        if(!group->IsLeader(GetPlayer()->GetGUID()) && !group->IsAssistant(GetPlayer()->GetGUID()))
507            return;
508
509        uint64 guid;
510        recv_data >> guid;
511        group->SetTargetIcon(x, guid);
512    }
513}
514
515void WorldSession::HandleRaidConvertOpcode( WorldPacket & /*recv_data*/ )
516{
517    Group *group = GetPlayer()->GetGroup();
518    if(!group)
519        return;
520
521    if(_player->InBattleGround())
522        return;
523
524    /** error handling **/
525    if(!group->IsLeader(GetPlayer()->GetGUID()) || group->GetMembersCount() < 2)
526        return;
527    /********************/
528
529    // everything's fine, do it (is it 0 (PARTY_OP_INVITE) correct code)
530    SendPartyResult(PARTY_OP_INVITE, "", PARTY_RESULT_OK);
531    group->ConvertToRaid();
532}
533
534void WorldSession::HandleGroupChangeSubGroupOpcode( WorldPacket & recv_data )
535{
536    CHECK_PACKET_SIZE(recv_data,1+1);
537
538    Group *group = GetPlayer()->GetGroup();
539    if(!group)
540        return;
541
542    std::string name;
543    uint8 groupNr;
544    recv_data >> name;
545
546    // recheck
547    CHECK_PACKET_SIZE(recv_data,(name.size()+1)+1);
548
549    recv_data >> groupNr;
550
551    /** error handling **/
552    if(!group->IsLeader(GetPlayer()->GetGUID()) && !group->IsAssistant(GetPlayer()->GetGUID()))
553        return;
554       
555    if (!group->HasFreeSlotSubGroup(groupNr))
556        return;
557    /********************/
558
559    // everything's fine, do it
560    group->ChangeMembersGroup(objmgr.GetPlayer(name.c_str()), groupNr);
561}
562
563void WorldSession::HandleGroupAssistantOpcode( WorldPacket & recv_data )
564{
565    CHECK_PACKET_SIZE(recv_data,8+1);
566
567    Group *group = GetPlayer()->GetGroup();
568    if(!group)
569        return;
570
571    uint64 guid;
572    uint8 flag;
573    recv_data >> guid;
574    recv_data >> flag;
575
576    /** error handling **/
577    if(!group->IsLeader(GetPlayer()->GetGUID()))
578        return;
579    /********************/
580
581    // everything's fine, do it
582    group->SetAssistant(guid, (flag==0?false:true));
583}
584
585void WorldSession::HandleGroupPromoteOpcode( WorldPacket & recv_data )
586{
587    CHECK_PACKET_SIZE(recv_data, 1+1+8);
588
589    Group *group = GetPlayer()->GetGroup();
590    if(!group)
591        return;
592
593    uint8 flag1, flag2;
594    uint64 guid;
595    recv_data >> flag1 >> flag2;
596    recv_data >> guid;
597    // if(flag1) Main Assist
598    //     0x4
599    // if(flag2) Main Tank
600    //     0x2
601
602    /** error handling **/
603    if(!group->IsLeader(GetPlayer()->GetGUID()))
604        return;
605    /********************/
606
607    // everything's fine, do it
608    if(flag1 == 1)
609        group->SetMainAssistant(guid);
610    if(flag2 == 1)
611        group->SetMainTank(guid);
612}
613
614void WorldSession::HandleRaidReadyCheckOpcode( WorldPacket & recv_data )
615{
616    Group *group = GetPlayer()->GetGroup();
617    if(!group)
618        return;
619
620    if(recv_data.empty())                                   // request
621    {
622        /** error handling **/
623        if(!group->IsLeader(GetPlayer()->GetGUID()) && !group->IsAssistant(GetPlayer()->GetGUID()))
624            return;
625        /********************/
626
627        // everything's fine, do it
628        WorldPacket data(MSG_RAID_READY_CHECK, 8);
629        data << GetPlayer()->GetGUID();
630        group->BroadcastPacket(&data, -1);
631
632        group->OfflineReadyCheck();
633    }
634    else                                                    // answer
635    {
636        uint8 state;
637        recv_data >> state;
638
639        // everything's fine, do it
640        WorldPacket data(MSG_RAID_READY_CHECK_CONFIRM, 9);
641        data << GetPlayer()->GetGUID();
642        data << state;
643        group->BroadcastReadyCheck(&data);
644    }
645}
646
647void WorldSession::HandleRaidReadyCheckFinishOpcode( WorldPacket & recv_data )
648{
649    //Group* group = GetPlayer()->GetGroup();
650    //if(!group)
651    //    return;
652
653    //if(!group->IsLeader(GetPlayer()->GetGUID()) && !group->IsAssistant(GetPlayer()->GetGUID()))
654    //    return;
655
656    // Is any reaction need?
657}
658
659void WorldSession::BuildPartyMemberStatsChangedPacket(Player *player, WorldPacket *data)
660{
661    uint32 mask = player->GetGroupUpdateFlag();
662
663    if (mask == GROUP_UPDATE_FLAG_NONE)
664        return;
665
666    if (mask & GROUP_UPDATE_FLAG_POWER_TYPE)                // if update power type, update current/max power also
667        mask |= (GROUP_UPDATE_FLAG_CUR_POWER | GROUP_UPDATE_FLAG_MAX_POWER);
668
669    if (mask & GROUP_UPDATE_FLAG_PET_POWER_TYPE)            // same for pets
670        mask |= (GROUP_UPDATE_FLAG_PET_CUR_POWER | GROUP_UPDATE_FLAG_PET_MAX_POWER);
671
672    uint32 byteCount = 0;
673    for (int i = 1; i < GROUP_UPDATE_FLAGS_COUNT; ++i)
674        if (mask & (1 << i))
675            byteCount += GroupUpdateLength[i];
676
677    data->Initialize(SMSG_PARTY_MEMBER_STATS, 8 + 4 + byteCount);
678    data->append(player->GetPackGUID());
679    *data << (uint32) mask;
680
681    if (mask & GROUP_UPDATE_FLAG_STATUS)
682    {
683        if (player)
684        {
685            if (player->IsPvP())
686                *data << (uint16) (MEMBER_STATUS_ONLINE | MEMBER_STATUS_PVP);
687            else
688                *data << (uint16) MEMBER_STATUS_ONLINE;
689        }
690        else
691            *data << (uint16) MEMBER_STATUS_OFFLINE;
692    }
693
694    if (mask & GROUP_UPDATE_FLAG_CUR_HP)
695        *data << (uint16) player->GetHealth();
696
697    if (mask & GROUP_UPDATE_FLAG_MAX_HP)
698        *data << (uint16) player->GetMaxHealth();
699
700    Powers powerType = player->getPowerType();
701    if (mask & GROUP_UPDATE_FLAG_POWER_TYPE)
702        *data << (uint8) powerType;
703
704    if (mask & GROUP_UPDATE_FLAG_CUR_POWER)
705        *data << (uint16) player->GetPower(powerType);
706
707    if (mask & GROUP_UPDATE_FLAG_MAX_POWER)
708        *data << (uint16) player->GetMaxPower(powerType);
709
710    if (mask & GROUP_UPDATE_FLAG_LEVEL)
711        *data << (uint16) player->getLevel();
712
713    if (mask & GROUP_UPDATE_FLAG_ZONE)
714        *data << (uint16) player->GetZoneId();
715
716    if (mask & GROUP_UPDATE_FLAG_POSITION)
717        *data << (uint16) player->GetPositionX() << (uint16) player->GetPositionY();
718
719    if (mask & GROUP_UPDATE_FLAG_AURAS)
720    {
721        uint64 auramask = player->GetAuraUpdateMask();
722        *data << uint64(auramask);
723        for(uint32 i = 0; i < MAX_AURAS; ++i)
724        {
725            if(auramask & (uint64(1) << i))
726            {
727                *data << uint16(player->GetUInt32Value(UNIT_FIELD_AURA + i));
728                *data << uint8(1);
729            }
730        }
731    }
732
733    Pet *pet = player->GetPet();
734    if (mask & GROUP_UPDATE_FLAG_PET_GUID)
735    {
736        if(pet)
737            *data << (uint64) pet->GetGUID();
738        else
739            *data << (uint64) 0;
740    }
741
742    if (mask & GROUP_UPDATE_FLAG_PET_NAME)
743    {
744        if(pet)
745            *data << pet->GetName();
746        else
747            *data << (uint8)  0;
748    }
749
750    if (mask & GROUP_UPDATE_FLAG_PET_MODEL_ID)
751    {
752        if(pet)
753            *data << (uint16) pet->GetDisplayId();
754        else
755            *data << (uint16) 0;
756    }
757
758    if (mask & GROUP_UPDATE_FLAG_PET_CUR_HP)
759    {
760        if(pet)
761            *data << (uint16) pet->GetHealth();
762        else
763            *data << (uint16) 0;
764    }
765
766    if (mask & GROUP_UPDATE_FLAG_PET_MAX_HP)
767    {
768        if(pet)
769            *data << (uint16) pet->GetMaxHealth();
770        else
771            *data << (uint16) 0;
772    }
773
774    if (mask & GROUP_UPDATE_FLAG_PET_POWER_TYPE)
775    {
776        if(pet)
777            *data << (uint8)  pet->getPowerType();
778        else
779            *data << (uint8)  0;
780    }
781
782    if (mask & GROUP_UPDATE_FLAG_PET_CUR_POWER)
783    {
784        if(pet)
785            *data << (uint16) pet->GetPower(pet->getPowerType());
786        else
787            *data << (uint16) 0;
788    }
789
790    if (mask & GROUP_UPDATE_FLAG_PET_MAX_POWER)
791    {
792        if(pet)
793            *data << (uint16) pet->GetMaxPower(pet->getPowerType());
794        else
795            *data << (uint16) 0;
796    }
797
798    if (mask & GROUP_UPDATE_FLAG_PET_AURAS)
799    {
800        if(pet)
801        {
802            uint64 auramask = pet->GetAuraUpdateMask();
803            *data << uint64(auramask);
804            for(uint32 i = 0; i < MAX_AURAS; ++i)
805            {
806                if(auramask & (uint64(1) << i))
807                {
808                    *data << uint16(pet->GetUInt32Value(UNIT_FIELD_AURA + i));
809                    *data << uint8(1);
810                }
811            }
812        }
813        else
814            *data << (uint64) 0;
815    }
816}
817
818/*this procedure handles clients CMSG_REQUEST_PARTY_MEMBER_STATS request*/
819void WorldSession::HandleRequestPartyMemberStatsOpcode( WorldPacket &recv_data )
820{
821    CHECK_PACKET_SIZE(recv_data, 8);
822
823    sLog.outDebug("WORLD: Received CMSG_REQUEST_PARTY_MEMBER_STATS");
824    uint64 Guid;
825    recv_data >> Guid;
826
827    Player *player = objmgr.GetPlayer(Guid);
828    if(!player)
829    {
830        WorldPacket data(SMSG_PARTY_MEMBER_STATS_FULL, 3+4+2);
831        data.appendPackGUID(Guid);
832        data << (uint32) GROUP_UPDATE_FLAG_STATUS;
833        data << (uint16) MEMBER_STATUS_OFFLINE;
834        SendPacket(&data);
835        return;
836    }
837
838    Pet *pet = player->GetPet();
839
840    WorldPacket data(SMSG_PARTY_MEMBER_STATS_FULL, 4+2+2+2+1+2*6+8+1+8);
841    data.append(player->GetPackGUID());
842
843    uint32 mask1 = 0x00040BFF;                              // common mask, real flags used 0x000040BFF
844    if(pet)
845        mask1 = 0x7FFFFFFF;                                 // for hunters and other classes with pets
846
847    Powers powerType = player->getPowerType();
848    data << (uint32) mask1;                                 // group update mask
849    data << (uint16) MEMBER_STATUS_ONLINE;                  // member's online status
850    data << (uint16) player->GetHealth();                   // GROUP_UPDATE_FLAG_CUR_HP
851    data << (uint16) player->GetMaxHealth();                // GROUP_UPDATE_FLAG_MAX_HP
852    data << (uint8)  powerType;                             // GROUP_UPDATE_FLAG_POWER_TYPE
853    data << (uint16) player->GetPower(powerType);           // GROUP_UPDATE_FLAG_CUR_POWER
854    data << (uint16) player->GetMaxPower(powerType);        // GROUP_UPDATE_FLAG_MAX_POWER
855    data << (uint16) player->getLevel();                    // GROUP_UPDATE_FLAG_LEVEL
856    data << (uint16) player->GetZoneId();                   // GROUP_UPDATE_FLAG_ZONE
857    data << (uint16) player->GetPositionX();                // GROUP_UPDATE_FLAG_POSITION
858    data << (uint16) player->GetPositionY();                // GROUP_UPDATE_FLAG_POSITION
859
860    uint64 auramask = 0;
861    size_t maskPos = data.wpos();
862    data << (uint64) auramask;                              // placeholder
863    for(uint8 i = 0; i < MAX_AURAS; ++i)
864    {
865        if(uint32 aura = player->GetUInt32Value(UNIT_FIELD_AURA + i))
866        {
867            auramask |= (uint64(1) << i);
868            data << uint16(aura);
869            data << uint8(1);
870        }
871    }
872    data.put<uint64>(maskPos,auramask);                     // GROUP_UPDATE_FLAG_AURAS
873
874    if(pet)
875    {
876        Powers petpowertype = pet->getPowerType();
877        data << (uint64) pet->GetGUID();                    // GROUP_UPDATE_FLAG_PET_GUID
878        data << pet->GetName();                             // GROUP_UPDATE_FLAG_PET_NAME
879        data << (uint16) pet->GetDisplayId();               // GROUP_UPDATE_FLAG_PET_MODEL_ID
880        data << (uint16) pet->GetHealth();                  // GROUP_UPDATE_FLAG_PET_CUR_HP
881        data << (uint16) pet->GetMaxHealth();               // GROUP_UPDATE_FLAG_PET_MAX_HP
882        data << (uint8)  petpowertype;                      // GROUP_UPDATE_FLAG_PET_POWER_TYPE
883        data << (uint16) pet->GetPower(petpowertype);       // GROUP_UPDATE_FLAG_PET_CUR_POWER
884        data << (uint16) pet->GetMaxPower(petpowertype);    // GROUP_UPDATE_FLAG_PET_MAX_POWER
885
886        uint64 petauramask = 0;
887        size_t petMaskPos = data.wpos();
888        data << (uint64) petauramask;                       // placeholder
889        for(uint8 i = 0; i < MAX_AURAS; ++i)
890        {
891            if(uint32 petaura = pet->GetUInt32Value(UNIT_FIELD_AURA + i))
892            {
893                petauramask |= (uint64(1) << i);
894                data << (uint16) petaura;
895                data << (uint8)  1;
896            }
897        }
898        data.put<uint64>(petMaskPos,petauramask);           // GROUP_UPDATE_FLAG_PET_AURAS
899    }
900    else
901    {
902        data << (uint8)  0;                                 // GROUP_UPDATE_FLAG_PET_NAME
903        data << (uint64) 0;                                 // GROUP_UPDATE_FLAG_PET_AURAS
904    }
905
906    SendPacket(&data);
907}
908
909/*!*/void WorldSession::HandleRequestRaidInfoOpcode( WorldPacket & /*recv_data*/ )
910{
911    // every time the player checks the character screen
912    _player->SendRaidInfo();
913}
914
915/*void WorldSession::HandleGroupCancelOpcode( WorldPacket & recv_data )
916{
917    sLog.outDebug( "WORLD: got CMSG_GROUP_CANCEL." );
918}*/
919
920void WorldSession::HandleGroupPassOnLootOpcode( WorldPacket & recv_data )
921{
922    CHECK_PACKET_SIZE(recv_data, 4);
923
924    sLog.outDebug("WORLD: Received CMSG_GROUP_PASS_ON_LOOT");
925
926    uint32 unkn;
927    recv_data >> unkn;
928
929    // ignore if player not loaded
930    if(!GetPlayer())                                        // needed because STATUS_AUTHED
931    {
932        if(unkn!=0)
933            sLog.outError("CMSG_GROUP_PASS_ON_LOOT value<>0 for not-loaded character!");
934        return;
935    }
936
937    if(unkn!=0)
938        sLog.outError("CMSG_GROUP_PASS_ON_LOOT: activation not implemented!");
939}
Note: See TracBrowser for help on using the browser.