One port, TCP for the lobby and UDP for the relay.
Newline-terminated JSON objects, at most 4,096 bytes each. The first message
must be hello, within 10 seconds; the connection closes after 60 seconds
without a message (clients send ping every 15 seconds).
| Client sends | Server answers |
|---|---|
{"op":"hello","proto":1,"name":"…","build":"<xbe sha1>:<runtime ABI>"} |
{"op":"welcome","player_id":N,"token":"<16 hex>","vaddr":"10.x.y.z","udp_port":P,"motd":"…","server":"1.0.0"} |
{"op":"list"} |
{"op":"lobbies","lobbies":[{"id","name","host","players","max_players","locked","build_ok"}]} |
{"op":"create","name":"…","max_players":2-16,"password":""} |
{"op":"joined","lobby":{… ,"members":[{"id","name","vaddr","host"}]}} |
{"op":"join","lobby_id":N,"password":""} |
joined, or an error |
{"op":"leave"} |
{"op":"left"} |
{"op":"ping"} |
{"op":"pong"} |
Server events: {"op":"lobby_update","lobby":{…}} when members change, and
{"op":"lobby_closed","lobby_id":N,"reason":"…"} when the host leaves.
Errors: {"op":"error","code":"…","message":"…"} with codes
bad_request, protocol_mismatch, server_full, too_many_connections,
rate_limited, already_in_lobby, not_in_lobby, no_such_lobby,
build_mismatch, wrong_password, lobby_full.
Client to server, big-endian, then the payload (at most 1,514 bytes: the runtime sends whole Ethernet frames from the emulated network card, with both ports 0):
| Bytes | Field |
|---|---|
| 4 | magic UC2R |
| 1 | version 1 |
| 1 | flags (bit 0: keep-alive) |
| 2 | reserved, 0 |
| 8 | token from welcome |
| 4 | destination virtual address (0xFFFFFFFF: everyone in the lobby) |
| 2 | source port (the game's) |
| 2 | destination port |
Server to client: the same layout with the token replaced by the 4-byte source virtual address followed by the destination (20 bytes of header).
A client sends a keep-alive (flags 1, no payload) right after welcome and
every 10 seconds; the server answers it, which also keeps NAT mappings open.
Packets from an address other than the client's TCP address, with an unknown
token, or over the rate limit are dropped silently.