Small text MMO engine

A small, hackable text MMORPG engine. It needs Python 3.12 or newer; CI covers 3.12 and 3.14. Rooms, NPCs, items, loot, respawns, parties, a player market, instanced dungeons, and 1v1 and 2v2 arena matches all run over WebSocket with plain JSON messages. Because the protocol is just JSON, a human, a bot, and an LLM agent look identical to the server on the game port; GM control is a separate loopback-only surface.
On top sits an ML stack: a Gym-style environment with (225 obs dims, 69 actions), linear and DQN agents with curiosity, scripted baselines, a 50-agent conductor, and deterministic evaluation. Population-based training (PBT) is a conductor library API only: the shipped soak.py CLI does not enroll agents or report fitness, so it produces no exploit/explore rounds.
A human designs and leads this project. AI coding assistants wrote much of the implementation.
Setup
Install the released package and run the console script:
pip install small-text-mmo-engine
small-text-mmo # world on ws://0.0.0.0:8765
# open http://localhost:8766/ for the live dashboard
Or run from a checkout:
pip install -r requirements.txt
python3 server.py # world on ws://0.0.0.0:8765
# open http://localhost:8766/ for the live dashboard
Both paths write mutable state to the directory you launch from; see State files. Run python start.py on any OS to start the server with a banner. Add --roles "gather:8,dungeon:4,market:3,commissioner:2" to also start bots. Edit world.json for your own rooms, NPCs, and items. The wiki covers game systems, the ML guide, and the API.
Configuration
Environment variables are read at startup. A boolean option is enabled by 1, true, yes, or on (case-insensitive); unset or any other value leaves it off.
| Variable |
Default |
Effect |
TEXTMMO_GM_SEED |
0 |
World RNG seed and starting GM treasury. Set it for reproducible runs and the live tests. |
TEXTMMO_DATA_DIR |
current directory |
Directory for mutable state files and their backups (scores.json, arena.json, guilds.json, freight.json, companions.json, intel.json, market.json, commissions.json). Bundled inputs (world.json, server_config.json, ml/ml_config.json) stay with the installed package. |
TEXTMMO_GM_HOST |
127.0.0.1 |
Bind address for the GM stream on port 8767. That stream has no auth, so 0.0.0.0 opts into Docker-network reachability only; keep the port unpublished (see SECURITY.md). |
TEXTMMO_REQUIRE_TOKEN |
off |
Security-sensitive: require a login token for every account. Unset leaves the server-wide gate off, but a name with existing progress still needs a token. |
TEXTMMO_ALLOW_LEGACY_TOKEN_CLAIM |
off |
Security-sensitive: let an account with no stored token hash claim a token at login. Off by default; only a server that never issued tokens should enable it. |
TEXTMMO_MAX_CONNECTIONS |
1000 |
Cap on total connections. |
TEXTMMO_MAX_ROOM_PLAYERS |
12 |
Cap on players per room. |
TEXTMMO_OUTBOUND_QUEUE |
64 |
Cap on the outbound queue. |
TEXTMMO_VERBOSE |
off |
Print extra server logs and full tracebacks for handler errors. |
TEXTMMO_LOG_FILE |
unset |
Append server stdout and stderr to this file instead of the console. |
TEXTMMO_METRICS |
off |
Serve /metrics on the dashboard port. Passing --metrics to server.py does the same; see Observability. |
TEXTMMO_TELEMETRY |
off |
Conductor/soak only: write telemetry.jsonl for a run. |
TEXTMMO_STRUCTURED_LOG |
off |
Conductor/soak only: write the structured.jsonl event log. |
TEXTMMO_RELOAD |
off |
Conductor/soak only: watch the reload directory for changed checkpoints. |
State files
The server keeps durable state in JSON files in TEXTMMO_DATA_DIR, which defaults to the directory you start the server from. A pip-installed server therefore writes state to a user-writable directory, never into site-packages. Set TEXTMMO_DATA_DIR to keep runs in separate directories. Saves go through a temporary file, and most files rotate the previous copy to a .1 name first, so a crash mid-write cannot leave a truncated file.
| File |
Holds |
If you delete it |
scores.json |
Short-lived per-player scores, flushed every five seconds and evicted on a TTL. |
Player score entries reset; the next start begins with an empty table. |
arena.json |
Arena ratings, recent match history, and the clamp count. |
The ladder, history, and clamps reset to empty. |
guilds.json |
Guilds, their vaults, and pending transfer offers with their rolling caps. |
Guilds, vault balances and pending offers are lost. |
market.json |
Open sell orders and escrowed standing bids. |
Listed items and bid escrow are lost; restore the file or its .1 backup. |
commissions.json |
Open and recent bounties with their prepaid escrow. |
Bounties and their escrow are lost; restore the file or its .1 backup. |
companions.json |
Player companions. |
Companion progress is lost. |
intel.json |
Bot-cadence intel rows. |
Intel history is lost. |
freight.json |
Freight contracts and the contract counter. |
Freight state is lost. |
world.json and server_config.json are inputs you edit, not saved state. Checkpoints record a canonical world.json hash alongside the config hash, so changing rooms, NPCs, items or recipes marks older checkpoints as world drift; checkpoints saved before that field existed are treated as compatible. The rotated backups are safe to delete only while their primary file is present and valid: scores.json.1 and scores.json.2 are its two generations, while guilds.json, market.json, commissions.json, intel.json, freight.json, and arena.json keep one .1 copy each (companions.json has none). A missing or unreadable primary falls back to a backup with a warning; a file written by a newer version is left on disk but not loaded. If both the primary and its backups are gone, that state is lost permanently.
Market and commission rows that fail validation are dropped with a warning, and their escrow is banked to the owner for the next login. An unknown version loads empty without blocking later saves. scores.json now carries a version field and a scores object; an unversioned file is read as version 1, invalid entries are skipped with a warning instead of breaking login, and a foreign version is left untouched and blocks later saves until it is moved away. Companions loaded with an out-of-range level are clamped to 1-10, and rows with non-finite XP or timestamps are dropped.
server_config.json overrides are limited to keys declared in config_schema.py and must fall inside that file's min/max bounds; out-of-range values are skipped with a warning and the code default stays in force. AUTH_TOKEN_REQUIRED remains a valid legacy boolean override outside the schema. GROUND_ITEM_CAP (default 200) and GROUND_ITEM_TTL_SECONDS (default 21600) bound the ground piles in persistent rooms: excess or expired drops become gold on that room's floor, so their value is not destroyed. GROUND_GOLD_CAP (default 100000) caps each floor pile; overflow is banked in the GM treasury. Freight poster and hauler names are stored and compared case-insensitively, and a future-version freight backup beside a healthy primary no longer blocks saves. A socket whose outbound writer fails is closed immediately, releasing its room and connection slots.
Docker
The full stack needs no local Python install.
docker compose up # server + dashboard + 4 scripted bots
# open http://localhost:8766/ (game on ws://localhost:8765)
docker compose --profile soak up soak # one-shot conductor soak
docker compose --profile torch up --build # torch farm (builds CPU torch)
compose.yaml builds one small image from python:3.14-slim and requirements.txt. Torch is only in the torch profile. The soak service shares the server's network namespace (network_mode: service:server) and snapshots tables over loopback at ws://127.0.0.1:8767, which passes the server's loopback-only GM gate. Port 8767 is not published to the host, and GM has no authentication, so leave it that way; publishing it does not bypass the gate (see SECURITY.md). The server uses protocol v2 (PROTOCOL_VERSION = 2; see the Protocol page).
Prebuilt images
Images are published to GitHub Container Registry, so a server needs only Docker.
docker run --detach --publish 8765:8765 --publish 8766:8766 \
--env TEXTMMO_GM_SEED=700 \
ghcr.io/killerboyyy777/machine-learning-mmo:edge
# open http://localhost:8766/ (game on ws://localhost:8765)
The publishing workflow builds images for linux/amd64 and linux/arm64 and pushes these tags to GHCR:
edge follows pushes to master. It is a moving tag for the newest development build.
edge-<short-sha> names the specific master commit used for a build. Use it to pin an edge image instead of following the moving tag.
X.Y.Z and X.Y come from version tags such as vX.Y.Z.
latest moves only for stable v* release tags. Prerelease tags do not move it.
Use edge for the current development image. Replace the tag with a version or commit tag to pin a build. Port 8767 stays unpublished, as above.
Quickstart
python3 server.py # terminal 1: world
python3 ml/ml_client.py # terminal 2: learning agent
python3 ml/ml_botfarm.py --bots 4 # or a 4-bot training farm
# Optional, only for the PyTorch DQN / Torch agents:
pip install -r requirements-train.txt
python3 torch_agents/dqn_agent.py --steps 5000 # or the PyTorch DQN
Trainer CLIs reject out-of-range settings with an argparse error before opening a server connection or a run record: --steps < 0, --save-every 0, --epsilon-decay-steps 0, epsilon endpoints outside [0, 1], --reward-window < 1, and --eval-every <= 0. Shared farms reserve a step before awaiting the environment step, so --steps caps total attempts across all bots; a step that loses its connection still spends its slot. The torch farm stops the remaining runners when one crashes and exits 1 for a failed run; a clean stop, Ctrl+C, and step-limit completion exit 0. Policies pass an integer action index to TextMMOEnv.step(); booleans are rejected.
python3 tests/test_server_unit.py # offline checks
echo '{}' > scores.json
TEXTMMO_GM_SEED=700 python3 server.py # terminal 1 (fresh world)
python3 tests/test_live.py # terminal 2 (protocol E2E)
Units you actually harvest at a gathering node sell to merchants for a quarter of their static value (at least 1 gold). The same item id looted from an NPC, picked up off the ground, bought or crafted still sells for full value. Station freight settles on delivery or expiry only - even a player named after the station cannot cancel or claim it.
Crafting economy