commit e9c2eed1574c5029ba384b14e4b6bd34da6afcc2
parent 9e97fa4971e1332e10e03cbca1ef04a29f562611
Author: anon <anon@example.com>
Date: Tue, 20 Oct 2026 04:36:04 +0000
Store each player in a separate YAML file
Diffstat:
15 files changed, 105 insertions(+), 43 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -38,7 +38,7 @@ node_modules/
/data/item-extraction-evidence.json
/data/*.tmp
/data/zone_links.yaml
-/data/users.yaml
+/data/users/
/data/maps/
!/old_wip/reconstruction/
/data/npc-spawns.json
diff --git a/README.md b/README.md
@@ -179,7 +179,7 @@ From WSL, copy to your mounted destination or substitute an SSH destination:
rsync -a --chmod=D755,F644 --info=progress2 --exclude=/local/ --exclude=/old_wip/ --exclude=/toolchains/ --exclude=/venv/ --exclude=/src/build/ --exclude=/anarchy-vanilla-14.9.1/ --exclude=/anarchy-runtime-14.9.1/ --exclude=/patches/ --exclude=__pycache__/ --exclude='Screenshots/*' /path/to/ao/ /path/to/ao/
```
-Keep `anarchy-assets-14.9.1/` and `data/`, including your `data/users.yaml`.
+Keep `anarchy-assets-14.9.1/` and `data/`, including your `data/users/` files.
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
diff --git a/docs/playfield-validation.md b/docs/playfield-validation.md
@@ -62,7 +62,7 @@ loading a scene; that startup failure is not playfield-specific.
The sweep needs Go, a C compiler, SDL2/OpenGL development libraries, Python 3.11
or newer with Pillow, `gnome-session-inhibit`, and `xset`. It reserves ports
-7520, 7521 and 8082. It does not use the user's server or `data/users.yaml`.
+7520, 7521 and 8082. It does not use the user's server or `data/users/` files.
Preferences and diagnostics are private to the run; large immutable assets
are shared. Results remain under `local/playfield-sweep/playfield-sweep-*`.
Ctrl-C stops the owned processes and keeps completed results.
diff --git a/docs/project-notes.md b/docs/project-notes.md
@@ -81,7 +81,7 @@ advertise the configured ports. Each flag can be used on its own.
Point a separate client's dimension-list URL at the second instance's HTTP
port; the direct-launch Python helpers still use their fixed default ports.
Run each instance from a separate working directory with its own `data/`
-copy, especially `data/users.yaml`, so the instances cannot overwrite each
+copy, especially `data/users/`, so the instances cannot overwrite each
other's saved users. Build an executable first to run it outside this checkout.
The main server selects the recovered 14.9.1 world layout from its cookie
@@ -103,14 +103,14 @@ The page uses plain HTML forms and a small JavaScript canvas map. The world star
13:30. Rubi-Ka has a 27-hour day, running at 15 game seconds per real second.
Hour values range from 0 to 26; minutes range from 0 to 59. The clock resets when
the server restarts. Users, character fields, zones, and received movement
-positions are saved in `data/users.yaml` and restored at startup. Each local
+positions are saved in `data/users/<id>.yaml` and restored at startup. Each local
user currently owns one character, with a stable ID. Walk/run mode is saved
in the `running` YAML field. The server supplies that
mode in the initial vehicle state on login and zone reconnect; older records
without the field start in walking mode. Saving character data
refreshes an online character through the native zone reconnect sequence.
-Edit the file directly while the server is stopped, or use the web editor while
-it runs. The storage file is local development data and is ignored by Git.
+Edit a user's file directly while the server is stopped, or use the web editor while
+it runs. The storage files are local development data and are ignored by Git.
To extract the control UI's map tiles from `anarchy-vanilla-14.9.1`, run from
the repository root:
diff --git a/server/browser_launch.go b/server/browser_launch.go
@@ -39,7 +39,7 @@ func (server *server) browserLaunch(w http.ResponseWriter, r *http.Request) {
character.rotation = [4]float32{0, 0.9238795, 0, -0.3826834}
// Solitus, normal build, Omni; random sex and one of eight original heads.
character.appearance = 1 | 1<<2 | 1<<4 | uint16(2+mathrand.IntN(2))<<7 | 2<<9 | uint16(mathrand.IntN(8))<<11
- if err := server.saveUsers_locked(); err != nil {
+ if err := server.saveUser_locked(character); err != nil {
delete(server.characters, character.id)
server.nextCharacter--
http.Error(w, err.Error(), http.StatusInternalServerError)
diff --git a/server/browser_launch_test.go b/server/browser_launch_test.go
@@ -60,10 +60,6 @@ func TestBrowserLaunchResumesOwnedCharacterAfterRestart(t *testing.T) {
world := &server{worldPort: 7501, characters: make(map[uint32]*character)}
first := httptest.NewRecorder()
world.browserLaunch(first, httptest.NewRequest("POST", "/browser-launch", nil))
- world.characters[1].name = "Visitor 1"
- if err := world.saveUsers_locked(); err != nil {
- t.Fatal(err)
- }
loaded := &server{worldPort: 7501, characters: make(map[uint32]*character), clients: map[uint32]*worldClient{1: {}}}
if err := loaded.loadUsers(); err != nil {
t.Fatal(err)
diff --git a/server/control.go b/server/control.go
@@ -84,7 +84,7 @@ func (server *server) createUser(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
- err := server.saveUsers_locked()
+ err := server.saveUser_locked(player)
if err != nil {
delete(server.characters, player.id)
server.nextCharacter--
@@ -228,7 +228,7 @@ func (server *server) updateUser(destination userData) error {
previous := *character
*character = *destination.character()
character.browserTokenHash = previous.browserTokenHash
- if err := server.saveUsers_locked(); err != nil {
+ if err := server.saveUser_locked(character); err != nil {
*character = previous
server.mutex.Unlock()
return err
diff --git a/server/main.go b/server/main.go
@@ -180,7 +180,7 @@ func (server *server) serveLogin(conn net.Conn) error {
if len(users) == 0 || len(packet) == 20 {
// The direct-launch test helpers request a fresh synthetic session.
character = server.newCharacter_locked()
- if err := server.saveUsers_locked(); err != nil {
+ if err := server.saveUser_locked(character); err != nil {
server.mutex.Unlock()
return err
}
@@ -468,7 +468,7 @@ func (server *server) serveWorldClient(client *worldClient) error {
}
continue
}
- if err := server.saveUsers_locked(); err != nil {
+ if err := server.saveUser_locked(character); err != nil {
server.mutex.Unlock()
return err
}
diff --git a/server/npcs_test.go b/server/npcs_test.go
@@ -16,7 +16,7 @@ import (
var authoredPopulations []byte
func TestMain(m *testing.M) {
- // Keep persistence tests away from the developer's live user file.
+ // Keep persistence tests away from the developer's live user files.
if err := os.Chdir(".."); err != nil {
panic(err)
}
@@ -56,7 +56,7 @@ func TestMain(m *testing.M) {
func newTestServer(t *testing.T) *server {
t.Helper()
- if err := os.Remove("data/users.yaml"); err != nil && !os.IsNotExist(err) {
+ if err := os.RemoveAll("data/users"); err != nil {
t.Fatal(err)
}
return newServer()
diff --git a/server/users.go b/server/users.go
@@ -6,6 +6,7 @@ import (
"io"
"math"
"os"
+ "path/filepath"
"sort"
"strings"
@@ -87,28 +88,32 @@ func decodeUsers(reader io.Reader, value any) error {
}
func (server *server) loadUsers() error {
- contents, err := os.ReadFile("data/users.yaml")
+ files, err := os.ReadDir("data/users")
if os.IsNotExist(err) {
return nil
}
if err != nil {
return err
}
- var users []userData
- if err := decodeUsers(bytes.NewReader(contents), &users); err != nil {
- return err
- }
- for _, user := range users {
+ for _, file := range files {
+ if !strings.HasSuffix(file.Name(), ".yaml") {
+ continue
+ }
+ path := filepath.Join("data/users", file.Name())
+ contents, err := os.ReadFile(path)
+ if err != nil {
+ return err
+ }
+ var user userData
+ if err := decodeUsers(bytes.NewReader(contents), &user); err != nil {
+ return fmt.Errorf("%s: %w", path, err)
+ }
if err := user.validate(); err != nil {
return fmt.Errorf("user %d: %w", user.ID, err)
}
if server.characters[user.ID] != nil {
return fmt.Errorf("duplicate user ID %d", user.ID)
}
- // Tell commands accept a single word for the recipient's name.
- if user.BrowserTokenHash != "" && user.Name == fmt.Sprintf("Visitor %d", user.ID) {
- user.Name = fmt.Sprintf("Visitor%d", user.ID)
- }
server.characters[user.ID] = user.character()
if user.ID > server.nextCharacter {
server.nextCharacter = user.ID
@@ -128,14 +133,18 @@ func (server *server) users_locked() []userData {
return users
}
-func (server *server) saveUsers_locked() error {
- contents, err := yaml.Marshal(server.users_locked())
+func (server *server) saveUser_locked(character *character) error {
+ contents, err := yaml.Marshal(character.userData())
if err != nil {
return err
}
- // Replace the file only after the complete new document has been written.
- if err := os.WriteFile("data/users.yaml.tmp", contents, 0600); err != nil {
+ // Replace the user's file only after the complete document has been written.
+ if err := os.MkdirAll("data/users", 0700); err != nil {
+ return err
+ }
+ path := fmt.Sprintf("data/users/%d.yaml", character.id)
+ if err := os.WriteFile(path+".tmp", contents, 0600); err != nil {
return err
}
- return os.Rename("data/users.yaml.tmp", "data/users.yaml")
+ return os.Rename(path+".tmp", path)
}
diff --git a/server/users_test.go b/server/users_test.go
@@ -12,8 +12,63 @@ import (
"strings"
"testing"
"time"
+
+ "go.yaml.in/yaml/v3"
)
+func TestUserFilesAreSeparateAndOnlyUpdatedUserIsRewritten(t *testing.T) {
+ useNPCData(t, editedNPCData)
+ world := newTestServer(t)
+ for _, name := range []string{"First", "Second"} {
+ request := httptest.NewRequest("POST", "/users", strings.NewReader("name="+name))
+ request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+ world.createUser(httptest.NewRecorder(), request)
+ }
+ before, err := os.Stat("data/users/2.yaml")
+ if err != nil {
+ t.Fatal(err)
+ }
+ edited := world.characters[1].userData()
+ edited.Name = "Edited First"
+
+ if err := world.updateUser(edited); err != nil {
+ t.Fatal(err)
+ }
+ restarted := newServer()
+
+ files, err := os.ReadDir("data/users")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(files) != 2 || files[0].Name() != "1.yaml" || files[1].Name() != "2.yaml" {
+ t.Fatalf("user files: %v", files)
+ }
+ for _, expected := range []struct {
+ path string
+ id uint32
+ name string
+ }{{"data/users/1.yaml", 1, "Edited First"}, {"data/users/2.yaml", 2, "Second"}} {
+ contents, err := os.ReadFile(expected.path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var user userData
+ if err := yaml.Unmarshal(contents, &user); err != nil {
+ t.Fatal(err)
+ }
+ if user.ID != expected.id || user.Name != expected.name || restarted.characters[expected.id].name != expected.name {
+ t.Fatalf("saved user in %s: %+v", expected.path, user)
+ }
+ }
+ after, err := os.Stat("data/users/2.yaml")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !os.SameFile(before, after) {
+ t.Fatal("editing the first user rewrote the second user's file")
+ }
+}
+
func TestUserCreationEditingAndOfflineTeleportSurviveRestart(t *testing.T) {
useNPCData(t, editedNPCData)
world := newTestServer(t)
@@ -60,7 +115,7 @@ running: true
if restarted.nextCharacter != 1 || !strings.Contains(page.Body.String(), "href='/users/1'>Edited Explorer</a>") || !strings.Contains(page.Body.String(), "Offline") {
t.Fatalf("offline user disappeared: %s", page.Body.String())
}
- contents, err := os.ReadFile("data/users.yaml")
+ contents, err := os.ReadFile("data/users/1.yaml")
if err != nil {
t.Fatal(err)
}
@@ -139,7 +194,7 @@ func TestUserEditorRejectsUnknownFieldsWithoutChangingSavedData(t *testing.T) {
creation := httptest.NewRequest("POST", "/users", strings.NewReader("name=Explorer"))
creation.Header.Set("Content-Type", "application/x-www-form-urlencoded")
world.createUser(httptest.NewRecorder(), creation)
- before, err := os.ReadFile("data/users.yaml")
+ before, err := os.ReadFile("data/users/1.yaml")
if err != nil {
t.Fatal(err)
}
@@ -149,7 +204,7 @@ func TestUserEditorRejectsUnknownFieldsWithoutChangingSavedData(t *testing.T) {
response := httptest.NewRecorder()
world.editUser(response, request)
- after, err := os.ReadFile("data/users.yaml")
+ after, err := os.ReadFile("data/users/1.yaml")
if err != nil {
t.Fatal(err)
}
diff --git a/tools/README.md b/tools/README.md
@@ -67,7 +67,7 @@ The existing isolated Windows server is
The WSL wrapper starts `local/client/linux-server-probe/server` itself. Both
use separate fixture data and ports 7510/7511/8081. They are preserved diagnostic
server builds; the normal server is always `go run ./server` on the default ports.
-Do not point these tests at the user's normal `data/users.yaml`.
+Do not point these tests at the user's normal `data/users/` directory.
With the isolated Windows server running:
diff --git a/tools/client/sweep_browser.py b/tools/client/sweep_browser.py
@@ -39,7 +39,8 @@ if not resuming:
(fixture / 'data' / name).symlink_to(root / 'data' / name)
(fixture / 'runtime').symlink_to(root / 'runtime')
(fixture / '.runtime-bundle').write_text(hashlib.sha256((root / 'runtime/manifest.json').read_bytes()).hexdigest() + '\n')
- (fixture / 'data/users.yaml').write_text('- id: 73\n name: WASM Sweep\n playfield: 705\n position: [960, 16.5, 510]\n rotation: [0, 0, 0, 1]\n appearance: 789\n monster_data: 0\n level: 1\n')
+ (fixture / 'data/users').mkdir()
+ (fixture / 'data/users/73.yaml').write_text('id: 73\nname: WASM Sweep\nplayfield: 705\nposition: [960, 16.5, 510]\nrotation: [0, 0, 0, 1]\nappearance: 789\nmonster_data: 0\nlevel: 1\n')
for name in ['sweep-game.js', 'sweep-game.wasm']:
shutil.copyfile(build / name, fixture / 'client' / name)
shutil.copyfile(build / 'build.json', output / 'client-build.json')
diff --git a/tools/client/sweep_playfields.py b/tools/client/sweep_playfields.py
@@ -53,7 +53,8 @@ if not resuming:
(fixture / name).symlink_to(root / name)
(fixture / 'anarchy-assets-14.9.1').symlink_to(assets)
(fixture / '.runtime-bundle').write_text(hashlib.sha256((root / 'runtime/manifest.json').read_bytes()).hexdigest() + '\n')
- (fixture / 'data/users.yaml').write_text('- id: 73\n name: Playfield Sweep\n playfield: 705\n position: [960, 16.5, 510]\n rotation: [0, 0, 0, 1]\n appearance: 789\n monster_data: 0\n level: 1\n')
+ (fixture / 'data/users').mkdir()
+ (fixture / 'data/users/73.yaml').write_text('id: 73\nname: Playfield Sweep\nplayfield: 705\nposition: [960, 16.5, 510]\nrotation: [0, 0, 0, 1]\nappearance: 789\nmonster_data: 0\nlevel: 1\n')
for port in [7520, 7521, 8082]:
with socket.socket() as connection:
assert connection.connect_ex(('127.0.0.1', port)) != 0, port
diff --git a/tools/client/verify_linux_game.py b/tools/client/verify_linux_game.py
@@ -82,16 +82,16 @@ def run_windows():
for name in ['stderr.txt', 'DXDiagOutput.txt', 'AnarchyCrashLog.txt']:
path = client / name
backups[path] = path.read_bytes() if path.exists() else None
- users = fixture / 'data/users.yaml'
+ users = fixture / 'data/users/73.yaml'
backups[users] = users.read_bytes()
output.mkdir(exist_ok=True)
for path in output.glob('*.json'):
path.unlink()
try:
data = users.read_text()
- assert re.findall(r'(?m)^- id: (\d+)$', data) == ['73'], 'Expected the isolated character fixture'
- data = re.sub(r'(?m)^ position:.*$', ' position: [960, 16.5, 510]', data)
- data = re.sub(r'(?m)^ rotation:.*$', ' rotation: [0, 0.9238795, 0, -0.3826834]', data)
+ assert re.findall(r'(?m)^id: (\d+)$', data) == ['73'], 'Expected the isolated character fixture'
+ data = re.sub(r'(?m)^position:.*$', 'position: [960, 16.5, 510]', data)
+ data = re.sub(r'(?m)^rotation:.*$', 'rotation: [0, 0.9238795, 0, -0.3826834]', data)
users.write_text(data)
with (output / 'client.log').open('w') as log:
subprocess.run([