From 43287c18c24b6acc21e6e03dc45f6dc3154d075b Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 19 Oct 2026 14:24:15 +0200 Subject: [PATCH] horizon-server whitelist add: the offline UUID on a running offline server The game resolves names as vanilla does, Mojang first, so on an offline server a name someone owns got that account's UUID and the player, who joins under the offline UUID, was refused. horizon-server now writes the offline entry and has the game reload the whitelist. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-server/src/lists.rs | 38 ++++++++++++++++++++++++++++++ docs/hosting.md | 5 +++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/crates/horizon-server/src/lists.rs b/crates/horizon-server/src/lists.rs index a6c466666..1a44251d3 100644 --- a/crates/horizon-server/src/lists.rs +++ b/crates/horizon-server/src/lists.rs @@ -1,6 +1,11 @@ //! `op`, `deop` and `whitelist`. While the server runs, the game owns the lists: the command goes to its //! console. While it is stopped, they edit vanilla's files with the code the game reads them with //! (horizon-server-files) and answer with vanilla's console messages. +//! +//! One exception: `whitelist add` on a running offline server. The game asks Mojang for the name first, as +//! vanilla does, so a name someone owns gets that account's UUID, and the player, who joins under the +//! offline UUID, is still refused. There the offline entry is written to whitelist.json and the game +//! reloads it (`whitelist reload`), as it would be written while the server is stopped. use crate::{config, supervisor}; use horizon_server_files::user_lists::{NameAndId, OpEntry, OpList, WhiteEntry, WhiteList}; @@ -10,6 +15,12 @@ pub fn run(dir: &Path, command: &str, args: &[String]) -> Result<(), String> { let config = config::Config::load(dir)?; // Holding the folder's lock keeps the server from starting halfway through. let Ok(_lock) = supervisor::lock(dir) else { + if let ("whitelist", [add, name]) = (command, args) + && add == "add" + && !config.server.online_mode + { + return add_offline(dir, name); + } let mut words = vec![command.to_owned()]; words.extend_from_slice(args); return crate::cli::command(dir, &words); @@ -99,6 +110,26 @@ pub fn run(dir: &Path, command: &str, args: &[String]) -> Result<(), String> { Ok(()) } +/// `whitelist add` on a running offline server: the offline entry, then the game reloads the list. +fn add_offline(dir: &Path, name: &str) -> Result<(), String> { + if crate::api::Client::open(dir)?.is_none() { + return Err(format!("no server is running in {}", dir.display())); + } + let user = account(name, false)?; + let mut white = load(WhiteList::new(dir.join("whitelist.json")))?; + if white.contains(&user) { + println!("Player is already whitelisted"); + return Ok(()); + } + white.add(WhiteEntry { user }); + white + .save() + .map_err(|e| format!("{}: {e}", white.file.display()))?; + crate::cli::command(dir, &["whitelist".to_owned(), "reload".to_owned()])?; + println!("Added {name} to the whitelist"); + Ok(()) +} + /// The profile a running server would store for `name`: the offline one, or in online mode the account the /// services know by that name. pub fn account(name: &str, online: bool) -> Result { @@ -161,12 +192,19 @@ mod tests { // A running server owns the lists: without its API, nothing changes. let lock = supervisor::lock(&dir).unwrap(); assert!(run(&dir, "op", &s(&["Alex"])).is_err()); + config::update(&dir, "server", "online_mode", toml::Value::Boolean(false)).unwrap(); + assert!(run(&dir, "whitelist", &s(&["add", "Kai"])).is_err()); drop(lock); assert!( !std::fs::read_to_string(dir.join("ops.json")) .unwrap() .contains("Alex") ); + assert!( + !std::fs::read_to_string(dir.join("whitelist.json")) + .unwrap() + .contains("Kai") + ); std::fs::remove_dir_all(&dir).unwrap(); } } diff --git a/docs/hosting.md b/docs/hosting.md index 15811ffd4..963083b16 100644 --- a/docs/hosting.md +++ b/docs/hosting.md @@ -13,7 +13,10 @@ plan are in [docs/server.md](https://github.com/ludovic111/horizon/blob/main/doc - **Names you add are accounts** (release v2026.10.17.14 and newer). `init --player`, `horizon-server whitelist add` and `op`, and the console's `whitelist add`, `op` and `ban` look a name up the way vanilla does: players already seen (kept in `usercache.json`), then Mojang's profile service. In online mode a name - with no account is refused. So you can whitelist friends before they first join. + with no account is refused. So you can whitelist friends before they first join. On an offline server, + `horizon-server whitelist add` always writes the offline UUID, the one the player joins with, also while + the server runs (it writes the entry and the game reloads the list): the console's own `whitelist add` + takes the account's UUID when someone owns that name, as vanilla does, and that player is then refused. - **Horizon's own client can't sign in to a Microsoft account yet.** That needs an Azure app registration and Mojang's approval, which the project doesn't have ([docs/microsoft-account.md](https://github.com/ludovic111/horizon/blob/main/docs/microsoft-account.md)).