# PROTOCOL DEFINITION Messages communicated between the client and server follow the same format, but have different meanings depending on which end is the recipient. A message's intent is determined by its packet ID, a unique identifier that tells the client or server how it should react to the received message. A message id that incites bidirectional communication between the client and server should typically be associated with the same message id on the client as on the server, so as to avoid confusion. A packet of communication between the client and server is considered to be a header followed by seamlessly connected regions of bytes, the boundaries of which are defined in the header. All references to the 'byte' in this document refers to individual 8-bit octets, as is the de facto standard in modern computing. All binary-encoded multi-byte quantities sent in a packet are to be sent in network byte order (big endian). ## Header Because the body of the packet is a sequence of many different regions of byte data that is not delimited, it is necessary for the header of the packet to determine boundaries for the regions of data. * The first two bytes will always be 0xB0 and 0x0B. If this is not set properly, the endpoint must close the connection. * The next four bytes are the total length of the entire packet, including the whole header. * The seventh byte is the packet id, the meanings of which are defined in the packet ID list section. * The eighth byte is the number of byte regions in the packet. * The bytes following the eighth byte are a list of binary length segments, each of which correspond to the number of bytes in its respective region. They each follow this format: * If length is less than 254, the length of the region is stored in a single byte. * If length is greater than or equal to 254 but less than 65,536, the first byte of the length segment will be 254 and the following two bytes is the length of the region. * If length is greater than or equal to 65,536, the first byte of the length segment will be 255 and the following four bytes is the length of the region. The number of length segments must equal the number of byte regions as defined in the second byte. The combined length of the regions must not exceed 232 - _n_ - 1 where _n_ is the length of the header. ### Packet IDs A packet ID may have a specific "direction" of communication, in that an endpoint may either act as a _requester_ or a _responder_. A _requester_ is an endpoint that drives all of the communication on that specific packet ID, while the _responder_ is responsible for providing a timely response to the requests it receives. A _responder_ for a specific packet ID should never send that packet ID unsolicited; either the packet will be ignored or the other endpoint will close the connection. Any packet ID marked as bidirectional may be initiated by either endpoint at any time. A _blind requester_ is an endpoint that sends out a packet of a certain ID and either does not expect a response or expects a response on a different packet ID. ## Body The message body immediately follows the header with no delimiter, and consists of a sequence of byte regions as defined in the header that are laid out in sequence without any delimiters. The position of a byte region in the body should correspond to the offset of the length segment in the header. ### Numeric Packing All numbers, unless otherwise specified, are the string representation of a base 10 number. Common exceptions are listed below: * User IDs: Hex string, 8 bytes unsigned * Co-ordinates: 8 bytes, double-precision float * Big Int: Hex string, variable size ## Master/Slave Servers To keep track of the status of multiple servers from a centralized point that the client may query, each server must be able to communicate with a "master" server that will record and dispense information regarding all servers to clients. All servers that report to the master server will hereby be refered to as "slave" servers. Communication between master and slave servers will be done over a TCP connection on a port that is defined by the master server's configuration. The protocol used for this communication is identical to the protocol defined for standard client/server communication; however, the Packet IDs are defined differently. Communication between the master server and clients will be done over a WebSocket connection on a port that is defined by the master server's configuration. The protocol used for this communication is identical to the protocol defined for standard client/server communication; however, the Packet IDs are defined differently. ## Packet ID List ### Master/Slave Packet IDs #### Master to Slave [Encrypted]
ID 0: Positive ACK Responder |
# | Region | Type |
---|---|---|
1 | Request Packet ID | Byte |
ID 1: Negative ACK Responder |
# | Region | Type |
---|---|---|
1 | Request Packet ID | Byte |
2 | Error Code | Packed Unsigned Short |
ID 0: Authentication Requester |
# | Region | Type |
---|---|---|
1 | Server Name | Text |
2 | Port | Packed Unsigned Short |
3 | License | Text |
4 | Secret | Blob (512b) |
ID 1: Status Update Blind Requester |
# | Region | Type |
---|---|---|
1 | User Count | Packed Unsigned Short |
2 | Max Users | Packed Unsigned Short |
ID 0: Login Response Responder |
# | Region | Type | if |
---|---|---|---|
1 | Succeeded | Boolean | |
2 | Message | String | ¬R1 |
2 | Secret | Bytes (128) | R1 |
ID 1: Registration Response Responder |
# | Region | Type |
---|---|---|
1 | Succeeded | Boolean |
2 | Message | String |
ID 2: Server Listing Responder |
# | Region | Type |
---|---|---|
1 | Server Count (n) | Packed Unsigned Short |
r > 1 | Iterated over n (0 ≤ i ≤ n - 1) | |
2 + 2i | Server Id | Packed Unsigned Short |
3 + 2i | User Count | Packed Unsigned Short |
ID 0: Login Request Requester |
# | Region | Type |
---|---|---|
1 | Username | String |
2 | Password | String |
ID 1: Registration Request Requester |
# | Region | Type |
---|---|---|
1 | Username | String |
2 | Password | String |
3 | String |
ID 2: Server List Request Requester |
Bodyless Packet |
---|