[PR #694] [MERGED] usercache.json, and console names resolved through it as vanilla does (stacked on #589) #2738

Closed
opened 2026-11-02 15:58:41 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/694
Author: @ludovic111
Created: 10/17/2026
Status: ✅ Merged
Merged: 10/17/2026
Merged by: @ludovic111

Base: main ← Head: feat/server-usercache-2


📝 Commits (3)

  • ae22d5d Online mode: players named in commands are their accounts
  • 09c039c Merge remote-tracking branch 'origin/main' into HEAD
  • b859b22 Keep usercache.json and find console players through it, as vanilla

📊 Changes

17 files changed (+892 additions, -56 deletions)

View changed files

📝 Cargo.lock (+1 -0)
📝 crates/horizon-client/src/game/dedicated.rs (+65 -27)
📝 crates/horizon-client/src/game/lan.rs (+1 -0)
📝 crates/horizon-server-files/Cargo.toml (+3 -1)
📝 crates/horizon-server-files/src/json.rs (+37 -0)
📝 crates/horizon-server-files/src/lib.rs (+6 -3)
➕ crates/horizon-server-files/src/profiles.rs (+100 -0)
➕ crates/horizon-server-files/src/user_cache.rs (+318 -0)
📝 crates/horizon-server-files/src/user_lists.rs (+2 -2)
📝 crates/horizon-server/src/config.rs (+1 -1)
📝 crates/horizon-server/src/init.rs (+25 -11)
📝 crates/horizon-server/src/lists.rs (+23 -4)
📝 crates/horizon-server/src/main.rs (+2 -1)
📝 docs/server.md (+6 -0)
📝 tools/test_dedicated_server_parity.py (+7 -2)
📝 tools/test_online_mode_parity.py (+49 -4)
➕ tools/test_user_cache_parity.py (+246 -0)

📄 Description

Stacked on #589. This replaces #589's in-memory name cache with vanilla's usercache.json (CachedUserNameToIdResolver), and keeps #589's profile lookup (profiles::find_by_name) and its kick.

What the dedicated server does now

  • On start: it loads <universe>/usercache.json.

    • Entries without an id, without a date, or not objects are skipped.
    • A bad date logs vanilla's Failed to parse date ….
    • Entries load in reverse, so the file's order is kept as the use order.
  • When a player joins, they are added and kept for a month (Calendar.add(MONTH, 1)), and the file is saved.

  • Saving: the 1000 most recently used entries, newest first, written the way Gson writes them (compact, HTML-safe: {"uuid","name","expiresOn"}).

  • Names given to op, deop, ban, pardon and whitelist add|remove:

    1. the cache, in any case (an expired entry is dropped);
    2. otherwise the profile service's getByName, asked with the lower-case name. Vanilla asks it on offline servers too, so Horizon now does as well;
    3. otherwise, on an offline server, the offline player of the lower-case name. That is vanilla's createUnknownProfile(userName): /op Bob before Bob ever joined stores bob. On an online server: "That player does not exist", as in #589.

    A failed lookup logs Couldn't find profile with name: …, as in #589.

Harness: tools/test_user_cache_parity.py (new)

  • Vanilla's server and Horizon's each start offline from a seeded usercache.json: a live entry, an expired one, and entries without a date, with a bad date, without an id, and not an object.

  • A mock profile service knows one account (Notch). Vanilla finds it through -Dminecraft.api.discovery.host, Horizon through HORIZON_API_DISCOVERY.

  • The console then whitelists, ops, deops and bans:

    • the cached player, in another case;
    • the expired one;
    • the account the mock knows;
    • names it doesn't know;
    • a name too long to look up.
  • The server restarts in online mode: a name nobody knows is refused, and an entry the offline run cached is still found.

  • Compared exactly:

    • every reply;
    • the names asked of the service, in order;
    • usercache.json, whitelist.json, ops.json and banned-players.json after each run.

    The dates written during the run are placeholders. Result: 38 lines identical.

test_dedicated_server_parity.py now also compares usercache.json after its player joins.

Not done

  • horizon-server (the supervisor, while the server is stopped) still resolves names through profiles::resolve without the file.
  • The renamed join message (multiplayer.player.joined.renamed, when an account's name changed since it was cached) isn't sent yet.

Checks

  • cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings: clean.
  • cargo test -p horizon-client --lib: 803 passed. cargo test -p horizon-server-files: 11 passed.
  • tools/parity.py --changed origin/feat/server-online-profiles: 87 passed, 0 failed, including user_cache, dedicated_server, online_mode and server_files.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/694 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/17/2026 **Status:** ✅ Merged **Merged:** 10/17/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/server-usercache-2` --- ### 📝 Commits (3) - [`ae22d5d`](https://github.com/horizon-rust/horizon/commit/ae22d5dd960c930f0fefc42b337d9c066e4af1be) Online mode: players named in commands are their accounts - [`09c039c`](https://github.com/horizon-rust/horizon/commit/09c039c423296d40cd2531d504f11775dee51935) Merge remote-tracking branch 'origin/main' into HEAD - [`b859b22`](https://github.com/horizon-rust/horizon/commit/b859b22111536811139069326de7ff8be1d2d1a3) Keep usercache.json and find console players through it, as vanilla ### 📊 Changes **17 files changed** (+892 additions, -56 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+1 -0) 📝 `crates/horizon-client/src/game/dedicated.rs` (+65 -27) 📝 `crates/horizon-client/src/game/lan.rs` (+1 -0) 📝 `crates/horizon-server-files/Cargo.toml` (+3 -1) 📝 `crates/horizon-server-files/src/json.rs` (+37 -0) 📝 `crates/horizon-server-files/src/lib.rs` (+6 -3) ➕ `crates/horizon-server-files/src/profiles.rs` (+100 -0) ➕ `crates/horizon-server-files/src/user_cache.rs` (+318 -0) 📝 `crates/horizon-server-files/src/user_lists.rs` (+2 -2) 📝 `crates/horizon-server/src/config.rs` (+1 -1) 📝 `crates/horizon-server/src/init.rs` (+25 -11) 📝 `crates/horizon-server/src/lists.rs` (+23 -4) 📝 `crates/horizon-server/src/main.rs` (+2 -1) 📝 `docs/server.md` (+6 -0) 📝 `tools/test_dedicated_server_parity.py` (+7 -2) 📝 `tools/test_online_mode_parity.py` (+49 -4) ➕ `tools/test_user_cache_parity.py` (+246 -0) </details> ### 📄 Description Stacked on #589. This replaces #589's in-memory name cache with vanilla's `usercache.json` (`CachedUserNameToIdResolver`), and keeps #589's profile lookup (`profiles::find_by_name`) and its `kick`. **What the dedicated server does now** - **On start:** it loads `<universe>/usercache.json`. - Entries without an id, without a date, or not objects are skipped. - A bad date logs vanilla's `Failed to parse date …`. - Entries load in reverse, so the file's order is kept as the use order. - **When a player joins,** they are added and kept for a month (`Calendar.add(MONTH, 1)`), and the file is saved. - **Saving:** the 1000 most recently used entries, newest first, written the way Gson writes them (compact, HTML-safe: `{"uuid","name","expiresOn"}`). - **Names given to `op`, `deop`, `ban`, `pardon` and `whitelist add|remove`:** 1. the cache, in any case (an expired entry is dropped); 2. otherwise the profile service's `getByName`, asked with the lower-case name. Vanilla asks it on offline servers too, so Horizon now does as well; 3. otherwise, on an offline server, the offline player of the **lower-case** name. That is vanilla's `createUnknownProfile(userName)`: `/op Bob` before Bob ever joined stores `bob`. On an online server: "That player does not exist", as in #589. A failed lookup logs `Couldn't find profile with name: …`, as in #589. **Harness: `tools/test_user_cache_parity.py` (new)** - Vanilla's server and Horizon's each start offline from a seeded `usercache.json`: a live entry, an expired one, and entries without a date, with a bad date, without an id, and not an object. - A mock profile service knows one account (Notch). Vanilla finds it through `-Dminecraft.api.discovery.host`, Horizon through `HORIZON_API_DISCOVERY`. - The console then whitelists, ops, deops and bans: - the cached player, in another case; - the expired one; - the account the mock knows; - names it doesn't know; - a name too long to look up. - The server restarts in online mode: a name nobody knows is refused, and an entry the offline run cached is still found. - Compared exactly: - every reply; - the names asked of the service, in order; - `usercache.json`, `whitelist.json`, `ops.json` and `banned-players.json` after each run. The dates written during the run are placeholders. Result: 38 lines identical. `test_dedicated_server_parity.py` now also compares `usercache.json` after its player joins. **Not done** - `horizon-server` (the supervisor, while the server is stopped) still resolves names through `profiles::resolve` without the file. - The renamed join message (`multiplayer.player.joined.renamed`, when an account's name changed since it was cached) isn't sent yet. **Checks** - `cargo fmt --all --check`, `cargo clippy --workspace --all-targets -- -D warnings`: clean. - `cargo test -p horizon-client --lib`: 803 passed. `cargo test -p horizon-server-files`: 11 passed. - `tools/parity.py --changed origin/feat/server-online-profiles`: **87 passed, 0 failed**, including `user_cache`, `dedicated_server`, `online_mode` and `server_files`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:58:41 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#2738
No description provided.