Feed a remote client's chat lines to the agent's event log
A client joined to a server (and the window on the server thread) keeps the server's chat lines in its own list. The event log only counted the local chat's lines, so `wait-for chat` never saw a line from the server. The remote client counts the lines it receives. The event log reads that count and those lines while connected. lan_e2e gets a `chat` check: a line the host sends reaches the guest's event log, and on the server thread the host window's too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<horizon_client::command::Dispatcher>,
|
||||
players: HashMap<u128, String>,
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user