roomkit

module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2026 License: MIT

README

roomkit

The multiplayer plumbing behind Dogfight: rooms, lobby, quick play, a hardened WebSocket server, rate limits, pilot tokens, blue/green drain, metrics, a load-test harness, and the browser half (reconnecting socket, input shaper, client prediction and reconciliation, interpolation, i18n, small UI primitives).

A game supplies its simulation, its messages and its screens by implementing a few interfaces; roomkit runs everything around them.

  • Go: go get github.com/ahmetbir/roomkit@latest — Go 1.26, one dependency (coder/websocket).
  • TypeScript: "roomkit": "git+https://github.com/ahmetbir/roomkit.git#v0.2.0" in package.json, then import { Socket } from "roomkit/net/socket". Ships compiled ES2022 with type declarations; no runtime dependencies, no three.

What is in it

Go package Does
room The room actor: one goroutine at a fixed tick (60 Hz) that owns a game, seats, per-player input queues with seq/ack, ping, quick chat, timeouts, panic recovery, the lobby summary. A game implements room.Game.
lobby Room codes, listing, quick play, room caps, drain, stats flush.
server HTTP + WebSocket server: handshake, origin check, per-address and per-/48 connection gates, create/join/API rate limits, inbound guard, security headers and CSP, fingerprinted static assets, /healthz, /api/rooms, /api/leaderboard, /api/me. A game implements server.Kit (and optionally server.Stats).
netproto The shared wire envelope (t, v, name, tok, code, seq, ts, id), core message types, error and API codes, CleanName.
wsconn A connection whose Send never blocks: bounded queue, evictable snapshots, write timeout.
limit Token buckets, keyed tables with refunds, connection gates.
pilot Anonymous pilot tokens: issue, validate, hash; log redaction.
metrics Prometheus text exposition with a per-game namespace.
drain SIGUSR1 drain / SIGUSR2 undrain for blue/green deploys, with a stats-store handoff hook.
loadtest A load-test harness (plan, ramp, histograms, gap detection) driven by a game's Script.
TS module Does
net/socket Reconnecting socket: backoff, 1012 rejoin, fatal codes, ping.
net/shaper Outbound shaping: newest-input-only under backpressure, one-shot merges, gapped picks.
net/codes, net/code, net/pilot Error codes, room-code helpers, pilot-token storage.
predict/reconcile, predict/interp, predict/sessionmodel Client prediction with replay, server clock, interpolation buffer.
i18n/* Dictionaries, plurals, params, live labels, formatting.
ui/* h/fill/text DOM helpers, modal key handling, error card, banner, language toggle, key labels.
audio/shell Lazy AudioContext, suspend while hidden, master gain + limiter.
store Namespaced localStorage slots.

Develop

npm install          # TypeScript + node types (dev only)
bash scripts/check.sh   # go vet, go test -race, tsc, node tests, dist/ is current

dist/ is committed (consumers' node --test cannot strip types inside node_modules). After changing ts/, run npm run build and commit dist/ with it; check.sh fails otherwise.

Agents and contributors: read AGENTS.md.

License

MIT

Directories

Path Synopsis
Package drain is the blue/green handover actor every game shares.
Package drain is the blue/green handover actor every game shares.
internal
fakegame
Package fakegame is the smallest game the core's tests drive: players move a counter by their input's D, a snapshot of every counter goes out every second tick, and a "color" message changes the room summary.
Package fakegame is the smallest game the core's tests drive: players move a counter by their input's D, a snapshot of every counter goes out every second tick, and a "color" message changes the room summary.
fakekit
Package fakekit plugs core/internal/fakegame into the server.
Package fakekit plugs core/internal/fakegame into the server.
tsconst
Package tsconst reads constants out of the TypeScript client core, so a Go test can pin a Go constant to its TS twin: a drift on either side fails the build's tests instead of the wire.
Package tsconst reads constants out of the TypeScript client core, so a Go test can pin a Go constant to its TS twin: a drift on either side fails the build's tests instead of the wire.
Package limit holds the small rate and concurrency limiters the server uses against floods: a token bucket, a per-key bucket table with bounded memory, and a per-key connection gate.
Package limit holds the small rate and concurrency limiters the server uses against floods: a token bucket, a per-key bucket table with bounded memory, and a per-key connection gate.
Package loadtest is a game-agnostic WebSocket load-test harness: slots and ramp, histograms, per-second rates, disconnect reasons and the player loop (player.go).
Package loadtest is a game-agnostic WebSocket load-test harness: slots and ramp, histograms, per-second rates, disconnect reasons and the player loop (player.go).
Package lobby creates rooms under short join codes and forgets them when they finish.
Package lobby creates rooms under short join codes and forgets them when they finish.
Package metrics is a dependency-free Prometheus text exposition: lock-free counters, gauges and fixed-bucket histograms, owned by one Registry that main builds and passes down (no globals).
Package metrics is a dependency-free Prometheus text exposition: lock-free counters, gauges and fixed-bucket histograms, owned by one Registry that main builds and passes down (no globals).
Package netproto is the part of the wire protocol every game shares: the message envelope, the core message types (handshake, ping, chat, errors, notices), the welcome envelope and the core error codes.
Package netproto is the part of the wire protocol every game shares: the message envelope, the core message types (handshake, ping, chat, errors, notices), the welcome envelope and the core error codes.
Package pilot issues and checks the anonymous pilot token.
Package pilot issues and checks the anonymous pilot token.
Package room runs one match as an actor: a single goroutine owns the game and talks to connections only through channels and Sender.
Package room runs one match as an actor: a single goroutine owns the game and talks to connections only through channels and Sender.
Package server wires HTTP routes and the WebSocket handshake to the lobby.
Package server wires HTTP routes and the WebSocket handshake to the lobby.
Package wsconn wraps a WebSocket with a bounded, non-blocking outbound queue and a reader goroutine, so a room actor never blocks on a socket.
Package wsconn wraps a WebSocket with a bounded, non-blocking outbound queue and a reader goroutine, so a room actor never blocks on a socket.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL