Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Networking

The client and the server talk over ENet, a thin reliability layer on top of UDP. Each side reads and writes buffers. Every packet starts with a 16-bit unsigned integer that names its ID.

Every packet goes out reliably. ENet sequences each channel on its own, so the world stream has a channel of its own. A burst of chunk packets does not hold back login, entity or timing packets, and the other way around. Blocks, biomes and light share that channel, because a light packet is only meaningful after the chunk that it belongs to. A single sequence is what guarantees that order.

A client goes through one of two exchanges after it connects: a status ping, or a full login. Both exchanges start the same way. Both end with the server closing the connection or keeping it open.

Status pings

A client can connect just to ask a server about itself: protocol version, MOTD, player count, and slot limit. The server does not keep this connection open.

Flow

The figure shows the exchange. The table lists the same steps.

StepSenderReceiverDescription
1ClientServerThe client connects
2ClientServerThe client sends a status request packet
3ServerClientThe server responds with a status response packet
4ClientServerThe client closes the connection

Authentication

If the client sends a login request instead of a status request, the server starts an authentication exchange.

Flow

The figure shows the exchange. The table lists the same steps.

StepSenderReceiverDescription
1ClientServerThe client connects
2ClientServerThe client sends a login request packet: username, public Ed25519 key, invite code, protocol version, and registry hashes
3ServerClientIf the server accepts the request, it responds with a challenge packet holding a random nonce
4ClientServerThe client signs the nonce plus the current UTC time (minute resolution), and sends the signature back in a challenge response packet
5ServerClientIf the signature matches, the server admits the client with a packet holding its assigned username
6N/AN/AEntity exchange and game packets start here
Spawn world

The server admits the client into the world that worlds.yml marks with default: true, or the first world when none is marked. The server sends the world shape, the weather seed and the clocks in the admission packets. The client therefore needs no world name of its own. The world seed never leaves the server.

Identity

The client proves its identity with an Ed25519 keypair. The server challenges the client with a random nonce, and the client signs it.

Invite codes

The invite code is a one-time code. On a successful login, the server consumes the invite code. The server then adds the client’s public key to its whitelist. The same client can then reconnect later without a new invite. An operator issues codes with invite.

Registry hashes

The client sends its block, biome, fluid, tint, entity class, weather and precipitation registry hashes. The server checks each hash against its own. A mismatch means the two sides disagree on what a given ID means. When that happens, the server disconnects the client with a checksum mismatch reason. Neither side acts on the disagreement.

This check protects both sides:

  • It stops a mismatched client from receiving chunk data it would render as corrupted or nonsensical.
  • It stops that same client from placing a block ID the server does not recognize.

Operator access

A server can mark an Ed25519 public key as an operator. The server keeps these keys in operators.txt next to whitelist.txt in the user directory. The file holds one exported public key per line, the same format as whitelist.txt.

The server tracks the status per session. An operator bypasses the whitelist, so the same key does not have to appear in both files.

Enrolling an operator

The player runs the whoami command in the console. The client prints its public key and its identity. The identity is the crc64 of the key, and server logs show the identity. The public key is the value that the files expect.

The first operator enrolls by hand:

StepWhoAction
1PlayerConnect and run whoami
2Server hostCopy the public key: line into operators.txt
3Server hostRestart the server

After that, an operator runs op <public key> or deop <public key>. These update operators.txt right away and promote or demote a matching live session without a reconnect. A hand edit still needs a restart, because the server loads the file during startup and writes it back on shutdown.

Operator commands

An operator connects like everyone else. The server sends the command list of an operator with the operator-only commands included, and every other client gets a list without them. A client that does not know a command reports it as unknown.

CommandDescription
whoList connected sessions with their client IDs, identities, public keys, and access levels
opAdd a public key to the operator list and promote that player
deopRemove a public key from the operator list and demote that player
kickDisconnect a player by client ID or username
inviteIssue a one-time invite code

The commands carry the admin and recall flags. recall lets the client forward the command to the server. admin makes cvar::exec refuse it unless the context holds a client that is an operator. The engine trusts a context without a client, such as server.conf or the client’s own console.

A demoted operator keeps the commands it already learned, but the server rejects them.

Kicking

kick sends a disconnect packet with the kicked reason and then closes the connection. The key is not banned. A kicked client can reconnect unless something else stops it, such as the whitelist or a full server.

Cvar replication

The server owns every variable flagged with FCVAR_REPLICATED. After admission it sends a full snapshot of them. On every fixed tick it sends the variables that changed since the previous tick.

The client keeps the server value in a shadow. A local variable with the same name must also carry the FCVAR_REPLICATED flag. Otherwise the client ignores the server value and logs a warning. A full snapshot drops stale remote variables and clears the old shadows.

The server accepts a cvar value from a client only when the variable carries the FCVAR_ADMIN flag and the caller is an operator. The client console forwards a write to a shadowed variable through the same Cvar_Command path as a command. The server applies the operator check and ignores every other remote value. Gamerules use the gr_ prefix. Match rules will use mp_. The console list_vars and list_cmds commands list every variable and command.

The command snapshot follows the same exchange. The server sends one full list to each admitted client. The list leaves out the commands that carry the FCVAR_ADMIN flag unless that client is an operator. When a live session gains or loses the operator status, the server sends the list again. A dirty variable update carries only the replicated variables that changed in that tick.

The snapshot packet carries a uint8 full flag and a uint32 count, then for each variable a string name and a string value. A full snapshot adds a uint16 flags and a string help for each entry.

World

Once the server admits a client, the client asks for chunks and reports block and entity actions. Only the server can make a world change final.

Chunk transfer

The client sends RequestChunk every fixed tick with two boxes: the chunk-aligned view it needs, and the XZ interest box for column data. The server intersects each box with its own view limit and sends only what the peer does not hold yet. The server answers with ChunkBlocks, holding that chunk’s full block data. It also sends ChunkBlocks on its own initiative, as a full resync.

Biomes and column heights belong to an XZ column, not to one chunk. The server sends ChunkBiomes and ChunkColumns once per column. ChunkColumns carries the surface and liquid heights that precipitation and the shelter checks use. When a column changes, the server sends Column to the sessions whose interest box holds that column. A client drops a column that leaves its interest box, and the server sends it again when the client comes back.

World info

The server sends World_Info at admission and again when a session moves to another world. It carries the world’s name, its vertical bounds and spawn point, its optional visual groups, the weather types it allows and the world’s weather seed. The client builds its one world from this packet instead of a local world definition. These values never change for a world, so the periodic packets do not repeat them. The world seed is not in the packet: the client streams terrain without being able to predict it. The client derives its star field seed from the weather seed, which both sides compute the same way. The length of a day is not here either: it is the replicated server variable sv_day_length, so a change reaches every connected client without another packet.

World switch

A session moves to another world only through tpe, which runs on the server. The server moves the player entity into the target registry, then repeats the admission state: World_Info, World_Timings and Entity_Client for the new entity. The client purges its world on World_Info, drops the player and resets its weather state, then streams the new world from its next World_Request. The server scopes entity, light and block packets to the session’s own world, so they never reach a session in another world.

Time

The server owns a world clock per world. World_Timings carries the universe-wide current_tick, the world’s daylight_tick, the whole day count (daylight_tick / sv_day_length), the world’s weather_tick and a reserved season_tick. The season_tick stays zero until the season cycle lands. Every world shares current_tick, so block ticks and chunk saves stay comparable across the server. daylight_tick advances per world at the same fixed rate, and that is what lets two worlds run different days. The gr_daylight_cycle gamerule stops only the daylight clock. The client runs its own smooth phase between packets and aligns it with the server. When a packet moves the clock by a second or more, which is what time_set does, the client snaps instead of easing. The packet carries no flag for this: the client sees the jump in the tick values that it already keeps. The server writes each world’s daylight tick into that world’s world.conf on shutdown, so a restart continues the day where it was. Operators set the clock with time_set <daylight tick>, which targets the caller’s world. Clients read what they see with time_query.

Weather

The engine derives the weather, and it does not stream it. The server rolls one weather seed per world and keeps it in that world’s world.conf, independent of the world seed. It sends the seed once in World_Info. Every tick the server advances a per-world weather_tick and sends it in World_Timings. That is the only weather value on the wire after admission. Both sides turn the pair (weather_seed, weather_tick) and a world position into the same field. Two drifting noise grids form the two axes of a climate square, and every weather type owns a target point in that square. The nearest target and its soft share decide the type and the local strength. There is no drift or baseline packet any more, and no accumulated drift to diverge. The same seed and the same tick always give the same field. A client advances its copy of the tick between packets, and it snaps when a packet jumps the clock by more than a second. That jump is what weather_force and a world switch look like. The replicated gr_weather_cycle gamerule stops the weather clock on the server and the client’s local advance together. The login checksums cover the weather and precipitation definitions, which travel as part of the mod content. The precipitation type is local: both sides derive it from the same weather field and the block climate, so no precipitation state travels.

Block and entity actions

The client sends one of four packets depending on what it targets and what it does: PlayerAttackE/PlayerInteractE for an entity target, PlayerAttackB/PlayerInteractB for a block target. There is no single unified packet with a nullable target field.

The entity variants carry only the targeted entity. Both block variants carry the block’s position and the ID the client expects to find there. PlayerInteractB also carries the hit face, normal and point, which match the physics::BlockHit fields the block callbacks expect.

Packet reference

Each packet starts with a 16-bit unsigned integer that names its ID. The packets use these names and structures:

0x0000 StatusRequestPacket

Request a status from server

TypeNameDescription
uint32majorMajor game version
uint32minorMinor game version
uint32patchPatch game version

0x0001 StatusResponsePacket

Server’s response to a StatusRequestPacket

TypeNameDescription
uint32majorMajor game version
uint16slotsMaximum player slots
uint16playersCurrent player count
stringmotdOne-line MOTD no longer than 32 characters
uint32minorMinor game version
uint32patchPatch game version
uint32tagsServer tags
Server flags
ValueDescription
0x00000001Server has whitelist enabled
0x00000002Server enforces strict version matching

0x0002 AuthRequestPacket

Request an authentication on a server

TypeNameDescription
uint32majorMajor game version
uint32minorMinor game version
uint32patchPatch game version
uint8[32]pkeyPublic Ed25519 key
uint64inviteInvite-code
uint64biomes_hashBiome registry hash
uint64blocks_hashBlock registry hash
uint64fluids_hashFluid registry hash
uint64tints_hashTint registry hash
uint64ents_hashEntity registry hash
uint64weather_hashWeather registry hash
uint64precip_hashPrecipitation registry hash
stringusernameDesired username

0x0003 AuthChallengePacket

Server’s response to AuthRequestPacket

TypeNameDescription
uint8[64]nonceNonce for the client to sign

0x0004 AuthResponsePacket

Client’s repsonse to AuthChallengePacket

TypeNameDescription
uint8[64]signatureSigned nonce + UNIX minutes

0x0005 AuthAdmissionPacket

On successful auth, server’s response to AuthResponsePacket

TypeNameDescription
uint16client_idClient ID
uint64identityClient identity
stringusernameAssigned username

0x0006 Disconnect

Disconnection notification. Each side should close the connection right after this packet, although it may keep the connection open

TypeNameDescription
uint32reasonDisconnect reason
Reason values
ValueDescriptionWhen
0x00000000Unspecified reasonAnything not specified below
0x00000001Client disconnectClient manually disconnects
0x00000002Client shutdownClient closes the game
0x00000003Entity ID desyncEnTT registry goes nuts
0x00000004Checksum mismatchClient isn’t synced up with server mods
0x00000005Not whitelistedClient’s public key is not in the whitelist
0x00000006Invalid signatureClient messed up nonce signing
0x00000007Outdated clientClient is too old for the server
0x00000008Outdated serverClient is too new for the server
0x00000009Server is fullNo more free slots available
0x0000000AServer shutdownServer is terminating
0x0000000BCvar rejectedA remote write to an admin variable was refused
0x0000000CKickedAn operator removed the client
0x0000000DWorld unknownThe client asked for a world the server does not have

0x0007 RequestChunk

The client sends this packet every fixed tick to describe what world data it wants. The packet carries a chunk-aligned view box, an XZ interest box for column data and a budget. The server intersects each box with its view limit, stores what the peer already has, and sends only the difference. A box with min > max is empty.

TypeNameDescription
vector3<int32>view_minMinimum chunk of the view
vector3<int32>view_maxMaximum chunk of the view
vector2<int32>interest_minMinimum XZ chunk of the column interest
vector2<int32>interest_maxMaximum XZ chunk of the column interest
uint16chunk_budgetHow many chunks the server may queue now

The budget carries the client’s backpressure. The client lowers the budget while its mesher queues more work than it can take. The sent sets live on the server, and the server fills them only when it hands a packet to ENet. The server therefore retries a request that produces no data instead of counting it as delivered.

0x0008 ChunkBlocks

The server sends this packet as a response to RequestChunk, or at arbitrary moments to synchronize chunk contents with clients

TypeNameDescription
vector3<int32>cposChunk position
datablocksSerialized and compressed block storage contents
datalightCompressed packed light, one byte per block: skylight in the high nibble, block light in the low nibble
uint8light_valid1 when light holds computed light. 0 makes the client fall back to its own estimate until a ChunkLight arrives

0x0009 ChunkBiomes

The server sends this packet as a response to RequestChunk to synchronize the biome caches that client rendering uses

TypeNameDescription
vector2<int32>cposXZ-position
databiomesCompressed list of 256 biome IDs

WriteBuffer::write_compressed writes every compressed field, and ReadBuffer::read_compressed reads it back. Such a field holds four parts. The parts are a mode byte, the size that the data had before compression, the size that it takes in the buffer, and the bytes. The bytes are either raw or a zlib stream. The engine compresses the whole array at once, so the ratio is the one that the codec gets over a chunk. A transport would get a different ratio out of a single datagram.

0x000A ChunkColumns

The server sends this packet once per XZ column to synchronize the surface and liquid heights that precipitation and the shelter checks use.

TypeNameDescription
vector2<int32>cposXZ chunk position
datacolumnsCompressed list of 256 columns. Each column holds two int32 values: surface_y and liquid_y

A stored height of INT32_MIN means that the column has no such block.

0x000B ChunkLight

The server sends this packet when the light of chunks that it has already synchronized changes. One packet carries every chunk whose light changed in a tick. Each entry is either a delta over the cells that changed or, when most of the chunk changed, the whole array.

TypeNameDescription
uint16countNumber of entries
entry[count]entriesOne per changed chunk

Each entry:

TypeNameDescription
vector3<int32>cposChunk position
uint8full1 when the entry carries the whole array, 0 for a delta
datalightOnly with full = 1. Packed light, same layout as the light field of ChunkBlocks
uint16cellsOnly with full = 0. Number of changed cells
uint16, uint8index, valueOnly with full = 0. One pair per changed cell, repeated cells times: the cell index, the same order as the light array, then the new packed light

The server applies a delta only to a chunk that the client already holds light for. When the server replaces a whole array, it always sends it whole. It does the same when the changed cells outnumber a quarter of the chunk, instead of sending a delta that would be larger.

The server splits a batch when it would exceed 32 KiB. A tick that relights a large part of the view distance therefore turns into several packets instead of one huge one.

0x000C SetBlock

The server sends this packet as a sub-chunk block update

TypeNameDescription
vector3<int64>bposWorld-scale block position
uint32blockResulting numeric block ID

0x000D Column

The server sends this packet when the surface or liquid height of a column changes.

TypeNameDescription
vector2<int64>bposWorld-scale XZ block position
int32surface_yTop surface block, or INT32_MIN
int32liquid_yTop liquid block, or INT32_MIN

0x000E WorldTimings

The server sends this packet every tick for the world a client is in

TypeNameDescription
uint64current_tickCurrent world tick
uint64daylight_tickTick the daylight cycle follows
uint64dayDay number
uint64weather_tickTick the weather clock stands at
uint64season_tickReserved for the season cycle, zero for now

0x000F WorldInfo

The server sends this packet when it admits a client, and again when the client moves to another world

TypeNameDescription
stringnameWorld name
uint64weather_seedSeed of the weather field of this world
int64min_yLowest buildable block Y
int64max_yHighest buildable block Y
vector3<int64>spawnSpawn position
uint16nweatherNumber of allowed weather types. Zero allows every type
uint32[nweather]weatherAllowed weather type IDs

0x0010 CvarServerVars

The server sends this packet with the variables a client may read

TypeNameDescription
uint8full1 for a full list, 0 for an update
uint32countNumber of variables
stringnameVariable name, per variable
stringvalueVariable value, per variable
uint16flagsVariable flags, per variable. Only with full = 1
stringhelpVariable help, per variable. Only with full = 1

0x0011 CvarServerCmds

The server sends this packet with the commands a client may run

TypeNameDescription
uint32countNumber of commands
stringnameCommand name, per command
uint16flagsCommand flags, per command
stringhelpCommand help, per command

0x0012 CvarCommand

The client sends this packet to run a console line on the server

TypeNameDescription
uint32request_idID the server echoes in its reply
stringlineConsole line, no longer than the protocol limit

0x0013 PlayerAttackE

Sent by client to specify an attack action against an entity

TypeNameDescription
uint64targetTargeted entity

0x0014 PlayerAttackB

Sent by client to specify an attach action against a block

TypeNameDescription
vector3<int64>bposTargeted block position
uint32expectedNumeric block ID the client expects at bpos

0x0015 PlayerInteractE

Sent by client to specify an interact action against an entity

TODO: send over specific part of an entity’s hitbox as well

TypeNameDescription
uint64targetTargeted entity

0x0016 PlayerInteractB

Sent by client to specify an interact action against a block

TypeNameDescription
vector3<int64>bposTargeted block position
uint32expectedNumeric block ID the client expects at bpos
uint8faceHit face used for interactions
vector3<float>normalHit normal
vector3<float>pointHit point local to the block

0x0017 PlayerMoveData

The client sends this packet with its own movement state

TypeNameDescription
vector3<int32>cposChunk position the client simulated in
vector3<float>anglesCamera angles
vector3<float>lposLocal position inside the chunk
vector3<float>velocityVelocity
vector3<float>wishdirDirection the player asks to move in

0x0018 EntitySpawn

The server sends this packet when it spawns an entity

TypeNameDescription
uint64idEntity ID
uint16class_idNumeric class ID

0x0019 EntityPatch

The server sends this packet when it updates a component of an entity

TypeNameDescription
uint64idEntity ID
uint32ncompComponent count
uint16idComponent ID, per component
uint32sizeByte length of the component, per component
databytesComponent bytes, per component

0x001A EntityRemove

The server sends this packet when it removes an entity

TypeNameDescription
uint64idEntity ID

0x001B EntityClient

The server sends this packet to tell a client which entity it controls

TypeNameDescription
uint64idEntity ID

0x001C MsgLog

The server sends this packet as the reply to a console line

TypeNameDescription
uint32request_idID of the request it answers
uint8levelLog level of the message
stringmessageMessage text