Networking
Wire format
Section titled "Wire format"A typed message (see Split parts) is sent as one Lua string:
"@atl2:" + COBS(bytes)A message that carries game objects is sent as {string, object1, ...}, and the bytes refer
to the objects by index. The code is in atl/wire.hpp.
The bytes start with a hash of the struct's name and a hash of its layout. That's how a
receiver tells a message from an older or newer build apart. It also means that changing a
struct makes old saves of it unreadable: loadState returns nothing instead of misreading
them.
The format is only used between the two halves of one part. Calls to and from Lua mods keep
using Lua values. The encoding runs in the loader's Lua (val_cobs_* and val_base64_*), not
in WASM.
Why COBS
Section titled "Why COBS"The game's network cuts a string off at its first zero byte ("ab\0cd" arrives as "ab"), but
keeps every other byte value intact. COBS rewrites the bytes so none of them are zero. It adds
at most 1 byte per 254, where base64 adds 1 byte per 3.
Building with -DATL_WIRE_BASE64 sends base64 (@atl1:) instead. Receivers read both
formats, so players on either build, or on builds from before COBS, can play together. Saved
state (saveState) is always base64.
Size limits
Section titled "Size limits"The game refuses any single network send over 65,437 bytes, counting the method name, the data and the game's own framing. The limit is available as:
sm::kNetworkPacketLimitandsm::Network::kPacketLimitin C++ATL_NETWORK_PACKET_LIMITin the C SDK
A raw string payload costs its length, plus the length of the method name, plus 14 bytes.
Typed messages deal with the limit for you:
sendandsendTosplit anything overatl::wire::kChunkBytes(60,000 encoded bytes, or 45,000 with base64) into several packets and put them back together on arrival, up toatl::wire::kMaxMessageBytes(1 MiB).synccan't be split, because the game keeps one value per channel. A synced state larger than one packet is logged and not sent.atl::wire::encodedSize(msg)andatl::wire::packetCount(msg)tell you a message's size in advance.
Raw sends such as sendToServer("name", value) aren't split. Check those against
sm::kNetworkPacketLimit yourself.