Server
The Server class is the authoritative multiplayer server. It manages client connections, processes commands, and broadcasts world state.
Setup
import { Server, BaseGame } from '@mavonengine/core'
import type { Channel } from '@geckos.io/server'
class MyServer extends Server {
onConnection(channel: Channel): void {
// A new client connected
console.log('client connected:', channel.id)
}
onCommand(command: unknown, delta: number): void {
// Process an incoming client command
}
getStateSyncDistance(): number {
// Return the visibility radius (units) for state sync
return 100
}
}
const game = MyBaseGame.instance()
const server = new MyServer(game)
server.start()
Ports
| Port | Purpose |
|---|---|
8081 | geckos.io WebRTC socket server |
8050 | HTTP server (health check, meta endpoints) |
Abstract methods
| Method | Description |
|---|---|
onConnection(channel) | Called when a new client connects |
onCommand(command, delta) | Called for each queued command on each tick |
getStateSyncDistance() | Returns the max distance for state sync visibility |
Command buffer
Clients send commands (e.g. input frames) to the server. The server queues them and processes them in order on each tick via onCommand. This prevents cheating and ensures deterministic simulation.
HTTP endpoints
Register custom HTTP routes using onHttp:
server.onHttp((app) => {
app.get('/status', (req, res) => {
res.json({ players: Object.keys(world.entities).length })
})
})
A built-in /health endpoint is registered automatically.
Bandwidth tracking
The server tracks outgoing bandwidth per tick. Access it via server.bandwidthTracker for monitoring.
ServerWorld
For the server-side world (with player/client tracking), use ServerWorld:
import { ServerWorld } from '@mavonengine/core'
ServerWorld extends BaseWorld and adds player management for connected clients.
The server maintains its own Three.js scene populated with simplified hitbox meshes rather than full visual geometry. This keeps memory and CPU overhead low while still allowing authoritative raycasts, hit detection, and spatial queries directly against the scene — no need to trust client-reported positions.