forked from nielsAD/gowarcraft3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
const.go
618 lines (543 loc) · 13.9 KB
/
const.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
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
// Author: Niels A.D.
// Project: gowarcraft3 (https://github.com/nielsAD/gowarcraft3)
// License: Mozilla Public License, v2.0
package w3gs
import (
"errors"
"fmt"
"github.com/nielsAD/gowarcraft3/protocol"
)
// Errors
var (
ErrNoFactory = errors.New("w3gs: Invalid w3gs packet (empty factory)")
ErrNoProtocolSig = errors.New("w3gs: Invalid w3gs packet (no signature found)")
ErrInvalidPacketSize = errors.New("w3gs: Invalid packet size")
ErrInvalidChecksum = errors.New("w3gs: Checksum invalid")
ErrUnexpectedConst = errors.New("w3gs: Unexpected constant value")
)
// CurrentGameVersion used by stable release
const CurrentGameVersion uint32 = 10032
// ProtocolSig is the W3GS magic number used in the packet header.
const ProtocolSig = 0xF7
// W3GS packet type identifiers
const (
PidPingFromHost = 0x01
PidSlotInfoJoin = 0x04
PidRejectJoin = 0x05
PidPlayerInfo = 0x06
PidPlayerLeft = 0x07
PidPlayerLoaded = 0x08
PidSlotInfo = 0x09
PidCountDownStart = 0x0A
PidCountDownEnd = 0x0B
PidIncomingAction = 0x0C
PidDesync = 0x0D
PidChatFromHost = 0x0F
PidStartLag = 0x10
PidStopLag = 0x11
PidGameOver = 0x14
PidPlayerKicked = 0x1C
PidLeaveAck = 0x1B
PidReqJoin = 0x1E
PidLeaveReq = 0x21
PidGameLoadedSelf = 0x23
PidOutgoingAction = 0x26
PidOutgoingKeepAlive = 0x27
PidChatToHost = 0x28
PidDropReq = 0x29
PidSearchGame = 0x2F
PidGameInfo = 0x30
PidCreateGame = 0x31
PidRefreshGame = 0x32
PidDecreateGame = 0x33
PidChatFromOthers = 0x34
PidPingFromOthers = 0x35
PidPongToOthers = 0x36
PidClientInfo = 0x37
PidPeerSet = 0x3B
PidMapCheck = 0x3D
PidStartDownload = 0x3F
PidMapSize = 0x42
PidMapPart = 0x43
PidMapPartOK = 0x44
PidMapPartError = 0x45
PidPongToHost = 0x46
PidIncomingAction2 = 0x48
PidPlayerExtra = 0x59
)
// Failover related: 0x15 0x16 0x2B 0x2C 0x39
// Game product
var (
ProductDemo = protocol.DString("W3DM") // Demo
ProductROC = protocol.DString("WAR3") // ROC
ProductTFT = protocol.DString("W3XP") // TFT
)
// SlotLayout enum
type SlotLayout uint8
// Slot layout
const (
LayoutMelee SlotLayout = 0x00
LayoutCustomForces SlotLayout = 0x01
LayoutFixedPlayerSettings SlotLayout = 0x02
LayoutLadder SlotLayout = 0xCC
)
func (s SlotLayout) String() string {
if s&(LayoutMelee|LayoutCustomForces|LayoutFixedPlayerSettings|LayoutLadder) != s {
return fmt.Sprintf("SlotLayout(0x%02X)", uint8(s))
}
var res string
if s&LayoutCustomForces != 0 {
res = "CustomForces"
} else {
res = "Melee"
}
if s&LayoutFixedPlayerSettings != 0 {
res += "(Fixed)"
}
if s&LayoutLadder != 0 {
res += "(Ladder)"
}
return res
}
// SlotStatus enum
type SlotStatus uint8
// Slot status
const (
SlotOpen SlotStatus = 0x00
SlotClosed SlotStatus = 0x01
SlotOccupied SlotStatus = 0x02
)
func (s SlotStatus) String() string {
switch s {
case SlotOpen:
return "Open"
case SlotClosed:
return "Closed"
case SlotOccupied:
return "Occupied"
default:
return fmt.Sprintf("SlotStatus(0x%02X)", uint8(s))
}
}
// RacePref enum
type RacePref uint8
// Race preference
const (
RaceHuman RacePref = 0x01
RaceOrc RacePref = 0x02
RaceNightElf RacePref = 0x04
RaceUndead RacePref = 0x08
RaceDemon RacePref = 0x10
RaceRandom RacePref = 0x20
RaceMask = RaceHuman | RaceOrc | RaceNightElf | RaceUndead | RaceDemon | RaceRandom
RaceSelectable RacePref = 0x40
)
func (r RacePref) String() string {
if r&(RaceMask|RaceSelectable) != r {
return fmt.Sprintf("RacePref(0x%02X)", uint8(r))
}
var res string
switch r & RaceMask {
case RaceHuman:
res = "Human"
case RaceOrc:
res = "Orc"
case RaceNightElf:
res = "Nightelf"
case RaceUndead:
res = "Undead"
case RaceDemon:
res = "Demon"
case RaceRandom:
res = "Random"
default:
return fmt.Sprintf("RacePref(0x%02X)", uint8(r))
}
if r&RaceSelectable != 0 {
res += "(Selectable)"
}
return res
}
// AI difficulty enum
type AI uint8
// AI difficulty
const (
ComputerEasy AI = 0x00
ComputerNormal AI = 0x01
ComputerInsane AI = 0x02
)
func (a AI) String() string {
switch a {
case ComputerEasy:
return "Easy"
case ComputerNormal:
return "Normal"
case ComputerInsane:
return "Insane"
default:
return fmt.Sprintf("AI(0x%02X)", uint8(a))
}
}
// RejectReason enum
type RejectReason uint32
// RejectJoin reason
const (
RejectJoinInvalid RejectReason = 0x07
RejectJoinFull RejectReason = 0x09
RejectJoinStarted RejectReason = 0x0A
RejectJoinWrongKey RejectReason = 0x1B
)
func (r RejectReason) String() string {
switch r {
case RejectJoinInvalid:
return "JoinInvalid"
case RejectJoinFull:
return "GameFull"
case RejectJoinStarted:
return "GameStarted"
case RejectJoinWrongKey:
return "WrongKey"
default:
return fmt.Sprintf("RejectReason(0x%02X)", uint32(r))
}
}
// LeaveReason enum
type LeaveReason uint32
// PlayerLeft reason
const (
LeaveDisconnect LeaveReason = 0x01
LeaveLost LeaveReason = 0x07
LeaveLostBuildings LeaveReason = 0x08
LeaveWon LeaveReason = 0x09
LeaveDraw LeaveReason = 0x0A
LeaveObserver LeaveReason = 0x0B
LeaveInvalidSaveGame LeaveReason = 0x0C // (?)
LeaveLobby LeaveReason = 0x0D
)
func (l LeaveReason) String() string {
switch l {
case LeaveDisconnect:
return "Disconnect"
case LeaveLost:
return "Lost"
case LeaveLostBuildings:
return "LostBuildings"
case LeaveWon:
return "Won"
case LeaveDraw:
return "Draw"
case LeaveObserver:
return "Observer"
case LeaveInvalidSaveGame:
return "InvalidSaveGame"
case LeaveLobby:
return "Lobby"
default:
return fmt.Sprintf("LeaveReason(0x%02X)", uint32(l))
}
}
// MessageType enum
type MessageType uint8
// Chat type
const (
MsgChat MessageType = 0x10
MsgTeamChange MessageType = 0x11
MsgColorChange MessageType = 0x12
MsgRaceChange MessageType = 0x13
MsgHandicapChange MessageType = 0x14
MsgChatExtra MessageType = 0x20
)
func (m MessageType) String() string {
switch m {
case MsgChat:
return "Chat"
case MsgTeamChange:
return "TeamChange"
case MsgColorChange:
return "ColorChange"
case MsgRaceChange:
return "RaceChange"
case MsgHandicapChange:
return "HandicapChange"
case MsgChatExtra:
return "ChatExtra"
default:
return fmt.Sprintf("MessageType(0x%02X)", uint8(m))
}
}
// MessageScope enum
type MessageScope uint32
// Message scope
const (
ScopeAll MessageScope = 0x00
ScopeAllies MessageScope = 0x01
ScopeObservers MessageScope = 0x02
// Directed chat to player N = Scope - ChatDirected, if Scope >= ChatDirected
ScopeDirected MessageScope = 0x03
)
func (s MessageScope) String() string {
switch s {
case ScopeAll:
return "All"
case ScopeAllies:
return "Allies"
case ScopeObservers:
return "Observers"
default:
return fmt.Sprintf("ToPlayer(%d)", uint32(s-ScopeDirected))
}
}
// GameSettingFlags enum
type GameSettingFlags uint32
// Game setting flags
const (
SettingSpeedSlow GameSettingFlags = 0x00000000
SettingSpeedNormal GameSettingFlags = 0x00000001
SettingSpeedFast GameSettingFlags = 0x00000002
SettingSpeedMask GameSettingFlags = 0x0000000F
SettingTerrainHidden GameSettingFlags = 0x00000100
SettingTerrainExplored GameSettingFlags = 0x00000200
SettingTerrainVisible GameSettingFlags = 0x00000400
SettingTerrainDefault GameSettingFlags = 0x00000800
SettingTerrainMask GameSettingFlags = 0x00000F00
SettingObsNone GameSettingFlags = 0x00000000
SettingObsEnabled GameSettingFlags = 0x00001000
SettingObsOnDefeat GameSettingFlags = 0x00002000
SettingObsFull GameSettingFlags = 0x00003000
SettingObsReferees GameSettingFlags = 0x40000000
SettingObsMask GameSettingFlags = 0x40003000
SettingTeamsTogether GameSettingFlags = 0x00004000
SettingTeamsFixed GameSettingFlags = 0x00060000
SettingSharedControl GameSettingFlags = 0x01000000
SettingRandomHero GameSettingFlags = 0x02000000
SettingRandomRace GameSettingFlags = 0x04000000
)
func (f GameSettingFlags) String() string {
var res string
switch f & SettingSpeedMask {
case SettingSpeedSlow:
res = "SpeedSlow"
case SettingSpeedNormal:
res = "SpeedNormal"
case SettingSpeedFast:
res = "SpeedFast"
default:
return fmt.Sprintf("GameSettingFlags(0x%07X)", uint32(f))
}
switch f & SettingTerrainMask {
case SettingTerrainHidden:
res += "|TerrainHidden"
case SettingTerrainExplored:
res += "|TerrainExplored"
case SettingTerrainVisible:
res += "|TerrainVisible"
case SettingTerrainDefault:
res += "|TerrainDefault"
case 0:
// No terrain setting
default:
return fmt.Sprintf("GameSettingFlags(0x%07X)", uint32(f))
}
switch f & SettingObsMask {
case SettingObsNone:
res += "|ObsNone"
case SettingObsEnabled:
res += "|ObsEnabled"
case SettingObsOnDefeat:
res += "|ObsOnDefeat"
case SettingObsFull:
res += "|ObsFull"
case SettingObsReferees, SettingObsReferees | SettingObsEnabled:
res += "|ObsReferees"
default:
return fmt.Sprintf("GameSettingFlags(0x%07X)", uint32(f))
}
f &= ^(SettingSpeedMask | SettingTerrainMask | SettingObsMask)
if f&SettingTeamsTogether != 0 {
res += "|TeamsTogether"
f &= ^SettingTeamsTogether
}
if f&SettingTeamsFixed != 0 {
res += "|TeamsFixed"
f &= ^SettingTeamsFixed
}
if f&SettingSharedControl != 0 {
res += "|SharedControl"
f &= ^SettingSharedControl
}
if f&SettingRandomHero != 0 {
res += "|RandomHero"
f &= ^SettingRandomHero
}
if f&SettingRandomRace != 0 {
res += "|RandomRace"
f &= ^SettingRandomRace
}
if f != 0 {
res += fmt.Sprintf("|GameSettingFlags(0x%02X)", uint32(f))
}
return res
}
// GameFlags enum
type GameFlags uint32
// Game flags
const (
GameFlagCustomGame GameFlags = 0x000001
GameFlagSinglePlayer GameFlags = 0x000005
GameFlagLadder1v1 GameFlags = 0x000010
GameFlagLadder2v2 GameFlags = 0x000020
GameFlagLadder3v3 GameFlags = 0x000040
GameFlagLadder4v4 GameFlags = 0x000080
GameFlagTeamLadder GameFlags = 0x000020 // Before Reforged, all team modes shared a ladder
GameFlagSavedGame GameFlags = 0x000200
GameFlagTypeMask GameFlags = 0x0002F5
GameFlagSignedMap GameFlags = 0x000008
GameFlagPrivateGame GameFlags = 0x000800
GameFlagCreatorUser GameFlags = 0x002000
GameFlagCreatorBlizzard GameFlags = 0x004000
GameFlagCreatorMask GameFlags = 0x006000
GameFlagMapTypeMelee GameFlags = 0x008000
GameFlagMapTypeScenario GameFlags = 0x010000
GameFlagMapTypeMask GameFlags = 0x018000
GameFlagSizeSmall GameFlags = 0x020000
GameFlagSizeMedium GameFlags = 0x040000
GameFlagSizeLarge GameFlags = 0x080000
GameFlagSizeMask GameFlags = 0x0E0000
GameFlagObsFull GameFlags = 0x100000
GameFlagObsOnDefeat GameFlags = 0x200000
GameFlagObsNone GameFlags = 0x400000
GameFlagObsMask GameFlags = 0x700000
// Used for filtering game list
GameFlagFilterMask GameFlags = 0x7FE000
)
func (f GameFlags) String() string {
var res string
switch f & GameFlagTypeMask {
case GameFlagCustomGame:
res = "|Custom"
case GameFlagSinglePlayer:
res = "|SinglePlayer"
case GameFlagLadder1v1:
res = "|Ladder1v1"
case GameFlagLadder2v2:
res = "|Ladder2v2"
case GameFlagLadder3v3:
res = "|Ladder3v3"
case GameFlagLadder4v4:
res = "|Ladder4v4"
case GameFlagSavedGame:
res = "|SavedGame"
case 0:
// No game type
default:
return fmt.Sprintf("GameFlags(0x%06X)", uint32(f))
}
if f&GameFlagSignedMap != 0 {
res += "|SignedMap"
}
if f&GameFlagPrivateGame != 0 {
res += "|Private"
}
switch f & GameFlagCreatorMask {
case GameFlagCreatorUser:
res += "|CreatorUser"
case GameFlagCreatorBlizzard:
res += "|CreatorBlizzard"
case GameFlagCreatorMask:
res += "|CreatorAny"
case 0:
// No map maker
default:
return fmt.Sprintf("GameFlags(0x%06X)", uint32(f))
}
switch f & GameFlagSizeMask {
case GameFlagSizeSmall:
res += "|SizeSmall"
case GameFlagSizeMedium:
res += "|SizeMedium"
case GameFlagSizeLarge:
res += "|SizeLarge"
case GameFlagSizeMask:
res += "|SizeAny"
case 0:
// No map size
default:
return fmt.Sprintf("GameFlags(0x%06X)", uint32(f))
}
switch f & GameFlagMapTypeMask {
case GameFlagMapTypeMelee:
res += "|MapTypeMelee"
case GameFlagMapTypeScenario:
res += "|MapTypeScenario"
case GameFlagMapTypeMask:
res += "|MapTypeAny"
case 0:
// No map type
default:
return fmt.Sprintf("GameFlags(0x%06X)", uint32(f))
}
switch f & GameFlagObsMask {
case GameFlagObsFull:
res += "|ObsFull"
case GameFlagObsOnDefeat:
res += "|ObsOnDefeat"
case GameFlagObsNone:
res += "|ObsNone"
case GameFlagObsMask:
res += "|ObsAny"
case 0:
// No obs info
default:
return fmt.Sprintf("GameFlags(0x%06X)", uint32(f))
}
f &= ^(GameFlagTypeMask | GameFlagSignedMap | GameFlagPrivateGame | GameFlagCreatorMask | GameFlagSizeMask | GameFlagMapTypeMask | GameFlagObsMask)
if f != 0 {
res += fmt.Sprintf("|GameFlags(0x%02X)", uint32(f))
}
if res != "" {
res = res[1:]
}
return res
}
// PlayerExtraType enum
type PlayerExtraType uint8
// PlayerExtra record type
const (
PlayerExtra2 PlayerExtraType = 0x02
PlayerProfile PlayerExtraType = 0x03
PlayerSkins PlayerExtraType = 0x04
PlayerExtra5 PlayerExtraType = 0x05
)
func (t PlayerExtraType) String() string {
switch t {
case PlayerProfile:
return "BNetProfile"
case PlayerSkins:
return "Skins"
default:
return fmt.Sprintf("PlayerExtraType(0x%02X)", uint8(t))
}
}
// ProfileRealm enum
type ProfileRealm uint32
// Realms
const (
RealmOffline ProfileRealm = 0
RealmAmericas ProfileRealm = 10
RealmEurope ProfileRealm = 20
RealmAsia ProfileRealm = 30
)
func (r ProfileRealm) String() string {
switch r {
case RealmOffline:
return "Offline"
case RealmAmericas:
return "Americas"
case RealmEurope:
return "Europe"
case RealmAsia:
return "Asia"
default:
return fmt.Sprintf("ProfileRealm(%d)", r)
}
}