Specification 1.1 · protocol 5 · bfe-sim-34 · CC BY 4.0
Multiplayer protocol and relay
How a Battlefront Eternal client, dedicated server, directory and relay talk to each other, written so another Battlefront port or tool can implement a compatible piece and use the same words for the same things.
About this specification
- Specification
- 1.130 November 2026
- Wire
- Protocol 5profile snapshot-delta-v1, simulation bfe-sim-34 (preview 395)
- Reference
- The codeengine 233d73a56, directory, relay
This page describes what the public code does at the commits named here. The code is the reference: where this text and the code disagree, the code is right, and a report of the difference is welcome. Anything the code did not settle when this was written is marked not specified here rather than guessed.
Must, must not, should and may are used as in RFC 2119. Integers are little endian unless a table says otherwise. A tick is one step of the 60 Hz simulation. "Client", "server", "directory" and "relay" are the four roles below.
This text and its diagrams are licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). The code they describe is licensed under the GNU General Public License, version 3 only.
Roles
Client: the desktop app. Dedicated server: bfeserver, which runs one battle at a time at 60 Hz and is the authority over it; the app's own HOST runs the same server. Directory: the master server at online.battlefronteternal.com, which lists servers, passes signalling between client and server, issues short-lived relay credentials and signs a global ban feed. Relay: a TURN server (coturn) at relay.battlefronteternal.com, used only when no direct path works. A client and a server on one network need neither directory nor relay: they find each other by LAN discovery or an address typed in.
Transport: BFE-UDP/1
Every game datagram is UDP and at most 1,200 bytes. The handshake proves both identities (Ed25519) and agrees keys (X25519, HKDF-SHA256); after it, every packet is sealed with AES-256-GCM. The construction follows established designs: a SIGMA-I handshake as TLS 1.3 uses, QUIC's acknowledgement ranges and loss detection, and WireGuard-style session ids, roaming and replay windows. Inside a sealed packet, frames carry acknowledgements, unreliable datagrams and two reliable ordered streams.
Packet types
The first byte of every datagram is its packet type.
| Type | Name | Direction | Purpose | Bytes | Reference |
|---|---|---|---|---|---|
| 177 | INITIATION | client to server | Opens a handshake: client session id, X25519 ephemeral public key, 16 random bytes, optional RETRY token. | 1200 to 1200 | layout.rs:89 |
| 178 | RESPONSE | server to client | Server ephemeral key and random, plus the server's sealed identity proof and signed server hello JSON. | 186 to 1200 | layout.rs:98 |
| 183 | CONFIRM | client to server | Client identity proof and signed client hello; completes the 1-RTT handshake. | 134 to 1200 | layout.rs:108 |
| 179 | RETRY | server to client | Stateless address validation: the client must resend INITIATION carrying the token. | 9 to 72 | layout.rs:115 |
| 182 | VERSION | server to client | Tells a client whose INITIATION version byte is not 1 which wire version the server speaks. | 6 to 6 | layout.rs:77 |
| 180 | DATA | both | Established 1-RTT packet, key phase 0. Carries frames. | 26 to 1200 | layout.rs:83 |
| 181 | DATA_PHASE | both | Same layout as DATA; marks key phase 1 after a key update. | 26 to 1200 | connection.rs:174 |
| 184 | PUNCH | server to client candidate addresses | NAT hole punching toward up to 8 candidate addresses supplied by the master; no reply expected; the server ignores received PUNCH packets. | 9 to 9 | server.rs:19 |
INITIATION (177) layout
| Offset | Size | Field | Type | Meaning |
|---|---|---|---|---|
| 0 | 1 | type | u8 | 177 |
| 1 | 1 | version | u8 | wire version 1; any other value gets a VERSION reply (handshake.rs:249-257) |
| 2 | 4 | session | u32 LE | client-chosen random session id, never 0 (handshake.rs:38,241-244) |
| 6 | 32 | ephemeral | bytes | client X25519 public key |
| 38 | 16 | random | bytes | client random |
| 54 | 2 | tokenLength | u16 LE | 0..64 (MAX_TOKEN); larger is dropped (handshake.rs:245-248) |
| 56 | tokenLength | token | bytes | opaque RETRY token echoed back, else absent |
| 56+tokenLength | to 1200 | padding | zero bytes | anti-amplification padding |
RESPONSE (178) layout
| Offset | Size | Field | Type | Meaning |
|---|---|---|---|---|
| 0 | 1 | type | u8 | 178 |
| 1 | 1 | version | u8 | 1 |
| 2 | 4 | clientSession | u32 LE | echo of INITIATION.session |
| 6 | 4 | serverSession | u32 LE | server-chosen random non-zero id, unique among pending and live sessions (handshake.rs:310-320); becomes the receiver id of client DATA |
| 10 | 32 | ephemeral | bytes | server X25519 public key |
| 42 | 16 | random | bytes | server random |
| 58 | 2 | sealedLength | u16 LE | bytes after the header = 110 + helloLength + 16; must equal datagram length - 60 (handshake.rs:79) |
| 60 | 44 | sealed.identity | bytes | server Ed25519 public key as SPKI DER (12-byte prefix 30 2a 30 05 06 03 2b 65 70 03 21 00 + 32-byte key) |
| 104 | 64 | sealed.signature | bytes | Ed25519 signature over 'BFE-UDP/1 server' || 0x00 || SHA-256(t2 || identity || hello) |
| 168 | 2 | sealed.helloLength | u16 LE | 0..1014 (MAX_HELLO) |
| 170 | helloLength | sealed.hello | UTF-8 JSON object | server hello (see messages.yaml server_hello) |
| end-16 | 16 | tag | bytes | AES-GCM tag |
bytes 60..end are AES-256-GCM sealed with the 's hs' handshake key at packet number 0; the 60-byte header is the AAD (handshake.rs:369-373)
CONFIRM (183) layout
| Offset | Size | Field | Type | Meaning |
|---|---|---|---|---|
| 0 | 1 | type | u8 | 183 |
| 1 | 1 | version | u8 | 1 |
| 2 | 4 | session | u32 LE | RESPONSE.serverSession |
| 6 | 2 | sealedLength | u16 LE | 110 + helloLength + 16; must equal datagram length - 8 (handshake.rs:413-416) |
| 8 | 44 | sealed.identity | bytes | client Ed25519 SPKI DER |
| 52 | 64 | sealed.signature | bytes | Ed25519 over 'BFE-UDP/1 client' || 0x00 || SHA-256(t3 || identity || hello) |
| 116 | 2 | sealed.helloLength | u16 LE | 0..1014 |
| 118 | helloLength | sealed.hello | UTF-8 JSON object | client hello (messages.yaml hello) |
| end-16 | 16 | tag | bytes | AES-GCM tag |
bytes 8..end sealed with the 'c hs' handshake key at packet number 0; the 8-byte header is the AAD (handshake.rs:109)
RETRY (179) layout
| Offset | Size | Field | Type | Meaning |
|---|---|---|---|---|
| 0 | 1 | type | u8 | 179 |
| 1 | 1 | version | u8 | 1 |
| 2 | 4 | session | u32 LE | INITIATION.session |
| 6 | 2 | tokenLength | u16 LE | 1..64; this server always sends 24 |
| 8 | tokenLength | token | bytes | opaque to the client. bfeserver's token: 8-byte LE f64 mint time (ms) + first 16 bytes of HMAC-SHA256(secret, '<time>|<source>|<session>' || clientEphemeral); valid 10 s back, 1 s ahead (crypto.rs:201-277) |
VERSION (182) layout
| Offset | Size | Field | Type | Meaning |
|---|---|---|---|---|
| 0 | 1 | type | u8 | 182 |
| 1 | 1 | version | u8 | server wire version (1) |
| 2 | 4 | session | u32 LE | INITIATION.session |
DATA (180) layout
| Offset | Size | Field | Type | Meaning |
|---|---|---|---|---|
| 0 | 1 | type | u8 | 180 (key phase 0) or 181 (key phase 1) |
| 1 | 4 | receiver | u32 LE | the receiving side's own session id (server routes by it: server.rs:482-493) |
| 5 | 4 | number | u32 LE | sender packet number, 0 upward, never reused; nonce input |
| 9 | 1..1175 | ciphertext | bytes | encrypted frames |
| end-16 | 16 | tag | bytes | AES-GCM tag |
frames sealed with AES-256-GCM under the sender's application key; the 9-byte header is the AAD; the packet number is NOT encrypted (no header protection) (connection.rs:374-376)
PUNCH (184) layout
| Offset | Size | Field | Type | Meaning |
|---|---|---|---|---|
| 0 | 1 | type | u8 | 184 |
| 1 | 8 | zero | zero bytes | always 0 |
Handshake and keys
A 1-RTT handshake: INITIATION, RESPONSE (the server's proof), CONFIRM (the client's proof), then the server's HANDSHAKE_DONE frame in the first DATA packet. Labels are ASCII; || is concatenation.
| Key agreement | X25519 (crate x25519-dalek 2, StaticSecret); an all-zero shared secret is refused on both sides (handshake.rs:82,306-309) |
|---|---|
| Signatures | Ed25519 (crate ed25519-dalek 2), verify_strict; public keys must be canonical and not small-order (crypto.rs:182-200) |
| Hash, KDF | SHA-256 (crate sha2); HKDF-SHA256 (crate hkdf 0.12); Extract(salt, ikm); Expand(secret, 'bfe-udp1 ' + label) (crypto.rs:36-46) |
| Sealing | AES-256-GCM (crate aes-gcm 0.10), 32-byte key, 12-byte IV, 16-byte detached tag (crypto.rs:279-310) |
| t1 | SHA-256('BFE-UDP/1 initiation' || INITIATION[0..54]) |
| t2 | SHA-256(t1 || RESPONSE[0..58]) (header up to but not including sealedLength) |
| Handshake secret | HKDF-Extract(salt = t2, ikm = X25519 shared secret); server key traffic secret Expand(handshake_secret, 'bfe-udp1 s hs'), client key traffic secret Expand(handshake_secret, 'bfe-udp1 c hs') |
| Server proof | Ed25519 sign('BFE-UDP/1 server' || 0x00 || SHA-256(t2 || server SPKI DER || server hello bytes)) |
| t3 | SHA-256(t2 || RESPONSE[58..end]) (sealedLength, sealed body and tag) |
| Client proof | Ed25519 sign('BFE-UDP/1 client' || 0x00 || SHA-256(t3 || client SPKI DER || client hello bytes)); the exact hello bytes are signed |
| Master secret | HKDF-Extract(salt = SHA-256(t3 || whole CONFIRM datagram), ikm = handshake_secret); client to server traffic secret Expand(master, 'bfe-udp1 c ap'), server to client traffic secret Expand(master, 'bfe-udp1 s ap') |
| Key and IV | key = Expand(secret, 'bfe-udp1 key', 32); iv = Expand(secret, 'bfe-udp1 iv', 12) (crypto.rs:283-287) |
| Nonce | IV with its last 4 bytes (big-endian u32) XORed with the packet number (crypto.rs:291-296); handshake packets use number 0 |
| Identity id | SHA-256 of the ASCII standard padded base64 text of the 44-byte SPKI DER (crypto.rs:51-56,191); the client pins this 32-byte id from /info, a listing or join data and rejects a RESPONSE with another id (handshake.rs:91-94) |
| Retransmission | client resends INITIATION (with its candidate's token) every 250 ms until a RESPONSE; after a RESPONSE it resends the identical CONFIRM every 250 ms until the first authenticated DATA (endpoint.rs:152-160); a duplicate RESPONSE also triggers a CONFIRM resend (handshake.rs:76-78; endpoint.rs:144) |
| Half-open limits | 1024 in all, 32 per network prefix, 15000 ms each; RETRY required above 256 pending. per address prefix (IPv4 /32, IPv6 /64) token bucket, bfeserver rate 8/s, burst 16, LRU of 4096 prefixes (server.rs:374-410; udp_server.rs:653-660) |
| Key update | the sender rotates to Aead(Expand(current secret, 'bfe-udp1 ku')) when its next packet number is a non-zero multiple of KEY_INTERVAL (1,048,576) and flips DATA<->DATA_PHASE; the receiver tries the current key, then the previous key for numbers below the phase start, then the next key, and commits only after authentication (crypto.rs:288-290; connection.rs:174-186,373) |
| Replay | 4096-packet sliding bitmap committed only after AEAD success (codec.rs:111-135; connection.rs:173,189) |
Frames inside a sealed packet
| Id | Frame | Fields | Rules | Reference |
|---|---|---|---|---|
| 0 | PADDING | one byte, skipped | connection.rs:207 | |
| 1 | PING | ack-eliciting (peer ACKs within 25 ms); sent as keepalive after 1000 ms without sending, or on a PTO with nothing to retransmit | connection.rs:210 | |
| 2 | ACK | largest varint, delay varint, rangeCount varint, firstRange varint, gap[i] varint, length[i] varint | QUIC-style descending ranges; at most one ACK frame per packet; acknowledging a packet number not yet sent is a protocol error; not ack-eliciting. The writer reports the newest 24 (MAX_ACK_RANGES) of up to 256 retained received ranges | connection.rs:43 |
| 3 | DATAGRAM | flags u8, length varint, payload bytes | unreliable, unordered state lane; never retransmitted; peer ACKs within 40 ms | state.rs:47 |
| 4 | FRAGMENT | flags u8, id varint, index u8, count u8, length varint, payload bytes | a state message too large for the current packet and larger than 1127 bytes of frame (PLAIN-48) is split into ceil(len/1111) parts; the receiver holds 16 assemblies (MAX_PENDING_FRAGMENTS) for 1000 ms each (FRAGMENT_LIFETIME), evicting the oldest; a repeated index or changed count is ignored; invalid count/index/length is a protocol error | state.rs:30 |
| 5 | STREAM | stream u8, offset varint, length varint, data bytes | reliable, ordered per stream, independent delivery cursors; lost ranges are retransmitted first; ack-eliciting (25 ms) | connection.rs:220 |
| 6 | CLOSE | code varint, reasonLength varint, reason UTF-8 bytes | ends the connection at once; the closing side keeps keys and re-sends its CLOSE at most every 100 ms for max(1000 ms, 3 PTO) while stray packets arrive; the bfeserver keeps closed sessions draining for 2000 ms (max 256) | connection.rs:154 |
| 7 | HANDSHAKE_DONE | sent by the server in its first DATA packet after admitting a session (and again for a duplicate CONFIRM); the client treats the first authenticated DATA as established | connection.rs:211 | |
| 8 | PATH_CHALLENGE | data 8 bytes | sent toward a new source address after an authenticated newest packet that is not probing-only; one challenge per candidate, new challenges at least 50 ms apart, resent after max(PTO, 50 ms); only the first PATH_CHALLENGE per packet is answered | connection.rs:196 |
| 9 | PATH_RESPONSE | data 8 bytes | answer on the current path goes in the control queue (max 16 frames); toward another address it is sent at once under a 64-token bucket refilled 128/s; a matching response from the challenged path switches the connection's path (migration) | connection.rs:224 |
Lanes
| Lane | Delivery | Reference |
|---|---|---|
none · state | unreliable, unordered DATAGRAM/FRAGMENT frames; replaceable: a full queue evicts the oldest whole message; never congestion-limited | state.rs:1 |
1 · EVENTS | reliable, ordered stream of length-prefixed messages; independent of BULK | layout.rs:44 |
2 · BULK | reliable, ordered stream like EVENTS; no message of this tree is observed on it (not confirmed that any sender uses it) | layout.rs:45 |
Close codes
| Code | Name | Sent when | Reference |
|---|---|---|---|
| 0 | NORMAL | client leaving ('left battle': rust/bfe-client/src/online/client.rs:477); code of an accepted admission (server.rs:150-156) | layout.rs:34 |
| 1 | IDLE | no authenticated packet for 20000 ms: 'idle timeout' (connection.rs:317); bfeserver session silent 30 s after start, 180 s before start: 'session silent' (game_session.rs:10-12,118-133) | layout.rs:35 |
| 2 | PROTOCOL | malformed or unknown frame, repeated ACK, ACK of unsent packet, stream/fragment limit errors (connection.rs:195-198,214,221,227); queue refusal (connection.rs:105-109); reliable data waiting 30 s without ACK progress 'reliable data not acknowledged' (connection.rs:318-321); packet numbers exhausted (connection.rs:372); endpoint poll error (endpoint.rs:163); bfeserver: events message over 65536 bytes 'oversized control frame' or non-object JSON 'invalid json' (game_session.rs:168-188); 'events backlog' over 262144 bytes (udp_peer.rs:281-284); more than 256 messages or 2 MiB in one server tick 'inbound message queue exceeded' (udp_server.rs:520-530,1081-1088); malformed 2005 battle request (udp_server.rs:496) | layout.rs:36 |
| 3 | VERSION | admission: protocol, profile or simulation differ, or (2004 battle) content differs without sitOut; reason = version_refusal text (udp_server.rs:438-455); 2005 match whose required record revision the client cannot take part in (udp_server.rs:502-504) | layout.rs:37 |
| 4 | REJECTED | server full 'The server is full.' (server.rs:635-636; udp_server.rs:486-488); 'Too many players are connected from your network.' (server.rs:637-641); banned 'You are banned from this server.' (udp_server.rs:472-477); password 'This server needs a password.' / 'Wrong password.' (udp_server.rs:458-464); password check answer 'Password accepted.' (udp_server.rs:468-470); spectator refusals (udp_server.rs:479-486); 2005 'match-changed' (udp_server.rs:494-501); older session replaced 'reconnected' (udp_server.rs:1003-1019); 'admission failed: <err>' after gameplay-error (local_server.rs:279-290) | layout.rs:38 |
| 5 | KICKED | operator kick with the operator's reason (local_server.rs:1300-1309; udp_server.rs:850); 2005 match: source over the inbound limit five seconds in a row 'inbound rate over the limit' (udp_server.rs:979-993; inbound.rs:1-17) | layout.rs:39 |
| 6 | SHUTDOWN | 'Server shutting down' (server.rs:907-919); 'server stopping' at battle hand-over or close (local_server.rs:1359-1369; udp_server.rs:1456-1462) | layout.rs:40 |
| 7 | APPLICATION | the player's updates failed for a second: 'your updates failed: <reason>' (local_server.rs:426-435) | layout.rs:41 |
Limits
Generated in the code from rust/sim/schema/transport-layout.json. Exceeding a limit is a protocol fault unless the table says otherwise.
| Limit | Value | Bounds | When exceeded |
|---|---|---|---|
MAX_DATAGRAM | 1200 bytes | any BFE-UDP/1 datagram | dropped (handshake.rs:64,395; connection.rs:169; udp_server.rs:902) |
TAG | 16 bytes | AES-GCM tag | n/a |
KEY_BYTES | 32 bytes | AES-256 key | n/a |
IV_BYTES | 12 bytes | GCM IV | n/a |
MAX_MESSAGE | 1048576 bytes | one EVENTS/BULK message | sender: queue refused and connection closed PROTOCOL; receiver: protocol error (streams.rs:46,104) |
MAX_TOKEN | 64 bytes | RETRY token | INITIATION or RETRY ignored (handshake.rs:48,70,246) |
MAX_HELLO | 1014 bytes | client and server hello JSON | client refuses to build; server drops CONFIRM; server does not answer (handshake.rs:34,90,325-327,429) |
INITIATION_BYTES | 1200 bytes | exact INITIATION length | dropped |
INITIATION_FIELDS | 54 bytes | INITIATION prefix hashed into t1 | n/a |
FRAGMENT_BYTES | 1111 bytes | sender fragment part size | n/a |
MAX_FRAGMENTS | 32 parts | parts per state message (so a state message is at most 35,552 bytes) | sender: 'state message too large' (state.rs:30) and connection closed PROTOCOL (connection.rs:108); receiver: protocol error |
MAX_PENDING_FRAGMENTS | 16 assemblies | concurrent reassemblies | oldest assembly evicted (state.rs:80-81) |
FRAGMENT_LIFETIME | 1000 ms | incomplete assembly age | assembly discarded (state.rs:79) |
MAX_STREAM_BUFFER | 4194304 bytes | unacknowledged send bytes per stream; receive horizon beyond delivered offset; congestion window cap | sender: close PROTOCOL 'reliable data not acknowledged'; receiver: protocol error 'stream buffer exceeded' (streams.rs:46,136; connection.rs:290) |
MAX_STREAM_SEGMENTS | 1024 ranges | out-of-order merged runs per receive stream | protocol error 'stream reassembly limit exceeded' (streams.rs:150) |
MAX_STREAM_PARTS | 4096 pieces | stored out-of-order pieces per receive stream | protocol error (streams.rs:127) |
MAX_CONTROL_FRAMES | 16 frames | queued PATH_RESPONSE control frames | extra answers dropped (connection.rs:238) |
MAX_SENT_PACKETS | 4096 packets | in-flight packet table | oldest entry declared lost (connection.rs:377) |
MAX_QUEUED_DATAGRAMS | 512 messages | state queue (and 512*1200 bytes) | oldest state message evicted, counted as dropped (state.rs:31) |
MAX_ACK_RANGES | 24 ranges | ranges written per ACK | older ranges omitted |
MAX_DECODED_ACK_RANGES | 64 ranges | ranges accepted per ACK | protocol error 'invalid ack' (connection.rs:47) |
REPLAY_WINDOW | 4096 packets | replay bitmap | older numbers treated as seen and dropped (codec.rs:119-123) |
MAX_RECEIVED_RANGES | 256 ranges | retained received-packet ranges for ACKs | oldest trimmed (connection.rs:192) |
MAX_PACKET_NUMBER | 4294967295 number | per-connection packet numbers | close PROTOCOL 'packet numbers exhausted' (connection.rs:372) |
KEY_INTERVAL | 1048576 packets | packets per key phase | key update |
MAX_SAFE_INTEGER | 9007199254740991 number | varint and stream offsets | 'varint too large' / 'stream offsets exhausted' |
KEEPALIVE_MS | 1000 ms | send idle | PING sent (connection.rs:326) |
IDLE_MS | 20000 ms | receive idle | close IDLE 'idle timeout' (connection.rs:317) |
STALL_MS | 30000 ms | reliable data without ACK progress | close PROTOCOL 'reliable data not acknowledged' |
ack_delay_target | 25 / 40 ms | ACK deadline after stream/ping/control/path frames (25) or state frames (40) | n/a |
initial_rtt | handshake RTT (min 1); 100 if unknown ms | RTT seed | n/a |
pto | srtt + max(4*rttvar, 1) + 25, doubled per consecutive PTO up to 2^6 ms | probe timeout | oldest in-flight stream ranges declared lost, else PING (connection.rs:301-303,323-325) |
loss_thresholds | 3 packets (adapts to 16) or 9/8 * max(latest, smoothed) RTT (adapts to 2x) mixed | loss declaration | ranges retransmitted |
congestion_window | 38400 initial, min 9600, max 4194304 bytes | reliable stream bytes in flight (NewReno-style: slow start, +1200*acked/window, halve once per recovery) | stream data waits; state is not limited |
flush_batch | 256 packets | packets emitted per flush | rest next flush |
server_datagram_read | 256 datagrams | bfeserver game socket reads per server tick | left in the kernel for the next tick |
max_sessions | max(maxPlayers*2+32, 32) sessions | bfeserver live transport sessions | REJECTED 'The server is full.' |
Versions
There is nothing to negotiate: one contract, every part required. Both hellos carry protocol, profile and simulation, and the server refuses any difference before a game session exists; a client refuses a different server the same way. Both show the update-required message, so the player knows which side is out of date.
| Value | Now | Changes when | A mismatch |
|---|---|---|---|
protocol | 5 | The framing or a format both games share changes | Refused before a session exists: close code 3, update required |
profile | snapshot-delta-v1 | The snapshot model changes | The same |
simulation | bfe-sim-34 | Any rule the client predicts changes, in either game | The same, since prediction would fight the server |
| Record revision (2005 match) | Per kind, in the match's record table | A 2005 record format or predicted 2005 rule changes | That match alone refuses the client: close code 3 with the update text |
| Content digest (per battle) | bfe-content-sha256- and 64 hex digits | The gameplay data prepared from the game changes | A 2004 battle refuses the join with the version text; a 2005 match seats the client to sit the battle out |
In the code
| Name | Value | Gates | Reference |
|---|---|---|---|
wire version (BFE-UDP/1) | 1 | every handshake packet; compared in handshake.rs:74-75,250,398 | layout.rs:2 |
protocol | 5 | application contract in both hellos and /info; compared by server on_admit (udp_server.rs:438-440), by client against /info (info.rs:60) and the signed server hello (info.rs:105-109; match2005.rs:139) | transport-layout.json:5 |
profile | snapshot-delta-v1 | same places as protocol; welcome also carries snapshotMode 'snapshot-delta-v1' (world_worker.rs:1186-1189) | transport-layout.json:6 |
simulation | bfe-sim-34 | same places as protocol; the number after 'bfe-sim-' picks which side is called older | transport-layout.json:7 |
serverAdapterABI | 4 | server-local: validate_network_contract refuses a contract manifest with another ABI ('Unsupported engine server adapter ABI'); reported on /healthz networkContract; not in any hello or packet | network_contract.rs:49 |
ownCorrectionSchema | 11 | server-local contract field (must be > 0) and the own-correction body schema the engine writes; not negotiated in a hello (not confirmed where clients compare it) | network_contract.rs:85 |
manifestVersion | 1 | server-local contract manifest | network_contract.rs:67 |
content fingerprint | bfe-content-sha256-<64 lowercase hex> | 2004 battle: hello content must equal the server fingerprint or its content label unless sitOut; 2005 match: mismatch or null seats the client in the sit-out role | udp_server.rs:383 |
2005 record revisions | per match table (revisions.rs WRITES / WRITES_SPACE) | required kinds in the server's signed battle descriptor vs the client's supports | revisions.rs:123 |
Joining a battle
A client finds a server in the directory's list, on the LAN, or by an address typed in. It then runs the transport handshake straight to the server's address (or, when needed, punched or relayed: below). The two hellos inside the handshake decide everything about the join before any game message flows.
The hellos
Both hellos are JSON objects sealed and authenticated inside the handshake. The server's hello carries protocol, profile, simulation, content, fingerprint and transport ({"probing":1}); in a Battlefront II match it adds battle with exactly five keys: family, mode (a playlist token of 1 to 32 lowercase letters, digits or underscores), map (swbf2/ and 1 to 32 of the same characters), match (exactly 32 lowercase hexadecimal digits) and records (the match's table of record kinds and revisions). In a 2005 match fingerprint and content are the match's verified content digest, bfe-content-sha256- and 64 lowercase hexadecimal digits. The client's hello carries protocol, profile, simulation, content (its own digest for the battle's map, or null without it) and name (the client sends at most 32 characters and the server keeps 24, without control characters), and may carry password, check and, in a 2004 battle, sitOut; for a 2005 match it adds battle with the first four keys and supports, the record revisions it implements; a spectator adds spectate.
| Client hello field | Type | Range | Required | Meaning |
|---|---|---|---|---|
protocol | integer | must be 5 | true | application protocol; missing reads as 0 and is refused (udp_server.rs:425,438) |
profile | string | must be 'snapshot-delta-v1' | true | snapshot profile |
simulation | string | must be 'bfe-sim-34' | true | simulation revision |
content | string or null | client-computed fingerprint 'bfe-content-sha256-' + 64 lowercase hex of its prepared files for the advertised battle (info.rs:69-80); null when sitting out | 2004: yes unless sitOut; 2005: no (null or mismatch = sit-out) | content fingerprint; the server also accepts its operator content label for a 2004 battle (udp_server.rs:441) |
name | string | client strips control characters and keeps 32 chars (info.rs:84); server strips U+0000-001F and U+007F-009F, trims, keeps 24 chars, default 'Player' (udp_server.rs:1609-1629) | false | display name |
password | string | any; only when the player gave one | when the server has a password | compared by the server (udp_server.rs:456-464) |
check | boolean | true | false | password check only: the server answers CLOSE 4 'Password accepted.' (or a password refusal) and never admits (udp_server.rs:465-470) |
sitOut | boolean | true | false | 2004 battle: join without a world (chat and score table only) with content null (info.rs:87-92; udp_server.rs:370-377) |
spectate | string | 'world' or 'scores' | false | spectator seat; 'world' only if the server allows world spectators; at most 8 spectators; other values refused 'Unknown spectator view.' (udp_server.rs:479-486) |
battle | object | exactly 5 keys: family 'swbf2', mode (mode token), map 'swbf2/<1-32 of a-z0-9_>', match (32 lowercase hex), supports (canonical padded base64 of 5 bytes per kind: kind u8, min u16, max u16, ascending, at most 32 kinds) | 2005 match: yes (missing: CLOSE 4 'match-changed'; malformed: CLOSE 2) | the 2005 match the client asks for and the record revisions it implements (match2005.rs:110-122; revisions.rs:275-305,412-472) |
Admission, in order
As bfeserver runs it. A refusal is a CLOSE sent under the new session keys, with the code and a reason the player sees.
- The transport: the server already has its maximum of sessions (twice its player limit plus 32, at least 32): close code 4, "The server is full."; too many players from one network (the same IPv4 address or IPv6 /64, loopback exempt): close code 4.
protocol,profileorsimulationdiffer, or in a 2004 battlecontentdiffers from the server's digest (unless the client asked to sit out): close code 3 with the version text, which says which side is older.- A password the server needs is missing or wrong: close code 4. A hello with
check: trueonly tests the password and is always closed (code 4, "Password accepted." when it is right). - A banned player: close code 4.
- Spectator rules, or no room for another player: close code 4.
- A 2005 match: a hello without
battle, or naming another match, close code 4 with reasonmatch-changed; a malformed request, close code 2; a required record revision the client does not read, close code 3 with the update text. - The role. In a 2005 match a client whose
contentis the match's verified digest plays, and any other client sits the battle out (missing-contentwithout a digest,content-mismatchwith another one).
Admitted, the server sends HANDSHAKE_DONE, then on the events stream entity-registry and welcome (or, for a client sitting out, the sit-out record and the score table). A new session of the same identity replaces the old one, which is closed with code 4, "reconnected".
Before reading any of a 2005 match's messages, the client checks the signed answer. Meanwhile it holds at most 64 messages and 256 KiB, each reliable message at most 64 KiB and each state datagram at most one datagram's payload; more is a fault. A refusal for the version or match-changed makes the client look for the server's current battle again rather than report a fault: the server may have moved on to its next battle while the client joined.
Loading. After admission the client loads the battle behind a loading screen of a fixed length that every client shares (13.5 seconds for a 2004 battle; a 2005 battle's duration comes from its prepared map data, in ticks), so a faster computer does not get into a battle earlier. Then it sends a call with method start; the server waits up to 180 seconds of silence for it, and 30 seconds once a player has started. The spawn screen's choices (team, class, command post) travel as commands like any other input, and the server spawns the soldier.
Message catalogue
After admission, two kinds of carrier hold the game. The reliable events stream carries JSON text messages, each an object with a type. The unreliable state lane carries binary messages that start with a four-letter magic: BNI1 (input), BNA1 (snapshot acknowledgement), BNS1 (entity snapshot part) and BNO1 (the player's own state). Each stream message is framed as a variable-length integer length (at most 1,048,576), a kind byte (0 binary, 1 text) and the payload; each state message is one DATAGRAM frame, or up to 32 FRAGMENT frames when it is larger. The bulk stream exists in the transport but no message of this release is sent on it.
entity-registry · server to client · EVENTS text
When: first message after admission (2004 and played 2005)
Encoding: JSON
| Field | Type | Range or meaning |
|---|---|---|
type | string | 'entity-registry' |
registry | object | combatDefinitions [names], contentEpoch u32 > 0, classes [[id,name]...] ids from 1, weapons [[id,name]], posts [[id,name]], inputCodes [names], bindingProfiles [[0,{}]]. server's id tables for this battle (world_worker.rs:829-845) |
records | array | 2005 scripted battle only: [record message kind 28 REGISTRY]. mission roster (world_worker.rs:2147-2155) |
The receiver checks:
- client: duplicate registry is a fault; contentEpoch must be a non-zero u32; registry must equal the client's own registry built from its content apart from contentEpoch, else fault 'entity content/input registry mismatch' (rust/bfe-client/src/online/receiver.rs:1363-1410)
Reference: world_worker.rs:803
welcome · server to client · EVENTS text
When: after entity-registry
Encoding: JSON
| Field | Type | Range or meaning |
|---|---|---|
type | string | 'welcome' |
(all /info fields) | mixed | the current /info object is copied in (world_worker.rs:1171-1173) |
serverId | string | 64 hex. server identity id |
unitId | number | player's unit |
playerId | number | player id (own entity id the client follows) |
generation | number | u32. life generation |
team | number | team |
className | string | assigned class |
spectator | boolean | spectator seat granted |
teamSelect | boolean | client must choose a team |
tick | number | server tick |
snapshotMode | string | 'snapshot-delta-v1' |
flightCeiling | number | finite f32-representable. 2005 only (world_worker.rs:2164-2170,1196-1198) |
The receiver checks:
- client: welcome before registry or a second welcome is a fault 'unexpected battle welcome'; a 2005 welcome without a usable flightCeiling is a fault (receiver.rs:1411-1435)
Reference: world_worker.rs:1169
reply · server to client · EVENTS text
When: answer to a call
Encoding: JSON
| Field | Type | Range or meaning |
|---|---|---|
type | string | 'reply' |
id | any | echo of the call id |
ok | boolean | true for start; false with error 'unknown method' or 'sitting-out' |
result | object | {"ok":true}. start only |
error | string | on failure |
Reference: local_server.rs:320
input-ack · server to client · EVENTS text (superseding)
When: every server tick for an admitted player (observed 60/s); not queued while that player's reliable backlog is over 8192 bytes (udp_server.rs:80-82,1301-1313)
Encoding: JSON
| Field | Type | Range or meaning |
|---|---|---|
type | string | 'input-ack' |
epoch | u32 | world epoch |
serverTick | u32 | current server tick |
generation | u32 | player life generation |
ack | u32 | highest input command sequence received |
ackTick | u32 | tick of that command |
dropped | u32 | server ticks dropped by overrun |
discardedInput | u32 | discarded commands |
discardedActions | u32 | discarded actions |
ackActions | number | always 0 |
The receiver checks:
- client applies it only when epoch and generation match its own (receiver.rs:1441-1456)
Reference: world_worker.rs:999
entity-edge-results · server to client · EVENTS text (superseding; an identical one within 100 ms is not queued)
When: edge outcomes are published
Encoding: JSON
| Field | Type | Range or meaning |
|---|---|---|
type | string | 'entity-edge-results' |
epoch | u32 | |
generation | u32 | |
received | [u32] | edge ids received |
results | [{id u32, status string, tick u32}] | edge outcomes |
The receiver checks:
- client applies only when epoch and generation match (receiver.rs:1457-1466)
Reference: world_worker.rs:1024
gameplay-events · server to client · EVENTS text
When: reliable combat records for this client
Encoding: JSON
| Field | Type | Range or meaning |
|---|---|---|
type | string | 'gameplay-events' |
tick | u32 | server tick |
records | [{kind 'combat', id u32, generation u32, tick u32, schema u32, payload base64}] | combat record bodies are engine-owned (layouts not extracted here) |
The receiver checks:
- client parses with events::receive; failure is a fault (receiver.rs:1436-1440)
Reference: world_worker.rs:1070
chat · server to client · EVENTS text
When: relay of a player's chat to started players (team lines to the same team); operator announcement
Encoding: JSON
| Field | Type | Range or meaning |
|---|---|---|
type | string | 'chat' |
sender | string | <= 80 UTF-16 units at the client. player name or 'Server' |
text | string | <= 240 UTF-16 units |
team | boolean | |
admin | boolean | true for operator messages |
The receiver checks:
- client refuses longer text or sender (rust/bfe-client/src/online/chat.rs:22-34)
Reference: local_server.rs:113
ping · server to client · EVENTS text
When: every 2000 ms per session
Encoding: JSON
| Field | Type | Range or meaning |
|---|---|---|
type | string | 'ping' |
time | integer | server ms clock |
The receiver checks:
- client queues a pong with the same time (receiver.rs:1495-1500,1529-1540)
Reference: game_session.rs:16
pong · both · EVENTS text
When: answer to ping
Encoding: JSON
| Field | Type | Range or meaning |
|---|---|---|
type | string | 'pong' |
time | number | echo |
The receiver checks:
- server: RTT sample if 0 <= now - time < 60000, smoothed 0.8/0.2 (game_session.rs:198-211)
Reference: game_session.rs:192
match · server to client · EVENTS text
When: next battle announced (rotation); sent to joiners while the end table runs
Encoding: JSON
| Field | Type | Range or meaning |
|---|---|---|
type | string | 'match' |
query | string | next battle query (a 2005 query names its game; includes padAimAssist=1 when the server enables controller reticle slowdown, config.rs:850) |
delayMs | integer | ms until the next battle |
The receiver checks:
- client: NextMatch::announce validates the query; failure is a fault (receiver.rs:1489-1494)
Reference: udp_server.rs:361
gameplay-error · server to client · EVENTS text
When: world refused to add the player; followed by CLOSE 4 'admission failed: <message>'
Encoding: JSON
| Field | Type | Range or meaning |
|---|---|---|
type | string | 'gameplay-error' |
message | string | reason; client shows at most 240 chars |
Reference: local_server.rs:279
record · both (2005 only) · EVENTS text
When: 2005 record kinds carried reliably, e.g. SIT_OUT 26 notice {match, mode, reason}, NOTICE 25, BOARD 27 (server); HERO_DECLINE 31 with body {} (client)
Encoding: JSON
| Field | Type | Range or meaning |
|---|---|---|
type | string | 'record' |
kind | integer | 1..255. record kind |
revision | integer | 1..65535. kind revision |
body | any | kind-specific |
The receiver checks:
- exactly these four keys (revisions.rs:591-599); a kind the match does not name or a revision other than the match's is refused, an optional kind the reader does not implement is skipped (revisions.rs:601-609)
Reference: revisions.rs:15
call start · client to server · EVENTS text
When: once, after welcome
Encoding: JSON
| Field | Type | Range or meaning |
|---|---|---|
type | string | 'call' (or 'rpc') |
id | any | the released client sends 1 |
method | string | 'start'. other methods get reply ok:false 'unknown method' |
args | object | the released client sends {} ('fields' is accepted as an alias) |
The receiver checks:
- sets the session started (30 s silence limit instead of 180 s); sitting-out peers get reply error 'sitting-out' (game_session.rs:247-262; udp_server.rs:1145-1159)
Reference: client.rs:327
chat (client) · client to server · EVENTS text
When: player chat
Encoding: JSON
| Field | Type | Range or meaning |
|---|---|---|
type | string | 'chat' |
text | string | client trims and cuts at 240 UTF-16 units |
team | boolean | team channel |
The receiver checks:
- server drops text over 240 UTF-16 units, more than 4 messages per 5 s, strips chars < 32 and U+007F, trims, drops empty (game_session.rs:223-246); only started players are relayed; spectators and sit-outs have no team channel (local_server.rs:332-372)
Reference: chat.rs:6
edge-ack / entity-edge-ack · client to server · server reads it on EVENTS text; the released client sends it as a TEXT state-lane DATAGRAM (input.rs:1480,1679)
When: after edge results arrive
Encoding: JSON
| Field | Type | Range or meaning |
|---|---|---|
type | string | 'entity-edge-ack' (server also accepts 'edge-ack') |
epoch | u32 | |
generation | u32 | |
ids | [u32] | edge outcome ids retired |
The receiver checks:
- server routes only binary state and text events messages (udp_server.rs:1101,1122): a text state datagram matches neither branch and is dropped (see transport.md 'not confirmed')
Reference: input.rs:1458
BNI1 input · client to server · state DATAGRAM, binary
When: client input sends (observed ~46 client DATA packets/s with acks only; the probe sent no BNI1)
Encoding: binary LE, 16..1100 bytes, no trailing bytes allowed
| Field | Type | Range or meaning |
|---|---|---|
magic | u32 | 0x31494e42 ('BNI1') |
epoch | u32 | world epoch |
generation | u32 | life generation |
nv | u8 | 0..8. views |
nc | u8 | 0..8. commands |
ne | u8 | 0..32. edges |
na | u8 | 0..1. snapshot ack present |
view[nv] | struct | flags u16 (<=1023), profile u16 (must be 0); then by flag: 32 mouseScale f64 (0,2]; 64 aspect f64 (0,10]; 128 viewTick f64 [0,2^32-1]; 256 sensitivity f64 (0,10] and 512 curve f64 [0.1,4] (both need flag 4 flight); 16: 4 axes f64 [-1,1] + buttons u16 |
command[nc] | struct | sequence u32, tick u32, view index u8 (< nv), held bitmap 16 bytes (bit i = inputCodes[i]; unknown bit refused), lookX f64, lookY f64 (cumulative look totals) |
edge[ne] | struct | id u32 (non-zero), tick u32, kind u8 0..5; kind 0 action u8 (index into inputActions; 21 in 2004, 24 in 2005); kind 1 fire flags u8 (bit0 button, bit1 pressed, <=3) + viewTick f64 + aimYaw f64 + aimPitch f64; kind 2 team u8 1..7; kind 3 classId u16 + postId u16; kind 4 suicide, kind 5 cancel spawn (no payload) |
ack | u16 epoch + u32 tick | if na=1: last complete snapshot |
records | 2005 only | records section after the ack: count u8 (<=16), per record kind u8, revision u16, length u16, body (revisions.rs:517-564); e.g. PILOT 16 |
The receiver checks:
- server: 10..1100 bytes and magic BNI1 with length >= 16 or BNA1 exactly 10, else dropped (udp_peer.rs:118-134); 75 datagrams/s token bucket, burst 360 (game_session.rs:6-8,90-100); full decode checks above (world_worker.rs:182-441); 2005 match: 32,000 B/s (burst 8,000) and 120 datagrams/s (burst 30) per source before decode (inbound.rs:1-17)
Test vector: rust/sim/src/wire/input.rs:116-130 (one view, one command code 22, one spawn edge, ack 65534/4294967295)
Reference: input.rs:48
BNA1 snapshot ack keepalive · client to server · state DATAGRAM, binary
When: acknowledges a complete snapshot when no input carries the ack; spectators may send only this
Encoding: exactly 10 bytes: magic u32 0x31414e42 ('BNA1'), epoch u16, tick u32
| Field | Type | Range or meaning |
|---|---|---|
magic | u32 | BNA1 |
epoch | u16 | |
tick | u32 | snapshot tick acknowledged |
The receiver checks:
- exact length 10 and magic (world_worker.rs:160-173)
Reference: input.rs:101
BNS1 entity snapshot part · server to client · state DATAGRAM, binary
When: every 3 server ticks (20 Hz) per world_worker.rs:1778-1786; observed 499 snapshots, tick step 3, interval byte 3
Encoding: binary LE, at most 1100 bytes per part, 1..256 parts per snapshot
| Field | Type | Range or meaning |
|---|---|---|
magic | u32 | 0x31534e42 'BNS1' |
epoch @4 | u16 | world epoch |
tick @6 | u32 | snapshot tick |
interval @10 | u8 | ticks between snapshots (3) |
baseline @11 | u32 | tick of the acknowledged baseline this delta applies to; 0 = keyframe |
parts @15 | u8 | (index << 4) | count when count <= 15; 0 means extended counters follow |
ack @16 | u32 | 0 in entity parts |
partIndex @20 | u16 | extended only (count > 15) |
partCount @22 | u16 | extended only |
worldLength @20 or 24 | u16 | bytes of the world section |
world | bytes | LEB128 count, then fields: id u32, schema u16, generation u32, op u8 (0 absolute: length u16 + payload; 1 removed; 2 word delta: length u16 + [flag 1, payload length u16, word count u16, bitmap ceil(words/8), changed 8-byte words]) |
slotCount | LEB128 | records in this part |
records | bytes | first slot u16, later slots as LEB128 deltas; each record: byte = op (bits 0-1: 1 new identity, 2 removal, 0 update) | group mask << 2; new identity adds class u8 (0 soldier,1 droideka,2 vehicle,3 turret,4 item,5 remote), generation u32, entity id u32, class id u16, team u8, then every group; update writes only changed groups |
Field groups: soldier/droideka/vehicle/item/remote: g0 position (mode u8: bit0 absolute, bit1 wide u24, bit7 discontinuity; then 3 x i8 delta or 3 x u16/u24 codes), g1 velocity (wide u8 then 3 x i8 at 0.25 m/s or 3 x i16 at 0.03125 m/s); soldier g2 yaw u16 + pitch i16, g3 health u16, g4 posture|charge<<2 u8 + state u8 + weapon u16 + seat slot u16 (65535 none) + seat index u8, g5 fire counter u8; droideka g3 health u16 + posture u8 + status, g4 mode u8 + flags u8 + anim f32[]; vehicle g2 smallest-three quaternion 6 bytes, g3 health u16 + state u8 + power u16, g4 mount (slot u8, tilt i16, roll i16, walk phase u16, walk blend u8, seat count u8, seats i16 pairs), g5 fire counter; turret g0 yaw/pitch/gunYaw/gunPitch i16, g1 health u16 + state u8 + team u8; item g2 yaw u16, g3 active u8 [+ definition u16 + up 3 x i16]; remote g3 active u8 [+ definition u16 + team u8 + health u16] (codec.rs:96-290; docs/snapshot-delta-design.md:39-46)
The receiver checks:
- client applies each part to its named baseline, waits for all parts before acknowledging, and treats a missing baseline as loss (docs/snapshot-delta-design.md:84-87)
Reference: codec.rs:9
BNO1 own datagram · server to client · state DATAGRAM, binary
When: with each snapshot, per player; never held back by congestion or staleness (udp_peer.rs:262-280)
Encoding: same 20-byte header as BNS1 with magic 0x314f4e42 'BNO1', 1..2 parts, ack = highest input acknowledged; then flags u8 (bit0 correction, bit1 summaries, bit2 cosmetics, bit3 second datagram) and each present section as u16 length + bytes
| Field | Type | Range or meaning |
|---|---|---|
correction | section | id u32, generation u32, schema u16, then word delta (op 0 absolute length u16 + payload, or op 1 delta) against the baseline (codec.rs:639-641,374-383) |
summaries | section | world-section format (private world fields) |
cosmetics | section | cosmetic bundle |
Reference: codec.rs:613
state budget and staleness (server side) · server to client · state
When: every state send
Encoding: n/a
The receiver checks:
- state message 1..32768 bytes, events message 1..262144 bytes (udp_peer.rs:24-27,253-261); shared snapshot parts older than 100 ms are dropped and parts are not sent while the path is congested (120 ms enter, 50 ms clear) (udp_peer.rs:29-36,262-280); a snapshot whose part cannot be sent is not sent further to that client (local_server.rs:442-455)
Reference: udp_peer.rs:24
What the server accepts per session
- per session per server tick: at most 256 messages and 2 MiB, else CLOSE 2 'inbound message queue exceeded' (udp_server.rs:520-530,1081-1088)
- binary state from a sit-out peer is dropped; a spectator's state must be BNA1 (udp_server.rs:1101-1112)
- events JSON: > 65536 bytes or not an object -> CLOSE 2; known types ping, pong, edge-ack, entity-edge-ack, record, chat, call, rpc; unknown types ignored (game_session.rs:164-276)
- silence: CLOSE 1 'session silent' after 30 s (started) or 180 s (not started) without any message (game_session.rs:10-12,118-133)
Input codes and actions
A BNI1 command's 16-byte held bitmap sets bit i for input code i; an action edge names an index into the battle's action list. The server sends the same lists in entity-registry, and a client must refuse a battle whose registry differs from its own. The 104 input codes are the same in both games.
Input codes, in order
0:KeyA 1:KeyB 2:KeyC 3:KeyD 4:KeyE 5:KeyF 6:KeyG 7:KeyH 8:KeyI 9:KeyJ 10:KeyK 11:KeyL 12:KeyM 13:KeyN 14:KeyO 15:KeyP 16:KeyQ 17:KeyR 18:KeyS 19:KeyT 20:KeyU 21:KeyV 22:KeyW 23:KeyX 24:KeyY 25:KeyZ 26:Digit0 27:Digit1 28:Digit2 29:Digit3 30:Digit4 31:Digit5 32:Digit6 33:Digit7 34:Digit8 35:Digit9 36:F1 37:F2 38:F3 39:F4 40:F5 41:F6 42:F7 43:F8 44:F9 45:F10 46:F11 47:F12 48:Numpad0 49:Numpad1 50:Numpad2 51:Numpad3 52:Numpad4 53:Numpad5 54:Numpad6 55:Numpad7 56:Numpad8 57:Numpad9 58:Space 59:Enter 60:Escape 61:Tab 62:Backquote 63:CapsLock 64:ShiftLeft 65:ShiftRight 66:ControlLeft 67:ControlRight 68:AltLeft 69:AltRight 70:ArrowUp 71:ArrowDown 72:ArrowLeft 73:ArrowRight 74:Backspace 75:Delete 76:Insert 77:Home 78:End 79:PageUp 80:PageDown 81:Minus 82:Equal 83:BracketLeft 84:BracketRight 85:Backslash 86:Semicolon 87:Quote 88:Comma 89:Period 90:Slash 91:NumpadEnter 92:NumpadAdd 93:NumpadSubtract 94:NumpadMultiply 95:NumpadDivide 96:NumpadDecimal 97:Mouse0 98:Mouse1 99:Mouse2 100:Mouse3 101:Mouse4 102:WheelUp 103:WheelDownActions, Battlefront (2004)
0:jump 1:crouch 2:prone 3:reload 4:use 5:nextPrimary 6:previousPrimary 7:nextSecondary 8:zoom 9:perspective 10:map 11:nextSpawn 12:stats 13:squadMoveOut 14:squadHold 15:squadFollow 16:squadAtEase 17:takeoff 18:trick 19:immelmann 20:targetLockActions, Battlefront II (2005)
0:jump 1:crouch 2:prone 3:reload 4:use 5:nextPrimary 6:previousPrimary 7:nextSecondary 8:zoom 9:perspective 10:map 11:nextSpawn 12:stats 13:squadMoveOut 14:squadHold 15:squadFollow 16:squadAtEase 17:takeoff 18:trick 19:immelmann 20:targetLock 21:roll 22:blockPress 23:blockReleaseNot specified here: the bodies of combat records (gameplay-events) and of the 2005 record kinds, which are engine-owned and versioned per kind; the replay file format; and whether the server uses the client's entity-edge-ack, which the released client sends as a text message on the state lane where the server reads only binary messages.
The 60 Hz model
The server steps the battle at a fixed 60 ticks a second (vehicles take 120 Hz substeps inside a tick) and is the only authority. Clients send commands, not results, and draw the world a little in the past for everyone else and a little in the future for themselves.
- Authority. The server runs every rule: movement, combat, vehicles, bots, command posts and scoring. It validates speed, teleports, damage and ammunition and rejects any result a client sends.
- Commands. A client aims each command at the server tick it should arrive for (its clock offset plus half the round trip plus a small margin) and adjusts gradually, never by jumps. Held movement and cumulative look totals travel as latest-state datagrams, so a later total recovers motion lost in an earlier packet. Discrete actions and fire edges travel in their own acknowledged sequences, repeated until acknowledged or expired, so a newer movement acknowledgement cannot discard a delayed jump, reload or short trigger press. The server rejects duplicates, stale lives and malformed payloads.
- Snapshots. Every third tick (20 a second) the server publishes the world, delta-encoded against the last complete snapshot the client acknowledged by epoch and tick; baseline tick 0 is a keyframe. The host keeps 128 snapshot ticks; if a client's baseline is gone, it picks another held one or sends a keyframe. Every relevant entity is in every snapshot, in slot order, split into parts of at most 1,100 bytes each. A lost datagram is never resent: the next snapshot replaces it. A client acknowledges a tick only once every required part has arrived.
- Your own soldier. The client predicts its own soldier or driven vehicle with the same rules. A correction carries the state needed to replay physics, not just position and velocity. On each one the client restores it, drops the commands it acknowledges and replays the rest; replay history is bounded and recovers explicitly when it no longer covers the authority. Gunners predict their own aim and see the hull interpolated.
- Everyone else is drawn between received snapshots on a playout clock that follows measured jitter.
- Events. Kills, captures, spawns, chat and map changes travel reliably on the events stream, numbered so they cover the ticks between snapshots, never inside a snapshot that can be lost.
- Shots. Blaster bolts are projectiles, not instant hits. The shooter's client draws its bolt at once; the server spawns the real bolt advanced by the shooter's latency and tests the skipped stretch against targets rewound to where the shooter saw them, up to a 300 ms round trip on top of the shooter's lead and playout delay. Old timestamps clamp to the cap and future ones get no compensation.
- Joining mid-battle: the entity registry and a welcome, then a full snapshot against the empty baseline, then deltas. Map changes: the server announces the next battle, the end screens play, the server builds the new world, and each client loads it and reports ready. Reconnecting within a minute keeps your team, score and slot (matched by player key); after that a bot takes the slot.
Spectators and replays
Spectators. A server may advertise an optional spectators field in discovery, scores or world; a missing or unknown value leaves the ordinary join. A spectator asks for the advertised view in its hello with "spectate":"scores" or "spectate":"world". A scores spectator gets the sit-out role (the score table and public chat). A world spectator must receive a spectator welcome before it starts, then receives snapshots and acknowledges them, with no soldier, no input mailbox, no team channel and no authority over the match. World spectating needs "worldSpectators": true in the server's configuration. Up to eight spectator slots share the server's authentication and address limits; they have no team and do not count towards the player limit. Everything else in the hellos and the required versions stays the same.
Replays. A replay is a local file the client writes; nothing extra travels on the wire. It records the accepted public world state of an Instant Action battle or an online match, under a header naming the game, map, battle, simulation, protocol, content digest and tick rate (60). Personal corrections, credentials and chat never enter the file. The replay file format itself is not specified here.
Directory
The directory is an HTTP JSON API behind HTTPS at https://online.battlefronteternal.com (a client may point elsewhere with BFE_MASTER_URL). Its own API version is 1, independent of the game protocol. It keeps the server list in memory and drops a server 60 seconds after its last heartbeat. It also passes rendezvous messages between players and servers over a WebSocket, issues short-lived relay credentials and publishes a signed global ban feed that each server operator may honour or ignore.
Every request
- The online notice. Every call except
/healthz,/v1/infoandOPTIONScarriesx-bfe-notice: 2026-10-11, the version of the online notice the player accepted; without it the answer is 428. - Signed changes.
POST,PUTandDELETEare signed with the caller's Ed25519 key. Headers:x-bfe-key(standard base64 of the 44-byte Ed25519 SPKI DER key),x-bfe-time(Unix seconds, 10 digits, within 60 s of the directory's clock),x-bfe-nonce(16 random bytes as 32 lowercase hex digits) andx-bfe-signature(base64 of the 64-byte signature). The signed text is five lines joined by a newline: the method, the request target exactly as sent (with any query), the time, the nonce, and the lowercase hex SHA-256 of the exact body bytes. A key's id, which is also the server or player id, is the lowercase hex SHA-256 of the base64 key text. A nonce is remembered for 125 seconds; a repeat is refused (401). - Limits. Bodies are JSON objects of at most 32,768 bytes. Every caller address (an IPv4 address or an IPv6 /64) gets 120 requests in a fixed 60 s window, and every key 120 changes; over that is 429. Errors are
{"error": "text"}. Answers carryaccess-control-allow-origin: *, so web pages and bots may read the list.
Endpoints
| Request | Purpose | Auth | Limits | Reference |
|---|---|---|---|---|
GET /healthz | liveness | none (no notice) | global | server.js:331 |
GET /v1/info | directory metadata, notice version, signing key, relay URLs, timing limits | none (no notice) | global | server.js:337 |
GET /v1/whoami | caller's address as the master sees it | notice header | global | server.js:360 |
GET /v1/servers | full public list (no server-side filters or query parameters) | notice header | global | server.js:364 |
GET /v1/servers/{id} | one listing | notice header | global | server.js:380 |
POST /v1/servers | register (or re-register) the caller's server; ID = caller key ID | signed | global + 120 mutations per key per window | server.js:422 |
PUT /v1/servers/{id} | heartbeat; same body and checks as register | signed | global + 120 mutations per key per window | server.js:422 |
DELETE /v1/servers/{id} | unregister | signed | global + 120 mutations per key per window | server.js:439 |
POST /v1/relay-credentials | time-limited TURN REST credentials; with peerId a per-player host grant | signed | without peerId: 6/key, 24/address bucket; with peerId: min(128, maxPlayers*2)/server key, 128/address bucket, 2/(server,peer); per 60 s window | server.js:444 |
POST /v1/signal-ticket | single-use ticket for the signal WebSocket | signed | 6 per key per window | server.js:471 |
GET (WebSocket upgrade) /v1/signal?ticket={ticket} | rendezvous signaling relay between a player and a listed server | ticket | 64 upgrades per address bucket per window (master:src/server.js:506) | server.js:502 |
POST /v1/reports | report a player or server | signed | 3 per key, 10 per address bucket, per window | server.js:478 |
GET /v1/bans | signed global player-ban feed (servers choose to honor it) | notice header | global | server.js:388 |
A listing
What a server sends in POST /v1/servers and every heartbeat, and what the list returns. "Text" is 1 to N characters with no control characters. The directory drops any other key.
| Field | Type | Rule |
|---|---|---|
id | string | set by master = key id |
publicKey | string | set by master = x-bfe-key |
name | string | required text <= 80 |
protocol | integer | required 0..65535 (game protocol, 5 at engine 233d73a56) |
simulation | string | required text <= 128 (bfe-sim-34 at 233d73a56) |
content | string | required text <= 128 |
rotation | array of string | 1..64 entries, each text <= 100 matching ^swbf[12]\/[a-z0-9_-]+:[a-z0-9_-]+:[a-z0-9_-]+$ |
players | integer | required 0..128, <= maxPlayers |
maxPlayers | integer | required 1..128 |
relayPolicy | string | auto (default) | never | always |
endpoints | array | <= 4 of {address?: must equal caller and be unicast, port: 1..65535, transport: udp|webrtc}; stored with verified:false; [] when always; per-family merge kept 90 s |
fingerprint | string | ^sha-256 (?:[A-Fa-f0-9]{2}:){31}[A-Fa-f0-9]{2}$ (sha256 of SPKI DER) |
location | string|null | optional text <= 80 (present but invalid -> 400) |
description | string|null | optional text <= 280, invalid -> null |
sponsor | object|null | {name: text <= 60, url: https <= 512 no userinfo | null, logo: same} |
query | string|null | '?' + keys map(required),side,mission [a-z0-9_-]{1,64}, era cw|gcw, ai classic|enhanced|off, seed 1-10 digits, match 32 hex; each once; <= 512 |
battle | object|null | map required ^(swbf2/)?[a-z0-9_-]{1,64}$; family only 'swbf2'; mapName text <= 60; side, mode slug; era cw|gcw; invalid members omitted, never null |
bots | boolean|null | |
autoAssignTeams | boolean|null | |
uptime | integer|null | 0..315360000 s |
password | true|absent | only when input === true; never the password |
games | array|absent | 1-2 distinct of swbf1, swbf2 (second-game field) |
The second game. A server whose battle is from Battlefront II sends battle.family: "swbf2" and a qualified battle.map such as swbf2/tat2; games lists the games its playlist reaches (swbf1, swbf2). A row without family is a Battlefront (2004) battle. Rotation entries are swbf1/ or swbf2/, then map, era and mode separated by colons.
Addresses. The directory takes no address on trust: an endpoint's address must be the request's own source address, and it is stored with verified: false. A server with relay policy never publishes its port (and the directory its source address); auto and always servers publish no endpoints and are reached through rendezvous, so the browser shows no ping for them.
Registration and heartbeat
- If it honours global bans:
GET /v1/bans, and on first useGET /v1/infoto pin the directory's signing key. The feed is{payload, signature, publicKey}, signed over the payload's bytes; the server refreshes it every 120 seconds. POST /v1/servers, signed, with the listing. The server's id is its key's id.POST /v1/relay-credentialswith its own id, to learn the relay and STUN host; thenPOST /v1/signal-ticketand the signalling WebSocket/v1/signal?ticket=…, kept open.- STUN from the game socket to learn its public addresses and whether it is behind NAT (again every 60 seconds).
PUT /v1/servers/{id}every 20 seconds, and at once when the battle changes.DELETE /v1/servers/{id}on shutdown. Without a heartbeat for 60 seconds the listing expires.
The browser
The client reads GET /v1/servers (with If-None-Match for the ETag) every 30 seconds while the browser is open. All filtering is on the client. Ping is a TCP connection to an endpoint's game port (the /info listener), timed to the connect, with a one-second timeout; up to four endpoints per server and sixteen servers at once. The client shows a server as joinable when protocol and simulation match its own and it can play the server's game.
LAN discovery: BFE-LAN/1
JSON datagrams on UDP 18452, at most 2048 bytes, by IPv4 broadcast and the IPv6 link-local multicast group ff02::bf:1. The client sends {"magic":"BFE-LAN/1","type":"discover","nonce":"…"} with a new 32-hex-digit nonce per scan; each server answers the sender alone with {"magic":"BFE-LAN/1","type":"server","nonce":"…","info":{…}}, echoing the nonce, where info is its /info document without description and sponsor. The client takes the address from the datagram's source, not from info, keeps servers by id (an IPv4 answer replaces an IPv6 one), and listens 250 ms. A server answers one query per source address every 250 ms and never sends beacons on its own. No internet, directory or relay is needed.
Direct Connect
The client opens TCP to the address and port (18451 by default) and reads GET /info, a plain HTTP JSON document with the server's id, name, versions, content, rotation, players and settings. It checks the id and versions and pins the handshake to that id (a first contact is trust on first use), then sends BFE-UDP/1 INITIATION to every address the name resolves to (up to 16) every 250 ms until an authentic RESPONSE arrives.
NAT traversal and the relay
A listed server with relay policy auto (the default) or always publishes no address. A client reaches it through the directory's signalling: the two exchange their candidate addresses, try them all at once, and fall back to the relay when nothing direct gets through. The policy never publishes the server's address and allows direct joins only.
Rendezvous and hole punching
- The client reads the server's listing, asks
POST /v1/relay-credentialsfor the STUN host (the firstturn:URL, elserelay.battlefronteternal.com:3478), and learns its own public IPv4 address by STUN. Its candidates are that address, its local route address and, when it has one, a global IPv6 address. - It takes a single-use ticket (
POST /v1/signal-ticket, valid 30 seconds), opens/v1/signal, and sends{"to": server id, "type": "offer", "payload": …}. The payload carriesudp: 1, a nonce and at most eight candidates. An offer opens a route between the two for 120 seconds; the directory forwards it as{"from": client id, "type": "offer", "payload": …}. - The server answers with its own candidates and its current and next battle, and sends
PUNCHpackets (type 184, 9 bytes) to the client's public candidates over the next 0 to 1.5 seconds so its NAT opens a path. The client repeats its offer every 2.5 seconds with a new nonce until an answer comes (for up to 10 seconds, or 90 while the server is between battles) and punches every 2 seconds while it loads. - The client sends
INITIATIONto every candidate every 250 ms. The first authenticRESPONSEwins, and it must come from the server id the listing named.
Signalling messages are JSON text frames of at most 32,768 bytes, payloads at most 24,000 characters, of type offer, answer, candidate, reject, matchProbe or matchReady. One socket per identity (a new one closes the old with 4000), 180 messages per identity a minute, a ping every 30 seconds. A message to an offline peer is dropped.
The relay
The relay is stock coturn speaking TURN (RFC 8656) at relay.battlefronteternal.com; there is no custom relay protocol. Only the game server speaks TURN. When a client needs the relay (the server's policy is always, or auto and the server is behind NAT), the server asks the directory for a grant for that one client and allocates a UDP relay address for it; the client just sends ordinary BFE-UDP/1 datagrams to that address. The game traffic stays end-to-end encrypted through the relay.
| Port | Transport | Use |
|---|---|---|
| 3478 | UDP and TCP | TURN and STUN |
| 5349 | TCP (TLS) | TURN over TLS |
| 49160-49415 | UDP | relayed allocation addresses (256 ports) |
- Credentials. coturn's TURN REST scheme: the directory and the relay share a secret.
POST /v1/relay-credentialsreturnsusername"<expiry Unix seconds>:<allocation id>",credentialbase64(HMAC-SHA1(secret, username)),expires(now plus 300 seconds) and the relayurls. For a server's grant the allocation id is<server id>:<client id>, issued only to the listed server and only for a client that sent it an offer within 120 seconds, never to aneverserver. - Allocation. The server opens a new UDP socket per relayed client and sends Allocate (UDP transport, lifetime 600 s); the unauthenticated first try is answered 401 and repeated with TURN long-term credentials (MESSAGE-INTEGRITY keyed by MD5 of username:realm:password, FINGERPRINT on every message). It then permits the client's public addresses (at most 16 per allocation, same family as the relayed address) and tells the client the relayed address as a
candidate(policyauto) oranswer(always). - Data. The server receives Data indications or ChannelData and replies by Send indication, then binds a channel and uses ChannelData with its 4-byte header.
- Refresh and teardown. The allocation is refreshed at half its granted lifetime (at least every 30 s), permissions every 240 s, channels every 540 s. An allocation unused by a playing client for 30 seconds is released with a zero-lifetime Refresh; a battle change keeps it; shutdown releases all. Longer sessions rely on coturn accepting refreshes after the credentials' five minutes; moving to a new allocation during a session is not implemented.
- Limits. 160 allocations in all and 4 per username; 1 MiB/s per session, traffic over it dropped; 256 relay ports; a server holds at most its player limit plus 8 allocations. The relay refuses private, loopback, link-local, carrier-grade NAT and multicast destinations. TURN over TCP or TLS is offered by the relay but not used by the game's transport yet, so a network that blocks UDP cannot join.
Security notes
- Every datagram is hostile until checked. Sizes and counts are checked before anything is allocated or copied, and the decoders are fuzzed. The limits in the transport tables are part of the contract: exceeding one closes the connection.
- The server decides. Clients send commands (held keys, action edges, look deltas, spawn choices), never results. Speed, teleports, damage, ammunition, action rates, team and seat access and command tick windows are enforced by the server.
- Identity is a key. A player is an Ed25519 key pair made by the client; the player id is a hash of the public key and the name is only a label. The client proves it holds the key inside the handshake, bound to the session. Clients check the server's Ed25519 identity against the listing, the server's
/infoanswer or the join data; a first contact by typed address is trust on first use. - No secret in the code. Security must not depend on hiding code. A build string or a content claim is not anti-cheat attestation: a modified client can still aim for you or see through walls, so admins have kick, ban, votes and logs.
- No admin port on the network.
/healthzand/adminlisten on loopback only. - Names, chat and art are untrusted. Decoded strings and image headers are validated before they are shown.
- Not protected: traffic analysis (packet sizes and timing are visible on the path), a server address already known to an attacker, and denial of service in general. A server's relay policy
alwayskeeps a home host's address out of listings and signalling; it cannot hide an address already known.
Conformance
A compatible implementation is one that a released Battlefront Eternal client or server of the same protocol and simulation accepts, and that accepts them. In practice the simulation rules are the hardest part: a client that predicts must step exactly the rules of the named simulation revision, whose reference is rust/sim at the commit above. Everything a player sees and hears (rendering, sound, menus) is the implementation's own choice.
Must
- Speak BFE-UDP/1 exactly as the transport tables give it: packet types and layouts, padding, the handshake and its keys, sealing, acknowledgement ranges, stream and datagram framing, and every limit, closing with the listed codes.
- Send
protocol5,profilesnapshot-delta-v1 andsimulationbfe-sim-34 in its hello, and refuse a peer whose values differ with close code 3 (update required). - Prove its identity with an Ed25519 key in the handshake, and check the other side's identity against what the listing, the typed address or the join data named.
- Validate every size and count before allocating or copying, and refuse what the receiver checks in the message tables refuse.
- As a client: send commands, never results; acknowledge a snapshot tick only when all of its required parts arrived; offer a content digest only for content it computed by the digest rules, and otherwise sit a 2005 battle out.
- As a client: keep the battle loading screen at the shared fixed length (13.5 s for a 2004 battle, the map's prepared duration for a 2005 battle) whatever its load speed, so a faster computer does not get into a battle earlier.
- As a server: be the authority, enforce the input, rate and access rules, and keep the admission order of the join section.
May
- Skip an optional 2005 record kind it does not implement, by the extent its carrier gives.
- Implement only part of the system: a directory reader, a LAN finder, a spectator, a server without punching or relay support.
- Present the battle in its own way, as long as what it sends is what the protocol allows.
Testing against a real server
Run the reference server and connect to it. Download the server archive from https://get.battlefronteternal.com/downloads/latest/ and check it against that folder's SHA256SUMS, or build rust/bfe-server from the engine repository at the commit above; the server repository has the install script and a Docker image. Prepare game data from your own copy of the game, then start it with bfeserver --serve. It uses UDP 18451 for the game, TCP 18451 for /info, UDP 18452 for LAN discovery, and loopback TCP 18450 for /healthz and /admin; the desktop app's HOST runs the same server on UDP and TCP 18461 (game and /info) and loopback 18460. For tests, keep it off the public directory. GET /healthz on loopback reports multiplayerReady only once the advertised contract is valid and a world is admitted. Join it with the desktop app of the same release to see the reference behaviour, then with your implementation.