Replication API best practices
Native UDP to Buddy. Browsers should use the GraphQL UDP proxy instead.
Authenticate, then assign
- Sign in for an identity session token.
- Mint an app-scoped token for the app (
mintAppToken). Buddy rejects the session token. - Call
serverWithLeastClientson that app'sapplicationApiUrl. - Wait ~1.5 seconds after assignment before the first spatial send.
- Sign every datagram with HMAC-SHA256 over the app-scoped token. HMAC.
Full sequence: Authenticate and assign.
Stay on the session
- Send a heartbeat at least every 4 seconds while the actor is present, and some traffic at least every 60 seconds. Operations.
- When a heartbeat is answered
UNAUTHORIZED(server v0.51.0), the player has noaccesswhere the actor stands. Keep the same cadence, and do not treat the player as present there. See the heartbeat rule. - Refresh the app token before
expiresAt. An expired token yieldsTOKEN_EXPIRED; mint/refresh and re-assign. - On
COMMAND_RECONNECT(type 22), verify the HMAC and callserverWithLeastClientsagain. Do not keep sending to the old host. - Bind the control frames to the assignment (replication server v0.45.0): send a new random
8-byte nonce in
CLIENT_CAPABILITIES(bit 1) after each assignment, and accept aCOMMAND_RECONNECT_BOUND(44) orCOMMAND_SESSION_RELEASED_BOUND(45) only with that nonce. One carrying another nonce was captured earlier and sent again: drop it. Keep handling the legacy 22 and 28 (older servers, and the Application API's proxy toward browsers still send them) until the server acknowledges the nonce (CONTROL_BOUND_ACK, 46, replication server v0.46.0); after that, drop every 22 and 28 on that assignment. Until then, treat a legacy idle release (28, reason 5) that arrives within a minute of your own gameplay input as a reconnect rather than the end of the session, since a captured one verifies too. Wire formats. - On
CHUNK_CHANGED_NOTIFICATION(146), read that chunk again: a hub or mod replaced it whole and sends no voxel update per voxel. - Handle
WRONG_DATACENTERby reconnecting toextensions.applicationApiUrl. Datacenter routing.
Permissions and silence
- Every spatial message is authorized. The sender needs an active access grant whose tier includes the relevant key, and a grid grant on the target chunk.
- A failed HMAC or bad token can be dropped with no NAK. Do not treat silence as ordinary packet loss.
UNAUTHORIZED(code 7) means the permission is missing. From replication server v0.42.0 the first message into a brand-new chunk waits for the chunk's permissions to load instead of being refused, so a refusal there is real unless they could not be loaded within about two seconds: retry once, then treat the permission as missing. Older servers refused that first message while the permissions loaded.
Gameplay authority
UDP carries poses and events. It is not the place to decide damage, captures, ownership, or team assignment. Those are decided by your server code's endpoints on ck-exec hubs (see best practices). The client sends input and presents the hub's confirmed result.
Load testing your integration
Drive the same public flow your players use. See Load testing. Sustained traffic is billed like real players — test against isolated capacity and set spend caps before hitting shared production.