diff --git a/crates/horizon-client/src/game/agent.rs b/crates/horizon-client/src/game/agent.rs index cd39606b3..48b24bbb3 100644 --- a/crates/horizon-client/src/game/agent.rs +++ b/crates/horizon-client/src/game/agent.rs @@ -460,7 +460,10 @@ impl Game<'_> { json!({ "screen": self.screen_label(), "menu": self.title.as_ref().map(|_| self.title_value()), - "world": (self.title.is_none()).then(|| self.level.name.clone()), + "world": (self.title.is_none()).then(|| match &self.integrated { + Some(server) => server.world_name.clone(), + None => self.level.name.clone(), + }), "dimension": self.dim.id(), "gamemode": format!("{:?}", self.mode).to_lowercase(), "time": { "day_time": self.world.day_time, "day": self.world.day_time.div_euclid(24000), "time_of_day": self.world.day_time.rem_euclid(24000) }, diff --git a/crates/horizon-client/src/game/chat.rs b/crates/horizon-client/src/game/chat.rs index 8f6bed0ca..bcf6426e1 100644 --- a/crates/horizon-client/src/game/chat.rs +++ b/crates/horizon-client/src/game/chat.rs @@ -425,6 +425,12 @@ impl Game<'_> { capture.push(text); return; } + // Connected to a server (single player's own included), the chat on + // screen is the connection's: the game's own messages join it. + if self.remote.is_some() { + self.chat_line(text.plain()); + return; + } let focused = self.screen == Screen::Chat; let heard = self.mods.mods.is_running().then(|| text.plain()); self.ui.chat.add( diff --git a/crates/horizon-client/src/game/control.rs b/crates/horizon-client/src/game/control.rs index e1169b2c8..7b51fe8ee 100644 --- a/crates/horizon-client/src/game/control.rs +++ b/crates/horizon-client/src/game/control.rs @@ -475,7 +475,10 @@ impl Game<'_> { } "chat-log" => { let n = words.get(1).map_or(Ok(10), |n| n.parse())?; - Ok(Some(json!({ "chat": self.ui.chat.recent_lines(n) }))) + let lines = self + .remote_chat(n) + .unwrap_or_else(|| self.ui.chat.recent_lines(n)); + Ok(Some(json!({ "chat": lines }))) } "stats" => { let summary = self.frame_stats.summary(); @@ -549,18 +552,20 @@ impl Game<'_> { self.leave_server(None)?; ok() } - "save" => { + "save" | "save-all" => { self.require_world()?; - self.save_game()?; - ok() - } - "save-all" => { - // Like `save-all flush`: also rewrite chunks that were not modified - // (the save round-trip harness compares them with vanilla's files). - self.require_world()?; - let keys: Vec<_> = self.world.chunks.keys().copied().collect(); - self.world.modified.extend(keys); - self.save_game()?; + // `save-all` is like `save-all flush`: it also rewrites chunks + // that were not modified (the save round-trip harness compares + // them with vanilla's files). + let all = words[0] == "save-all"; + // Single player's world is its server thread's. + if let Some(server) = &self.integrated { + server + .call(move |g| g.control_save(all).map_err(|e| e.to_string())) + .ok_or("the integrated server stopped")??; + } else { + self.control_save(all)?; + } ok() } "dragon-hurt" => { @@ -581,6 +586,15 @@ impl Game<'_> { } } + /// `horizon-ctl save` and `save-all`. + fn control_save(&mut self, all: bool) -> Result<()> { + if all { + let keys: Vec<_> = self.world.chunks.keys().copied().collect(); + self.world.modified.extend(keys); + } + self.save_game() + } + fn require_world(&self) -> Result<()> { if self.title.is_some() { return Err("no world open; use: open WORLD [SEED] [creative]".into()); diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 7e5c9f1e2..37be759dc 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -442,7 +442,7 @@ impl Game<'_> { } Some(stack) } - fn chat_line(&mut self, text: String) { + pub(super) fn chat_line(&mut self, text: String) { log::info!("[chat] {text}"); if let Some(r) = self.remote.as_mut() { r.chat.push((text, Instant::now())); @@ -1154,6 +1154,14 @@ impl Game<'_> { } } C::EntityEvent(p) => { + // EntityEvent.PERMISSION_LEVEL_ALL..OWNERS (24..=28) for this + // player: LocalPlayer.setPermissionLevel, which the commands + // the chat offers and checks follow. + if (24..=28).contains(&p.event) + && self.remote.as_ref().is_some_and(|r| r.entity_id == p.id) + { + self.ui.registries.permission = (p.event - 24) as u8; + } if p.event == 1 && let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32) && m.species() == horizon_client::mobs::Species::Rabbit