uncategorized protocols - wxyz-abcd/node-haxball GitHub Wiki

Protocols

Here are all of the streaming protocols used in Haxball.

1. Basic Data Types

1.1. uint8

Index Length Type
0 1 uint8

1.2. int16

Index Length Type
0 2 int16

1.3. uint16

Index Length Type
0 2 uint16

1.4. int32

Index Length Type
0 4 int32

1.5. uint32

Index Length Type
0 4 uint32

1.6. float32

Index Length Type
0 4 float32

1.7. float64

Index Length Type
0 8 float64

1.8. uint8array

Index Length Type
0 end uint8(loop)

1.9. shortstring

Index Length Type Description
0 1 uint8 # of chars in the string
1 end utf8char(loop) all chars in the string

1.10. string

Index Length Type Description
0 L utf8char # of chars in the string
L end utf8char(loop) all chars in the string

1.11. nullable_string

Index Length Type Description
0 L utf8char null => 0, otherwise => (1+# of chars in the string)
L end utf8char(loop) all chars in the string

1.12. json

Index Length Type Description
0 end string stringified version of the json

2. Game Structures

2.1. spawn_point

Index Length Type Description
0 8 float64 x coordinate
8 8 float64 y coordinate

2.2. vertex

Index Length Type Description
0 8 float64 x coordinate
8 8 float64 y coordinate
16 8 float64 bouncing coefficient
24 4 int32 collision mask
28 4 int32 collision group

2.3. segment

Index Length Type Description
0 1 uint8 flags(*)
1 1 uint8 id of 1st vertex
2 1 uint8 id of 2nd vertex
3 8 float64 bias(*)
11 8 float64 curve(*)
19 4 int32 color(*)
23 8 float64 bouncing coefficient
31 4 int32 collision mask
35 4 int32 collision group

NOTE: "flags" contain whether bias(default=0, flag value=1), curve(default=Infinity, flag value=2), color(default=0, flag value=4) or visibility(default=false, flag value=8) is different from its default value. Only the values that are different from its default value are written to/read from stream.

2.4. goal

Index Length Type Description
0 8 float64 x coordinate of first point
8 8 float64 y coordinate of first point
16 8 float64 x coordinate of second point
24 8 float64 y coordinate of second point
32 1 uint8 team id

2.5. disc

Index Length Type Description
0 8 float64 x coordinate of position
8 8 float64 y coordinate of position
16 8 float64 x component of speed
24 8 float64 y component of speed
32 8 float64 x component of gravity
40 8 float64 y component of gravity
48 8 float64 radius
56 8 float64 bouncing coefficient
64 8 float64 inverse mass
72 8 float64 damping
80 4 uint32 color
84 4 int32 collision mask
88 4 int32 collision group

2.6. joint

Index Length Type Description
0 1 uint8 index of the first disc
1 1 uint8 index of the second disc
2 8 float64 minimum length
10 8 float64 maximum length
18 8 float64 strength
26 4 int32 color

2.7. game_state

Index Length Type Description
0 1 uint8 number of discs in the game
1 L disc(loop) every disc in the array
L+1 4 int32 goal tick counter
L+5 4 int32 state
L+9 4 int32 red score
L+13 4 int32 blue score
L+17 8 float64 elapsed time
L+25 4 int32 pause game tick counter
L+29 1 uint8 id of the last team that conceded a goal

2.8. team_colors

Index Length Type Description
0 1 uint8 angle of stripes
1 5 int32 text color
5 6 uint8 number of stripe colors(<=3)
6 end int32(loop) every stripe color in the array

2.9. player_physics

Index Length Type Description
0 8 float64 bouncing coefficient
8 8 float64 inverse mass
16 8 float64 damping
24 8 float64 acceleration
32 8 float64 acceleration while kicking
40 8 float64 damping while kicking
48 8 float64 kick strength
56 8 float64 x component of gravity
64 8 float64 y component of gravity
72 4 int32 collision group
76 8 float64 radius
84 8 float64 kickback

2.10. stadium

Index Length Type Description
0 1 uint8 default stadium id(255 = custom)
1 4 int32 background type
5 8 float64 background width
13 8 float64 background height
21 8 float64 background kickoff radius
29 8 float64 background corner radius
37 8 float64 background goal line
45 4 int32 background color
49 8 float64 width
57 8 float64 height
65 8 float64 spawn distance
73 L1 player_physics player physics data
73+L1 2 uint16 max view width
75+L1 1 uint8 camera follow
76+L1 1 uint8 storeable(1) or not(0)
77+L1 1 uint8 full reset on kick off(1) or not(0)
78+L1 1 uint8 length of vertices array
79+L1 L2 vertex(loop) vertices array
79+L1+L2 1 uint8 length of segments array
80+L1+L2 L3 segment(loop) segments array
80+L1+L2+L3 1 uint8 length of planes array
81+L1+L2+L3 L4 plane(loop) planes array
81+L1+L2+L3+L4 1 uint8 length of goals array
82+L1+L2+L3+L4 L5 goal(loop) goals array
82+L1+L2+L3+L4+L5 1 uint8 length of discs array
83+L1+L2+L3+L4+L5 L6 disc(loop) discs array
83+L1+L2+L3+L4+L5+L6 1 uint8 length of joints array
84+L1+L2+L3+L4+L5+L6 L7 joint(loop) joints array
84+L1+L2+L3+L4+L5+L6+L7 1 uint8 length of red spawn points array
85+L1+L2+L3+L4+L5+L6+L7 L8 spawn_point(loop) red spawn points array
85+L1+L2+L3+L4+L5+L6+L7+L8 1 uint8 length of blue spawn points array
86+L1+L2+L3+L4+L5+L6+L7+L8 end spawn_point(loop) blue spawn points array

2.11. player

Index Length Type Description
0 1 uint8 admin(1) or not(0)
1 4 int32 number on avatar
5 L1 nullable_string avatar
5+L1 L2 nullable_string headless avatar
5+L1+L2 1 uint8 synced(1) or not(0)
6+L1+L2 L3 nullable_string flag
6+L1+L2+L3 4 int32 unknown
10+L1+L2+L3 L4 nullable_string name
10+L1+L2+L3+L4 4 int32 input
14+L1+L2+L3+L4 L5 utf8char id
14+L1+L2+L3+L4+L5 1 uint8 kicking(1) or not(0)
15+L1+L2+L3+L4+L5 2 int16 kick rate tick counter max
17+L1+L2+L3+L4+L5 1 uint8 kick rate tick counter min
18+L1+L2+L3+L4+L5 1 uint8 team id
19+L1+L2+L3+L4+L5 2 int16 disc index if playing, -1 otherwise

2.12. room_state

Index Length Type Description
0 L1 nullable_string name
L1 1 uint8 teams locked(1) or not(0)
1+L1 4 int32 score limit
5+L1 4 int32 time limit
9+L1 2 int16 kick rate(max)
11+L1 1 uint8 kick rate(rate)
12+L1 1 uint8 kick rate(min)
13+L1 L2 stadium stadium
13+L1+L2 1 uint8 game active(1) or not(0)
14+L1+L2 L3 game_state* game state
14+L1+L2+L3 1 uint8 length of players array
15+L1+L2+L3 L4 player(loop) players array
15+L1+L2+L3+L4 L5 team_colors red team colors
15+L1+L2+L3+L4+L5 L5 team_colors blue team colors

NOTE: Game state is not read/written if game is not active.

3. Events

3.1. event

Index Length Type Description
0 1 uint8 event type
1 end event_contents event-dependent information(check below)

3.2. binary_custom_event_contents

Index Length Type Description
0 4 uint32 packed_contents length
4 end packed_contents first unpack using pako

3.2.1. packed_contents

Index Length Type Description
0 4 uint32 type
4 end uint8array data

3.3. check_consistency_event_contents

Index Length Type Description
0 4 utf8char length of consistency data
4 end uint8array consistency data

3.4. custom_event_contents

Index Length Type Description
0 4 uint32 type of the custom event
4 end json custom event information

3.5. identity_event_contents

Index Length Type Description
0 4 uint32 player id
4 end json identity data

3.6. join_room_event_contents

Index Length Type Description
0 4 int32 player id
4 len1 nullable_string player name
4+len1 len2 nullable_string player flag
4+len1+len2 end nullable_string player avatar

3.7. kick_ban_player_event_contents

Index Length Type Description
0 4 int32 player id
4 len nullable_string reason(len<=100)
4+len 1 uint8 kick(0) or ban(1)

3.8. pause_resume_game_event_contents

Index Length Type Description
0 1 uint8 resume(0) or pause(1)

3.9. ping_event_contents

Index Length Type Description
0 L utf8char length of pings array
L+1 end utf8char(loop) every ping in array

3.10. reorder_players_event_contents

Index Length Type Description
0 1 uint8 move to top(1) or bottom(2)
1 1 uint8 length of player id array
2 end int32(loop) every player id in array

3.11. send_announcement_event_contents

Index Length Type Description
0 L string announcement message(length<=1000)
L 4 int32 color of announcement
L+4 1 uint8 style of announcement
L+5 1 uint8 sound of announcement

3.12. send_chat_event_contents

Index Length Type Description
0 L string chat message(length<=140)

3.13. send_chat_indicator_event_contents

Index Length Type Description
0 1 uint8 indicator active(1) or passive(0)

3.14. send_input_event_contents

Index Length Type Description
0 4 uint32 player input

3.15. set_avatar_event_contents

Index Length Type Description
0 end nullable_string player avatar

3.16. set_disc_properties_event_contents

Index Length Type Description
0 4 int32 player/disc id
4 1 uint8 type: player(1) or disc(0)
5 2 uint16 flags(*)
7 L float32(loop) all changed float properties(*)
L+7 end int32(loop) all changed int32 properties(*)

NOTE: "flags" contain the information about which properties of the disc are being changed. The order of variables written are as follows: float: [x, y, xspeed, yspeed, xgravity, ygravity, radius, bCoeff, invMass, damping], int: [color, cMask, cGroup].

3.17. set_gameplay_limit_event_contents

Index Length Type Description
0 4 int32 type: scorelimit(0) or timelimit(1)
4 4 int32 value

3.18. set_headless_avatar_event_contents

Index Length Type Description
0 L nullable_string new avatar value
L end int32 player id

3.19. set_kickrate_limit_event_contents

Index Length Type Description
0 4 int32 "min" value
4 4 int32 "rate" value
8 4 int32 "burst" value

3.20. set_player_admin_event_contents

Index Length Type Description
0 4 int32 player id
4 1 uint8 admin(1) or not(0)

3.21. set_player_sync_event_contents

Index Length Type Description
0 1 uint8 sync(1) or not(0)

3.22. set_player_team_event_contents

Index Length Type Description
0 4 int32 player id
4 1 uint8 team id

3.23. set_stadium_event_contents

Index Length Type Description
0 2 uint16 length of packed_contents
2 end uint8array packed_contents(first unpack using pako)

3.23.1. packed_contents

Index Length Type Description
0 end stadium contents of the stadium

3.24. set_team_colors_event_contents

Index Length Type Description
0 1 uint8 team id
1 end team_colors contents of team colors

3.25. set_teams_lock_event_contents

Index Length Type Description
0 1 uint8 locked(1) or not(0)

4. Replay File Structure

Index Length Type Description
0 4 utf8char x 4 replay file signature ("HBR2")
4 4 uint32 version
8 4 uint32 number of frames
12 end uint8array packed_contents(first unpack using pako)

4.1. goal_marker

Index Length Type Description
0 L utf8char number of frames passed from the goal before this one
L 1 uint8 team id

4.2. replay_event

Index Length Type Description
0 L utf8char number of frames passed from the event before this one
L 2 uint16 id of the player who initiated this event
2+L end event the event's internal data

4.3. packed_contents

Index Length Type Description
0 2 uint16 length of goal markers array
2 L1 goal_marker(loop) goal markers array
2+L1 L2 room_state room state at the beginning
2+L1+L2 end replay_event(loop) events array