Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
BattlefieldHandler.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 "
Common.h
"
7
#include "
Object.h
"
8
#include "
ObjectAccessor.h
"
9
#include "
ObjectMgr.h
"
10
#include "
WorldPacket.h
"
11
#include "
WorldSession.h
"
12
13
#include "
Battlefield.h
"
14
#include "
BattlefieldMgr.h
"
15
#include "
Opcodes.h
"
16
#include "
Player.h
"
17
18
//This send to player windows for invite player to join the war
19
//Param1:(guid) the guid of Bf
20
//Param2:(ZoneId) the zone where the battle is (4197 for wg)
21
//Param3:(time) Time in second that the player have for accept
22
void
WorldSession::SendBfInvitePlayerToWar
(
uint64
guid,
uint32
zoneId,
uint32
pTime)
23
{
24
ObjectGuid
guidBytes = guid;
25
26
WorldPacket
data(
SMSG_BATTLEFIELD_MGR_ENTRY_INVITE
, 16);
27
28
data.
WriteGuidMask
(guidBytes, 5, 3, 7, 2, 6, 4, 1, 0);
29
30
data.
WriteGuidBytes
(guidBytes, 6);
31
data <<
uint32
(zoneId);
// Zone Id
32
data.
WriteGuidBytes
(guidBytes, 1, 3, 4, 2, 0);
33
data <<
uint32
(time(NULL) + pTime);
// Invite lasts until
34
data.
WriteGuidBytes
(guidBytes, 7, 5);
35
36
//Sending the packet to player
37
SendPacket
(&data);
38
}
39
40
//This send invitation to player to join the queue
41
void
WorldSession::SendBfInvitePlayerToQueue
(
uint64
guid)
42
{
43
ObjectGuid
guidBytes = guid;
44
45
WorldPacket
data(
SMSG_BATTLEFIELD_MGR_QUEUE_INVITE
, 5);
46
47
data.
WriteBit
(1);
// unk
48
data.
WriteBit
(0);
// Has Warmup
49
data.
WriteBit
(1);
// unk
50
data.
WriteBit
(guidBytes[0]);
51
data.
WriteBit
(1);
// unk
52
data.
WriteBit
(guidBytes[2]);
53
data.
WriteBit
(guidBytes[6]);
54
data.
WriteBit
(guidBytes[3]);
55
data.
WriteBit
(1);
// unk
56
data.
WriteBit
(0);
// unk
57
data.
WriteBit
(guidBytes[1]);
58
data.
WriteBit
(guidBytes[5]);
59
data.
WriteBit
(guidBytes[4]);
60
data.
WriteBit
(1);
// unk
61
data.
WriteBit
(guidBytes[7]);
62
63
data.
FlushBits
();
64
65
data.
WriteByteSeq
(guidBytes[2]);
66
data.
WriteByteSeq
(guidBytes[3]);
67
data.
WriteByteSeq
(guidBytes[6]);
68
data <<
uint8
(1);
// Warmup
69
data.
WriteByteSeq
(guidBytes[5]);
70
data.
WriteByteSeq
(guidBytes[0]);
71
data.
WriteByteSeq
(guidBytes[4]);
72
data.
WriteByteSeq
(guidBytes[1]);
73
data.
WriteByteSeq
(guidBytes[7]);
74
75
//Sending packet to player
76
SendPacket
(&data);
77
}
78
79
//This send packet for inform player that he join queue
80
//Param1:(guid) the guid of Bf
81
//Param2:(ZoneId) the zone where the battle is (4197 for wg)
82
//Param3:(CanQueue) if able to queue
83
//Param4:(Full) on log in is full
84
void
WorldSession::SendBfQueueInviteResponse
(
uint64
guid,
uint32
ZoneId,
bool
CanQueue,
bool
Full)
85
{
86
const
bool
hasSecondGuid =
false
;
87
const
bool
warmup =
true
;
88
ObjectGuid
guidBytes = guid;
89
90
WorldPacket
data(
SMSG_BATTLEFIELD_MGR_QUEUE_REQUEST_RESPONSE
, 16);
91
92
data.
WriteBit
(guidBytes[1]);
93
data.
WriteBit
(guidBytes[6]);
94
data.
WriteBit
(guidBytes[5]);
95
data.
WriteBit
(guidBytes[7]);
96
data.
WriteBit
(Full);
// Logging In, VERIFYME
97
data.
WriteBit
(guidBytes[0]);
98
data.
WriteBit
(!hasSecondGuid);
99
data.
WriteBit
(guidBytes[4]);
100
101
// if (hasSecondGuid) 7 3 0 4 2 6 1 5
102
103
data.
WriteBit
(guidBytes[3]);
104
data.
WriteBit
(guidBytes[2]);
105
106
// if (hasSecondGuid) 2 5 3 0 4 6 1 7
107
108
data.
FlushBits
();
109
110
data <<
uint8
(CanQueue);
// Accepted
111
112
data.
WriteByteSeq
(guidBytes[1]);
113
data.
WriteByteSeq
(guidBytes[3]);
114
data.
WriteByteSeq
(guidBytes[6]);
115
data.
WriteByteSeq
(guidBytes[7]);
116
data.
WriteByteSeq
(guidBytes[0]);
117
118
data <<
uint8
(warmup);
119
120
data.
WriteByteSeq
(guidBytes[2]);
121
data.
WriteByteSeq
(guidBytes[4]);
122
data.
WriteByteSeq
(guidBytes[5]);
123
124
data <<
uint32
(ZoneId);
125
126
SendPacket
(&data);
127
}
128
129
//This is call when player accept to join war
130
void
WorldSession::SendBfEntered
(
uint64
guid)
131
{
132
uint8
isAFK =
_player
->isAFK() ? 1 : 0;
133
ObjectGuid
guidBytes = guid;
134
135
WorldPacket
data(
SMSG_BATTLEFIELD_MGR_ENTERED
, 11);
136
data.
WriteBit
(guidBytes[5]);
137
data.
WriteBit
(guidBytes[0]);
138
data.
WriteBit
(0);
// unk
139
data.
WriteBit
(isAFK);
// Clear AFK
140
data.
WriteBit
(guidBytes[7]);
141
data.
WriteBit
(guidBytes[4]);
142
data.
WriteBit
(guidBytes[2]);
143
data.
WriteBit
(0);
// unk
144
data.
WriteBit
(guidBytes[1]);
145
data.
WriteBit
(guidBytes[3]);
146
data.
WriteBit
(guidBytes[6]);
147
148
data.
FlushBits
();
149
150
data.
WriteByteSeq
(guidBytes[2]);
151
data.
WriteByteSeq
(guidBytes[5]);
152
data.
WriteByteSeq
(guidBytes[0]);
153
data.
WriteByteSeq
(guidBytes[6]);
154
data.
WriteByteSeq
(guidBytes[7]);
155
data.
WriteByteSeq
(guidBytes[3]);
156
data.
WriteByteSeq
(guidBytes[4]);
157
data.
WriteByteSeq
(guidBytes[1]);
158
SendPacket
(&data);
159
}
160
161
void
WorldSession::SendBfLeaveMessage
(
uint64
guid,
BFLeaveReason
reason)
162
{
163
ObjectGuid
guidBytes = guid;
164
165
WorldPacket
data(
SMSG_BATTLEFIELD_MGR_EJECTED
, 11);
166
data.
WriteGuidMask
(guidBytes, 5);
167
data.
WriteBit
(0);
// Relocated
168
data.
WriteGuidMask
(guidBytes, 4, 0, 2, 7, 1, 6, 3);
169
170
data.
WriteGuidBytes
(guidBytes, 0, 2, 3, 4, 6, 5);
171
data <<
uint8
(2);
// BattleStatus
172
data <<
uint8
(reason);
// Reason
173
data.
WriteGuidBytes
(guidBytes, 7, 1);
174
SendPacket
(&data);
175
}
176
177
//Send by client when he click on accept for queue
178
void
WorldSession::HandleBfQueueInviteResponse
(
WorldPacket
& recvData)
179
{
180
uint8
accepted;
181
ObjectGuid
guid;
182
183
recvData.
ReadGuidMask
(guid, 3, 6, 0, 2);
184
accepted = recvData.
ReadBit
();
185
recvData.
ReadGuidMask
(guid, 1, 5, 7, 4);
186
187
recvData.
ReadGuidBytes
(guid, 4, 1, 2, 6, 0, 7, 5, 3);
188
189
SF_LOG_ERROR
(
"misc"
,
"HandleQueueInviteResponse: GUID:"
UI64FMTD
" Accepted:%u"
, (
uint64
)guid, accepted);
190
191
Battlefield
* bf =
sBattlefieldMgr
->GetBattlefieldByGUID(guid);
192
if
(!bf)
193
return
;
194
195
if
(accepted)
196
bf->
PlayerAcceptInviteToQueue
(
_player
);
197
}
198
199
//Send by client on clicking in accept or refuse of invitation windows for join game
200
void
WorldSession::HandleBfEntryInviteResponse
(
WorldPacket
& recvData)
201
{
202
uint8
accepted;
203
ObjectGuid
guid;
204
205
recvData.
ReadGuidMask
(guid, 0, 7);
206
accepted = recvData.
ReadBit
();
207
recvData.
ReadGuidMask
(guid, 4, 3, 1, 6, 2, 5);
208
209
recvData.
ReadGuidBytes
(guid, 1, 6, 2, 5, 3, 4, 7, 0);
210
211
SF_LOG_ERROR
(
"misc"
,
"HandleBattlefieldInviteResponse: GUID:"
UI64FMTD
" Accepted:%u"
, (
uint64
)guid, accepted);
212
213
Battlefield
* bf =
sBattlefieldMgr
->GetBattlefieldByGUID(guid);
214
if
(!bf)
215
return
;
216
217
if
(accepted)
218
bf->
PlayerAcceptInviteToWar
(
_player
);
219
else
220
if
(
_player
->GetZoneId() == bf->
GetZoneId
())
221
bf->
KickPlayerFromBattlefield
(
_player
->GetGUID());
222
}
223
224
void
WorldSession::HandleBfExitRequest
(
WorldPacket
& recvData)
225
{
226
ObjectGuid
guid;
227
228
recvData.
ReadGuidMask
(guid, 3, 2, 4, 1, 7, 0, 5, 6);
229
recvData.
ReadGuidBytes
(guid, 5, 6, 2, 3, 0, 4, 7, 1);
230
231
SF_LOG_ERROR
(
"misc"
,
"HandleBfExitRequest: GUID:"
UI64FMTD
" "
, (
uint64
)guid);
232
233
if
(
Battlefield
* bf =
sBattlefieldMgr
->GetBattlefieldByGUID(guid))
234
bf->AskToLeaveQueue(
_player
);
235
}
236
237
void
WorldSession::HandleBattlefieldRatedInfoRequest
(
WorldPacket
& recvData)
238
{
239
WorldPacket
data(
SMSG_BATTLEFIELD_RATED_INFO
, 4 * (8 * 4));
240
for
(
uint8
i = 0; i < 4; i++)
241
{
242
//TODO: PLAYER_FIELD_PVP_INFO, Updatefield Data 8*3 = size 24
243
data <<
uint32
(0);
244
data <<
uint32
(0);
245
data <<
uint32
(0);
246
data <<
uint32
(0);
247
data <<
uint32
(0);
248
data <<
uint32
(0);
249
data <<
uint32
(0);
250
data <<
uint32
(0);
251
}
252
SendPacket
(&data);
253
}
Battlefield.h
BattlefieldMgr.h
sBattlefieldMgr
#define sBattlefieldMgr
Definition
BattlefieldMgr.h:65
Common.h
UI64FMTD
#define UI64FMTD
Definition
Define.h:64
uint8
std::uint8_t uint8
Definition
Define.h:79
uint32
std::uint32_t uint32
Definition
Define.h:77
uint64
std::uint64_t uint64
Definition
Define.h:76
SF_LOG_ERROR
#define SF_LOG_ERROR(filterType__,...)
Definition
Log.h:143
Object.h
ObjectAccessor.h
ObjectMgr.h
Opcodes.h
Player.h
WorldPacket.h
WorldSession.h
Battlefield
Definition
Battlefield.h:184
Battlefield::GetZoneId
uint32 GetZoneId() const
Definition
Battlefield.h:225
Battlefield::PlayerAcceptInviteToWar
void PlayerAcceptInviteToWar(Player *player)
Definition
Battlefield.cpp:349
Battlefield::PlayerAcceptInviteToQueue
void PlayerAcceptInviteToQueue(Player *player)
Definition
Battlefield.cpp:333
Battlefield::KickPlayerFromBattlefield
void KickPlayerFromBattlefield(uint64 guid)
Kick player from battlefield and teleport him to kick-point location.
Definition
Battlefield.cpp:262
ByteBuffer::WriteGuidBytes
void WriteGuidBytes(const ObjectGuid &guid, Offsets... offsets)
Definition
ByteBuffer.h:264
ByteBuffer::WriteBit
bool WriteBit(uint32 bit)
Definition
ByteBuffer.h:164
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
ByteBuffer::WriteByteSeq
void WriteByteSeq(uint8 b)
Definition
ByteBuffer.h:227
ByteBuffer::FlushBits
void FlushBits()
Definition
ByteBuffer.h:154
ByteBuffer::ReadBit
bool ReadBit()
Definition
ByteBuffer.h:180
WorldPacket
Definition
WorldPacket.h:16
WorldSession::HandleBfExitRequest
void HandleBfExitRequest(WorldPacket &recvData)
Definition
BattlefieldHandler.cpp:224
WorldSession::SendBfLeaveMessage
void SendBfLeaveMessage(uint64 guid, BFLeaveReason reason=BF_LEAVE_REASON_EXITED)
Definition
BattlefieldHandler.cpp:161
WorldSession::HandleBfQueueInviteResponse
void HandleBfQueueInviteResponse(WorldPacket &recvData)
Definition
BattlefieldHandler.cpp:178
WorldSession::HandleBfEntryInviteResponse
void HandleBfEntryInviteResponse(WorldPacket &recvData)
Definition
BattlefieldHandler.cpp:200
WorldSession::SendBfEntered
void SendBfEntered(uint64 guid)
Definition
BattlefieldHandler.cpp:130
WorldSession::SendPacket
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
Definition
WorldSession.cpp:196
WorldSession::SendBfQueueInviteResponse
void SendBfQueueInviteResponse(uint64 guid, uint32 zoneId, bool canQueue=true, bool full=false)
Definition
BattlefieldHandler.cpp:84
WorldSession::HandleBattlefieldRatedInfoRequest
void HandleBattlefieldRatedInfoRequest(WorldPacket &recvData)
Definition
BattlefieldHandler.cpp:237
WorldSession::_player
Player * _player
Definition
WorldSession.h:1188
WorldSession::SendBfInvitePlayerToWar
void SendBfInvitePlayerToWar(uint64 guid, uint32 zoneId, uint32 time)
Definition
BattlefieldHandler.cpp:22
WorldSession::SendBfInvitePlayerToQueue
void SendBfInvitePlayerToQueue(uint64 guid)
Definition
BattlefieldHandler.cpp:41
BFLeaveReason
BFLeaveReason
Definition
WorldSession.h:97
SMSG_BATTLEFIELD_MGR_EJECTED
@ SMSG_BATTLEFIELD_MGR_EJECTED
Definition
Opcodes.h:537
SMSG_BATTLEFIELD_MGR_ENTRY_INVITE
@ SMSG_BATTLEFIELD_MGR_ENTRY_INVITE
Definition
Opcodes.h:539
SMSG_BATTLEFIELD_RATED_INFO
@ SMSG_BATTLEFIELD_RATED_INFO
Definition
Opcodes.h:543
SMSG_BATTLEFIELD_MGR_ENTERED
@ SMSG_BATTLEFIELD_MGR_ENTERED
Definition
Opcodes.h:538
SMSG_BATTLEFIELD_MGR_QUEUE_REQUEST_RESPONSE
@ SMSG_BATTLEFIELD_MGR_QUEUE_REQUEST_RESPONSE
Definition
Opcodes.h:541
SMSG_BATTLEFIELD_MGR_QUEUE_INVITE
@ SMSG_BATTLEFIELD_MGR_QUEUE_INVITE
Definition
Opcodes.h:540
ObjectGuid
Definition
ByteBuffer.h:66
src
server
game
Handlers
BattlefieldHandler.cpp
Generated on
for Project SkyFire Core by
1.17.0