VERTEXDocsGitHub

Multiplayer and MMO servers

Any cartridge can be served to many players. The server runs the authoritative simulation; clients send only input and receive what is near them.

npx vertex serve game.json --port 8080 --root .
# players open http://host:8080/?online   (scaffolded projects)  or  /play.html?server=auto
# status: http://host:8080/status

Make a cartridge multiplayer#

Add a multiplayer block. Your single-player rules usually need no changes:

"multiplayer": {
  "player": { "shape": "hero", "tags": ["player"], "body": {}, "data": { "gold": 0 } },  // each joiner
  "spawn": { "x": 160, "y": 160, "spread": 60 },
  "interest": 480,              // each client receives only entities within this radius
  "publicData": ["name", "hp"], // data keys other players can see (own player sees everything)
  "sendRate": 20                // snapshots per second
}

How existing rules keep working: each player gets an id (p1, p2, …) and an entity with data.player. When a rule runs for that entity (each → self, or a in hit/contact), held(), pressed(), axis() and pointer read that player's input. So { "each": "player", "when": "held('left')", ... } moves every player by their own keys.

Things to keep per player: store them on the player entity's data (gold, inventory, quest flags), not in global state. Show a per-player HUD by setting self.data.hud; clients display their own. Dialogue state automatically lives on the player in multiplayer, and each client draws only its own dialogue box.

Events: { "on": "join", "do": "..." } / "leave" with event.player, event.entity.

Scale#

Measured (one Node process, test/net.test.js): 500 players spread over an endless streamed world, ~24,000 awake entities, physics and rules: ~54 ms per tick including all snapshots, ~300 bytes per player per snapshot. For more players, run the server at a lower fps, raise sendRate intervals, or shard the world across processes by region (each GameServer is independent; route players by position).

Embedding the server#

import { serve, GameServer } from 'vertex-engine/node';
const { url, server, stop } = await serve({ cartridge, port: 8080, root: 'public' });

// or bring your own transport (anything with send(text) and on('message'|'close'))
const game = new GameServer(cartridge, { seed: 1, fps: 30 });
wss.on('connection', (socket) => game.connect(adapt(socket)));
setInterval(() => game.step(), 1000 / 30);

Clients: createPlayer({ canvas, server: 'wss://host/ws' }) or the lower-level NetClient.connect(url) which you can drive with bindKeys, touchControls, etc.

Limits (honest)#

Edit this page