[PR #1894] [MERGED] Server mods run in the game: server thread, in-frame, LAN hosts, dedicated #3847

Closed
opened 2026-11-03 04:12:44 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: feat/server-mods-game


📝 Commits (4)

  • 3a35e14 Server mods run in the game: server thread, in-frame, LAN hosts, dedicated
  • 593b99a Merge branch 'feat/server-mod-test-scripts' into feat/server-mods-game
  • a27579d Merge remote-tracking branch 'origin/main' into feat/server-mods-game
  • 8fa967a Merge remote-tracking branch 'origin/main' into feat/server-mods-game

📊 Changes

11 files changed (+519 additions, -46 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+7 -0)
📝 crates/horizon-client/src/game/chat.rs (+5 -1)
📝 crates/horizon-client/src/game/integrated.rs (+3 -1)
📝 crates/horizon-client/src/game/lan.rs (+3 -0)
📝 crates/horizon-client/src/game/lan_actions.rs (+4 -0)
📝 crates/horizon-client/src/game/mods.rs (+87 -31)
➕ crates/horizon-client/src/game/server_mods.rs (+356 -0)
📝 crates/horizon-client/src/lan/hub.rs (+5 -0)
📝 crates/horizon-client/src/lan/hub/chat.rs (+4 -0)
📝 docs/api/mods.md (+7 -5)
📝 docs/mods.md (+38 -8)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Stacked on #1837 (test scripts for server mods), itself on #1833 (API 0.3) and #1816 (the test runner). This PR's own diff is the last commit.

What

Server mods (API 0.3, experimental) now run in the game, in every mode that simulates a world:

Mode Who runs them Players they see
Single player (default, server thread) the server thread's Game the window's player, a connection like any other
Single player --in-frame the window's own Game, beside client mods (Runs::Both) the window's player
LAN / Play with Friends host the host's server thread, or its window in-frame host and guests
Dedicated server the server every connected player

A window that is a client of a server (single player's window, a LAN guest, multiplayer) never runs them (Runs::Client); the server thread and the dedicated server run only server mods (Runs::Server).

  • game/server_mods.rs (new): tick_server_mods at the end of fn tick diffs the players against the last tick (player_joined, player_left), delivers the tick's chat and block events in order, then calls tick. mod_block_event is called from break_block_as_player and placement (the acting player is lan_acting during as_guest, else the window's player); mod_player_chat from the local chat path and from the hub's new HostEvent::PlayerChat. A guest's /command reaches its mod from guest_command before the vanilla dispatcher, whatever the guest's permission level; the in-frame player's from handle_chat_input.
  • Output routing: tell and a command's reply go to their player: the window's chat for the in-frame player, a SystemChat to that connection for the others. broadcast goes to every player and the log (dedicated::log on a dedicated server). The routing takes the hub as a parameter where guest_command has it out of self.lan.
  • Dev mods on the server thread: --dev-mod used to be dropped for the server thread (options.dev_mods.clear()); it now starts them, and a server (server thread, dedicated) checks a dev mod's file once a second from its tick, since it draws no frames.
  • No mod, no cost: every hook starts with if !self.mods.server (or hears_players, which is the same flag and remote.is_none()); without the mods feature they are empty stubs.
  • Docs: docs/mods.md (where server mods run, when hooks run, what's not there yet, Multiplayer), docs/api/mods.md.

How tested

The welcome example (greets a joining player, broadcasts a first visit, /online, /mined counting the player's broken blocks), built with cargo horizon-mod build, given as --dev-mod, with a scratch driver over horizon-ctl, every game with fresh HORIZON_HOME, launcher home, XDG folders, HORIZON_NO_AUDIO=1:

Mode Greeting Broadcast (host and guest) /online break, then /mined = 1 log
single player, server thread ✅ ✅ ✅ ✅ no panic, mod running
single player, --in-frame ✅ ✅ ✅ ✅ ✅
LAN, host in-frame + guest ✅ guest ✅ both ✅ guest and host list both ✅ guest ✅
LAN, host on its server thread + guest ✅ guest ✅ both ✅ ✅ guest ✅
--dedicated + a guest ✅ ✅ (and [Welcome] Guest is here for the first time in the server log) ✅ ✅ ✅

In each single-player mode /help still runs vanilla's command after the mod's commands are registered.

A/B, no mod loaded (this branch against its parent bcd42f50e, both --profile fast --features mods, on the Mac mini M4 Pro, alternating A B A B, shared machine):

  • Server ticks, tools/server_bench.py --servers horizon --bots 10 --behaviour walk --warmup 30 --seconds 90, 3 runs each:

    MSPT mean P50 P95 P99 CPU %
    parent (A) 3.32, 3.29, 3.60 → 3.40 3.18, 3.18, 3.45 4.36, 4.15, 4.91 5.62, 6.02, 7.93 14.0, 14.4, 14.6
    this PR (B) 3.59, 3.30, 3.28 → 3.39 3.44, 3.19, 3.19 4.86, 4.16, 3.99 6.72, 5.22, 6.06 15.3, 14.0, 14.4
  • Frames, tools/perf_bench.py --game horizon --distances 12 --sizes 1280x720 --offscreen (single player on its server thread, four scenes, 2 runs each): median frame time per scene

    village forest ocean mountain mean
    parent (A) 0.49, 0.53 0.95, 0.80 0.71, 0.71 0.76, 0.80 0.719 ms
    this PR (B) 0.53, 0.51 0.82, 0.86 0.71, 0.69 0.78, 0.81 0.714 ms

    The 1 % lows swing between runs on both sides (other sessions share the machine); medians and MSPT are equal within the noise.

Self-check. pr_ready --quick ran on the world branch (the next PR of this stack, which contains this commit; its scope line counts the whole stack against main, #1816 → #1833 → #1837 → this):

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at 6a065fa48, 25 min 53 s)

Check Result
Scope ⚠️ 39 files, +3119 −177; 2629 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ changes with a Cargo.toml
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (10 s)
clippy ✅ (36 s)
tests: workspace ✅ 2064 passed (18 min 8 s)
doc tests ✅ 2 passed (1 min 57 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ✅ (2 s)
launcher clippy ✅ (2 min 19 s)
launcher tests ✅ 119 passed (2 min 40 s)
Parity ➖ 331 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 319 more

Parity: parity.py --changed-files over the whole stack's files (#1894, #1895, #1901) on its top commit c5bb51bb0: 110 passed, 0 failed (42 min, Mac mini).

Label skip-release: server mods are experimental API 0.3 and nothing changes for players without one.

Leftovers

  • Clients aren't sent server mods' commands in the command tree, so a player's chat box doesn't complete or colour them (typing works).
  • Block events are players' own breaking and placing; explosions, pistons and commands don't send them.
  • Next: world (read blocks, write through the block log), designed once for server mods and client mods (Orbital Laser's crater).

🤖 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/1894 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/25/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/server-mods-game` --- ### 📝 Commits (4) - [`3a35e14`](https://github.com/horizon-rust/horizon/commit/3a35e147e54714c6cc626e6c3277131ef4776a68) Server mods run in the game: server thread, in-frame, LAN hosts, dedicated - [`593b99a`](https://github.com/horizon-rust/horizon/commit/593b99a68b845fdb33cee1514ed0576325e01f9d) Merge branch 'feat/server-mod-test-scripts' into feat/server-mods-game - [`a27579d`](https://github.com/horizon-rust/horizon/commit/a27579dd724a21e7e6c79f307e28fbb2a4729fe8) Merge remote-tracking branch 'origin/main' into feat/server-mods-game - [`8fa967a`](https://github.com/horizon-rust/horizon/commit/8fa967ac0741096f5c69c90df104ac0463b07018) Merge remote-tracking branch 'origin/main' into feat/server-mods-game ### 📊 Changes **11 files changed** (+519 additions, -46 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+7 -0) 📝 `crates/horizon-client/src/game/chat.rs` (+5 -1) 📝 `crates/horizon-client/src/game/integrated.rs` (+3 -1) 📝 `crates/horizon-client/src/game/lan.rs` (+3 -0) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+4 -0) 📝 `crates/horizon-client/src/game/mods.rs` (+87 -31) ➕ `crates/horizon-client/src/game/server_mods.rs` (+356 -0) 📝 `crates/horizon-client/src/lan/hub.rs` (+5 -0) 📝 `crates/horizon-client/src/lan/hub/chat.rs` (+4 -0) 📝 `docs/api/mods.md` (+7 -5) 📝 `docs/mods.md` (+38 -8) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Stacked on #1837 (test scripts for server mods), itself on #1833 (API 0.3) and #1816 (the test runner). This PR's own diff is the last commit. ## What Server mods (API 0.3, experimental) now run in the game, in every mode that simulates a world: | Mode | Who runs them | Players they see | | --- | --- | --- | | Single player (default, server thread) | the server thread's `Game` | the window's player, a connection like any other | | Single player `--in-frame` | the window's own `Game`, beside client mods (`Runs::Both`) | the window's player | | LAN / Play with Friends host | the host's server thread, or its window in-frame | host and guests | | Dedicated server | the server | every connected player | A window that is a client of a server (single player's window, a LAN guest, multiplayer) never runs them (`Runs::Client`); the server thread and the dedicated server run only server mods (`Runs::Server`). - **`game/server_mods.rs`** (new): `tick_server_mods` at the end of `fn tick` diffs the players against the last tick (`player_joined`, `player_left`), delivers the tick's chat and block events in order, then calls `tick`. `mod_block_event` is called from `break_block_as_player` and placement (the acting player is `lan_acting` during `as_guest`, else the window's player); `mod_player_chat` from the local chat path and from the hub's new `HostEvent::PlayerChat`. A guest's `/command` reaches its mod from `guest_command` before the vanilla dispatcher, whatever the guest's permission level; the in-frame player's from `handle_chat_input`. - **Output routing**: `tell` and a command's reply go to their player: the window's chat for the in-frame player, a `SystemChat` to that connection for the others. `broadcast` goes to every player and the log (`dedicated::log` on a dedicated server). The routing takes the hub as a parameter where `guest_command` has it out of `self.lan`. - **Dev mods on the server thread**: `--dev-mod` used to be dropped for the server thread (`options.dev_mods.clear()`); it now starts them, and a server (server thread, dedicated) checks a dev mod's file once a second from its tick, since it draws no frames. - **No mod, no cost**: every hook starts with `if !self.mods.server` (or `hears_players`, which is the same flag and `remote.is_none()`); without the `mods` feature they are empty stubs. - Docs: docs/mods.md (where server mods run, when hooks run, what's not there yet, Multiplayer), docs/api/mods.md. ## How tested The `welcome` example (greets a joining player, broadcasts a first visit, `/online`, `/mined` counting the player's broken blocks), built with `cargo horizon-mod build`, given as `--dev-mod`, with a scratch driver over horizon-ctl, every game with fresh `HORIZON_HOME`, launcher home, XDG folders, `HORIZON_NO_AUDIO=1`: | Mode | Greeting | Broadcast (host and guest) | `/online` | break, then `/mined` = 1 | log | | --- | --- | --- | --- | --- | --- | | single player, server thread | ✅ | ✅ | ✅ | ✅ | no panic, mod running | | single player, `--in-frame` | ✅ | ✅ | ✅ | ✅ | ✅ | | LAN, host in-frame + guest | ✅ guest | ✅ both | ✅ guest and host list both | ✅ guest | ✅ | | LAN, host on its server thread + guest | ✅ guest | ✅ both | ✅ | ✅ guest | ✅ | | `--dedicated` + a guest | ✅ | ✅ (and `[Welcome] Guest is here for the first time` in the server log) | ✅ | ✅ | ✅ | In each single-player mode `/help` still runs vanilla's command after the mod's commands are registered. **A/B, no mod loaded** (this branch against its parent bcd42f50e, both `--profile fast --features mods`, on the Mac mini M4 Pro, alternating A B A B, shared machine): - Server ticks, `tools/server_bench.py --servers horizon --bots 10 --behaviour walk --warmup 30 --seconds 90`, 3 runs each: | | MSPT mean | P50 | P95 | P99 | CPU % | | --- | --- | --- | --- | --- | --- | | parent (A) | 3.32, 3.29, 3.60 → **3.40** | 3.18, 3.18, 3.45 | 4.36, 4.15, 4.91 | 5.62, 6.02, 7.93 | 14.0, 14.4, 14.6 | | this PR (B) | 3.59, 3.30, 3.28 → **3.39** | 3.44, 3.19, 3.19 | 4.86, 4.16, 3.99 | 6.72, 5.22, 6.06 | 15.3, 14.0, 14.4 | - Frames, `tools/perf_bench.py --game horizon --distances 12 --sizes 1280x720 --offscreen` (single player on its server thread, four scenes, 2 runs each): median frame time per scene | | village | forest | ocean | mountain | mean | | --- | --- | --- | --- | --- | --- | | parent (A) | 0.49, 0.53 | 0.95, 0.80 | 0.71, 0.71 | 0.76, 0.80 | **0.719 ms** | | this PR (B) | 0.53, 0.51 | 0.82, 0.86 | 0.71, 0.69 | 0.78, 0.81 | **0.714 ms** | The 1 % lows swing between runs on both sides (other sessions share the machine); medians and MSPT are equal within the noise. **Self-check.** `pr_ready --quick` ran on the world branch (the next PR of this stack, which contains this commit; its scope line counts the whole stack against main, #1816 → #1833 → #1837 → this): **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at 6a065fa48, 25 min 53 s) | Check | Result | | --- | --- | | Scope | ⚠️ 39 files, +3119 −177; 2629 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ changes with a Cargo.toml | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (10 s) | | clippy | ✅ (36 s) | | tests: workspace | ✅ 2064 passed (18 min 8 s) | | doc tests | ✅ 2 passed (1 min 57 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ✅ (2 s) | | launcher clippy | ✅ (2 min 19 s) | | launcher tests | ✅ 119 passed (2 min 40 s) | | Parity | ➖ 331 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 319 more | Parity: `parity.py --changed-files` over the whole stack's files (#1894, #1895, #1901) on its top commit c5bb51bb0: **110 passed, 0 failed** (42 min, Mac mini). Label `skip-release`: server mods are experimental API 0.3 and nothing changes for players without one. ## Leftovers - Clients aren't sent server mods' commands in the command tree, so a player's chat box doesn't complete or colour them (typing works). - Block events are players' own breaking and placing; explosions, pistons and commands don't send them. - Next: `world` (read blocks, write through the block log), designed once for server mods and client mods (Orbital Laser's crater). 🤖 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-03 04:12:44 +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#3847
No description provided.