/
party.go
477 lines (420 loc) · 11.1 KB
/
party.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
package party
import (
"encoding/binary"
"fmt"
"io"
"github.com/Gophercraft/core/guid"
"github.com/Gophercraft/core/packet"
"github.com/Gophercraft/core/vsn"
)
const (
GroupNormal = 0
GroupRaid = 1
)
type MemberStatus uint8
const (
MemberOffline = 0x0000
MemberOnline = 0x0001 // Lua_UnitIsConnected
MemberPVP = 0x0002 // Lua_UnitIsPVP
MemberDead = 0x0004 // Lua_UnitIsDead
MemberGhost = 0x0008 // Lua_UnitIsGhost
MemberPVPFFA = 0x0010 // Lua_UnitIsPVPFreeForAll
MemberZoneOut = 0x0020 // Lua_GetPlayerMapPosition
MemberAFK = 0x0040 // Lua_UnitIsAFK
MemberDND = 0x0080 // Lua_UnitIsDND
)
const (
GroupUpdateNone = 0x00000000 // nothing
GroupUpdateStatus = 0x00000001 // uint16, flags
GroupUpdateCurrentHealth = 0x00000002 // uint32
GroupUpdateMaxHealth = 0x00000004 // uint32
GroupUpdatePowerType = 0x00000008 // uint8
GroupUpdateCurrentPower = 0x00000010 // uint16
GroupUpdateMaxPower = 0x00000020 // uint16
GroupUpdateLevel = 0x00000040 // uint16
GroupUpdateZone = 0x00000080 // uint16
GroupUpdatePosition = 0x00000100 // uint16, uint16
GroupUpdateAuras = 0x00000200 // uint64 mask, for each bit set uint32 spellid + uint8 unk
GroupUpdatePetGUID = 0x00000400 // uint64 pet guid
GroupUpdatePetName = 0x00000800 // pet name, nullptr terminated string
GroupUpdatePetModelID = 0x00001000 // uint16, model id
GroupUpdatePetCurrentHP = 0x00002000 // uint32 pet cur health
GroupUpdatePetMaxHP = 0x00004000 // uint32 pet max health
GroupUpdatePetPowerType = 0x00008000 // uint8 pet power type
GroupUpdatePetCurrentPower = 0x00010000 // uint16 pet cur power
GroupUpdatePetMaxPower = 0x00020000 // uint16 pet max power
GroupUpdatePetAuras = 0x00040000 // uint64 mask, for each bit set uint32 spellid + uint8 unk, pet auras...
GroupUpdateVehicleSeat = 0x00080000 // uint32 vehicle_seat_id (index from VehicleSeat.dbc)
GroupUpdatePet = 0x0007FC00 // all pet flags
GroupUpdateFull = 0x0007FFFF // all known flags
)
type Operation uint32
const (
Invite Operation = 0
Leave Operation = 2
Swap Operation = 4
)
type Result uint32
const (
OK Result = iota
BadPlayerName
TargetNotInGroup
TargetNotInInstance
GroupFull
AlreadyInGroup
NotInGroup
NotLeader
WrongFaction
IgnoringYou
InviteRestricted
LFGPending
)
type ResultDescriptor map[Result]uint32
var ResultDescriptors = map[vsn.BuildRange]ResultDescriptor{
{0, 3368}: {
OK: 0,
BadPlayerName: 1,
TargetNotInGroup: 2,
TargetNotInInstance: 3,
GroupFull: 4,
AlreadyInGroup: 5,
NotInGroup: 6,
NotLeader: 7,
WrongFaction: 8,
IgnoringYou: 9,
InviteRestricted: 13,
},
{5875, 6005}: {
OK: 0,
BadPlayerName: 1,
TargetNotInGroup: 2,
GroupFull: 3,
AlreadyInGroup: 4,
NotInGroup: 5,
NotLeader: 6,
WrongFaction: 7,
IgnoringYou: 8,
},
{vsn.V2_0_1, vsn.Max}: {
OK: 0,
BadPlayerName: 1,
TargetNotInGroup: 2,
TargetNotInInstance: 3,
GroupFull: 4,
AlreadyInGroup: 5,
NotInGroup: 6,
NotLeader: 7,
WrongFaction: 8,
IgnoringYou: 9,
LFGPending: 12,
InviteRestricted: 13,
},
}
func EncodeResult(build vsn.Build, out io.Writer, pr Result) error {
var desc ResultDescriptor
if err := vsn.QueryDescriptors(build, ResultDescriptors, &desc); err != nil {
return err
}
op, ok := desc[pr]
if !ok {
return fmt.Errorf("packet: no Result code found for %v in %s", pr, build)
}
var u32 [4]byte
binary.LittleEndian.PutUint32(u32[:], op)
_, err := out.Write(u32[:])
return err
}
func DecodeResult(build vsn.Build, in io.Reader) (Result, error) {
var desc ResultDescriptor
if err := vsn.QueryDescriptors(build, ResultDescriptors, &desc); err != nil {
return 0, err
}
var u32 [4]byte
if _, err := in.Read(u32[:]); err != nil {
return 0, err
}
code := binary.LittleEndian.Uint32(u32[:])
for k, vcode := range desc {
if vcode == code {
return k, nil
}
}
return 0, fmt.Errorf("packet: no Result code found for %v in %s", code, build)
}
type RequestMemberStats struct {
Member guid.GUID
}
func (p *RequestMemberStats) Encode(build vsn.Build, out *packet.WorldPacket) error {
out.Type = packet.CMSG_REQUEST_PARTY_MEMBER_STATS
p.Member.EncodeUnpacked(build, out)
return nil
}
func (p *RequestMemberStats) Decode(build vsn.Build, in *packet.WorldPacket) error {
var err error
p.Member, err = guid.DecodeUnpacked(build, in)
return err
}
type MemberAuraState struct {
SpellID int32
Flags uint16
ActiveFlags uint32
Points []float32
}
type MemberStats struct {
ChangeMask uint32
Member guid.GUID
Status MemberStatus
CurrentHealth uint32
MaxHealth uint32
PowerType uint8
Power uint16
MaxPower uint16
Level uint16
ZoneID uint16
PositionX uint16
PositionY uint16
Auras []MemberAuraState
Pet guid.GUID
PetName string
PetDisplayID uint32
PetCurrentHealth uint32
PetMaxHealth uint32
PetPowerType uint16
PetPower uint16
PetMaxPower uint16
PetAuras []MemberAuraState
VehicleSeat uint32
}
func (p *MemberStats) Change(status uint32) bool {
return p.ChangeMask&status != 0
}
func writeHealth(build vsn.Build, value uint32, out *packet.WorldPacket) {
if build.AddedIn(vsn.V2_0_1) {
out.WriteUint32(value)
return
}
out.WriteUint16(uint16(value))
}
func readHealth(build vsn.Build, in *packet.WorldPacket) uint32 {
if build.AddedIn(vsn.V2_0_1) {
return in.ReadUint32()
}
return uint32(in.ReadUint16())
}
func writeAuras(build vsn.Build, auras []MemberAuraState, out *packet.WorldPacket) {
var mask uint64
for i, aura := range auras {
if aura.SpellID > 0 {
mask |= 1 << uint64(i)
}
}
if build.AddedIn(vsn.V2_0_1) {
out.WriteUint64(mask)
} else {
out.WriteUint32(uint32(mask))
}
for i, aura := range auras {
if mask&(1<<uint64(i)) != 0 {
switch {
case build < vsn.V2_0_1:
out.WriteUint16(uint16(aura.SpellID))
case vsn.Range(vsn.V2_0_1, vsn.V3_3_5a).Contains(build):
out.WriteInt32(aura.SpellID)
out.WriteByte(uint8(aura.Flags))
default:
panic("verify behavior in writeAuras for this build")
}
}
}
}
func readAuras(build vsn.Build, in *packet.WorldPacket) []MemberAuraState {
var mask uint64
var maskLen int
if build.AddedIn(vsn.V2_0_1) {
mask = in.ReadUint64()
maskLen = 64
} else {
mask = uint64(in.ReadUint32())
maskLen = 32
}
pmas := make([]MemberAuraState, maskLen)
for i := 0; i < maskLen; i++ {
if mask&(1<<uint64(i)) != 0 {
state := &pmas[i]
switch {
case build < vsn.V2_0_1:
state.SpellID = in.ReadInt32()
case vsn.Range(vsn.V2_0_1, vsn.V3_3_5a).Contains(build):
state.SpellID = in.ReadInt32()
state.Flags = uint16(in.ReadByte())
default:
panic("verify behavior in readAuras for this build")
}
}
}
return pmas
}
func (p *MemberStats) Encode(build vsn.Build, out *packet.WorldPacket) error {
out.Type = packet.SMSG_PARTY_MEMBER_STATS_FULL
if build.AddedIn(vsn.V2_0_1) {
out.WriteByte(0)
}
p.Member.EncodePacked(build, out)
out.WriteUint32(p.ChangeMask)
if p.Change(GroupUpdateStatus) {
out.WriteByte(uint8(p.Status))
}
if p.Change(GroupUpdateCurrentHealth) {
writeHealth(build, p.CurrentHealth, out)
}
if p.Change(GroupUpdateMaxHealth) {
writeHealth(build, p.MaxHealth, out)
}
if p.Change(GroupUpdatePowerType) {
out.WriteByte(p.PowerType)
}
if p.Change(GroupUpdateCurrentPower) {
out.WriteUint16(p.Power)
}
if p.Change(GroupUpdateMaxPower) {
out.WriteUint16(p.MaxPower)
}
if p.Change(GroupUpdateLevel) {
out.WriteUint16(p.Level)
}
if p.Change(GroupUpdateZone) {
out.WriteUint16(p.ZoneID)
}
if p.Change(GroupUpdatePosition) {
out.WriteUint16(p.PositionX)
out.WriteUint16(p.PositionY)
}
if p.Change(GroupUpdateAuras) {
writeAuras(build, p.Auras, out)
}
if p.Change(GroupUpdatePetGUID) {
p.Pet.EncodeUnpacked(build, out)
}
if p.Change(GroupUpdatePetName) {
out.WriteCString(p.PetName)
}
if p.Change(GroupUpdatePetModelID) {
out.WriteUint16(uint16(p.PetDisplayID))
}
if p.Change(GroupUpdatePetCurrentHP) {
writeHealth(build, p.PetCurrentHealth, out)
}
if p.Change(GroupUpdatePetMaxHP) {
writeHealth(build, p.PetMaxHealth, out)
}
if p.Change(GroupUpdatePetPowerType) {
out.WriteByte(uint8(p.PetPowerType))
}
if p.Change(GroupUpdatePetCurrentPower) {
out.WriteUint16(p.PetPower)
}
if p.Change(GroupUpdatePetMaxPower) {
out.WriteUint16(p.PetMaxPower)
}
if p.Change(GroupUpdatePetAuras) {
writeAuras(build, p.PetAuras, out)
}
if p.Change(GroupUpdateVehicleSeat) {
out.WriteUint32(uint32(p.VehicleSeat))
}
return nil
}
func (p *MemberStats) Decode(build vsn.Build, in *packet.WorldPacket) error {
var err error
if build.AddedIn(vsn.V2_0_1) {
in.ReadByte()
}
p.Member, err = guid.DecodePacked(build, in)
if err != nil {
return err
}
p.ChangeMask = in.ReadUint32()
if p.Change(GroupUpdateStatus) {
p.Status = MemberStatus(in.ReadByte())
}
if p.Change(GroupUpdateCurrentHealth) {
p.CurrentHealth = readHealth(build, in)
}
if p.Change(GroupUpdateMaxHealth) {
p.MaxHealth = readHealth(build, in)
}
if p.Change(GroupUpdatePowerType) {
p.PowerType = in.ReadByte()
}
if p.Change(GroupUpdateCurrentPower) {
p.Power = in.ReadUint16()
}
if p.Change(GroupUpdateMaxPower) {
p.MaxPower = in.ReadUint16()
p.MaxPower = in.ReadBigUint16()
}
if p.Change(GroupUpdateLevel) {
p.Level = in.ReadUint16()
}
if p.Change(GroupUpdateZone) {
p.ZoneID = in.ReadUint16()
}
if p.Change(GroupUpdatePosition) {
p.PositionX = in.ReadUint16()
p.PositionY = in.ReadUint16()
}
if p.Change(GroupUpdateAuras) {
p.Auras = readAuras(build, in)
}
if p.Change(GroupUpdatePetGUID) {
p.Pet, err = guid.DecodeUnpacked(build, in)
if err != nil {
return err
}
}
if p.Change(GroupUpdatePetName) {
p.PetName = in.ReadCString()
}
if p.Change(GroupUpdatePetModelID) {
p.PetDisplayID = uint32(in.ReadUint16())
}
if p.Change(GroupUpdatePetCurrentHP) {
p.PetCurrentHealth = readHealth(build, in)
}
if p.Change(GroupUpdatePetMaxHP) {
p.PetMaxHealth = readHealth(build, in)
}
if p.Change(GroupUpdatePetPowerType) {
p.PetPowerType = uint16(in.ReadByte())
}
if p.Change(GroupUpdatePetCurrentPower) {
p.PetPower = in.ReadUint16()
}
if p.Change(GroupUpdatePetMaxPower) {
p.PetMaxPower = in.ReadUint16()
}
if p.Change(GroupUpdatePetAuras) {
p.PetAuras = readAuras(build, in)
}
if p.Change(GroupUpdateVehicleSeat) {
p.VehicleSeat = in.ReadUint32()
}
return nil
}
type CommandResult struct {
Operation Operation
Member string
Result Result
}
func (pcr *CommandResult) Encode(build vsn.Build, out *packet.WorldPacket) error {
out.Type = packet.SMSG_PARTY_COMMAND_RESULT
out.WriteUint32(uint32(pcr.Operation))
out.WriteCString(pcr.Member)
return EncodeResult(build, out, pcr.Result)
}
func (pcr *CommandResult) Decode(build vsn.Build, in *packet.WorldPacket) (err error) {
pcr.Operation = Operation(in.ReadUint32())
pcr.Member = in.ReadCString()
pcr.Result, err = DecodeResult(build, in)
return
}