A web[sockets] server for playing the Brogue over the internet. Brogue is a game for Mac OS X, Windows, and Linux by Brian Walker. For more information go https://sites.google.com/site/broguegame/. The server only can be run on a POSIX environment at the moment.
Use Node.js 24 LTS and MongoDB 8.0 (latest patch releases).
The repository's .nvmrc selects Node 24:
nvm install
nvm useInstall a C++ compiler, make, and Python 3 for the unix-dgram native module
(on Ubuntu: sudo apt-get install build-essential python3).
For local MongoDB, install MongoDB 8.0 or run docker compose up -d mongo.
The Compose database is bound to localhost and persists in a named volume.
Alternatively, after installing server dependencies, run npm run db in server.
This downloads MongoDB 8.0.34 if needed, listens on localhost:27017, and persists
its data in the ignored server/db/ directory. Leave it running in a separate
terminal; Ctrl+C stops the database without deleting its data. This development
command requires dev dependencies; production uses a separately managed MongoDB.
Navigate to the server directory and run npm ci. Lockfiles are committed
for reproducible installs. Also run npm ci in scripts/news if you use the news utility.
Browser libraries are committed in client/libs. To regenerate them from the
client lockfile, run npm ci && npm run build inside client.
The custom autocomplete view and the small paginator adapter are local application code.
The paths to the binaries is stored in server/config.js.
Brogue binaries are stored in the binaries/ directory. Linux ELF binaries are included in the distribution for all supported brogue versions. If there's a new version of a brogue variant, or a replay-breaking change is added to a brogue version without changing the version, create a new variant and add a new brogue binary. This allows old recordings to still work. (Note that a new variant means separate high scores for now.)
The lineage of each brogue version and build instructions is given below. You shouldn't need to follow these unless you're building for a different platform.
- Brogue (1.7.4):
cd broguemake web - Brogue (1.7.5):
cd brogue-1.7.5make web - gBrogue:
cd gbroguemake -f Makefile.linux web - unBrogue:
cd unBroguemake web - broguePlus:
cd brogueplusmake web - Brogue CE (1.8): Clone
https://github.com/flend/BrogueCEand checkout branchtracking/web-brogue.make bin/broguethen copy binary tobinaries/brogue-ce18 - Brogue CE (1.9): Clone
https://github.com/flend/BrogueCEand checkout branchtracking/web-brogue-v193.make bin/broguethen copy binary tobinaries/brogue-ce19-c813284(or similar filename) - Brogue CE (1.10): Clone
https://github.com/flend/BrogueCEand checkout branchtracking/web-brogue-v110.make bin/broguethen copy binary tobinaries/brogue-ce110(or similar filename) - Brogue CE (1.11+): Clone
https://github.com/flend/BrogueCEand checkout branchtracking/web-brogue-v1XX.make bin/broguethen copy binary tobinaries/brogue-ce111(or similar filename). This binary also includes RapidBrogue from v1.5+ - Rapid Brogue (v1.4 and earlier): Clone
https://github.com/flend/rapidbrogueand checkout branchtracking/rapid-brogue-vXXX.make bin/broguethen copy binary tobinaries/rapid-brogue-vXXX(or similar filename)
Starting the server should be as simple as starting up mongoDB and starting the node process.
- To start the mongodb daemon type
mongod(this should be started at system init in most cases) - To start the server type
npm startin theserverdirectory.
You will probably want to edit server/config.js and client/config.js to set the ports and the server secret.
If everything is running correctly it should say "Server listening on port XXXX"
Note that you might need root access if you are running on a privileged port (e.g. 80).
Server global configuration variables are defined in server/config.js.
MONGODB_URI overrides the default mongodb://127.0.0.1:27017/brogue;
PORT overrides HTTP port 8080; SESSION_SECRET overrides the configured token secret.
Keep your existing session secret during migration to preserve saved login tokens.
Authentication work runs in a bounded pool of two worker threads. config.auth.rateLimit
defaults to 30 attempts per IP and 10 per IP/username pair per minute, shared across
connections. trustedProxyAddresses defaults to loopback proxies; forwarding headers
from other peers are ignored. Set this list to the actual proxy addresses if needed.
Only trust proxies that append or replace X-Forwarded-For with the real client address.
Client configuration variables are defined in client/config.js.
In particular, make sure to get the client and server to agree on the websocketPort.
Live games remain running when their browser disconnects. config.gameLifecycle
retains them for 14 days after the last valid player input, checking hourly.
Spectator refreshes and native output do not extend that deadline. Reaping sends
SIGTERM, escalates to SIGKILL after 5 seconds, and retains ownership until the OS
reports an exit. Final score datagrams get a short drain window on process exit.
Fatal socket errors also terminate an owned child instead of discarding its handle and leaving it running. Startup failures and unexpected child exits close their sockets, timers, and registry entries. Reaper and escalation messages in the server log include the PID for operational diagnosis.
A Node restart is different: detached native games can survive, but JavaScript child handles do not. An interface attached to a process created by an earlier Node run cannot prove ownership or terminate it through a ChildProcess handle. External cleanup of those older processes is still required. Do not use a broad process-name kill command on a live host without first checking ownership and which games should be retained.
On Ubuntu 24.04, set BROGUE_CPU_QUOTA_PERCENT=20 in the environment used to
start Node (including Forever) to cap each newly launched game or replay at 20%
of one CPU core. Without this variable games launch directly. Invalid values
are rejected. Existing games must exit before the cap can apply to them.
One shared shell launcher, server/scripts/limit-game-cpu.sh, runs each binary
in its own systemd user scope. Both launch stages use exec, preserving the
PID tracked by the reaper. No native source changes or renamed binaries are
needed. A scope setup failure exits the launcher; it never falls back to an
uncapped game.
The app user needs a running systemd user manager and a delegated CPU
controller. Enable lingering with sudo loginctl enable-linger APP_USER on
the new droplet. Ensure the startup environment has
XDG_RUNTIME_DIR=/run/user/UID and
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/UID/bus, using the app user's UID.
Verify the wrapper as that user before enabling it in production; a process's
cgroup cpu.max should read 20000 100000 for a 20% cap. The web server and
MongoDB are outside these per-game scopes.
Run npm test in server. By default it starts a temporary MongoDB 8.0.34
process and removes it afterward. The first run downloads the MongoDB binary;
subsequent runs reuse the cached binary. No running database service is needed.
The suite covers APIs, legacy bcrypt password hashes, new registration,
Socket.IO 4 login/token/chat flows, 64-bit seed output, native Unix datagram
communication, and client initialization in a DOM environment. Full browser
canvas rendering and interactive gameplay still need a real-browser check.
To use an existing disposable test database, set TEST_MONGODB_URI.
Its database name must end in _test; tests delete their fixtures.
The tested MongoDB 3.6 export path uses per-collection legacy Extended JSON.
From server, set MIGRATION_MONGODB_URI to a new empty database and run
npm run migrate:json -- /path/to/json-export --check-only, then repeat without
--check-only to import and validate it. Current MongoDB Database Tools must be
installed. See the migration instructions for setup,
reports, and final cutover. The script never overwrites an existing database.