TrinityCore
Loading...
Searching...
No Matches
ReferAFriendHandler.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "WorldSession.h"
19#include "Log.h"
20#include "ObjectAccessor.h"
21#include "Player.h"
22#include "World.h"
23
25{
26 TC_LOG_DEBUG("network", "WORLD: CMSG_GRANT_LEVEL");
27
28 ObjectGuid guid;
29 recvData >> guid.ReadAsPacked();
30
32
33 // check cheating
35 uint8 error = 0;
36 if (!target)
38 else if (levels == 0)
40 else if (GetRecruiterId() != target->GetSession()->GetAccountId())
42 else if (target->GetTeamId() != _player->GetTeamId() && !sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP))
44 else if (target->GetLevel() >= _player->GetLevel())
46 else if (target->GetLevel() >= sWorld->getIntConfig(CONFIG_MAX_RECRUIT_A_FRIEND_BONUS_PLAYER_LEVEL))
48 else if (!target->IsInSameRaidWith(_player))
50
51 if (error)
52 {
54 data << uint32(error);
56 data << target->GetName();
57
58 SendPacket(&data);
59 return;
60 }
61
63 data2 << _player->GetPackGUID();
64 target->SendDirectMessage(&data2);
65}
66
68{
69 TC_LOG_DEBUG("network", "WORLD: CMSG_ACCEPT_LEVEL_GRANT");
70
71 ObjectGuid guid;
72 recvData >> guid.ReadAsPacked();
73
75
76 if (!(other && other->GetSession()))
77 return;
78
79 if (GetAccountId() != other->GetSession()->GetRecruiterId())
80 return;
81
82 if (other->GetGrantableLevels())
83 other->SetGrantableLevels(other->GetGrantableLevels() - 1);
84 else
85 return;
86
89}
uint8_t uint8
Definition Define.h:135
uint32_t uint32
Definition Define.h:133
#define TC_LOG_DEBUG(filterType__,...)
Definition Log.h:156
@ ERR_REFER_A_FRIEND_TARGET_TOO_HIGH
Definition Player.h:813
@ ERR_REFER_A_FRIEND_DIFFERENT_FACTION
Definition Player.h:816
@ ERR_REFER_A_FRIEND_NO_TARGET
Definition Player.h:819
@ ERR_REFER_A_FRIEND_INSUFFICIENT_GRANTABLE_LEVELS
Definition Player.h:814
@ ERR_REFER_A_FRIEND_NOT_REFERRED_BY
Definition Player.h:812
@ ERR_REFER_A_FRIEND_NOT_IN_GROUP
Definition Player.h:820
@ ERR_REFER_A_FRIEND_GRANT_LEVEL_MAX_I
Definition Player.h:818
PackedGuidReader ReadAsPacked()
Definition ObjectGuid.h:146
PackedGuid const & GetPackGUID() const
Definition Object.h:80
uint8 GetGrantableLevels() const
Definition Player.h:1845
bool IsInSameRaidWith(Player const *p) const
Definition Player.cpp:2297
void GiveLevel(uint8 level)
Definition Player.cpp:2405
void SendDirectMessage(WorldPacket const *data) const
Definition Player.cpp:6161
void SetGrantableLevels(uint8 val)
Definition Player.h:1846
WorldSession * GetSession() const
Definition Player.h:1719
TeamId GetTeamId() const
Definition Player.h:1833
void SetBeenGrantedLevelsFromRaF()
Definition Player.h:1014
uint8 GetLevel() const
Definition Unit.h:889
std::string const & GetName() const
Definition Object.h:382
void SendPacket(WorldPacket const *packet)
Send a packet to the client.
uint32 GetRecruiterId() const
void HandleAcceptGrantLevel(WorldPacket &recvData)
uint32 GetAccountId() const
Player * _player
void HandleGrantLevel(WorldPacket &recvData)
@ SMSG_REFER_A_FRIEND_FAILURE
Definition Opcodes.h:1086
@ SMSG_PROPOSE_LEVEL_GRANT
Definition Opcodes.h:1084
#define sWorld
Definition World.h:900
@ CONFIG_MAX_RECRUIT_A_FRIEND_BONUS_PLAYER_LEVEL
Definition World.h:246
@ CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP
Definition World.h:98
TC_GAME_API Player * GetPlayer(Map const *, ObjectGuid const &guid)