diff --git a/crates/horizon-client/src/game/events.rs b/crates/horizon-client/src/game/events.rs index 0ffff1b59..8a4207a7f 100644 --- a/crates/horizon-client/src/game/events.rs +++ b/crates/horizon-client/src/game/events.rs @@ -167,7 +167,11 @@ impl Game<'_> { Snapshot { screen: self.screen_label(), dimension: self.dim.id().to_string(), - chat: self.ui.chat.received, + // A remote client counts the server's lines itself. + chat: self + .remote + .as_ref() + .map_or(self.ui.chat.received, |r| r.chat_received), counts: if world.is_some() { self.inventory_counts() } else { @@ -189,8 +193,19 @@ impl Game<'_> { if let Some(before) = &self.events.last && *before != now { - let new_chat = (now.chat - before.chat).min(100) as usize; - let lines = self.ui.chat.recent_lines(new_chat); + // Joining or leaving a server starts another count. + let new_chat = now.chat.saturating_sub(before.chat).min(100) as usize; + // Newest first; the remote client keeps its lines oldest first. + let lines = match &self.remote { + Some(r) => r + .chat + .iter() + .rev() + .take(new_chat) + .map(|(t, _)| t.clone()) + .collect(), + None => self.ui.chat.recent_lines(new_chat), + }; for event in diff(before, &now, &lines) { self.events.push(self.ticks, event); } diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 680360c93..5f0699e0c 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -125,6 +125,8 @@ pub(super) struct Remote { health: (f32, i32, f32), game_mode: i32, pub chat: Vec<(String, Instant)>, + /// Lines received since joining, for the control socket's events. + pub chat_received: u64, /// The server's command tree (ClientboundCommandsPacket). pub commands: Option, players: HashMap, @@ -314,6 +316,7 @@ impl Game<'_> { health: (20.0, 20, 5.0), game_mode: 0, chat: Vec::new(), + chat_received: 0, commands: None, players: HashMap::new(), tab_players: HashMap::new(), @@ -487,6 +490,7 @@ impl Game<'_> { log::info!("[chat] {text}"); if let Some(r) = self.remote.as_mut() { r.chat.push((text, Instant::now())); + r.chat_received += 1; if r.chat.len() > 100 { r.chat.remove(0); } diff --git a/tools/lan_e2e.py b/tools/lan_e2e.py index 4d13b1c22..f8d4c3ebb 100755 --- a/tools/lan_e2e.py +++ b/tools/lan_e2e.py @@ -22,6 +22,8 @@ address. The script then checks, from both sides, what a guest's game used to ge - containers: the guest's ender chest holds the guest's items, not the host's, and a double chest opens as 9x6 with the right half first; - feedback: the guest's command feedback names the guest and shows the numbers; +- chat: a line the host sends reaches the guest's event log (`wait-for chat`), and on the + server thread the host window's too; - effects: a beacon's power reaches every player in range, the host and the guest; - distance: (--server-thread) the server follows the host's render distance, past vanilla's 32 too (IntegratedServer.tickServer), and the guest's chunks follow the server's (#804) @@ -84,7 +86,7 @@ ROOT = Path(__file__).resolve().parents[1] GUEST_NAME = 'Guest' # The host plays single player on its server thread (--server-thread). SERVER_THREAD = False -CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'containers', 'feedback', 'titles', 'commands', 'recipes', 'trials', 'clicks', 'sleep', 'push', 'eat', 'xp', 'objects', 'projectiles', 'light', 'effects', 'portals', 'distance'] +CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'trials', 'clicks', 'sleep', 'push', 'eat', 'xp', 'objects', 'projectiles', 'light', 'effects', 'portals', 'distance'] class Game: @@ -853,6 +855,17 @@ def check_titles(host, guest, out): return {'shown': shown, 'cleared': cleared} +def check_chat(host, guest, out): + # The agent's event log follows a remote client's chat: `wait-for chat` sees the line another + # player sends (and on the server thread the host window's own line, back from the server). + line = f'chat check {int(time.time())}' + host.raw('chat', line) + seen = {g.name: g.raw('wait-for', 'chat', line, '--timeout', 10, '--since', 0).get('ok') + for g in ((guest, host) if SERVER_THREAD else (guest,))} + guest.shot(out, 'chat') + return seen + + def png_rows(path): """The rows of an 8-bit RGB or RGBA PNG, unfiltered, as bytes of 4 (or 3) per pixel.""" data = Path(path).read_bytes() @@ -1272,7 +1285,7 @@ def check_light(host, guest, out): CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour, 'nametags': check_nametags, 'chest': check_chest, 'crafting': check_crafting, 'sign': check_sign, 'damage': check_damage, 'mobs': check_mobs, 'hazards': check_hazards, 'pvp': check_pvp, - 'containers': check_containers, 'feedback': check_feedback, 'titles': check_titles, + 'containers': check_containers, 'feedback': check_feedback, 'titles': check_titles, 'chat': check_chat, 'commands': check_commands, 'recipes': check_recipes, 'trials': check_trials, 'walls': check_walls, 'effects': check_effects, 'portals': check_portals, 'distance': check_distance, 'clicks': check_clicks,