Packs / game-dev-web-public
websocket-multiplayer-room
Run a small authoritative multiplayer room over WebSockets (join, input, server tick, state broadcast, leave) with no dependencies, and know when to move to Colyseus
Install
logicpacks pack use game-dev-web-public/websocket-multiplayer-roomget_pack game-dev-web-public/websocket-multiplayer-roomThe second line is the MCP tool call for the LogicPacks connector (Claude Code, Codex, Claude.ai and others). The first run of a pack someone else wrote asks for your yes.
Keys it needs (names only)
None.
Playbooks included
- Spec:
spec/SPEC.md(goal, steps, edge cases, don’ts) - Routes:
node-localcolyseus - Checks: 1 in
outcome/checks.yaml - Code:
room.test.mjsserver.mjs - Tools: node
Usage, last 8 weeks
New: no recorded use yet.
Purpose (from spec/SPEC.md)
Goal
Two or more browser clients see the same game state, driven by a server that owns the truth (clients send inputs, not positions).
Steps
- Start the server:
node code/server.mjs 8787(Node 18+, no npm install; minimal RFC 6455 text frames). - Clients:
new WebSocket('ws://host:8787/room/lobby'), send{t:'input', dx, dy}; receive{t:'state', tick, players}at 20 Hz. - The server clamps speed per tick (basic anti-cheat) and drops players that stop sending pings.
- Production: move to Colyseus (MIT; rooms, schema sync, matchmaking) or WebRTC data channels for P2P, behind TLS (wss://) on our host or a Cloudflare tunnel.
- Check:
node code/room.test.mjs(starts the server, two clients, verifies sync).
Edge cases
- This server handles text frames < 64 KB, no compression or fragmentation: fine for a room of a few players, not for production.
- Latency: add client-side prediction + server reconciliation when moving feels laggy.
- WebRTC needs a STUN/TURN server for players behind strict NATs.
Don'ts
- Don't trust client positions or scores.
- Don't expose the raw ws port publicly without TLS and a rate limit.