Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
ReferAFriendHandler.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of Project SkyFire https://www.projectskyfire.org.
3
* See LICENSE.md file for Copyright information
4
*/
5
6
#include "
Log.h
"
7
#include "
ObjectMgr.h
"
8
#include "
Opcodes.h
"
9
#include "
Player.h
"
10
#include "
WorldSession.h
"
11
12
void
WorldSession::HandleGrantLevel
(
WorldPacket
& recvData)
13
{
14
SF_LOG_DEBUG
(
"network"
,
"WORLD: CMSG_GRANT_LEVEL"
);
15
16
ObjectGuid
guid;
17
18
recvData.
ReadGuidMask
(guid, 2, 1, 5, 3, 7, 4, 0, 6);
19
recvData.
ReadGuidBytes
(guid, 1, 4, 2, 7, 5, 3, 6, 0);
20
21
Player
* target =
ObjectAccessor::GetObjectInWorld
(guid,
_player
);
22
23
// check cheating
24
uint8
levels =
_player
->GetGrantableLevels();
25
uint8
error = 0;
26
if
(!target)
27
error =
ERR_REFER_A_FRIEND_NO_TARGET
;
28
else
if
(levels == 0)
29
error =
ERR_REFER_A_FRIEND_INSUFFICIENT_GRANTABLE_LEVELS
;
30
else
if
(
GetRecruiterId
() != target->
GetSession
()->
GetAccountId
())
31
error =
ERR_REFER_A_FRIEND_NOT_REFERRED_BY
;
32
else
if
(target->
GetTeamId
() !=
_player
->GetTeamId())
33
error =
ERR_REFER_A_FRIEND_DIFFERENT_FACTION
;
34
else
if
(target->
getLevel
() >=
_player
->getLevel())
35
error =
ERR_REFER_A_FRIEND_TARGET_TOO_HIGH
;
36
else
if
(target->
getLevel
() >=
sWorld
->getIntConfig(
WorldIntConfigs::CONFIG_MAX_RECRUIT_A_FRIEND_BONUS_PLAYER_LEVEL
))
37
error =
ERR_REFER_A_FRIEND_GRANT_LEVEL_MAX_I
;
38
else
if
(target->
GetGroup
() !=
_player
->GetGroup())
39
error =
ERR_REFER_A_FRIEND_NOT_IN_GROUP
;
40
41
if
(error)
42
{
43
WorldPacket
data(
SMSG_REFER_A_FRIEND_FAILURE
, 24);
44
data <<
uint32
(error);
45
if
(error ==
ERR_REFER_A_FRIEND_NOT_IN_GROUP
)
46
data << target->
GetName
();
47
48
SendPacket
(&data);
49
return
;
50
}
51
52
WorldPacket
data2(
SMSG_PROPOSE_LEVEL_GRANT
, 8);
53
54
data2.
WriteGuidMask
(guid, 6, 7, 2, 5, 3, 0, 1, 4);
55
data2.
WriteGuidBytes
(guid, 2, 5, 6, 7, 1, 4, 3, 0);
56
57
target->
GetSession
()->
SendPacket
(&data2);
58
}
59
60
void
WorldSession::HandleAcceptGrantLevel
(
WorldPacket
& recvData)
61
{
62
SF_LOG_DEBUG
(
"network"
,
"WORLD: CMSG_ACCEPT_LEVEL_GRANT"
);
63
64
ObjectGuid
guid;
65
66
recvData.
ReadGuidMask
(guid, 2, 7, 5, 4, 3, 0, 1, 6);
67
recvData.
ReadGuidBytes
(guid, 5, 3, 2, 7, 4, 1, 0, 6);
68
69
Player
* other =
ObjectAccessor::GetObjectInWorld
(guid,
_player
);
70
if
(!(other && other->
GetSession
()))
71
return
;
72
73
if
(
GetAccountId
() != other->
GetSession
()->
GetRecruiterId
())
74
return
;
75
76
if
(other->
GetGrantableLevels
())
77
other->
SetGrantableLevels
(other->
GetGrantableLevels
() - 1);
78
else
79
return
;
80
81
_player
->GiveLevel(
_player
->getLevel() + 1);
82
}
uint8
std::uint8_t uint8
Definition
Define.h:79
uint32
std::uint32_t uint32
Definition
Define.h:77
Log.h
SF_LOG_DEBUG
#define SF_LOG_DEBUG(filterType__,...)
Definition
Log.h:134
ObjectMgr.h
Opcodes.h
Player.h
ERR_REFER_A_FRIEND_TARGET_TOO_HIGH
@ ERR_REFER_A_FRIEND_TARGET_TOO_HIGH
Definition
Player.h:964
ERR_REFER_A_FRIEND_DIFFERENT_FACTION
@ ERR_REFER_A_FRIEND_DIFFERENT_FACTION
Definition
Player.h:967
ERR_REFER_A_FRIEND_NO_TARGET
@ ERR_REFER_A_FRIEND_NO_TARGET
Definition
Player.h:970
ERR_REFER_A_FRIEND_INSUFFICIENT_GRANTABLE_LEVELS
@ ERR_REFER_A_FRIEND_INSUFFICIENT_GRANTABLE_LEVELS
Definition
Player.h:965
ERR_REFER_A_FRIEND_NOT_REFERRED_BY
@ ERR_REFER_A_FRIEND_NOT_REFERRED_BY
Definition
Player.h:963
ERR_REFER_A_FRIEND_NOT_IN_GROUP
@ ERR_REFER_A_FRIEND_NOT_IN_GROUP
Definition
Player.h:971
ERR_REFER_A_FRIEND_GRANT_LEVEL_MAX_I
@ ERR_REFER_A_FRIEND_GRANT_LEVEL_MAX_I
Definition
Player.h:969
WorldSession.h
ByteBuffer::WriteGuidBytes
void WriteGuidBytes(const ObjectGuid &guid, Offsets... offsets)
Definition
ByteBuffer.h:264
ByteBuffer::WriteGuidMask
void WriteGuidMask(const ObjectGuid &guid, Offsets... offsets)
Definition
ByteBuffer.h:248
ByteBuffer::ReadGuidBytes
void ReadGuidBytes(ObjectGuid &guid, Offsets... offsets)
Definition
ByteBuffer.h:256
ByteBuffer::ReadGuidMask
void ReadGuidMask(ObjectGuid &guid, Offsets... offsets)
Definition
ByteBuffer.h:240
ObjectAccessor::GetObjectInWorld
static T * GetObjectInWorld(uint64 guid, T *)
Definition
ObjectAccessor.h:84
Player
Definition
Player.h:1289
Player::GetGrantableLevels
uint8 GetGrantableLevels() const
Definition
Player.h:2546
Player::SetGrantableLevels
void SetGrantableLevels(uint8 val)
Definition
Player.h:2550
Player::GetSession
WorldSession * GetSession() const
Definition
Player.h:2417
Player::GetTeamId
TeamId GetTeamId() const
Definition
Player.h:2531
Player::GetGroup
Group * GetGroup()
Definition
Player.h:2972
Unit::getLevel
uint8 getLevel() const
Definition
Unit.h:1528
WorldObject::GetName
std::string const & GetName() const
Definition
Object.h:664
WorldPacket
Definition
WorldPacket.h:16
WorldSession::GetRecruiterId
uint32 GetRecruiterId() const
Definition
WorldSession.h:512
WorldSession::HandleAcceptGrantLevel
void HandleAcceptGrantLevel(WorldPacket &recvData)
Definition
ReferAFriendHandler.cpp:60
WorldSession::SendPacket
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
Definition
WorldSession.cpp:196
WorldSession::GetAccountId
uint32 GetAccountId() const
Definition
WorldSession.h:294
WorldSession::_player
Player * _player
Definition
WorldSession.h:1188
WorldSession::HandleGrantLevel
void HandleGrantLevel(WorldPacket &recvData)
Definition
ReferAFriendHandler.cpp:12
SMSG_REFER_A_FRIEND_FAILURE
@ SMSG_REFER_A_FRIEND_FAILURE
Definition
Opcodes.h:932
SMSG_PROPOSE_LEVEL_GRANT
@ SMSG_PROPOSE_LEVEL_GRANT
Definition
Opcodes.h:890
sWorld
#define sWorld
Definition
World.h:910
WorldIntConfigs::CONFIG_MAX_RECRUIT_A_FRIEND_BONUS_PLAYER_LEVEL
@ CONFIG_MAX_RECRUIT_A_FRIEND_BONUS_PLAYER_LEVEL
Definition
World.h:240
ObjectGuid
Definition
ByteBuffer.h:66
src
server
game
Handlers
ReferAFriendHandler.cpp
Generated on
for Project SkyFire Core by
1.17.0