diff --git a/crates/horizon-client/src/audio.rs b/crates/horizon-client/src/audio.rs index e59ffd867..be6628ece 100644 --- a/crates/horizon-client/src/audio.rs +++ b/crates/horizon-client/src/audio.rs @@ -161,6 +161,9 @@ pub struct Audio { /// How many times each positional sound played (the control socket's `status`), /// with or without an audio device. pub heard: std::collections::BTreeMap, + /// How many times each selection was stopped ("record *", "* minecraft:…", `*` for + /// any), with or without an audio device, as `heard`. + pub stopped: std::collections::BTreeMap, } fn decode(path: &Path) -> Option<(Vec, u32)> { use symphonia::core::{ @@ -595,6 +598,7 @@ impl Audio { source_override: None, capture: None, heard: Default::default(), + stopped: Default::default(), } } #[cfg(not(feature = "audio"))] @@ -825,6 +829,14 @@ impl Audio { /// and/or a source. pub fn stop_sounds(&mut self, event: Option<&str>, source: Option) { let event = event.map(crate::sound_events::normalize); + let selection = format!( + "{} {}", + source + .and_then(|s| crate::settings::SOUND_SOURCES.get(s)) + .map_or("*", |s| s), + event.as_deref().unwrap_or("*") + ); + *self.stopped.entry(selection).or_default() += 1; self.engine .stop_matching(event.as_deref(), source, &mut self.backend); } diff --git a/crates/horizon-client/src/game/control.rs b/crates/horizon-client/src/game/control.rs index 205a66074..d48f657ed 100644 --- a/crates/horizon-client/src/game/control.rs +++ b/crates/horizon-client/src/game/control.rs @@ -981,6 +981,7 @@ impl Game<'_> { status["destroying"] = json!(destroying); status["physical_keys"] = json!(physical_keys); status["heard"] = json!(self.audio.heard); + status["stopped_sounds"] = json!(self.audio.stopped); // Boats, minecarts, armor stands, item frames and paintings. status["objects"] = json!(self.objects_status()); status["lightning"] = json!({"bolts": self.bolts.len(), "struck": self.lightning_seen[0], diff --git a/tools/lan_e2e.py b/tools/lan_e2e.py index 3ece4b448..98de75b3f 100755 --- a/tools/lan_e2e.py +++ b/tools/lan_e2e.py @@ -228,6 +228,9 @@ address. The script then checks, from both sides, what a guest's game used to ge - villagers: the guest sees each villager's and zombie villager's type, profession and level as the host has them, and an unemployed villager that takes a composter becomes a farmer on the guest too (the guest used to draw every villager as an unemployed plains one). +- stopsound: the host's and the guest's own /stopsound, by source and by event, reach their own + client's sounds, and the host's /stopsound of the guest only the guest's (StopSoundCommand + sends each target its packet). Each check is reported on its own (a failing one doesn't stop the others) and the screenshots of both sides go to --out (host-*.png, guest-*.png). @@ -5496,5 +5499,39 @@ CHECKS += ['villagers'] CHECK_FNS.update(villagers=check_villagers) +def check_stopsound(host, guest, out): + """StopSoundCommand sends each target ClientboundStopSoundPacket: a player's own /stopsound by + source and by event reaches its own client's sound engine, and the host's /stopsound of the + guest reaches the guest's (sounds stopped, counted in the status as `heard` is, audio or not).""" + event = 'minecraft:music_disc.cat' + + def stopped(game): + return game('status')['stopped_sounds'] + + seen = {} + for game in (host, guest): + before = stopped(game) + game('command', command='stopsound @s record') + game('command', command=f'stopsound @s * {event}') + game.wait(10) + after = stopped(game) + seen[game.name] = {k: after.get(k, 0) - before.get(k, 0) for k in after} + assert seen[game.name].get('record *') == 1 and seen[game.name].get(f'* {event}') == 1, \ + f'{game.name}: its own /stopsound did not reach its client: {seen}' + before = {g.name: stopped(g) for g in (host, guest)} + host('command', command=f'stopsound {GUEST_NAME}') + guest.wait(10) + for game in (host, guest): + after = stopped(game) + seen[f'{game.name}-by-host'] = after.get('* *', 0) - before[game.name].get('* *', 0) + assert seen['guest-by-host'] == 1 and seen['host-by-host'] == 0, \ + f"the host's /stopsound of the guest stopped the wrong client: {seen}" + return seen + + +CHECKS += ['stopsound'] +CHECK_FNS.update(stopsound=check_stopsound) + + if __name__ == '__main__': main()