commit 26e8045985887e0f6605cd9524c60e537ad5d759
parent 907583635308c50bbc8b3ec6bc061a18c5021b1c
Author: anon <anon@example.com>
Date: Tue, 3 Nov 2026 09:16:39 +0000
Document SQLite persistence and safe state copying
Diffstat:
| M | DEVELOPERS.md | | | 103 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------- |
| M | TODO.md | | | 13 | +++++++++---- |
2 files changed, 80 insertions(+), 36 deletions(-)
diff --git a/DEVELOPERS.md b/DEVELOPERS.md
@@ -8,7 +8,7 @@ See [README.md](README.md) for the quick start and repository overview.
Game definitions and their provenance are embedded YAML in `server/gamedata`.
NPC behavior is Go code in that directory, linked to YAML group IDs through
`NPCScripts`; see [the conversation API and source evidence](docs/npc-scripts.md).
-Static resources live in `server/assets` and are embedded in the server. Build with Go 1.24 or
+Static resources live in `server/assets` and are embedded in the server. Build with Go 1.26 or
newer from the repository root:
```sh
@@ -18,26 +18,32 @@ go build -o ao-server ./server
Distribute `ao-server` by itself (or the corresponding Windows binary). It can
run from an empty directory; static resources are served directly from the
-binary. Saved characters remain in `data/players/` and certificates in
+binary. Mutable world state is stored in `data/world.sqlite` and certificates in
`data/https/`. Server logs go to `logs/server.log` and profiles to `logs/profiles/`.
Packet, movement and HTTP request traces stay in `logs/server.log`; the terminal
shows startup, connections and errors.
Back up `data/` when moving servers. Paths are relative to the working directory.
-Each `data/players/<id>/` directory contains `player.yaml` for identity,
-credentials and character properties, `position.yaml` for the current playfield,
-coordinates, rotation and return-door context, and the player's chat files.
-Owned items are saved separately in `inventory.yaml`; see
+The SQLite database contains character identity and credentials, stats, poses,
+vitals, item instances and locations, credits, missions, NPC/corpse state,
+skill locks, nanos and chat history. The server enables foreign keys, WAL
+journaling and FULL synchronization, with one connection ordering writes.
+Significant changes such as equipment, inventory transfers, ammunition use
+and rewards commit atomically before success is reported. See
[inventory behavior](docs/inventory.md) for the current scope and wire evidence.
-Movement updates memory immediately. Changed positions are saved to
-`position.yaml` every 20 seconds on a fixed schedule with a random offset per
-player. The scheduler checks once per second; stationary players cause no writes.
-New players get an initial position file immediately. An unexpected stop can lose
-about 20 seconds of position updates. `player.yaml` is saved when its contents change.
-Complete YAML files and HTTPS key/certificate files are written to a
-temporary file, synced and closed, then renamed over the destination. On Unix,
-each file replacement is atomic.
-Chat history uses serialized, synced record appends and size-based rotation.
+
+Movement updates memory immediately. Player poses and vitals are checked once
+per second and checkpointed on staggered 20-second schedules; unchanged values
+are not rewritten. Observed NPCs also use periodic checkpoints, with staggered
+starts and a final snapshot when their zone becomes unobserved. An unexpected
+stop can lose simulation changes since the last checkpoint. Ctrl+C or SIGTERM
+flushes player positions and world state before closing the database; check
+`logs/server.log` for shutdown errors.
+
+The control panel's YAML is an editing format generated from the current state.
+Saving it validates and writes the database; there are no per-player YAML
+storage files. HTTPS key/certificate files are separate and use atomic file
+replacement.
The matching browser build is checked in under `server/assets/client/`:
`index.html`, `game.js`, `game.wasm.br`, `profile-worker.js`, `audio-worklet.js`,
@@ -75,6 +81,36 @@ prefix. Game and control pages have no login.
Keep saved player data and logs outside the public static directory.
+### Backups and restore
+
+Stop the server normally and wait for it to exit before copying mutable state.
+From its working directory, copy the entire `data/` directory into a fresh backup
+directory, preserving file permissions:
+
+```sh
+mkdir -m 700 backup
+cp -a data backup/
+```
+
+This includes `world.sqlite`, any `world.sqlite-wal`/`world.sqlite-shm` sidecars
+and `https/`. The WAL can contain committed transactions that are absent from
+the main database file; copying only a running server's `world.sqlite` is not a
+complete backup. See [SQLite's WAL documentation](https://www.sqlite.org/wal.html).
+The database contains credentials and browser-token hashes, so keep backups
+private. Logs and profiles under `logs/` are separate from saved game state.
+
+To restore an existing installation, keep the server stopped, move its current
+`data/` directory aside and restore the complete saved directory. Use a fresh
+name for the directory being set aside:
+
+```sh
+mv data data-before-restore
+cp -a backup/data data
+```
+
+Replacing the whole directory keeps the database and sidecars from the same
+snapshot, and preserves the browser's trusted HTTPS certificate.
+
## Browser client
Open [the game](http://127.0.0.1:8080/) in a browser supporting shared WebAssembly
@@ -125,25 +161,23 @@ Forced disconnects discard queued output and wake the connection's writer;
socket shutdown also runs there, so a transport close handshake cannot delay
shared work or a replacement session.
-The server saves each player's sent and received messages in
-`data/players/<id>/chat.ndjson`, alongside `player.yaml` and `position.yaml`.
-Shared messages are duplicated into each participant's history. Records
-are UTF-8 JSON Lines with a UTC timestamp, channel, sender ID/name and message,
-plus the playfield for vicinity or recipient ID/name for tells. Files are
-created with owner-only permissions on Unix and are not exposed over HTTP.
+The server saves each player's sent and received messages in the database's
+`chat_history` table. The sender's and recipients' copies commit in one
+transaction. Rows contain readable UTF-8 text, a UTC timestamp, channel,
+sender ID/name and message, plus the playfield for vicinity or recipient ID/name
+for tells. The database has owner-only file permissions on Unix.
Connecting restores the newest 500 entries into the native chat scrollback as
timestamped history text, before delivering new messages. The server reads
-only that player's files. Browser sessions using the same token resolve to
+only that player's rows. Browser sessions using the same token resolve to
the same saved player ID and see the same history, even after moving zones or
restarting the server. Changing the authentication method can keep that ID.
History text does not trigger private-message notifications or automatic replies.
-Each player's files rotate before exceeding 10 MiB, keeping `chat.ndjson.1`
-(newest) through `chat.ndjson.5` (oldest), for at most 60 MiB per player.
-Rotation continues across restarts; no external logrotate job is needed. Back
-up `data/` to preserve both characters and chat. History errors are reported in
-the server log while live chat remains available.
+History rows currently remain in the database without pruning; the 500-entry
+limit applies to login replay. Back up `data/` to preserve both characters and
+chat. History errors are reported in the server log while live chat remains
+available.
[Server controls](http://127.0.0.1:8080/control)
provide character editing, teleporting and time controls.
@@ -157,7 +191,7 @@ continues until you leave melee range. Player fists use the shipped QL 1
aggression. The Stats window's DEF/AGG slider changes this setting. Player
health uses breed/level/Body Development and Soldier title data (37 HP for the
default level 1 Solitus). Six abilities and eight trained skills are editable in
-the character page's stats section and persist in player.yaml. Health, nano,
+the character page's stats section and persist in `data/world.sqlite`. Health, nano,
initiative timing and regeneration derive from those base values. Absolute
resource corrections reconcile client prediction outside active weapon queues;
see [regeneration and stats](docs/combat-regeneration.md). NPCs still have 100 HP and hit for 5 with one-second
@@ -322,13 +356,17 @@ Wayland operation is not yet validated. No Wine,
The four local Verdana files above preserve the tested font choice; otherwise
Fontconfig may silently substitute a different font. They remain local assets.
+Use a fresh destination `data/` directory. For an existing installation, move
+its stopped data aside as described under [Backups and restore](#backups-and-restore).
From WSL, copy to your mounted destination or substitute an SSH destination:
```sh
-rsync -a --chmod=D755,F644 --info=progress2 --exclude=/local/ --exclude=/toolchains/ --exclude=/venv/ --exclude=/client/build/ --exclude=/anarchy-vanilla-14.9.1/ --exclude=/anarchy-runtime-14.9.1/ --exclude=__pycache__/ --exclude='Screenshots/*' /path/to/source/ao/ /path/to/destination/ao/
+rsync -a --chmod=D755,F644 --info=progress2 --exclude=/data/ --exclude=/local/ --exclude=/toolchains/ --exclude=/venv/ --exclude=/client/build/ --exclude=/anarchy-vanilla-14.9.1/ --exclude=/anarchy-runtime-14.9.1/ --exclude=__pycache__/ --exclude='Screenshots/*' /path/to/source/ao/ /path/to/destination/ao/
+rsync -a --chmod=D700,F600 --info=progress2 /path/to/source/ao/data/ /path/to/destination/ao/data/
```
-Keep `anarchy-assets-14.9.1/` and `data/`, including your `data/players/` files.
+Keep `anarchy-assets-14.9.1/` and the complete `data/` directory, including
+`world.sqlite`, its sidecars if present, and `https/`.
The asset directory contains game data/configuration only; Windows launchers,
DLLs and Miles audio plug-ins are excluded. All zones' assets are retained.
Its preparation script is `tools/client/prepare_portable_assets.py`; ordinary
@@ -339,8 +377,9 @@ rsync exclusions: that would omit required local assets and server data.
Do not reuse Ubuntu-built objects on Debian. In the destination, `make clean`
then `make -j4` forces a native rebuild. Reduce parallelism if memory is tight.
Some generated C files take several minutes and multiple GB of RAM to compile.
-The rsync permissions option avoids copying Windows-mounted files as executable
-source files. Python and the Windows virtual environment are not needed for
+The first rsync command removes executable bits from Windows-mounted source
+files. The separate data copy keeps world state and HTTPS keys private.
+Python and the Windows virtual environment are not needed for
ordinary builds.
Debian 13 supplies the [SDL2 development package](https://packages.debian.org/trixie/libsdl2-dev)
diff --git a/TODO.md b/TODO.md
@@ -4382,10 +4382,13 @@ and server restarts. Turn every reproduced bug into a focused regression test.
## Checks that apply to each milestone
-- [ ] [P2] Update developer persistence and backup documentation to the current
- SQLite store. `DEVELOPERS.md` still describes `player.yaml`, `position.yaml`,
- `inventory.yaml` and chat files as durable storage. Distinguish the control
- panel's YAML editing format from the actual database files and checkpoints.
+- [x] [P2] Document the current SQLite persistence and backup/restore process.
+ `DEVELOPERS.md` distinguishes control-panel YAML from stored database rows,
+ describes periodic checkpoints and immediate transactions, and includes
+ stopped-server copying/restoration of the complete data directory. The exact
+ commands retain character/item/chat state, certificate/key bytes and private
+ permissions in a current-schema fixture; integrity and foreign-key checks
+ pass. Evidence: `local/persistence-backup/`.
- [ ] [P3] Reconcile obsolete resource/stat feature-status statements.
`docs/combat-regeneration.md` still says native IP spending and level-based
IP awards are separate work, despite the implemented paths documented in
@@ -4394,6 +4397,8 @@ and server restarts. Turn every reproduced bug into a focused regression test.
`docs/early-melee.md` also describes a fixed QL2/two-item mission reward
pool; current `missions.yaml` and `mission_offers.go` select from seven
reviewed families at the requested supported level/quality.
+ The `DEVELOPERS.md` combat introduction also retains obsolete fixed NPC
+ HP/damage and missing equipment/loot/XP claims.
- [x] Repair the browser-profile worker test fixture. Its VM context supplies
`URL`/`location` and checks build/upload URLs relative to the worker location.
`node client/tests/browser_profile.mjs` now exercises all existing assertions.