Documentation ¶
Overview ¶
Package w3gs implements the game protocol for Warcraft III.
Based on protocol documentation by https://bnetdocs.org/
Each packet type is mapped to a struct type that implements the Packet interface. To deserialize from a binary stream, use w3gs.Read().
This package tries to keep ammortized heap memory allocations to 0.
General serialization format:
(UINT8) Protocol signature (0xF7) (UINT8) Packet type ID (UINT16) Packet size [Packet Data]
Index ¶
- Constants
- Variables
- func Serialize(p Packet, e Encoding) ([]byte, error)
- func Write(w io.Writer, p Packet, e Encoding) (int, error)
- type AI
- type CacheFactory
- type CountDownEnd
- type CountDownStart
- type CreateGame
- type Decoder
- type DecreateGame
- type Desync
- type DropLaggers
- type Encoder
- type Encoding
- type FactoryFunc
- type GameAction
- type GameFlags
- type GameInfo
- type GameLoaded
- type GameOver
- type GameSettingFlags
- type GameSettings
- type GameVersion
- type Join
- type LagPlayer
- type Leave
- type LeaveAck
- type LeaveReason
- type MapCheck
- type MapFactory
- type MapPart
- type MapPartError
- type MapPartOK
- type MapState
- type Message
- type MessageRelay
- type MessageScope
- type MessageType
- type Packet
- type PacketFactory
- type PeerConnect
- type PeerMessage
- type PeerPing
- type PeerPong
- type PeerSet
- type Ping
- type PlayerAction
- type PlayerData5
- type PlayerDataProfile
- type PlayerDataSkin
- type PlayerDataSkins
- type PlayerExtra
- func (pkt *PlayerExtra) Deserialize(buf *protocol.Buffer, enc *Encoding) error
- func (pkt *PlayerExtra) DeserializeContent(buf *protocol.Buffer, enc *Encoding) error
- func (pkt *PlayerExtra) Serialize(buf *protocol.Buffer, enc *Encoding) error
- func (pkt *PlayerExtra) SerializeContent(buf *protocol.Buffer, enc *Encoding) error
- type PlayerExtraType
- type PlayerInfo
- type PlayerKicked
- type PlayerLeft
- type PlayerLoaded
- type Pong
- type ProfileRealm
- type RacePref
- type RefreshGame
- type RejectJoin
- type RejectReason
- type SearchGame
- type SlotData
- type SlotInfo
- func (pkt *SlotInfo) Deserialize(buf *protocol.Buffer, enc *Encoding) error
- func (pkt *SlotInfo) DeserializeContent(buf *protocol.Buffer, enc *Encoding) error
- func (pkt *SlotInfo) Serialize(buf *protocol.Buffer, enc *Encoding) error
- func (pkt *SlotInfo) SerializeContent(buf *protocol.Buffer, enc *Encoding)
- type SlotInfoJoin
- type SlotLayout
- type SlotStatus
- type StartDownload
- type StartLag
- type StopLag
- type TimeSlot
- type TimeSlotAck
- type UnknownPacket
Constants ¶
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 )
W3GS packet type identifiers
const CurrentGameVersion uint32 = 10032
CurrentGameVersion used by stable release
const ProtocolSig = 0xF7
ProtocolSig is the W3GS magic number used in the packet header.
Variables ¶
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") )
Errors
var ( ProductDemo = protocol.DString("W3DM") // Demo ProductROC = protocol.DString("WAR3") // ROC ProductTFT = protocol.DString("W3XP") // TFT )
Game product
var DefaultFactory = MapFactory{ PidPingFromHost: func(_ *Encoding) Packet { return &Ping{} }, PidSlotInfoJoin: func(_ *Encoding) Packet { return &SlotInfoJoin{} }, PidRejectJoin: func(_ *Encoding) Packet { return &RejectJoin{} }, PidPlayerInfo: func(_ *Encoding) Packet { return &PlayerInfo{} }, PidPlayerLeft: func(_ *Encoding) Packet { return &PlayerLeft{} }, PidPlayerLoaded: func(_ *Encoding) Packet { return &PlayerLoaded{} }, PidSlotInfo: func(_ *Encoding) Packet { return &SlotInfo{} }, PidCountDownStart: func(_ *Encoding) Packet { return &CountDownStart{} }, PidCountDownEnd: func(_ *Encoding) Packet { return &CountDownEnd{} }, PidIncomingAction: func(_ *Encoding) Packet { return &TimeSlot{} }, PidDesync: func(_ *Encoding) Packet { return &Desync{} }, PidChatFromHost: func(_ *Encoding) Packet { return &MessageRelay{} }, PidStartLag: func(_ *Encoding) Packet { return &StartLag{} }, PidStopLag: func(_ *Encoding) Packet { return &StopLag{} }, PidGameOver: func(_ *Encoding) Packet { return &GameOver{} }, PidPlayerKicked: func(_ *Encoding) Packet { return &PlayerKicked{} }, PidLeaveAck: func(_ *Encoding) Packet { return &LeaveAck{} }, PidReqJoin: func(_ *Encoding) Packet { return &Join{} }, PidLeaveReq: func(_ *Encoding) Packet { return &Leave{} }, PidGameLoadedSelf: func(_ *Encoding) Packet { return &GameLoaded{} }, PidOutgoingAction: func(_ *Encoding) Packet { return &GameAction{} }, PidOutgoingKeepAlive: func(_ *Encoding) Packet { return &TimeSlotAck{} }, PidChatToHost: func(_ *Encoding) Packet { return &Message{} }, PidDropReq: func(_ *Encoding) Packet { return &DropLaggers{} }, PidSearchGame: func(_ *Encoding) Packet { return &SearchGame{} }, PidGameInfo: func(_ *Encoding) Packet { return &GameInfo{} }, PidCreateGame: func(_ *Encoding) Packet { return &CreateGame{} }, PidRefreshGame: func(_ *Encoding) Packet { return &RefreshGame{} }, PidDecreateGame: func(_ *Encoding) Packet { return &DecreateGame{} }, PidChatFromOthers: func(_ *Encoding) Packet { return &PeerMessage{} }, PidPingFromOthers: func(_ *Encoding) Packet { return &PeerPing{} }, PidPongToOthers: func(_ *Encoding) Packet { return &PeerPong{} }, PidClientInfo: func(_ *Encoding) Packet { return &PeerConnect{} }, PidPeerSet: func(_ *Encoding) Packet { return &PeerSet{} }, PidMapCheck: func(_ *Encoding) Packet { return &MapCheck{} }, PidStartDownload: func(_ *Encoding) Packet { return &StartDownload{} }, PidMapSize: func(_ *Encoding) Packet { return &MapState{} }, PidMapPart: func(_ *Encoding) Packet { return &MapPart{} }, PidMapPartOK: func(_ *Encoding) Packet { return &MapPartOK{} }, PidMapPartError: func(_ *Encoding) Packet { return &MapPartError{} }, PidPongToHost: func(_ *Encoding) Packet { return &Pong{} }, PidIncomingAction2: func(_ *Encoding) Packet { return &TimeSlot{} }, PidPlayerExtra: func(_ *Encoding) Packet { return &PlayerExtra{} }, }
DefaultFactory maps packet ID to matching type
Functions ¶
Types ¶
type CacheFactory ¶ added in v1.5.0
type CacheFactory struct {
// contains filtered or unexported fields
}
CacheFactory implements a PacketFactory that will only create a type once
type CountDownEnd ¶
type CountDownEnd struct { }
CountDownEnd implements the [0x0B] W3GS_COUNTDOWN_END packet (S -> C).
The game has finished the countdown and has now started. Players should see a loading screen for the map once this is received.
[0x0A] W3GS_COUNTDOWN_START should be received before this packet, even if there is no countdown or if the countdown was 0 seconds.
Format:
[blank]
func (*CountDownEnd) Deserialize ¶
func (pkt *CountDownEnd) Deserialize(buf *protocol.Buffer, enc *Encoding) error
Deserialize decodes the binary data generated by Serialize.
type CountDownStart ¶
type CountDownStart struct { }
CountDownStart implements the [0x0A] W3GS_COUNTDOWN_START packet (S -> C).
The game has begun the countdown to start.
The official clients countdown from 5 seconds, however it is possible to use any time you wish. For example, the GHost++ bot uses 10 seconds when auto-hosted, but 5 seconds when started using an administrative command.
Format:
[blank]
func (*CountDownStart) Deserialize ¶
func (pkt *CountDownStart) Deserialize(buf *protocol.Buffer, enc *Encoding) error
Deserialize decodes the binary data generated by Serialize.
type CreateGame ¶
type CreateGame struct { GameVersion HostCounter uint32 }
CreateGame implements the [0x31] W3GS_CreateGame packet (S -> C).
Notifies the local area network that a game was created.
Format:
(UINT32) Product (UINT32) Version (UINT32) HostCounter
func (*CreateGame) Deserialize ¶
func (pkt *CreateGame) Deserialize(buf *protocol.Buffer, enc *Encoding) error
Deserialize decodes the binary data generated by Serialize.
type Decoder ¶ added in v1.5.0
type Decoder struct { Encoding PacketFactory // contains filtered or unexported fields }
Decoder keeps amortized allocs at 0 for repeated Packet.Deserialize calls.
func NewDecoder ¶ added in v1.5.0
func NewDecoder(e Encoding, f PacketFactory) *Decoder
NewDecoder initialization
func (*Decoder) Deserialize ¶ added in v1.5.0
Deserialize reads exactly one packet from b and returns it in the proper (deserialized) packet type.
type DecreateGame ¶
type DecreateGame struct {
HostCounter uint32
}
DecreateGame implements the [0x33] W3GS_DecreateGame packet (S -> C).
Notifies the local area network that a game is no longer being hosted.
Format:
(UINT32) Host Counter
func (*DecreateGame) Deserialize ¶
func (pkt *DecreateGame) Deserialize(buf *protocol.Buffer, enc *Encoding) error
Deserialize decodes the binary data generated by Serialize.
type Desync ¶
Desync implements the [0x0D] W3GS_DESYNC packet (S -> C).
This is sent whenever the server detects a split state based on checksums sent by [0x27] W3GS_OUTGOING_KEEPALIVE. Each client continues the game with the given player numbers, other players are dropped.
(UINT32) Unknown (0x01) (UINT8) Unknown (0x04) (UINT32) Checksum (UINT8) NumPlayersInState (UINT8)[] Player numbers
func (*Desync) Deserialize ¶
Deserialize decodes the binary data generated by Serialize.
func (*Desync) DeserializeContent ¶ added in v1.5.0
DeserializeContent decodes the binary data generated by SerializeContent.
type DropLaggers ¶
type DropLaggers struct { }
DropLaggers implements the [0x2F] W3GS_STOP_DROPREQ packet (C -> S).
This is sent when a player votes to drop lagging players.
Format:
[blank]
func (*DropLaggers) Deserialize ¶
func (pkt *DropLaggers) Deserialize(buf *protocol.Buffer, enc *Encoding) error
Deserialize decodes the binary data generated by Serialize.
type Encoder ¶ added in v1.5.0
type Encoder struct { Encoding // contains filtered or unexported fields }
Encoder keeps amortized allocs at 0 for repeated Packet.Serialize calls.
type Encoding ¶ added in v1.5.0
type Encoding struct {
GameVersion uint32
}
Encoding options for (de)serialization
type FactoryFunc ¶ added in v1.5.0
FactoryFunc creates new Packet
type GameAction ¶
type GameAction struct {
Data []byte
}
GameAction implements the [0x26] W3GS_OUTGOING_ACTION packet (C -> S).
A client sends this to the game host to execute an action in-game.
Format:
(UINT32) CRC-32 checksum (VOID) Action data
func (*GameAction) Deserialize ¶
func (pkt *GameAction) Deserialize(buf *protocol.Buffer, enc *Encoding) error
Deserialize decodes the binary data generated by Serialize.
type GameFlags ¶
type GameFlags uint32
GameFlags enum
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 )
Game flags
type GameInfo ¶
type GameInfo struct { GameVersion HostCounter uint32 EntryKey uint32 GameName string GameSettings GameSettings SlotsTotal uint32 GameFlags GameFlags SlotsUsed uint32 SlotsAvailable uint32 UptimeSec uint32 GamePort uint16 }
GameInfo implements the [0x30] W3GS_GameInfo packet (S -> C).
This is sent in response to [0x2F] W3GS_SearchGame (on the local area network).
Format:
(UINT32) Product (UINT32) Version (UINT32) Host Counter (UINT32) Entry key (STRING) Game name (UINT8) Unknown (0x00) (STRING) Statstring (UINT32) Slots total (UINT32) Game Type Info (UINT32) Player slots used (UINT32) Player slots available (total slots - closed slots - AI slots) (UINT32) Time since creation (UINT16) Listen Port
func (*GameInfo) Deserialize ¶
Deserialize decodes the binary data generated by Serialize.
type GameLoaded ¶
type GameLoaded struct { }
GameLoaded implements the [0x23] W3GS_GAMELOADED_SELF packet (C -> S).
The client sends this to the host when they have finished loading the map.
Format:
[blank]
func (*GameLoaded) Deserialize ¶
func (pkt *GameLoaded) Deserialize(buf *protocol.Buffer, enc *Encoding) error
Deserialize decodes the binary data generated by Serialize.
type GameOver ¶
type GameOver struct {
PlayerID uint8
}
GameOver implements the [0x14] W3GS_GameOver packet (S -> C).
Notify clients that the game has ended and the connection will be closed.
Format:
(UINT8) Player number
func (*GameOver) Deserialize ¶
Deserialize decodes the binary data generated by Serialize.
type GameSettingFlags ¶
type GameSettingFlags uint32
GameSettingFlags enum
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 SettingRandomHero GameSettingFlags = 0x02000000 SettingRandomRace GameSettingFlags = 0x04000000 )
Game setting flags
func (GameSettingFlags) String ¶
func (f GameSettingFlags) String() string
type GameSettings ¶
type GameSettings struct { GameSettingFlags GameSettingFlags MapWidth uint16 MapHeight uint16 MapXoro uint32 MapPath string HostName string MapSha1 [20]byte }
GameSettings stores the settings of a created game.
Flags:
Speed: (mask 0x00000003) cannot be combined 0x00000000 - Slow game speed 0x00000001 - Normal game speed 0x00000002 - Fast game speed Visibility: (mask 0x00000F00) cannot be combined 0x00000100 - Hide terrain 0x00000200 - Map explored 0x00000400 - Always visible (no fog of war) 0x00000800 - Default Observers/Referees: (mask 0x40003000) cannot be combined 0x00000000 - No Observers 0x00002000 - Observers on Defeat 0x00003000 - Additional players as observer allowed 0x40000000 - Referees Teams/Units/Hero/Race: (mask 0x07064000) can be combined 0x00004000 - Teams Together (team members are placed at neighbored starting locations) 0x00060000 - Fixed teams 0x01000000 - Unit share 0x02000000 - Random hero 0x04000000 - Random races
Format:
(UINT32) Flags (UINT16) Map width (UINT16) Map height (UINT32) Map xoro (STRING) Map path (STRING) Host name (UINT8)[20] Map Sha1 hash
Encoded as a null terminated string where every even byte-value was incremented by 1. So all encoded bytes are odd. A control-byte stores the transformations for the next 7 bytes.
func (*GameSettings) DeserializeContent ¶ added in v1.5.0
func (gs *GameSettings) DeserializeContent(buf *protocol.Buffer, enc *Encoding) error
DeserializeContent GameSettings from StatString
func (*GameSettings) SerializeContent ¶ added in v1.5.0
func (gs *GameSettings) SerializeContent(buf *protocol.Buffer, enc *Encoding)
SerializeContent GameSettings into StatString
type GameVersion ¶
type GameVersion struct { Product protocol.DWordString Version uint32 }
GameVersion stores the game version tuple.
Format: (UINT32) Product (UINT32) Version
func (*GameVersion) DeserializeContent ¶ added in v1.5.0
func (gv *GameVersion) DeserializeContent(buf *protocol.Buffer, enc *Encoding)
DeserializeContent decodes the binary data generated by SerializeContent.
func (*GameVersion) SerializeContent ¶ added in v1.5.0
func (gv *GameVersion) SerializeContent(buf *protocol.Buffer, enc *Encoding)
SerializeContent encodes the struct into its binary form without packet ID.
type Join ¶
type Join struct { HostCounter uint32 EntryKey uint32 ListenPort uint16 JoinCounter uint32 PlayerName string InternalAddr protocol.SockAddr }
Join implements the [0x1E] W3GS_ReqJoin packet (C -> S).
A client sends this to the host to enter the game lobby.
The internal IP uses the Windows in_addr structure which is thus used by the sockaddr_in structure.
Format:
(UINT32) Host Counter (Game ID) (UINT32) Entry Key (used in LAN) (UINT8) Unknown (0x00) (UINT16) Listen Port (UINT32) Join counter (STRING) Player name (UINT8) Number of bytes that follow (0x01 < 1.29; 0x02 >= 1.29) (UINT8)[] Unknown (0x00) (UINT16) AF_INET (0x02) (UINT16) Internal Port (UINT32) Internal IP (UINT32) Unknown (0x00) (UINT32) Unknown (0x00)
func (*Join) Deserialize ¶
Deserialize decodes the binary data generated by Serialize.
type LagPlayer ¶
LagPlayer stores the data for a single lagging player.
(UINT8) Player number (UINT32) Lag duration in milliseconds
func (*LagPlayer) DeserializeContent ¶ added in v1.5.0
DeserializeContent decodes the binary data generated by SerializeContent.
type Leave ¶
type Leave struct {
Reason LeaveReason
}
Leave implements the [0x21] W3GS_LeaveReq packet (C -> S).
A client requests to leave.
Reason:
0x01 PLAYERLEAVE_DISCONNECT 0x07 PLAYERLEAVE_LOST 0x08 PLAYERLEAVE_LOSTBUILDINGS 0x09 PLAYERLEAVE_WON 0x0A PLAYERLEAVE_DRAW 0x0B PLAYERLEAVE_OBSERVER 0x0D PLAYERLEAVE_LOBBY
Format:
(UINT32) Reason
func (*Leave) Deserialize ¶
Deserialize decodes the binary data generated by Serialize.
type LeaveAck ¶
type LeaveAck struct { }
LeaveAck implements the [0x1B] W3GS_LeaveAck packet (S -> C).
This is the response to [0x21] W3GS_LeaveReq.
You will leave the game once the connection is terminated.
Format:
[blank]
func (*LeaveAck) Deserialize ¶
Deserialize decodes the binary data generated by Serialize.
type LeaveReason ¶
type LeaveReason uint32
LeaveReason enum
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 )
PlayerLeft reason
func (LeaveReason) String ¶
func (l LeaveReason) String() string
type MapCheck ¶
type MapCheck struct { FilePath string FileSize uint32 FileCRC uint32 MapXoro uint32 MapSha1 [20]byte }
MapCheck implements the [0x3D] W3GS_MapCheck packet (S -> C).
This is sent from the game host to a client that just joined to check if the client has the map.
Map hash is not only based on map file, as it takes common.j/blizzard.j from current patch into account as well.
Format:
(UINT32) Unknown (0x01) (STRING) File Path (UINT32) File size (UINT32) File CRC hash (UINT32) Map XOR/RotateLeft hash (UINT8)[20] Map SHA-1 hash
func (*MapCheck) Deserialize ¶
Deserialize decodes the binary data generated by Serialize.
type MapFactory ¶ added in v1.5.0
type MapFactory map[uint8]FactoryFunc
MapFactory implements PacketFactory using a map
type MapPart ¶
MapPart implements the [0x43] W3GS_MapPart packet (S -> C).
This is received when you are downloading a map from the host.
You can calculate how many more chunks you have left based on the file size and the chunk position in file. You are done downloading when the chunk position in file (plus the size of the chunk) matches the file size received in 0x42 W3GS_MapSize.
If the data does not match the CRC-32, you should send the host 0x45 W3GS_MapPartError, otherwise you should always send 0x44 W3GS_MapPartOK in reply to this packet.
Format:
(UINT8) To player number (UINT8) From player number (UINT32) Unknown (0x01) (UINT32) Chunk position in file (UINT32) CRC-32 checksum (UINT8)[1442] Data
func (*MapPart) Deserialize ¶
Deserialize decodes the binary data generated by Serialize.
type MapPartError ¶
type MapPartError struct { }
MapPartError implements the [0x45] W3GS_MapPartError packet (C -> S).
This is sent when downloading a map in reply to 0x43 W3GS_MapPart and a chunk of the map file does not match its CRC checksum.
Format:
[unknown]
func (*MapPartError) Deserialize ¶
func (pkt *MapPartError) Deserialize(buf *protocol.Buffer, enc *Encoding) error
Deserialize decodes the binary data generated by Serialize.
type MapPartOK ¶
MapPartOK implements the [0x44] W3GS_MapPartOK packet (C -> S).
The client sends this when it has successfully received a chunk of the map file from the host client.
Format:
(UINT8) From player number (UINT8) To player number (UINT32) Unknown (0x01) (UINT32) Chunk position in file
func (*MapPartOK) Deserialize ¶
Deserialize decodes the binary data generated by Serialize.
type MapState ¶
MapState implements the [0x42] W3GS_MapSize packet (C -> S).
This is sent from the client to tell the host about the map file on the client'buf local system.
Format:
(UINT32) Unknown (0x01) (UINT8) Size Flag (0x01 is ready, 0x03 to request the next 0x43] W3GS_MapPart) (UINT32) Map Size
func (*MapState) Deserialize ¶
Deserialize decodes the binary data generated by Serialize.
type Message ¶
type Message struct { RecipientIDs []uint8 SenderID uint8 Type MessageType Scope MessageScope NewVal uint8 Content string }
Message implements the [0x28] W3GS_CHAT_TO_HOST packet (C -> S).
This is sent from the client to the host to send a message to the other clients.
Format:
(UINT8) Player count (UINT8)[] Player numbers that will receive the message (UINT8) From player number (UINT8) Flags For Flag 0x10: (STRING) Message For Flag 0x11: (UINT8) NewVal (Team) For Flag 0x12: (UINT8) NewVal (Color) For Flag 0x13: (UINT8) NewVal (Race) For Flag 0x14: (UINT8) NewVal(Handicap) For Flag 0x20: (UINT32) Message scope (0x00 all, 0x01 allies, 0x02 observers, else directed to N-0x03) (STRING) Message
func (*Message) Deserialize ¶
Deserialize decodes the binary data generated by Serialize.
type MessageRelay ¶
type MessageRelay struct {
Message
}
MessageRelay implements the [0x0F] W3GS_CHAT_FROM_HOST packet (S -> C).
This is sent to the clients to print a message on the screen from another player.
Format:
(UINT8) Player count (UINT8)[] Player numbers that will receive the message (UINT8) From player number (UINT8) Flags For Flag 0x10: (STRING) Message For Flag 0x11: (UINT8) NewVal (Team) For Flag 0x12: (UINT8) NewVal (Color) For Flag 0x13: (UINT8) NewVal (Race) For Flag 0x14: (UINT8) NewVal(Handicap) For Flag 0x20: (UINT32) Extra Flags (STRING) Message
type MessageScope ¶ added in v1.5.0
type MessageScope uint32
MessageScope enum
const ( ScopeAll MessageScope = 0x00 ScopeAllies MessageScope = 0x01 ScopeObservers MessageScope = 0x02 // Directed chat to player N = Scope - ChatDirected, if Scope >= ChatDirected ScopeDirected MessageScope = 0x03 )
Message scope
func (MessageScope) String ¶ added in v1.5.0
func (s MessageScope) String() string
type MessageType ¶
type MessageType uint8
MessageType enum
const ( MsgChat MessageType = 0x10 MsgTeamChange MessageType = 0x11 MsgColorChange MessageType = 0x12 MsgRaceChange MessageType = 0x13 MsgHandicapChange MessageType = 0x14 MsgChatExtra MessageType = 0x20 )
Chat type
func (MessageType) String ¶
func (m MessageType) String() string
type Packet ¶
type Packet interface { Serialize(buf *protocol.Buffer, enc *Encoding) error Deserialize(buf *protocol.Buffer, enc *Encoding) error }
Packet interface.
func Deserialize ¶ added in v1.5.0
Deserialize reads exactly one packet from b and returns it in the proper (deserialized) packet type.
type PacketFactory ¶ added in v1.5.0
PacketFactory returns a struct of the appropiate type for a packet ID
func NewFactoryCache ¶ added in v1.5.0
func NewFactoryCache(factory PacketFactory) PacketFactory
NewFactoryCache initializes CacheFactory
type PeerConnect ¶
type PeerConnect struct { JoinCounter uint32 EntryKey uint32 PlayerID uint8 PeerSet protocol.BitSet32 }
PeerConnect implements the [0x37] W3GS_ClientInfo packet (C -> C).
A client sends this to another client to gain information about self when connected.
Peer set is a bitset with bits set for every peer connected to this client.
Format:
(UINT32) Player Counter (UINT32) Entry key (UINT8) Player number (UINT8) Unknown (0xFF, status / provider version constant?) (UINT32) Peer set
func (*PeerConnect) Deserialize ¶
func (pkt *PeerConnect) Deserialize(buf *protocol.Buffer, enc *Encoding) error
Deserialize decodes the binary data generated by Serialize.
type PeerMessage ¶
type PeerMessage struct {
Message
}
PeerMessage implements the [0x34] W3GS_CHAT_FROM_OTHERS packet (C -> C).
This is sent to connected peers to print a message on the screen from another player.
Format:
(UINT8) Player count (UINT8)[] Player numbers that will receive the message (UINT8) From player number (UINT8) Flags For Flag 0x10: (STRING) Message For Flag 0x11: (UINT8) NewVal (Team) For Flag 0x12: (UINT8) NewVal (Color) For Flag 0x13: (UINT8) NewVal (Race) For Flag 0x14: (UINT8) NewVal(Handicap) For Flag 0x20: (UINT32) Extra Flags (STRING) Message
type PeerPing ¶
PeerPing implements the [0x35] W3GS_PING_FROM_OTHERS packet (C -> C).
Client requests an echo from another client (occurs every 10 seconds).
Format:
(UINT32) Ping (UINT32) Peer set (see [0x37] W3GS_ClientInfo) (UINT32) Game ticks
func (*PeerPing) Deserialize ¶
Deserialize decodes the binary data generated by Serialize.
type PeerPong ¶
type PeerPong struct {
Ping
}
PeerPong implements the [0x36] W3GS_PONG_TO_OTHERS packet (C -> C).
This is sent in response to an echo from another client.
Format:
(UINT32) Pong (copy of Ping payload)
type PeerSet ¶
PeerSet implements the [0x3B] W3GS_PEER_SET packet (C -> S).
Client sends this to the server to let it know which peers are connected to the client.
Format:
(UINT16) Peer Set
func (*PeerSet) Deserialize ¶
Deserialize decodes the binary data generated by Serialize.
type Ping ¶
type Ping struct {
Payload uint32
}
Ping implements the [0x01] W3GS_PING_FROM_HOST packet (S -> C).
This is sent every 30 seconds to make sure that the client is still responsive.
Format:
(UINT32) Ping (GetTickCount)
func (*Ping) Deserialize ¶
Deserialize decodes the binary data generated by Serialize.
type PlayerAction ¶
PlayerAction stores the data for a single game action.
(UINT8) Player number (UINT16) Length of action data (VOID) Action data
type PlayerData5 ¶ added in v1.6.0
PlayerData5 stores the info for a single battle.net player profile.
Format (protobuf):
(UINT8) Player ID (UINT32) Unknown
type PlayerDataProfile ¶ added in v1.6.0
type PlayerDataProfile struct { PlayerID uint32 BattleTag string Clan string Portrait string Realm ProfileRealm Unknown1 string }
PlayerDataProfile stores the info for a single battle.net player profile.
Format (protobuf):
(UINT8) Player ID (STRING) Battletag (STRING) Clan (STRING) Portrait (UINT8) Team (STRING) Unknown
type PlayerDataSkin ¶ added in v1.6.0
PlayerDataSkin stores in-game skin info.
Format (protobuf):
(UINT64) Unit ID (UINT64) Skin ID (STRING) Skin collection
type PlayerDataSkins ¶ added in v1.6.0
type PlayerDataSkins struct { PlayerID uint32 Skins []PlayerDataSkin }
PlayerDataSkins stores the in-game skin usage for a single player.
Format (protobuf):
(UINT8) Player ID For each in-game skin: (UINT64) Unit ID (UINT64) Skin ID (STRING) Skin collection
type PlayerExtra ¶ added in v1.6.0
type PlayerExtra struct { Type PlayerExtraType Profiles []PlayerDataProfile Skins []PlayerDataSkins Unknown5 []PlayerData5 }
PlayerExtra implements the [0x59] protobuf packet (C -> S, S -> C).
Sub packet is encoded in protobuf.
Format:
(UINT8) Sub type (0x03) 0x02 Unknown, found when leaving LAN game 0x03 Battle.net profile data 0x04 In-game skins 0x05 Unknown, found when joining LAN game (UINT32) Number of bytes following (UINT8)[n] Protobuf encoded struct For each battle.net profile (sub type 0x03, encoded with protobuf): (UINT8) Player ID (STRING) Battletag (STRING) Clan (STRING) Portrait (UINT8) Team (STRING) Unknown For each player (sub type 0x04, encoded with protobuf): (UINT8) Player ID For each in-game skin: (UINT64) Unit ID (UINT64) Skin ID (STRING) Skin collection For sub type 0x05 (encoded with protobuf): (UINT8) Player ID (UINT32) Unknown
func (*PlayerExtra) Deserialize ¶ added in v1.6.0
func (pkt *PlayerExtra) Deserialize(buf *protocol.Buffer, enc *Encoding) error
Deserialize decodes the binary data generated by Serialize.
func (*PlayerExtra) DeserializeContent ¶ added in v1.6.0
func (pkt *PlayerExtra) DeserializeContent(buf *protocol.Buffer, enc *Encoding) error
DeserializeContent decodes the binary data generated by SerializeContent.
func (*PlayerExtra) Serialize ¶ added in v1.6.0
func (pkt *PlayerExtra) Serialize(buf *protocol.Buffer, enc *Encoding) error
Serialize encodes the struct into its binary form.
func (*PlayerExtra) SerializeContent ¶ added in v1.6.0
func (pkt *PlayerExtra) SerializeContent(buf *protocol.Buffer, enc *Encoding) error
SerializeContent encodes the struct into its binary form without packet ID.
type PlayerExtraType ¶ added in v1.6.0
type PlayerExtraType uint8
PlayerExtraType enum
const ( PlayerExtra2 PlayerExtraType = 0x02 PlayerProfile PlayerExtraType = 0x03 PlayerSkins PlayerExtraType = 0x04 PlayerExtra5 PlayerExtraType = 0x05 )
PlayerExtra record type
func (PlayerExtraType) String ¶ added in v1.6.0
func (t PlayerExtraType) String() string
type PlayerInfo ¶
type PlayerInfo struct { JoinCounter uint32 PlayerID uint8 PlayerName string ExternalAddr protocol.SockAddr InternalAddr protocol.SockAddr }
PlayerInfo implements the [0x06] W3GS_PlayerInfo packet (S -> C).
Tells a client about a player'buf information.
The external and internal IP are always zero for the host.
Format:
(UINT32) Join Counter (UINT8) Player number (STRING) Player name (UINT8) Number of bytes that follow (0x01) (UINT8)[] Unknown (0x00) (UINT16) AF_INET (0x02) (UINT16) Port (UINT32) External IP (UINT32) Unknown (0x00) (UINT32) Unknown (0x00) (UINT16) AF_INET (0x02) (UINT16) Port (UINT32) Internal IP (UINT32) Unknown (0x00) (UINT32) Unknown (0x00)
func (*PlayerInfo) Deserialize ¶
func (pkt *PlayerInfo) Deserialize(buf *protocol.Buffer, enc *Encoding) error
Deserialize decodes the binary data generated by Serialize.
type PlayerKicked ¶
type PlayerKicked struct {
Leave
}
PlayerKicked implements the [0x1C] W3GS_PlayerKicked packet (S -> C).
The host has kicked the client from the lobby.
Reason:
0x01 PLAYERLEAVE_DISCONNECT 0x07 PLAYERLEAVE_LOST 0x08 PLAYERLEAVE_LOSTBUILDINGS 0x09 PLAYERLEAVE_WON 0x0A PLAYERLEAVE_DRAW 0x0B PLAYERLEAVE_OBSERVER 0x0D PLAYERLEAVE_LOBBY
Format:
(UINT32) Reason
type PlayerLeft ¶
type PlayerLeft struct { PlayerID uint8 Reason LeaveReason }
PlayerLeft implements the [0x07] W3GS_PlayerLeft packet (S -> C).
This is received from the game host when a player leaves.
Reason:
0x01 PLAYERLEAVE_DISCONNECT 0x07 PLAYERLEAVE_LOST 0x08 PLAYERLEAVE_LOSTBUILDINGS 0x09 PLAYERLEAVE_WON 0x0A PLAYERLEAVE_DRAW 0x0B PLAYERLEAVE_OBSERVER 0x0D PLAYERLEAVE_LOBBY
Format:
(UINT8) Player number (UINT32) Reason
func (*PlayerLeft) Deserialize ¶
func (pkt *PlayerLeft) Deserialize(buf *protocol.Buffer, enc *Encoding) error
Deserialize decodes the binary data generated by Serialize.
type PlayerLoaded ¶
type PlayerLoaded struct {
PlayerID uint8
}
PlayerLoaded implements the [0x08] W3GS_PlayerLoaded packet (S -> C).
Sent to all other clients in-game to notify that a player has finished loading.
Format:
(UINT8) Player number
func (*PlayerLoaded) Deserialize ¶
func (pkt *PlayerLoaded) Deserialize(buf *protocol.Buffer, enc *Encoding) error
Deserialize decodes the binary data generated by Serialize.
type Pong ¶
type Pong struct {
Ping
}
Pong implements the [0x46] W3GS_PONG_TO_HOST packet (C -> S).
This is sent in response to 0x01 W3GS_PING_FROM_HOST.
The pong value is just a copy of whatever was sent in SEND_W3GS_PING_FROM_HOST which was GetTicks( ) at the time of sending so as long as we trust that the client isn't trying to fake us out and mess with the pong value we can find the round trip time by simple subtraction (the subtraction is done elsewhere because the very first pong value seems to be 1 and we want to discard that one)
Format:
(UINT32) Pong (copy of Ping payload)
type ProfileRealm ¶ added in v1.6.0
type ProfileRealm uint32
ProfileRealm enum
const ( RealmOffline ProfileRealm = 0 RealmAmericas ProfileRealm = 10 RealmEurope ProfileRealm = 20 RealmAsia ProfileRealm = 30 )
Realms
func (ProfileRealm) String ¶ added in v1.6.0
func (r ProfileRealm) String() string
type RacePref ¶
type RacePref uint8
RacePref enum
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 )
Race preference
type RefreshGame ¶
RefreshGame implements the [0x32] W3GS_RefreshGame packet (S -> C).
Notifies the local area network about a game (occurs every 5 seconds or refresh slots).
Format:
(UINT32) Host Counter (UINT32) Player slots used (UINT32) Player slots available (total slots - closed slots - AI slots)
func (*RefreshGame) Deserialize ¶
func (pkt *RefreshGame) Deserialize(buf *protocol.Buffer, enc *Encoding) error
Deserialize decodes the binary data generated by Serialize.
type RejectJoin ¶
type RejectJoin struct {
Reason RejectReason
}
RejectJoin implements the [0x05] W3GS_RejectJoin packet (S -> C).
This is sent in a response to a request to join the game lobby and indicates that the request was denied.
Reason:
0x09 RejectJoin_FULL The game lobby is full 0x07 RejectJoin_INVALID There was an error in your request 0x10 RejectJoin_STARTED The game has already been started 0x27 RejectJoin_WRONGPASS The password you sent was incorrect
Format:
(UINT32) Reason
func (*RejectJoin) Deserialize ¶
func (pkt *RejectJoin) Deserialize(buf *protocol.Buffer, enc *Encoding) error
Deserialize decodes the binary data generated by Serialize.
type RejectReason ¶
type RejectReason uint32
RejectReason enum
const ( RejectJoinInvalid RejectReason = 0x07 RejectJoinFull RejectReason = 0x09 RejectJoinStarted RejectReason = 0x0A RejectJoinWrongKey RejectReason = 0x1B )
RejectJoin reason
func (RejectReason) String ¶
func (r RejectReason) String() string
type SearchGame ¶
type SearchGame struct { GameVersion HostCounter uint32 }
SearchGame implements the [0x2F] W3GS_SearchGame packet (C -> S).
This is broadcasted to the entire local area network to detect games during initial search of local games. After that, it is sent directly to clients that broadcasted [0x31] W3GS_CreateGame.
Product is either WAR3 or W3XP.
Format:
(UINT32) Product (UINT32) Version (UINT32) Host Counter
func (*SearchGame) Deserialize ¶
func (pkt *SearchGame) Deserialize(buf *protocol.Buffer, enc *Encoding) error
Deserialize decodes the binary data generated by Serialize.
type SlotData ¶
type SlotData struct { PlayerID uint8 DownloadStatus uint8 SlotStatus SlotStatus Computer bool Team uint8 Color uint8 Race RacePref ComputerType AI Handicap uint8 }
SlotData stores the info for a single game slot.
Download status:
- This is a percentage of their download progress. As such, this value can only be between 0 and 100.
Slot status:
0x00 Open 0x01 Closed 0x02 Occupied
Computer status:
0x00 Human 0x01 Computer
Race:
0x01 Human 0x02 Orc 0x04 Night Elf 0x08 Undead 0x20 Random 0x40 Selectable
Computer type:
0x00 Easy 0x01 Normal / Human 0x02 Hard Format: (UINT8) Player number (UINT8) Download status (UINT8) Slot status (UINT8) Computer status (UINT8) Team (UINT8) Color (UINT8) Race (UINT8) Computer type (UINT8) Handicap
type SlotInfo ¶
type SlotInfo struct { Slots []SlotData RandomSeed uint32 SlotLayout SlotLayout NumPlayers uint8 }
SlotInfo implements the [0x09] W3GS_SlotInfo packet (S -> C).
This is sent for slot updates.
The length of slot info should always be `0x0B`.
Format:
(UINT16) Length of Slot data (UINT8) Number of slots (UINT8)[] Slot data (UINT32) Random seed (GetTickCount) (UINT8) Slots layout (UINT8) Number of player slots without observers For each slot: (UINT8) Player number (UINT8) Download status (UINT8) Slot status (UINT8) Computer status (UINT8) Team (UINT8) Color (UINT8) Race (UINT8) Computer type (UINT8) Handicap
func (*SlotInfo) Deserialize ¶
Deserialize decodes the binary data generated by Serialize.
func (*SlotInfo) DeserializeContent ¶ added in v1.5.0
DeserializeContent decodes the binary data generated by SerializeContent.
type SlotInfoJoin ¶
SlotInfoJoin implements the [0x04] W3GS_SlotInfoJoin packet (S -> C).
This is sent to tell the client about the game slots, upon entry of the lobby.
Format:
Embedded [0x09] W3GS_SlotInfo: (UINT16) Length of Slot data (UINT8) Number of slots (UINT8)[] Slot data (UINT32) Random seed (UINT8) Slots layout (UINT8) Number of player slots without observers (UINT8) Player number (UINT16) AF_INET (0x02) (UINT16) Port (UINT32) External IP (UINT32) Unknown (0x00) (UINT32) Unknown (0x00)
func (*SlotInfoJoin) Deserialize ¶
func (pkt *SlotInfoJoin) Deserialize(buf *protocol.Buffer, enc *Encoding) error
Deserialize decodes the binary data generated by Serialize.
type SlotLayout ¶
type SlotLayout uint8
SlotLayout enum
const ( LayoutMelee SlotLayout = 0x00 LayoutCustomForces SlotLayout = 0x01 LayoutFixedPlayerSettings SlotLayout = 0x02 LayoutLadder SlotLayout = 0xCC )
Slot layout
func (SlotLayout) String ¶
func (s SlotLayout) String() string
type SlotStatus ¶
type SlotStatus uint8
SlotStatus enum
const ( SlotOpen SlotStatus = 0x00 SlotClosed SlotStatus = 0x01 SlotOccupied SlotStatus = 0x02 )
Slot status
func (SlotStatus) String ¶
func (s SlotStatus) String() string
type StartDownload ¶
type StartDownload struct {
PlayerID uint8
}
StartDownload implements the [0x3F] W3GS_StartDownload packet (C -> S, S -> C).
C -> S: Client sends this to the host to initiate a map download. S -> C: This tells the client that it is now in the downloading state and should expect chunks of file data.
Format:
(UINT32) Unknown (0x01) (UINT8) Player number
func (*StartDownload) Deserialize ¶
func (pkt *StartDownload) Deserialize(buf *protocol.Buffer, enc *Encoding) error
Deserialize decodes the binary data generated by Serialize.
type StartLag ¶
type StartLag struct {
Players []LagPlayer
}
StartLag implements the [0x10] W3GS_START_LAG packet (S -> C).
This is sent to the clients to initiate the lag screen.
Format:
(UINT8) Number of lagging players For every lagging player: (UINT8) Player number (UINT32) Lag duration in milliseconds
func (*StartLag) Deserialize ¶
Deserialize decodes the binary data generated by Serialize.
type StopLag ¶
type StopLag struct {
LagPlayer
}
StopLag implements the [0x11] W3GS_STOP_LAG packet (S -> C).
This is sent to the clients to indicate that a player stopped lagging.
Format:
(UINT8) Player number (UINT32) Lag duration in milliseconds
func (*StopLag) Deserialize ¶
Deserialize decodes the binary data generated by Serialize.
type TimeSlot ¶
type TimeSlot struct { Fragment bool TimeIncrementMS uint16 Actions []PlayerAction }
TimeSlot implements the [0x0C] W3GS_INCOMING_ACTION packet (S -> C).
Informs the client about an action in-game.
Format:
(UINT16) Send interval (UINT16) CRC-16 checksum For each action: (UINT8) Player number (UINT16) Length of action data (VOID) Action data
func (*TimeSlot) Deserialize ¶
Deserialize decodes the binary data generated by Serialize.
type TimeSlotAck ¶
TimeSlotAck implements the [0x27] W3GS_OUTGOING_KEEPALIVE packet (C -> S).
This is sent to the host from each client.
Format:
(UINT8) Unknown (UINT32) Unknown (checksum?)
func (*TimeSlotAck) Deserialize ¶
func (pkt *TimeSlotAck) Deserialize(buf *protocol.Buffer, enc *Encoding) error
Deserialize decodes the binary data generated by Serialize.
type UnknownPacket ¶
UnknownPacket is used to store unknown packets.
func (*UnknownPacket) Deserialize ¶
func (pkt *UnknownPacket) Deserialize(buf *protocol.Buffer, enc *Encoding) error
Deserialize decodes the binary data generated by Serialize.