Networking

Networking

Authoritative multiplayer server with WebRTC and tick-based state sync.

MavonEngine uses an authoritative server architecture for multiplayer. The server is the single source of truth — clients send commands, the server processes them, and broadcasts state back to clients.

Reference: The architecture is inspired by Gaffer On Games and Source Engine Multiplayer Networking.

Transport

Real-time data is sent over UDP via WebRTC using geckos.io. This gives low-latency unreliable messaging suitable for game state synchronization.

Architecture overview

Client                          Server
  │                               │
  │── command (input) ──────────► │
  │                               │  1) process command
  │                               │  2) step physics
  │                               │  3) update state
  │◄── state sync (tick) ──────── │
  │                               │
  1. Client captures input and sends commands to the server
  2. Server queues commands in a command buffer
  3. On each tick, the server processes commands, steps physics, and broadcasts world state
  4. State is only sent to clients within the visibility radius of each entity

Shared 3D scene

Both server and client run a Three.js scene, but they serve different purposes. The client holds the full scene - detailed meshes, materials, and visual geometry. The server holds simplified hitbox meshes - lightweight geometry used exclusively for spatial queries.

This means the server can perform authoritative raycasting, hit detection, and area-of-effect checks directly against its scene without trusting client-reported positions, and without the overhead of full visual geometry.

// Server-side raycasting against hitbox meshes
const raycaster = new THREE.Raycaster()
raycaster.set(origin, direction)
const hits = raycaster.intersectObjects(game.scene.children, true)

Key classes

Server

Authoritative server with command buffer, tick loop, and HTTP health endpoint.

NetworkManager

Client-side WebRTC connection with ping monitoring.

Networked Actors

NetworkedActor, NetworkedGameObject, and state synchronization utilities.

State Sync

How entity state is serialized and synchronized between server and clients.