Control Messages

Control messages are transmitted to signal events related to the creation and maintenance of sessions and connections in general.

The following explains the purpose and structure of various types of control messages.

TODO: Figure out opcode 0x1 and 0x2.

Opcode

To identify a control message in the first place, the frame body encodes the message opcode. Opcodes are unique values that map to exactly one type of frame and tell the parser how the message data should be interpreted.

For concrete values, see the following message types.

Session Offer

Opcode: 0x0

When a new client connects to the server, it is greeted with this type of frame. Since most of the game data exchange requires an active session, it must first be established through the client completing the handshake by responding with a Session Accept message.

OffsetTypeDescription
0x0uint16The proposed session ID to agree on
0x2int32The high 4 bytes of the UNIX timestamp the message was sent at
0x6int32The low 4 bytes of the UNIX timestamp the message was sent at
0xAuint32The milliseconds into the second this message was sent at
0xEuint32Length prefix for unknown field
0x12uint8[]Unknown
-uint8Reserved; always zero

Keep Alive

Opcode: 0x3

A bi-directional opcode that may be initiated independently by both, client and server. These messages are exchanged at fixed intervals and a Keep Alive Rsp from the other peer ensures the session is still alive.

The structure of this message (and the response to it) varies depending on the party sending it:

Client-initiated Keep Alive:

OffsetTypeDescription
0x0uint16The corresponding session ID
0x2uint16The milliseconds into the second the message was sent at
0x4uint16How many minutes have elapsed since the session was started

Server-initiated Keep Alive:

OffsetTypeDescription
0x0uint16Invalid session ID value
0x2uint32The number of milliseconds since the server was started

Keep Alive Rsp

Opcode: 0x4

This message is used to acknowledge a received Keep Alive message and confirm that the other end of the connection is still listening. Either peer should respond to this using the structure of the preceding Keep Alive message.

Session Accept

Opcode: 0x5

Sent from the client to the server as a response to a Session Offer message. This completes the handshake and confirms the creation of a new session bound to the proposed ID.

From that point onwards, the session must be kept alive by heartbeating.

OffsetTypeDescription
0x0uint16Reserved; always zero
0x2int32The high 4 bytes of the UNIX timestamp the message was sent at
0x6int32The low 4 bytes of the UNIX timestamp the message was sent at
0xAuint32The milliseconds into the second the message was sent at
0xEuint16The proposed session ID from Session Offer
0x10uint32Length prefix for unknown field
0x14uint8[]Unknown
-uint8Reserved; always zero