Skip to main content

VIVIA โ€” Multiplayer Networking

Protocolโ€‹

TCP-based protocol at 20 Hz with bincode serialization:

Client โ†’ Serverโ€‹

PacketDescription
JoinPlayer name, handshake
PlayerInputPosition, yaw, flying, sprinting
BlockBreakBlock coordinates
BlockPlaceBlock coordinates + type
AttackMelee reach distance
ChatMessage text
RequestChunksChunk coordinate list
DamageEntityEntity ID + damage amount
PingRTTTimestamp for RTT measurement

Server โ†’ Clientโ€‹

PacketDescription
WelcomePlayer ID, spawn, seed, tick rate
ChunkBlock data (compressed)
PlayerUpdateOther player positions
EntityBatchBulk mob updates
EntitySpawn / EntityDespawnMob lifecycle
BlockUpdateBlock changes from other players
StatsSyncServer-authoritative stats
CombatEventDamage, knockback, enrage
ServerTickDay time, night, blood moon
PlayerListConnected players
ServerChatSystem/player messages

Anti-Cheatโ€‹

  • Name sanitisation โ€” max 24 chars, no control characters
  • Chat sanitisation โ€” max 256 chars, control chars stripped
  • Block coordinate validation โ€” ยฑ16,384 X/Z, 0..512 Y
  • Position validation โ€” finite, ยฑ1,000,000 (rejects NaN/Inf/teleport bombs)
  • Rate limiting โ€” >120 packets/sec โ†’ disconnect
  • Handshake timeout โ€” 10s anti-slowloris
  • Pending connection limit โ€” 64 max pre-handshake

Client-Side Interpolationโ€‹

Remote players and entities are interpolated between updates:

  • Each update stores previous position + new position
  • Interpolation factor t advances with delta time
  • Position = lerp(prev, new, t) for smooth movement at any frame rate

Chunk Streamingโ€‹

  • View distance: 8 chunks radius
  • Backpressure: max 4 chunks sent per tick per client
  • Dedup: client sends ChunkAck, server skips already-sent chunks
  • Request filtering: client doesn't re-request cached chunks

Server Architectureโ€‹

  • Authoritative: server owns all entity HP, positions, block state
  • Broadcast: all state changes broadcast to all clients
  • Per-entity sync: only entities within ENTITY_SYNC_RADIUS (48m) are synced
  • Despawn radius: entities beyond 64m are despawned on client