Area triggers heartbeat first; far swings stop attack; ignored GMs speak (#2925)

Three wire gaps:

- An area trigger sent CMSG_AREATRIGGER alone and at any health. `0x5e2110` runs only while health is above 0 (`0x5e215e`). On entry it sends a heartbeat from the live pose (`0x5e221e`), then the trigger (`0x5e225d`), so the server checks the trigger against a fresh position. benilla now does both.
- A landed swing on a far victim kept auto-attack on. `0x5ea800` sends CMSG_ATTACKSTOP when the 3D distance is at or beyond 4 × max(both combat reaches + 4/3, 5) (`0x5ea899`, `0x5ea8a8`), as after a knockback or a blink. benilla now does the same.
- An ignored GM was silenced, and every ignored whisper drew CMSG_CHAT_IGNORED. `0x49d736` drops an ignored sender only under a non-GM tag, and replies only to such a whisper. benilla now does the same.

Tests: the heartbeat-then-trigger order, the reach boundary, and the tag and type matrix.

Fixes #2595
Fixes #2598
Fixes #2603

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Sam Sung
2026-11-01 03:39:48 +07:00
committed by GitHub
parent d69afa8155
commit 01ef631ab3
9 changed files with 280 additions and 18 deletions
+53 -4
View File
@@ -18,7 +18,7 @@ use benilla_assets::coords::bevy_to_wow;
use benilla_formats::AreaTriggerCatalog;
use bevy::prelude::*;
use crate::net::{ClientCommand, NetCommands};
use crate::net::{ClientCommand, NetCommands, ObjectStore, SelfPlayer};
use crate::player::Player;
use benilla_assets::{AssetSet, LockRecover, WorldAssets};
use benilla_world::schedule::WorldStage;
@@ -84,11 +84,26 @@ fn load_area_triggers(mut commands: Commands, assets: Option<Res<WorldAssets>>)
}
}
/// Whether the check runs at all: the reference's gate `0x5e215e` wants the player's health
/// above 0 (signed), and no player object skips it too (`0x5e214f`).
fn check_runs(store: Option<&ObjectStore>) -> bool {
store.is_some_and(|s| !s.0.unit_is_dead())
}
/// An entry's two sends, in the reference's order: the heartbeat with the live pose
/// (`0x5e221e`, `0x600a10` with 0xee), then CMSG_AREATRIGGER (`0x5e225d`).
fn send_entry(net: &NetCommands, player: &mut Player, now: f32, trigger_id: u32) {
crate::player::send_heartbeat(&net.0, player, now);
let _ = net.0.send(ClientCommand::AreaTrigger { trigger_id });
}
/// The per-frame check (`0x5e2110`).
fn check_area_triggers(
triggers: Option<Res<AreaTriggers>>,
map: Option<Res<CurrentMap>>,
player: Res<Player>,
mut player: ResMut<Player>,
me: Query<&ObjectStore, With<SelfPlayer>>,
time: Res<Time>,
mut inside: ResMut<InsideTrigger>,
net: Res<NetCommands>,
) {
@@ -96,14 +111,14 @@ fn check_area_triggers(
return;
};
// Before the server has placed us, `pos` is not a server position.
if !player.active {
if !player.active || !check_runs(me.single().ok()) {
return;
}
let here = bevy_to_wow(player.pos);
let Some(trigger_id) = inside.step(&triggers.0, map.0, here) else {
return;
};
let _ = net.0.send(ClientCommand::AreaTrigger { trigger_id });
send_entry(&net, &mut player, time.elapsed_secs(), trigger_id);
// At `info`: entries are rare, and this line tells whether the client saw the volume at all.
info!(
"area_trigger: entered {trigger_id} on map {} at [{:.2}, {:.2}, {:.2}]",
@@ -155,6 +170,40 @@ mod tests {
assert_eq!(inside.step(&cat, 0, [-11208.5, 1685.34, 25.7612]), Some(78));
}
#[test]
fn an_entry_sends_the_heartbeat_with_the_live_pose_before_the_trigger() {
let (tx, rx) = crossbeam_channel::unbounded();
let net = NetCommands(tx);
let mut player = Player::default();
player.pos = benilla_assets::coords::wow_to_bevy([8799.41, 969.787, 30.2409]);
send_entry(&net, &mut player, 5.0, 542);
let ClientCommand::Move { kind, pos, .. } = rx.try_recv().expect("heartbeat first") else {
panic!("the first send is a move");
};
assert_eq!(kind, crate::net::MoveKind::Heartbeat);
for (got, want) in pos.iter().zip([8799.41, 969.787, 30.2409]) {
assert!((got - want).abs() < 0.01, "{pos:?}");
}
assert!(matches!(
rx.try_recv(),
Ok(ClientCommand::AreaTrigger { trigger_id: 542 })
));
assert!(rx.try_recv().is_err());
}
#[test]
fn a_dead_player_or_no_player_skips_the_check() {
let alive = |hp: u32| {
ObjectStore(benilla_protocol::ObjectFields::from_pairs(&[(
benilla_protocol::field::FIELD_UNIT_HEALTH,
hp,
)]))
};
assert!(check_runs(Some(&alive(10))));
assert!(!check_runs(Some(&alive(0))));
assert!(!check_runs(None));
}
#[test]
fn open_ground_and_unknown_maps_are_silent() {
let Some(cat) = real_catalog() else { return };
+3
View File
@@ -972,6 +972,9 @@ mod tests {
/// line first, then the animation layer's, which runs ahead of it.
fn swing_world(held: &[u64]) -> App {
let mut app = world(held);
// The landed swing's far-victim stop sends on the wire (`0x5ea8a8`).
let (tx, _rx) = crossbeam_channel::unbounded();
app.insert_resource(crate::net::NetCommands(tx));
app.add_message::<crate::creature_anim::SwingMessage>()
.add_message::<crate::creature_anim::SwingImpact>()
.add_message::<crate::creature_anim::SheathRequest>()
+9
View File
@@ -204,6 +204,15 @@ pub(crate) fn cancel_auto_repeat_local(
core.reports.auto_repeat(false);
}
/// The reach test of our landed swing (`0x5ea880`-`0x5ea8a4`): the squared 3D distance between
/// the two units' positions against `(4 * max(r1 + r2 + 4/3, 5))^2`, `reach` being the melee reach
/// `max(...)` ([`crate::target::cursor_mode::melee_reach`]). At or beyond it, `SendAttackStop`
/// (`0x5ea8a8`); a NaN distance does not stop (`0x5ea8a4` jp).
fn swing_beyond_stop_reach(dist_sq: f32, reach: f32) -> bool {
let limit = reach * 4.0;
dist_sq >= limit * limit
}
/// The local StopAttack, reference `0x5ecac0`, for a caller with nobody to signal between its
/// steps: [`stop_attack_head`], [`stop_attack_send`], then the save's leg of `CancelQueuedCast`
/// ([`crate::spell::CastCore::cancel_queued_save`]). A queued on-next-swing spell is cancelled
@@ -163,6 +163,11 @@ fn on_attacker_state(
mut pending: ResMut<PendingImpacts>,
mut sinks: ImpactSinks,
mut play_seq: ResMut<PlaySeq>,
stop: (
Res<crate::net::NetCommands>,
ResMut<super::AttackStopInFlight>,
Query<&Transform>,
),
tutorials: Option<Res<crate::tutorial::Tutorials>>,
// The self-defence acquire the swing owes, absent in a harness without the target plugin.
acquires: Option<ResMut<crate::target::OwedSelects>>,
@@ -186,6 +191,7 @@ fn on_attacker_state(
&mut pending,
&mut sinks,
play_seq.next(),
stop,
);
// A held attacker's auto-move other than mode 2, the facing turn, ends (`0x625a03`-
// `0x625a21` → `StopAutoMove(1, 1)`), after the self-defence acquire (`0x6259fe`) and ahead
@@ -307,6 +313,32 @@ fn ai_reaction(
}
}
/// The tail of `0x5ea800` after the latch clear: with the victim at or beyond four melee reaches
/// (`0x5ea880`-`0x5ea8a4`), `SendAttackStop` (`0x5ea8a8` → `0x624370`) sends `CMSG_ATTACKSTOP`
/// and sets `me`'s stop in flight. The squared distance is 3D, between the two units' positions.
fn stop_on_far_victim(
me: Entity,
them: Entity,
stores: &Query<&crate::net::ObjectStore>,
places: &Query<&Transform>,
net: &crossbeam_channel::Sender<crate::net::ClientCommand>,
stop_word: &mut super::AttackStopInFlight,
) {
let (Ok(t), Ok(m), Ok(tp), Ok(mp)) = (
stores.get(them),
stores.get(me),
places.get(them),
places.get(me),
) else {
return;
};
let d2 = tp.translation.distance_squared(mp.translation);
if super::swing_beyond_stop_reach(d2, crate::target::cursor_mode::melee_reach(t, m)) {
let _ = net.send(crate::net::ClientCommand::AttackStop);
stop_word.set(me);
}
}
/// One melee swing (`SMSG_ATTACKERSTATEUPDATE`): the attacker's swing plays now and the victim's
/// feedback waits for the clip's attack-hit key (`0x6247d0`); the combat-log line and its
/// `COMBAT_TEXT_UPDATE` word come off the same packet in [`crate::combat_log`], after this.
@@ -322,6 +354,11 @@ fn attacker_state(
pending: &mut PendingImpacts,
sinks: &mut ImpactSinks,
seq: u64,
(net, mut stop_word, places): (
Res<crate::net::NetCommands>,
ResMut<super::AttackStopInFlight>,
Query<&Transform>,
),
) {
let victim = index.0.get(&s.victim).copied();
// Our landed swing clears the refusal latch (`0x6259b6` → `0x5ea800` → `0x5ecdb0(0)`) when we
@@ -333,6 +370,9 @@ fn attacker_state(
std::time::Duration::ZERO,
None,
);
if let (Some(me), Some(them)) = (index.0.get(&s.attacker).copied(), victim) {
stop_on_far_victim(me, them, &sinks.stores, &places, &net.0, &mut stop_word);
}
}
if benilla_assets::trace::enabled() {
benilla_assets::trace::line(
@@ -531,4 +571,41 @@ mod tests {
assert!(world.get::<Engaged>(e).is_some());
assert_eq!(world.get::<super::super::Precast>(e), Some(&precast));
}
/// A landed swing at a victim `d` yards away stops our attack from four melee reaches out
/// (`0x5ea880`-`0x5ea8a4`): default reaches 1.5 + 1.5 + 4/3 sit under the floor of 5, so the limit is 20.
#[test]
fn a_landed_swing_stops_the_attack_from_four_reaches_out() {
use crate::net::{ClientCommand, ObjectStore};
for (d, stops) in [(19.9_f32, false), (20.1, true), (40.0, true), (3.0, false)] {
let mut world = World::new();
let (tx, rx) = crossbeam_channel::unbounded();
world.init_resource::<super::super::AttackStopInFlight>();
let me = world
.spawn((ObjectStore::default(), Transform::from_xyz(0.0, 0.0, 0.0)))
.id();
let them = world
.spawn((
ObjectStore::default(),
Transform::from_xyz(d * 0.6, d * 0.48, d * 0.64),
))
.id();
world
.run_system_once(
move |stores: Query<&ObjectStore>,
places: Query<&Transform>,
mut word: ResMut<super::super::AttackStopInFlight>| {
stop_on_far_victim(me, them, &stores, &places, &tx, &mut word);
},
)
.unwrap();
let sent: Vec<ClientCommand> = rx.try_iter().collect();
assert_eq!(sent.len(), usize::from(stops), "{d} yd: {sent:?}");
assert_eq!(
world.resource::<super::super::AttackStopInFlight>().of(me),
stops,
"{d} yd: the stop in flight"
);
}
}
}
+1
View File
@@ -58,6 +58,7 @@ mod input;
pub(crate) mod land;
mod move_trace;
mod movement_net;
pub(crate) use movement_net::send_heartbeat;
mod posture;
// A movement command's press or release, run inside the frame's input records.
mod press;
@@ -441,6 +441,30 @@ fn send_move(
player.last_pos = wire.pos;
}
/// A standalone `MSG_MOVE_HEARTBEAT` with the live pose, as a caller outside the movement stream
/// sends it (`0x600a10` with 0xee, from the area-trigger check at `0x5e221e`): the sent flags, the
/// position, the fall time and the deck pose now. A send re-arms the heartbeat deadline
/// (`0x600a30` → `0x615b80`).
pub(crate) fn send_heartbeat(sender: &Sender<ClientCommand>, player: &mut Player, now: f32) {
let facing = player.face_yaw.rem_euclid(std::f32::consts::TAU);
let flags = player.move_flags & OUTBOUND_FLAG_MASK;
let wire = Wire {
flags,
pos: bevy_to_wow(player.pos),
facing,
pitch: player.wire_pitch,
fall_time: super::flags::fall_ms(player, now),
jump: jump_tail(player, flags, facing),
transport: wire_transport(player),
};
let mut out = Sends {
sent: false,
precast_ended: false,
};
send_move(sender, player, &wire, MoveKind::Heartbeat, &mut out);
player.last_heartbeat = now;
}
/// The jump tail, on every airborne packet: the take-off vertical speed and the horizontal
/// velocity frozen at take-off, in world XY.
fn jump_tail(player: &Player, wire_flags: u32, facing: f32) -> Option<JumpInfo> {
+1 -1
View File
@@ -157,7 +157,7 @@ const ATTACK_RANGE_SQ: f32 = 109.2025;
pub(super) const MELEE_OFFSET: f32 = 1.333_33;
pub(super) const MELEE_FLOOR: f32 = 5.0;
pub(super) fn melee_reach(target: &ObjectStore, me: &ObjectStore) -> f32 {
pub(crate) fn melee_reach(target: &ObjectStore, me: &ObjectStore) -> f32 {
(target.0.unit_combat_reach() + me.0.unit_combat_reach() + MELEE_OFFSET).max(MELEE_FLOOR)
}
+111 -12
View File
@@ -128,6 +128,22 @@ fn on_session_end(
rosters.clear();
}
/// The ignore gate of the player-chat path (`FriendList::IsIgnored` at `0x49d72d`): a sender on
/// the list is dropped unless its chat tag is GM (`0x49d736`, tag 3), and a dropped whisper
/// (type 6, `0x49d73c`) sends `CMSG_CHAT_IGNORED` (`0x49d74e` → `0x49d4b0`), so the sender hears
/// "is ignoring you". A GM-tagged line passes whatever its type. Whether the line is dropped.
fn drops_ignored(m: &ChatMessage, social: &SocialState, net_commands: &NetCommands) -> bool {
if !social.is_ignored(m.sender_guid) || m.chat_tag == benilla_protocol::messages::chat_tag::GM {
return false;
}
if m.chat_type == CHAT_MSG_WHISPER {
let _ = net_commands.0.send(ClientCommand::ChatIgnored {
guid: m.sender_guid,
});
}
true
}
/// A spoken line (`SMSG_MESSAGECHAT`). System lines (`0x0A`), the server's answers to GM
/// commands, log at `info!` and go out as [`ServerSaidMessage`]; other chat logs at `debug!`.
fn chat(
@@ -140,11 +156,10 @@ fn chat(
// Addon traffic: 1.12 has no addon opcode or chat type, so `LANG_ADDON` on any lane is the
// whole test (`0x49a89e`, in the display function `0x49a870`). The line never renders
// (`0x49a970`); it fires `CHAT_MSG_ADDON` once the sender's name resolves (`0x49d7ba`,
// `0x49ccc0`). An ignored sender's fires nothing, as the reference drops ignored lines first
// (`0x49d72d`), and needs no `CMSG_CHAT_IGNORED`: vmangos refuses addon whispers
// (`ChatHandler.cpp:84-103`).
// `0x49ccc0`). No language test precedes the ignore gate (`0x49d72d`), so an addon line meets
// it as any line does ([`drops_ignored`]).
if m.is_addon() {
if !social.is_ignored(m.sender_guid) {
if !drops_ignored(&m, social, net_commands) {
debug!(
"net: addon chat [{:#04x}] from {:#x}: {:?} (suppressed — not a chat line)",
m.chat_type, m.sender_guid, m.text
@@ -186,14 +201,7 @@ fn chat(
}
m.chat_type = CHAT_MSG_WHISPER;
}
// An ignored speaker is dropped silently (`FriendList::IsIgnored`, `0x5ae5a0`); a dropped
// whisper also sends `CMSG_CHAT_IGNORED`, so the sender hears "is ignoring you".
if social.is_ignored(m.sender_guid) {
if m.chat_type == CHAT_MSG_WHISPER {
let _ = net_commands.0.send(ClientCommand::ChatIgnored {
guid: m.sender_guid,
});
}
if drops_ignored(&m, social, net_commands) {
return;
}
chat_log.push_wire(m);
@@ -345,6 +353,97 @@ mod tests {
}
}
/// One line from sender 0x21 through [`chat`] with that sender ignored: the chat log, and the
/// commands that went on the wire.
fn from_an_ignored_sender(m: ChatMessage) -> (World, Vec<ClientCommand>) {
let mut world = World::new();
world.init_resource::<Messages<ServerSaidMessage>>();
let (tx, rx) = crossbeam_channel::unbounded();
world.insert_resource(NetCommands(tx));
let mut social = SocialState::default();
social.ignore_for_test(0x21);
world.insert_resource(social);
world.insert_resource(ChatLog::default());
world
.run_system_once(
move |chat_log: Res<ChatLog>,
social: Res<SocialState>,
net_commands: Res<NetCommands>,
mut server_said: MessageWriter<ServerSaidMessage>| {
chat(
m.clone(),
&chat_log,
&social,
&net_commands,
&mut server_said,
);
},
)
.unwrap();
(world, rx.try_iter().collect())
}
/// The ignore gate (`0x49d72d`, `0x49d736`, `0x49d73c`): an ignored sender is dropped unless
/// tagged GM, and only a dropped whisper draws `CMSG_CHAT_IGNORED`.
#[test]
fn an_ignored_gm_passes_and_only_an_ignored_whisper_draws_the_reply() {
use benilla_protocol::messages::chat_tag;
let line = |chat_type: u8, tag: u8| ChatMessage {
chat_type,
chat_tag: tag,
..a_party_line(0, "hi")
};
for (chat_type, tag, delivered, replies) in [
(CHAT_MSG_PARTY, chat_tag::NONE, false, false),
(CHAT_MSG_WHISPER, chat_tag::NONE, false, true),
(CHAT_MSG_WHISPER, chat_tag::DND, false, true),
(CHAT_MSG_PARTY, chat_tag::GM, true, false),
(CHAT_MSG_WHISPER, chat_tag::GM, true, false),
] {
let (world, sent) = from_an_ignored_sender(line(chat_type, tag));
assert_eq!(
world.resource::<ChatLog>().pending_wire().len(),
usize::from(delivered),
"type {chat_type:#x} tag {tag}: delivered"
);
assert_eq!(
sent.len(),
usize::from(replies),
"type {chat_type:#x} tag {tag}: wire {sent:?}"
);
if replies {
assert!(matches!(sent[0], ClientCommand::ChatIgnored { guid: 0x21 }));
}
}
}
/// An addon line meets the same gate: no language test precedes it (`0x49d72d`).
#[test]
fn an_addon_line_meets_the_ignore_gate_like_any_other() {
use benilla_protocol::messages::chat_tag;
let addon = |chat_type: u8, tag: u8| ChatMessage {
chat_type,
chat_tag: tag,
..a_party_line(LANGUAGE_ADDON, "Quiver\tVERSION:3.1.4")
};
let (world, sent) = from_an_ignored_sender(addon(CHAT_MSG_PARTY, chat_tag::NONE));
assert!(world.resource::<ChatLog>().pending_addons().is_empty());
assert!(sent.is_empty());
let (world, sent) = from_an_ignored_sender(addon(CHAT_MSG_PARTY, chat_tag::GM));
assert_eq!(world.resource::<ChatLog>().pending_addons().len(), 1);
assert!(sent.is_empty());
// A whisper-typed addon line is dropped and answered as a whisper is (`0x49d73c`).
let (world, sent) = from_an_ignored_sender(addon(CHAT_MSG_WHISPER, chat_tag::NONE));
assert!(world.resource::<ChatLog>().pending_addons().is_empty());
assert!(matches!(
sent[..],
[ClientCommand::ChatIgnored { guid: 0x21 }]
));
let (world, sent) = from_an_ignored_sender(addon(CHAT_MSG_WHISPER, chat_tag::GM));
assert_eq!(world.resource::<ChatLog>().pending_addons().len(), 1);
assert!(sent.is_empty());
}
/// `SMSG_PLAYED_TIME` (`0x401850`) puts `TIME_PLAYED_MSG` on the notice lane (`0x4018df`) and
/// prints nothing to chat itself: its own lines go to the console (`0x401878`-`0x4018c8`), and
/// the stock `ChatFrame_DisplayTimePlayed` is the answer's one printer.
+1 -1
View File
@@ -210,7 +210,7 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
- The starting zoom, `CAM_DIST_DEFAULT`, is 15 yd where the reference starts at 5.55, the third-person-A row of its default table `0x84f488` that `cameraView` 1 picks (`0x50c17a`, `0x50c18b`; the `cameraDistance` CVar itself registers "0.0"), because that gives a wider view. ([`src/player/camera_zoom.rs:10`](../crates/benilla-app/src/player/camera_zoom.rs#L10))
- No drunk field-of-view lane, because the reference's is invisible in play: its target `(179° − 90°)·fraction` (camera `+0x10c`, setter `0x511250`) eases at `cameraFoVSmoothSpeed`, 0.5°/s, and restarts on every drunk-byte change, so it creeps under 1°. Not built: entering the world already drunk, the reference snaps the full fisheye (`0x50d0f0`). ([`src/player/drunk.rs:46`](../crates/benilla-app/src/player/drunk.rs#L46))
- Every end signals `END`, because the reference's three silent ends are a bug: two writers reset the follow mode cell `0xc4d888` directly (`0x5fb646`, `0x60396f`), leaving a stale guid at `0xc4d980`, and the canceller's early-out (`0x60fb70`) fires nothing. ([`src/player/follow.rs:24`](../crates/benilla-app/src/player/follow.rs#L24))
- A settle hold is summed and sent once on release, without the push, because it stands in for the reference's blocking load (`0x694920`), not a refused substep, and lasts seconds. ([`src/player/movement_net.rs:470`](../crates/benilla-app/src/player/movement_net.rs#L470))
- A settle hold is summed and sent once on release, without the push, because it stands in for the reference's blocking load (`0x694920`), not a refused substep, and lasts seconds. ([`src/player/movement_net.rs:494`](../crates/benilla-app/src/player/movement_net.rs#L494))
- The reference's blocking load (`0x694920`) waits out its reads before the frame goes on and has no such release; the timeout exists because without one a model that never loads would freeze our body for good. ([`src/player/state.rs:120`](../crates/benilla-app/src/player/state.rs#L120))
- Root is not merged, because a bare pose unrooting us while the server still roots us streams motion into `CHEAT_TYPE_ROOT_MOVE`; vmangos keeps a rooted mover's root bit (`MovementHandler.cpp:1064`), so the reference's merge of it is a no-op anyway. ([`src/player/state.rs:203`](../crates/benilla-app/src/player/state.rs#L203))
- Applied at arrival, because our own avatar has no motion to de-jitter; the reference routes it through the replay chain remotes use, which paces to the sender's cadence and can hold an early packet (up to 1000 ms in `net::motion`). A self-addressed stream, such as bursting anticheat snap-backs, would need that pacing. ([`src/player/wire_in.rs:503`](../crates/benilla-app/src/player/wire_in.rs#L503))