Project SkyFire Core
SkyFire 5.4.8 server core API documentation
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
23{
24 ObjectGuid guidBytes = guid;
25
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
42{
43 ObjectGuid guidBytes = guid;
44
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
84void 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
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
131{
132 uint8 isAFK = _player->isAFK() ? 1 : 0;
133 ObjectGuid guidBytes = guid;
134
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
162{
163 ObjectGuid guidBytes = guid;
164
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
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)
197}
198
199//Send by client on clicking in accept or refuse of invitation windows for join game
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)
219 else
220 if (_player->GetZoneId() == bf->GetZoneId())
221 bf->KickPlayerFromBattlefield(_player->GetGUID());
222}
223
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
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}
#define sBattlefieldMgr
#define UI64FMTD
Definition Define.h:64
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
std::uint64_t uint64
Definition Define.h:76
#define SF_LOG_ERROR(filterType__,...)
Definition Log.h:143
uint32 GetZoneId() const
void PlayerAcceptInviteToWar(Player *player)
void PlayerAcceptInviteToQueue(Player *player)
void KickPlayerFromBattlefield(uint64 guid)
Kick player from battlefield and teleport him to kick-point location.
void WriteGuidBytes(const ObjectGuid &guid, Offsets... offsets)
Definition ByteBuffer.h:264
bool WriteBit(uint32 bit)
Definition ByteBuffer.h:164
void WriteGuidMask(const ObjectGuid &guid, Offsets... offsets)
Definition ByteBuffer.h:248
void ReadGuidBytes(ObjectGuid &guid, Offsets... offsets)
Definition ByteBuffer.h:256
void ReadGuidMask(ObjectGuid &guid, Offsets... offsets)
Definition ByteBuffer.h:240
void WriteByteSeq(uint8 b)
Definition ByteBuffer.h:227
void FlushBits()
Definition ByteBuffer.h:154
bool ReadBit()
Definition ByteBuffer.h:180
void HandleBfExitRequest(WorldPacket &recvData)
void SendBfLeaveMessage(uint64 guid, BFLeaveReason reason=BF_LEAVE_REASON_EXITED)
void HandleBfQueueInviteResponse(WorldPacket &recvData)
void HandleBfEntryInviteResponse(WorldPacket &recvData)
void SendBfEntered(uint64 guid)
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
void SendBfQueueInviteResponse(uint64 guid, uint32 zoneId, bool canQueue=true, bool full=false)
void HandleBattlefieldRatedInfoRequest(WorldPacket &recvData)
Player * _player
void SendBfInvitePlayerToWar(uint64 guid, uint32 zoneId, uint32 time)
void SendBfInvitePlayerToQueue(uint64 guid)
BFLeaveReason
@ SMSG_BATTLEFIELD_MGR_EJECTED
Definition Opcodes.h:537
@ SMSG_BATTLEFIELD_MGR_ENTRY_INVITE
Definition Opcodes.h:539
@ SMSG_BATTLEFIELD_RATED_INFO
Definition Opcodes.h:543
@ SMSG_BATTLEFIELD_MGR_ENTERED
Definition Opcodes.h:538
@ SMSG_BATTLEFIELD_MGR_QUEUE_REQUEST_RESPONSE
Definition Opcodes.h:541
@ SMSG_BATTLEFIELD_MGR_QUEUE_INVITE
Definition Opcodes.h:540