[PR #4514] [MERGED] Native mods: server commands and players (API 8) #5667

Closed
opened 2026-11-03 05:14:11 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: feat/smp-native-hooks


📝 Commits (2)

  • 076c41f Native mods: server commands and players (API 8)
  • 768d20d Native mods: a server player's game mode

📊 Changes

9 files changed (+534 additions, -4 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+1 -0)
📝 crates/horizon-client/src/game/lan.rs (+5 -0)
📝 crates/horizon-client/src/game/lan_actions.rs (+19 -2)
📝 crates/horizon-client/src/game/native_hooks.rs (+28 -2)
➕ crates/horizon-client/src/game/native_server.rs (+435 -0)
📝 crates/horizon-client/src/lan/commands.rs (+5 -0)
📝 crates/horizon-client/src/lan/hub.rs (+5 -0)
📝 docs/native-mods.md (+26 -0)
📝 native-hooks.json (+10 -0)

📄 Description

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

What and why

Hook points for server mods (API 8), the first piece of the official server's SMP mod (docs/smp.md, #4494), which stays out of Horizon's own server: the SMP is a native mod only that server builds. These points are general: any native mod that adds commands to a server can use them.

  • native_register_commands(&mut Vec<NativeCommand>): asked once when a world opens to players (dedicated server, LAN host, single player's server thread). A usage is words then arguments, optional ones last: NativeCommand::new("pay <player:player> <amount:integer>"), NativeCommand::op("eco set <player:word> <amount:integer>", 3). The usages are merged into one tree in the commands report's format and put in the hub's mod-command slot (the one WebAssembly server mods used), so every player's command tree has them after vanilla's, filtered by level like vanilla's nodes (permissions), and the chat box completes them. A name vanilla has, or a usage that doesn't parse, is left out with a warning.
  • native_perform_command(&NativeServerPlayer, &str, &mut bool): a guest's command for a registered name their level allows, whether the world allows commands or not. It runs in run_guest_command, inside the guest's swap, so the acting player's state is in Game. A registered command that no mod takes answers as vanilla's unknown command.
  • Helpers (game/native_server.rs): native_server_players() (uuid, name, level, dimension, position, game mode), native_tell(uuid, Text), native_broadcast(Text) (players and the server's log), native_feedback(Text) (the command's answer, through chat_capture, as vanilla feedback), native_world_dir() (the open world's folder, so a mod's data travels with the world's backups).
  • NATIVE_HOOKS_API 7 → 8, native-hooks.json, docs/native-mods.md ("Server commands and players").

With no mod hooking them nothing changes: the tree is empty (the hub's slot stays Null, so no packet is resent), the gate in guest_command finds no name, and perform_native_command returns at a hash lookup.

Kind

  • extra: Horizon-only, off by default

Vanilla reference

Horizon-only. Commands are run where Commands.performCommand runs a guest's command; the tree follows commands.json's format and Commands.sendCommands' filtering by permissions.

Proof

The SMP mod's economy (horizon-rust/horizon-mods#55, native/smp/) built on this branch with native/tools/native.py proof smp: a dedicated server built with the mod and two real clients (horizon-ctl --offscreen, fresh folders). Run on the stacked items branch (API 9, which contains this one), with the economy and the market in the bundle:

  • /eco give Steve 500 from an operator, then Steve's /balance = 500 coins;
  • /pay Alex 120: both players got their line;
  • refusals: paying yourself, paying more than you have, an unknown player, a bad amount;
  • /eco from a non-operator: vanilla's unknown command, and it is not in their tree;
  • /baltop listed both players;
  • the files: economy.json held Alex 380 and Steve 435, and audit.log had one line per change (open, open, eco_give, pay, sell, sell, buy);
  • after a restart, Alex's balance was still 380.

native.py check smp on this exact head (768d20d) applies the economy bundle and compiles the game: ok.

Self-check

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at f6a757ac2, 8 min 26 s)

Check Result
Scope ⚠️ 9 files, +534 −4; 512 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 481 passed (1 min 25 s)
rustfmt ✅ (5 s)
clippy ✅ (1 min 19 s)
tests: horizon-client ✅ 1067 passed (4 min 51 s)
doc tests ✅ 0 passed (3 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 33 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, hardcore_respawn, lan_integration, locator_bar and 21 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Over 500 lines by 12, of which ~150 are the doc and the tests; the tree builder, the gate and the helpers ship together (no part works alone).

🤖 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/4514 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/smp-native-hooks` --- ### 📝 Commits (2) - [`076c41f`](https://github.com/horizon-rust/horizon/commit/076c41fc27336c8ba886471bf3a1ced1b76c9b3d) Native mods: server commands and players (API 8) - [`768d20d`](https://github.com/horizon-rust/horizon/commit/768d20d9980c2e04cc76951d18ec6c72ccef0176) Native mods: a server player's game mode ### 📊 Changes **9 files changed** (+534 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+1 -0) 📝 `crates/horizon-client/src/game/lan.rs` (+5 -0) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+19 -2) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+28 -2) ➕ `crates/horizon-client/src/game/native_server.rs` (+435 -0) 📝 `crates/horizon-client/src/lan/commands.rs` (+5 -0) 📝 `crates/horizon-client/src/lan/hub.rs` (+5 -0) 📝 `docs/native-mods.md` (+26 -0) 📝 `native-hooks.json` (+10 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What and why Hook points for **server mods** (API 8), the first piece of the official server's SMP mod ([docs/smp.md](https://github.com/horizon-rust/horizon/blob/feat/smp-design/docs/smp.md), #4494), which stays out of Horizon's own server: the SMP is a native mod only that server builds. These points are general: any native mod that adds commands to a server can use them. - **`native_register_commands(&mut Vec<NativeCommand>)`**: asked once when a world opens to players (dedicated server, LAN host, single player's server thread). A usage is words then arguments, optional ones last: `NativeCommand::new("pay <player:player> <amount:integer>")`, `NativeCommand::op("eco set <player:word> <amount:integer>", 3)`. The usages are merged into one tree in the commands report's format and put in the hub's mod-command slot (the one WebAssembly server mods used), so every player's command tree has them after vanilla's, filtered by level like vanilla's nodes (`permissions`), and the chat box completes them. A name vanilla has, or a usage that doesn't parse, is left out with a warning. - **`native_perform_command(&NativeServerPlayer, &str, &mut bool)`**: a guest's command for a registered name their level allows, whether the world allows commands or not. It runs in `run_guest_command`, inside the guest's swap, so the acting player's state is in `Game`. A registered command that no mod takes answers as vanilla's unknown command. - Helpers (`game/native_server.rs`): `native_server_players()` (uuid, name, level, dimension, position, game mode), `native_tell(uuid, Text)`, `native_broadcast(Text)` (players and the server's log), `native_feedback(Text)` (the command's answer, through `chat_capture`, as vanilla feedback), `native_world_dir()` (the open world's folder, so a mod's data travels with the world's backups). - `NATIVE_HOOKS_API` 7 → 8, `native-hooks.json`, docs/native-mods.md ("Server commands and players"). **With no mod hooking them nothing changes**: the tree is empty (the hub's slot stays `Null`, so no packet is resent), the gate in `guest_command` finds no name, and `perform_native_command` returns at a hash lookup. ## Kind - [x] extra: Horizon-only, off by default ## Vanilla reference Horizon-only. Commands are run where `Commands.performCommand` runs a guest's command; the tree follows `commands.json`'s format and `Commands.sendCommands`' filtering by `permissions`. ## Proof The SMP mod's economy (horizon-rust/horizon-mods#55, `native/smp/`) built on this branch with `native/tools/native.py proof smp`: a dedicated server built with the mod and two real clients (`horizon-ctl --offscreen`, fresh folders). Run on the stacked items branch (API 9, which contains this one), with the economy and the market in the bundle: - `/eco give Steve 500` from an operator, then Steve's `/balance` = 500 coins; - `/pay Alex 120`: both players got their line; - refusals: paying yourself, paying more than you have, an unknown player, a bad amount; - `/eco` from a non-operator: vanilla's unknown command, and it is not in their tree; - `/baltop` listed both players; - the files: `economy.json` held Alex 380 and Steve 435, and `audit.log` had one line per change (`open, open, eco_give, pay, sell, sell, buy`); - after a restart, Alex's balance was still 380. `native.py check smp` on this exact head (768d20d) applies the economy bundle and compiles the game: ok. ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at f6a757ac2, 8 min 26 s) | Check | Result | | --- | --- | | Scope | ⚠️ 9 files, +534 −4; 512 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 481 passed (1 min 25 s) | | rustfmt | ✅ (5 s) | | clippy | ✅ (1 min 19 s) | | tests: horizon-client | ✅ 1067 passed (4 min 51 s) | | doc tests | ✅ 0 passed (3 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 33 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, hardcore_respawn, lan_integration, locator_bar and 21 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | Over 500 lines by 12, of which ~150 are the doc and the tests; the tree builder, the gate and the helpers ship together (no part works alone). 🤖 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 05:14:11 +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#5667
No description provided.