[PR #7155] [MERGED] horizon-server: management protocol notifications for world saves and players joining and leaving #7381

Closed
opened 2026-11-03 06:38:39 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7155
Author: @Akirabane
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: feat/management-notifications-2


📝 Commits (1)

  • 0c54f51 horizon-server: the management protocol notifies world saves and players joining and leaving

📊 Changes

6 files changed (+110 additions, -6 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+9 -0)
📝 crates/horizon-client/src/game/dedicated/events.rs (+18 -2)
📝 crates/horizon-server/src/events.rs (+7 -0)
📝 crates/horizon-server/src/management.rs (+70 -2)
📝 docs/api/server.md (+2 -1)
📝 docs/server.md (+4 -1)

📄 Description

🤖 Opened by both Akirabane's AI agent (Claude Code), and Akirabane Himself after his review.

Refs #7118 (step 2 of 4; step 1 is #7121).

What was wrong

After #7121 the management protocol sends server/started and server/stopping, but a client still learns nothing when the world saves or when a player joins or leaves, which vanilla's JsonRpcNotificationService pushes.

What changed

  • game.rs (save_game_with, the one funnel of the dedicated server's saves: save-all, the autosave, the pause when empty): the game records a typed saving event before the save and a saved one after it, only on a dedicated server and only when the save didn't fail. Vanilla sends serverSaveStarted first in DedicatedServer.saveAllChunks and serverSaveCompleted after it returns, with no handler for a failure.
  • dedicated/events.rs: record_server for an event that has no player; record shares its numbering with it.
  • events.rs (the supervisor's fetch of the game's events) hands each event to management::game_event, which maps join and leave to notification/players/joined and notification/players/left (the player as a PlayerDto, {"id": uuid, "name": name}, as the players method already writes it) and saving and saved to notification/server/saving and notification/server/saved. The saves the game made while it started (in the first fetch of a run) are left out: no client could have heard of them. The events are fetched four times a second, so a notification comes within about 250 ms.
  • Docs: docs/server.md section 8, docs/api/server.md.

Vanilla classes followed: JsonRpcNotificationService (playerJoined, playerLeft, serverSaveStarted, serverSaveCompleted), PlayerDto.from, DedicatedServer.saveAllChunks.

Not covered, said here so nobody is surprised: the save the game makes while it stops happens after the supervisor stopped fetching events, so it isn't told; and players/joined goes out at the game's join event (after the player is placed), which is where vanilla's placeNewPlayer calls the service, but that order against the join message in the log isn't compared.

How it was checked

  • A new unit test in management.rs: a client on a real socket gets, in order, players/joined, server/saving, server/saved, players/left with the exact frames, and nothing for a chat event. The test for rpc.discover now checks the four new names are listed.
  • events.rs (game): the numbering test also covers a server event with no player.
  • cargo test -p horizon-server management: 13 passed. cargo test -p horizon-client --lib dedicated::events: passed. cargo clippy -p horizon-server -p horizon-client --all-targets -- -D warnings and cargo fmt are clean. Rebased on main (4f1b75f5b) and rechecked.

Not tested: no run against a real vanilla server (the parity script runs on the maintainers' machines and doesn't compare notifications yet), no real server with a client connected, tools/pr_ready.py not run.

Next

Step 3 of #7118: the list notifications (operators, allowlist, bans, IP bans).


🔄 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/7155 **Author:** [@Akirabane](https://github.com/Akirabane) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/management-notifications-2` --- ### 📝 Commits (1) - [`0c54f51`](https://github.com/horizon-rust/horizon/commit/0c54f51081c1958300878d8c796dc12553db41fc) horizon-server: the management protocol notifies world saves and players joining and leaving ### 📊 Changes **6 files changed** (+110 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+9 -0) 📝 `crates/horizon-client/src/game/dedicated/events.rs` (+18 -2) 📝 `crates/horizon-server/src/events.rs` (+7 -0) 📝 `crates/horizon-server/src/management.rs` (+70 -2) 📝 `docs/api/server.md` (+2 -1) 📝 `docs/server.md` (+4 -1) </details> ### 📄 Description > 🤖 Opened by both Akirabane's AI agent (Claude Code), and Akirabane Himself after his review. Refs #7118 (step 2 of 4; step 1 is #7121). ## What was wrong After #7121 the management protocol sends `server/started` and `server/stopping`, but a client still learns nothing when the world saves or when a player joins or leaves, which vanilla's `JsonRpcNotificationService` pushes. ## What changed - `game.rs` (`save_game_with`, the one funnel of the dedicated server's saves: `save-all`, the autosave, the pause when empty): the game records a typed `saving` event before the save and a `saved` one after it, only on a dedicated server and only when the save didn't fail. Vanilla sends `serverSaveStarted` first in `DedicatedServer.saveAllChunks` and `serverSaveCompleted` after it returns, with no handler for a failure. - `dedicated/events.rs`: `record_server` for an event that has no player; `record` shares its numbering with it. - `events.rs` (the supervisor's fetch of the game's events) hands each event to `management::game_event`, which maps `join` and `leave` to `notification/players/joined` and `notification/players/left` (the player as a `PlayerDto`, `{"id": uuid, "name": name}`, as the `players` method already writes it) and `saving` and `saved` to `notification/server/saving` and `notification/server/saved`. The saves the game made while it started (in the first fetch of a run) are left out: no client could have heard of them. The events are fetched four times a second, so a notification comes within about 250 ms. - Docs: `docs/server.md` section 8, `docs/api/server.md`. Vanilla classes followed: `JsonRpcNotificationService` (`playerJoined`, `playerLeft`, `serverSaveStarted`, `serverSaveCompleted`), `PlayerDto.from`, `DedicatedServer.saveAllChunks`. Not covered, said here so nobody is surprised: the save the game makes while it stops happens after the supervisor stopped fetching events, so it isn't told; and `players/joined` goes out at the game's `join` event (after the player is placed), which is where vanilla's `placeNewPlayer` calls the service, but that order against the join message in the log isn't compared. ## How it was checked - A new unit test in `management.rs`: a client on a real socket gets, in order, `players/joined`, `server/saving`, `server/saved`, `players/left` with the exact frames, and nothing for a chat event. The test for `rpc.discover` now checks the four new names are listed. - `events.rs` (game): the numbering test also covers a server event with no player. - `cargo test -p horizon-server management`: 13 passed. `cargo test -p horizon-client --lib dedicated::events`: passed. `cargo clippy -p horizon-server -p horizon-client --all-targets -- -D warnings` and `cargo fmt` are clean. Rebased on main (4f1b75f5b) and rechecked. Not tested: no run against a real vanilla server (the parity script runs on the maintainers' machines and doesn't compare notifications yet), no real server with a client connected, `tools/pr_ready.py` not run. ## Next Step 3 of #7118: the list notifications (operators, allowlist, bans, IP bans). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:38:39 +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#7381
No description provided.