A server's Warden request is read past and the login goes on (#1717)

A server that sent `SMSG_WARDEN_DATA` ended the login at character select with a terminal failure. Servers that send it without enforcing it were unplayable, and vmangos serves the roster and the world entry regardless (no handler gates on Warden; `World.cpp:325-338` starts it after AUTH_OK) and only kicks a silent client after `Warden.ClientResponseDelay` (`Warden.cpp:686-691`).

benilla now reads the message past, answers nothing and goes on; the server's policy decides what follows, and a kick is the ordinary lost link. This is a `Deviation:` at the read: the reference hands the message to its loaded module (`0x6ca2f0`, `0x6ca5c0`) and sends its answer (`0x6ca6a0`). `WardenRequired` and the terminal-failure path it alone used are gone.

Tests: a login past a Warden request reaches the world with nothing sent back; a kick after it is a lost link; the handshake reads one past. Each fails with the old refusal.

Fixes #854

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sam Sung
2026-10-17 03:33:17 +07:00
committed by GitHub
parent 112601c2a9
commit 52cc825e60
15 changed files with 183 additions and 243 deletions
@@ -278,20 +278,6 @@ pub(crate) fn drive_policy(
// it says a person typed this attempt; only an untyped attempt may end the run.
let typed = attempt.intent.announced;
let may_end_the_run = !typed;
if msg.terminal {
// No resubmit can change it: show the server's words and drop the credentials.
warn!("login: {}", msg.reason);
attempt.intent.clear();
if may_end_the_run
&& crate::run_mode::fatal_when_driverless(&format!(
"terminal login failure with nobody at the keyboard ({})",
msg.reason
))
{
exit.write(AppExit::error());
}
continue;
}
match msg.refusal {
Some(refusal) => {
// A refusal from either server: shown even on the silent path, never retried.
@@ -678,7 +664,6 @@ mod tests {
app.world_mut().write_message(LoginFailedMessage {
refusal: None,
reason: "connection refused".into(),
terminal: false,
});
// The arm's cancel and its dialog's press, as the glue manager asks them.
app.world_mut().write_message(GlueLogin::CloseLink);
@@ -779,7 +764,6 @@ mod tests {
app.world_mut().write_message(LoginFailedMessage {
refusal: Some(benilla_protocol::LoginRefusal::Logon(0x05)),
reason: "server rejected logon: result 0x05".into(),
terminal: false,
});
app.update();
assert!(
-2
View File
@@ -2288,13 +2288,11 @@ impl DisconnectedMessage {
}
/// A login attempt failed before the roster; the IO thread is back at its pre-logon park.
/// `terminal` is a failure retrying cannot fix (the server requires Warden, say): never resubmit.
#[derive(Message, Clone)]
pub(crate) struct LoginFailedMessage {
/// Which server refused us, with which byte; `None` on a transport failure.
pub(crate) refusal: Option<benilla_protocol::LoginRefusal>,
pub(crate) reason: String,
pub(crate) terminal: bool,
}
/// A same-map teleport of our player: snap, then ack. Read by the controller in `Input`.
+25 -36
View File
@@ -31,7 +31,7 @@ use anyhow::{anyhow, Result};
use benilla_assets::LockRecover;
use benilla_protocol::{
messages::SurveyAnswer, AuthReject, CharAction, LoginStage, Poll, RosterCause, SessionEnd,
SessionEvent, WardenRequired, WorldReader, WorldSession, WorldWriter,
SessionEvent, WorldReader, WorldSession, WorldWriter,
};
use crossbeam_channel::{Receiver, Sender};
@@ -174,8 +174,6 @@ enum Parked {
Renamed(u8, Option<(u64, String)>),
/// `CMSG_CHAR_ENUM` was serviced in place; the roster is re-emitted, with no result.
Listed,
/// The server refused the roster to a client without Warden: the login fails for good.
Refused(String),
/// Stay parked: a realm-list refresh, a Cancel over this screen, or a tick that found the link up.
StayPut,
/// Drop the parked world session and dial this realm under the abandon generation its ask
@@ -532,7 +530,6 @@ fn run(
let _ = events_tx.send(SessionEvent::LoginFailed {
refusal: if dial.is_some() { None } else { refusal },
reason: format!("{e:#}"),
terminal: false,
dial,
});
return Ok(Cycle::Repark);
@@ -616,17 +613,6 @@ fn world(
let _ = events_tx.send(SessionEvent::LoginFailed {
refusal,
reason,
terminal: false,
dial: None,
});
Ok(WorldEnd::Failed)
};
// A failure resubmitting cannot fix: the app shows it and does not retry.
let fail_terminal = |reason: String| {
let _ = events_tx.send(SessionEvent::LoginFailed {
refusal: None,
reason,
terminal: true,
dial: None,
});
Ok(WorldEnd::Failed)
@@ -680,10 +666,6 @@ fn world(
if canceled() {
return Ok(WorldEnd::Failed);
}
// A Warden refusal is the server's answer, not a transport fault.
if let Some(w) = e.downcast_ref::<WardenRequired>() {
return fail_terminal(w.to_string());
}
// The world server's refusal code, for the screen's `AUTH_*` string.
if let Some(r) = e.downcast_ref::<benilla_protocol::WorldAuthReject>() {
return fail(
@@ -711,6 +693,8 @@ fn world(
// its wants.
while park_rx.try_recv().is_ok() {}
let epoch = WORLD_EPOCH.fetch_add(1, Ordering::SeqCst) + 1;
// Whether this link's unanswered Warden request has been logged.
let mut warden_noted = false;
// A server that sends the addon reply in front of the authentication answer (vmangos
// builds it in the auth handler, `WorldSocket.cpp:447`) has had it read by now.
let mut addon_news = AddonNews::default();
@@ -785,34 +769,29 @@ fn world(
}
// `GetCharacterListUpdate` (`0x4723d0` → `0x46b880` → `0x5aabb0` → `0x5b4690`):
// the reference asks the world server again whenever the glue screen wants
// the list. A Warden refusal is the server's answer, as at the park entry.
// the list.
Ok(ParkRequest::Char(CharRequest::Enumerate)) => match session.char_enum() {
Ok(c) => {
characters = c;
Parked::Listed
}
Err(e) => match e.downcast_ref::<WardenRequired>() {
Some(w) => Parked::Refused(w.to_string()),
// The stream failed under the ask: the screen's query fails
// (`0x5ab300`), and the session ends as a dropped socket does.
None => {
let _ = events_tx.send(SessionEvent::RosterFailed { epoch });
return Err(e);
}
},
// The stream failed under the ask: the screen's query fails
// (`0x5ab300`), and the session ends as a dropped socket does.
Err(e) => {
let _ = events_tx.send(SessionEvent::RosterFailed { epoch });
return Err(e);
}
},
},
recv(login_rx) -> msg => msg.map_or(Parked::Exit, Parked::Login),
recv(link_check) -> _ => match session.poll_link() {
Ok(()) => Parked::StayPut,
Err(e) => match e.downcast_ref::<WardenRequired>() {
Some(w) => Parked::Refused(w.to_string()),
// The server dropped the link: the session ends as a stream failure
// does, `DISCONNECTED_FROM_SERVER` and the login screen.
None => return Err(e),
},
// The server dropped the link (a kick among them): the session ends as a
// stream failure does, `DISCONNECTED_FROM_SERVER` and the login screen.
Err(e) => return Err(e),
},
};
note_warden(&session, &mut warden_noted);
let (action, code) = match answer {
Parked::Exit => return Ok(WorldEnd::Cycle(Cycle::Exit)),
Parked::Repark => return Ok(WorldEnd::Cycle(Cycle::Repark)),
@@ -824,7 +803,6 @@ fn world(
continue 'realm;
}
Parked::Leave => return Ok(WorldEnd::Failed),
Parked::Refused(reason) => return fail_terminal(reason),
Parked::Acted(action, code) => (action, code),
// The reference renames its record in place (`0x4725f0`) and asks for no
// roster; the park's own copy, which names the character at the world entry,
@@ -1070,6 +1048,17 @@ fn stream(
}
}
/// Logs, once per link, that the server asked for Warden before the world entry and was left
/// unanswered ([`WorldSession::warden_asked`]).
fn note_warden(session: &WorldSession, noted: &mut bool) {
if !*noted && session.warden_asked() {
*noted = true;
bevy::log::debug!(
"net: SMSG_WARDEN_DATA read past unanswered: benilla runs no Warden module"
);
}
}
/// Takes the world writer back from the write thread, the world session over and the link kept.
/// `None` once the write thread is gone (app exit).
fn reclaim(writer_tx: &Sender<WriterSwap>) -> Result<Option<WorldWriter>> {
+66 -15
View File
@@ -401,34 +401,85 @@ fn a_world_session_has_one_epoch_and_a_realm_change_a_new_one() {
assert_ne!(seen[0], seen[1], "a new session has a new epoch");
}
/// A server that wants Warden answers the select screen's first ask with `SMSG_WARDEN_DATA`: the
/// login fails for good with the server's words, not as a lost stream.
/// `CMSG_WARDEN_DATA`, the answer the reference's Warden module sends (`0x6ca6a0`).
const CMSG_WARDEN_DATA: u16 = 0x02E7;
/// A server with Warden on asks behind the authentication answer and serves the roster and the
/// world entry without waiting for the answer (vmangos, `World.cpp:333-338`): benilla reads the
/// request past, answers nothing, and the login goes on to select and into the world.
#[test]
fn a_warden_demand_at_the_asked_roster_is_a_terminal_login_failure() {
fn a_warden_request_is_read_past_and_the_login_goes_on() {
let (realmd, world) = fake::servers(|world| vec![FakeRealm::new(REALM, world)]);
world.demand_warden();
world.ask_warden();
world.set_roster(&[crate::glue_session::roster::test_character(GUID, "Alpha")]);
let cycles = fake::spawn_cycles();
fake::login(&cycles, &realmd.addr);
let (realms, _) = next_list(&cycles.events);
cycles.realm.send(enter(realms[0].clone())).unwrap();
let epoch = dial(&cycles, realms[0].clone());
cycles.pick.send(CharRequest::Enumerate).unwrap();
match next_event(&cycles.events) {
SessionEvent::CharacterList {
characters,
epoch: listed,
..
} => {
assert_eq!(listed, epoch);
assert_eq!(characters.len(), 1, "the roster past the Warden request");
}
other => panic!("expected the roster, got {other:?}"),
}
cycles.pick.send(CharRequest::Enter(GUID)).unwrap();
match next_event(&cycles.events) {
SessionEvent::Connected { self_guid, .. } => assert_eq!(self_guid, GUID),
other => panic!("expected the world entry, got {other:?}"),
}
wait_until(
|| {
world
.sent
.lock()
.unwrap()
.contains(&opcode::CMSG_PLAYER_LOGIN)
},
"the entry goes out",
);
assert!(
!world.sent.lock().unwrap().contains(&CMSG_WARDEN_DATA),
"benilla never answers Warden"
);
assert_eq!(world.open(), 1, "the world link is kept");
}
/// The kick of a server whose Warden clock ran out (`Warden.cpp:686-691`, `KickSession` closing
/// the socket, `WorldSession.cpp:873-876`) is a bare close, which ends the world session as any
/// lost link does: `Disconnected` with `SessionEnd::Lost`.
#[test]
fn a_kick_after_an_unanswered_warden_request_is_a_lost_link() {
let (realmd, world) = fake::servers(|world| vec![FakeRealm::new(REALM, world)]);
world.ask_warden();
let cycles = fake::spawn_cycles();
fake::login(&cycles, &realmd.addr);
let (realms, _) = next_list(&cycles.events);
dial(&cycles, realms[0].clone());
// The roster ask reads the request at select, ahead of its answer.
ask_roster(&cycles);
cycles.pick.send(CharRequest::Enter(GUID)).unwrap();
assert!(matches!(
next_event(&cycles.events),
SessionEvent::WorldAuthenticated { .. }
SessionEvent::Connected { .. }
));
cycles.pick.send(CharRequest::Enumerate).unwrap();
world.drop_links();
loop {
match cycles.events.recv_timeout(WAIT).expect("went quiet") {
SessionEvent::LoginFailed { terminal, .. } => {
assert!(terminal);
match next_event(&cycles.events) {
SessionEvent::Disconnected { end, .. } => {
assert_eq!(end, benilla_protocol::SessionEnd::Lost);
break;
}
SessionEvent::LoginStage { .. } => {}
other => panic!("expected the terminal login failure, got {other:?}"),
SessionEvent::PacketDropped { .. } => {}
other => panic!("expected the loss, got {other:?}"),
}
}
// The world socket is closed and the realmd link kept, as after any failed world dial.
wait_until(|| world.open() == 0, "the world socket closes");
assert_eq!(realmd.open(), 1, "the realmd link is kept");
assert!(!world.sent.lock().unwrap().contains(&CMSG_WARDEN_DATA));
}
/// A roster ask that fails on the stream (the server cut the connection) tells the screen its
+18 -8
View File
@@ -348,7 +348,7 @@ pub(crate) struct World {
creates: Arc<Mutex<u8>>,
/// How long a `CMSG_CHAR_ENUM` waits before its answer.
enum_delay: Arc<Mutex<Duration>>,
/// Answer `CMSG_CHAR_ENUM` with `SMSG_WARDEN_DATA`, as a server does that wants Warden.
/// Send `SMSG_WARDEN_DATA` behind the authentication answer, as vmangos does with Warden on.
warden: Arc<AtomicBool>,
/// Close the socket on `CMSG_CHAR_ENUM` instead of answering.
cut: Arc<AtomicBool>,
@@ -405,8 +405,13 @@ impl World {
.collect()
}
/// Have the server demand Warden in place of the roster from now on.
pub(crate) fn demand_warden(&self) {
/// Ask every session from now on for Warden as vmangos does with it on: the session starts
/// Warden right behind `AUTH_OK` (`World.cpp:333-338`) and its thread sends the first request
/// within a second (`Anticheat.cpp:111-127`, `WardenWin.cpp:1403-1405`). No handler waits on
/// the answer, so the roster and the world entry are served as ever; a client that never
/// answers is kicked later by the server's own clock (`Warden.cpp:686-691`), which this
/// server leaves to [`World::drop_links`].
pub(crate) fn ask_warden(&self) {
self.warden.store(true, Ordering::SeqCst);
}
@@ -606,6 +611,16 @@ pub(crate) fn world(listener: TcpListener, keys: Receiver<Key>) -> World {
if let Some((body, true)) = &reply {
send(&mut s, Some(&mut crypto), opcode::SMSG_ADDON_INFO, body);
}
// An opaque body: the client hands it to its Warden module and reads none of it
// (`0x6ca5c0`).
if warden_flag.load(Ordering::SeqCst) {
send(
&mut s,
Some(&mut crypto),
opcode::SMSG_WARDEN_DATA,
&[0x02; 21],
);
}
let log = Arc::clone(&log);
let packet_log = Arc::clone(&packet_log);
let roster_bodies = Arc::clone(&roster_bodies);
@@ -613,7 +628,6 @@ pub(crate) fn world(listener: TcpListener, keys: Receiver<Key>) -> World {
let create_answer = Arc::clone(&create_answer);
let session_log = Arc::clone(&session_log);
let enum_wait = Arc::clone(&enum_wait);
let warden_flag = Arc::clone(&warden_flag);
let cut_flag = Arc::clone(&cut_flag);
let refuse_flag = Arc::clone(&refuse_flag);
let refuse_wait = Arc::clone(&refuse_wait);
@@ -642,10 +656,6 @@ pub(crate) fn world(listener: TcpListener, keys: Receiver<Key>) -> World {
if cut_flag.load(Ordering::SeqCst) {
break;
}
if warden_flag.load(Ordering::SeqCst) {
send(&mut s, Some(&mut crypto), opcode::SMSG_WARDEN_DATA, &[]);
continue;
}
send(&mut s, Some(&mut crypto), opcode::SMSG_CHAR_ENUM, &body);
}
// A success appends the character at level 1 with the next guid.
+3 -11
View File
@@ -132,11 +132,8 @@ fn on_login_edge(In(ev): In<SessionEvent>, mut e: Edges) {
e.login_queued.write(LoginQueuedMessage { position, realm });
}
SessionEvent::LoginFailed {
refusal,
reason,
terminal,
..
} => login_failed(refusal, reason, terminal, &mut e.login_failures),
refusal, reason, ..
} => login_failed(refusal, reason, &mut e.login_failures),
SessionEvent::RealmList { realms, failed } => {
e.realm_lists.write(RealmListMessage { realms, failed });
}
@@ -453,14 +450,9 @@ fn login_stage(stage: benilla_protocol::LoginStage, out: &mut MessageWriter<Logi
fn login_failed(
refusal: Option<benilla_protocol::LoginRefusal>,
reason: String,
terminal: bool,
out: &mut MessageWriter<LoginFailedMessage>,
) {
out.write(LoginFailedMessage {
refusal,
reason,
terminal,
});
out.write(LoginFailedMessage { refusal, reason });
}
/// `SMSG_CHAR_CREATE`/`SMSG_CHAR_DELETE`: the glue screen turns the code into its string.
+3 -27
View File
@@ -369,8 +369,6 @@ struct Operation {
status: u8,
done: bool,
ok: bool,
/// The text of a failure the reference has no status for, shown in place of the status's.
raw: Option<String>,
/// A connect or a query whose realm list reply has not come (`0x5abb90` dispatches the reply
/// on the operation pending).
awaiting_list: bool,
@@ -394,13 +392,7 @@ impl Operation {
/// `GetStatus`'s text: the status's key once completed, none while it runs (`0x5aaa35`).
fn text(&self) -> Option<Text> {
if !self.done {
return None;
}
Some(match &self.raw {
Some(t) => Text::Raw(t.clone()),
None => status_text(self.status).0,
})
self.done.then(|| status_text(self.status).0)
}
}
@@ -1295,28 +1287,15 @@ impl GlueMgr {
self.cells.result = result;
}
}
// The character list query's reply never came: the server refused the roster to a
// client without Warden (the park's `char_enum`), the one failure it reports. The
// query completes failed with the words, and the link is gone.
ScreenState::CharList if self.op.kind != OpKind::CharList || self.op.done => {}
ScreenState::Connect | ScreenState::CharList => {
if self.state == ScreenState::CharList {
self.connected = false;
}
ScreenState::Connect => {
let status = match msg.refusal {
Some(LoginRefusal::World(code)) => code,
Some(LoginRefusal::Logon(_) | LoginRefusal::LogonProof(_)) => {
STATUS_RESPONSE_FAILURE
}
None if msg.terminal => STATUS_RESPONSE_FAILURE,
None => STATUS_FAILED_TO_CONNECT,
};
self.op.complete(false, status);
// A server refusing a client without Warden has no reference status: its own
// words.
if msg.terminal && msg.refusal.is_none() {
self.op.raw = Some(msg.reason.clone());
}
}
_ => {}
}
@@ -1328,10 +1307,7 @@ impl GlueMgr {
fn world_failed(&mut self, op: &Operation) {
let status = op.status;
if status != STATUS_CANCELLED {
let (text, code) = match op.text() {
Some(Text::Raw(t)) => (Text::Raw(t), None),
_ => status_text(status),
};
let (text, code) = status_text(status);
match code.and_then(|c| URL_STATUSES.iter().find(|(s, _)| *s == c)) {
Some((_, url)) => self.outbox.push(Outgoing::Open {
which: "OKAY_WITH_URL",
@@ -37,11 +37,10 @@ fn open(which: &'static str, key: Option<&'static str>) -> Outgoing {
}
}
fn failed(refusal: Option<LoginRefusal>, terminal: bool) -> LoginFailedMessage {
fn failed(refusal: Option<LoginRefusal>) -> LoginFailedMessage {
LoginFailedMessage {
refusal,
reason: "test".into(),
terminal,
}
}
@@ -91,7 +90,7 @@ fn a_proof_0x0a_changes_no_dialog() {
m.tick();
settle(&mut m);
m.outbox.clear();
m.on_failed(&failed(Some(LoginRefusal::LogonProof(0x0a)), false));
m.on_failed(&failed(Some(LoginRefusal::LogonProof(0x0a))));
m.tick();
settle(&mut m);
assert!(m.outbox.is_empty(), "{:?}", m.outbox);
@@ -181,7 +180,7 @@ fn a_logon_refusal_opens_its_result_and_ends_the_logon() {
m.login("a".into(), "b".into());
settle(&mut m);
m.outbox.clear();
m.on_failed(&failed(refusal, false));
m.on_failed(&failed(refusal));
m.tick();
settle(&mut m);
assert_eq!(m.outbox, [open(which, Some(key))], "{refusal:?}");
@@ -305,7 +304,7 @@ fn a_world_refusal_opens_its_status_and_url() {
button: None,
};
let mut m = connected();
m.on_failed(&failed(Some(LoginRefusal::World(0x1c)), false));
m.on_failed(&failed(Some(LoginRefusal::World(0x1c))));
m.tick();
settle(&mut m);
assert_eq!(
@@ -325,7 +324,7 @@ fn a_world_refusal_opens_its_status_and_url() {
assert_eq!(m.state, ScreenState::Idle);
let mut m = connected();
m.on_failed(&failed(Some(LoginRefusal::World(0x0d)), false));
m.on_failed(&failed(Some(LoginRefusal::World(0x0d))));
m.tick();
settle(&mut m);
assert_eq!(
@@ -341,7 +340,7 @@ fn a_world_refusal_opens_its_status_and_url() {
);
let mut m = connected();
m.on_failed(&failed(None, false));
m.on_failed(&failed(None));
m.tick();
settle(&mut m);
assert_eq!(
@@ -362,7 +361,7 @@ fn a_world_refusal_opens_its_status_and_url() {
// With no realm held the arm asks for the list (`0x46c06e` → `0x46b8d0` with 1).
let mut m = connected();
m.holder.clear();
m.on_failed(&failed(None, false));
m.on_failed(&failed(None));
m.tick();
settle(&mut m);
assert_eq!(
@@ -613,39 +612,6 @@ fn a_late_roster_reply_is_dropped_unless_it_lands_before_the_tick() {
assert!(m.op.done && m.op.ok);
}
/// A server that wants Warden refuses the roster ask with its words (a terminal login failure):
/// the query completes failed and the next tick opens `OKAY` with them (`0x46c173`), where state 3
/// would otherwise stand on its `CANCEL` dialog for ever. The link is gone.
#[test]
fn a_terminal_failure_fails_the_character_list_query_with_its_words() {
let mut m = fresh();
m.connected = true;
m.get_character_list();
settle(&mut m);
m.park_out.clear();
m.outbox.clear();
m.on_failed(&failed(None, true));
m.tick();
settle(&mut m);
let words = || Text::Raw("test".into());
assert_eq!(
m.outbox,
[
Outgoing::Update {
text: words(),
button: None,
},
Outgoing::Open {
which: "OKAY",
text: Some(words()),
data: None,
},
]
);
assert_eq!(m.state, ScreenState::Idle);
assert!(!m.connected);
}
/// A roster ask that failed on the stream completes the query `CHAR_LIST_FAILED`
/// (`0x5ab300`'s failure leg), which the tick opens as `OKAY`, instead of leaving the retrieving
/// dialog up; one of another link changes nothing.
@@ -1366,7 +1332,7 @@ fn a_world_status_past_the_table_reads_its_number() {
let mut m = fresh();
m.state = ScreenState::Connect;
m.holder = vec![realm("Fake")];
m.on_failed(&failed(Some(LoginRefusal::World(code)), false));
m.on_failed(&failed(Some(LoginRefusal::World(code))));
m.tick();
settle(&mut m);
m.outbox
@@ -1944,7 +1910,7 @@ fn a_failed_logons_dialog_is_pressed_in_state_1() {
m.settle();
m.outbox.clear();
m.login_out.clear();
m.on_failed(&failed(Some(LoginRefusal::Logon(0x04)), false));
m.on_failed(&failed(Some(LoginRefusal::Logon(0x04))));
}
frame(&shared, &mut s);
let m = shared.get();
@@ -2230,7 +2196,7 @@ fn the_stock_login_reaches_the_login_engine_and_shows_its_status() {
assert_eq!(dialog(&app), Some(("CANCEL".into(), connecting)));
app.world_mut()
.write_message(failed(Some(LoginRefusal::Logon(0x04)), false));
.write_message(failed(Some(LoginRefusal::Logon(0x04))));
app.update();
let unknown = vm(&app).global_text("LOGIN_UNKNOWN_ACCOUNT");
assert!(!unknown.is_empty());
@@ -2433,16 +2399,9 @@ fn pump(
lists.write(RealmListMessage { realms, failed });
}
E::LoginFailed {
refusal,
reason,
terminal,
..
refusal, reason, ..
} => {
failures.write(LoginFailedMessage {
refusal,
reason,
terminal,
});
failures.write(LoginFailedMessage { refusal, reason });
}
E::CharacterList {
characters,
+1 -3
View File
@@ -164,12 +164,10 @@ pub enum SessionEvent {
position: Option<u32>,
realm: Option<String>,
},
/// A login failed before the roster; `refusal` is `None` for a transport failure. A `terminal`
/// one ([`crate::WardenRequired`]) no retry can fix: show `reason` and stop.
/// A login failed before the roster; `refusal` is `None` for a transport failure.
LoginFailed {
refusal: Option<LoginRefusal>,
reason: String,
terminal: bool,
/// `Some` only when the socket never opened: which dial failure, and the address.
dial: Option<crate::DialFailure>,
},
+2 -2
View File
@@ -20,8 +20,8 @@ pub use messages::{
CHARACTER_FLAG_HIDE_CLOAK, CHARACTER_FLAG_HIDE_HELM, CHARACTER_FLAG_RENAME,
};
pub use world::{
observe_sends, SendObserver, Unparsed, WardenRequired, WorldAuthReject, WorldConnectEvent,
WorldReader, WorldSession, WorldWriter, WORLD_PORT,
observe_sends, SendObserver, Unparsed, WorldAuthReject, WorldConnectEvent, WorldReader,
WorldSession, WorldWriter, WORLD_PORT,
};
use std::net::{SocketAddr, TcpStream};
@@ -69,9 +69,8 @@ pub const CMSG_SET_FACTION_INACTIVE: u16 = 0x0317; // 791
pub const CMSG_SET_WATCHED_FACTION: u16 = 0x0318; // 792
pub const SMSG_AUTH_CHALLENGE: u16 = 0x01EC;
pub const SMSG_AUTH_RESPONSE: u16 = 0x01EE;
/// The Warden anticheat challenge; vmangos kicks a client that leaves it unanswered for 30 s
/// (`Warden::Update`). Deviation: benilla cannot run a Warden module, so the connect refuses such
/// a server; [`crate::WardenRequired`] says why.
/// The Warden anticheat channel, which the reference hands to its Warden module (`0x6ca5c0`).
/// benilla runs none and reads it past unanswered ([`crate::WorldSession::warden_asked`]).
pub const SMSG_WARDEN_DATA: u16 = 0x02E6;
/// The answer to `CMSG_AUTH_SESSION`'s addon block: one record per `## Secure:` addon, in order,
/// with no count or names.
+1 -1
View File
@@ -19,7 +19,7 @@ mod session;
mod writer;
pub use reader::WorldReader;
pub use session::{WardenRequired, WorldAuthReject, WorldConnectEvent, WorldSession};
pub use session::{WorldAuthReject, WorldConnectEvent, WorldSession};
pub use writer::WorldWriter;
+34 -45
View File
@@ -18,15 +18,6 @@ const HANDSHAKE_READ_TIMEOUT: std::time::Duration = std::time::Duration::from_se
/// waits forever; a bound tells a server that died mid-queue from a long wait.
const QUEUE_READ_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(300);
/// The server requires Warden. Deviation: benilla cannot answer it. The answers come from a module,
/// native Win32 x86 code the server sends, which the client maps, links and runs in its own
/// process (`0x7a79d0`); the client itself parses none of the payload (`0x6ca5c0`). benilla runs no
/// such code on any platform, so it has nothing that could answer. vmangos ships Warden off
/// (`Warden.WinEnabled`, `Warden.OSXEnabled`) and kicks a client that leaves a request unanswered
/// for 30 s (`Warden.cpp`), so the connect refuses rather than log in to be kicked.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct WardenRequired;
/// The world server refused the session. Its code is from `messages`' `AUTH_*` block, not
/// [`crate::AuthReject`]'s, whose numbers overlap with unrelated meanings.
#[derive(Debug, Clone, Copy)]
@@ -46,17 +37,6 @@ impl std::fmt::Display for WorldAuthReject {
impl std::error::Error for WorldAuthReject {}
impl std::fmt::Display for WardenRequired {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"this server requires the Warden anticheat, which benilla does not implement"
)
}
}
impl std::error::Error for WardenRequired {}
/// An authenticated world-server session with 1.12 header obfuscation active.
pub struct WorldSession {
stream: TcpStream,
@@ -84,6 +64,9 @@ pub(super) struct LinkFacts {
/// (`WorldSocket.cpp:446-448`), and the reference applies it to add-on records that outlive
/// the world session (`0x5b4260` → `0x51da70`), so every login on the link reads it.
addon_info: Option<Vec<messages::AddonRecord>>,
/// The server sent `SMSG_WARDEN_DATA` before the world entry, which was read past
/// ([`WorldSession::recv`]).
warden_asked: bool,
}
/// What a world connect reports on its way to `SMSG_AUTH_RESPONSE`.
@@ -162,7 +145,7 @@ impl WorldSession {
tutorial_flags: None,
};
// AUTH_RESPONSE is not always first, so others are skipped; Warden data ends the connect.
// AUTH_RESPONSE is not always first, so others are skipped.
loop {
match session.recv()? {
ServerPacket::AuthResponse {
@@ -193,9 +176,6 @@ impl WorldSession {
ServerPacket::AuthResponse { result, .. } => {
return Err(WorldAuthReject { code: result }.into())
}
ServerPacket::Other {
opcode: opcode::SMSG_WARDEN_DATA,
} => return Err(WardenRequired.into()),
_ => continue,
}
}
@@ -230,12 +210,27 @@ impl WorldSession {
pub fn recv(&mut self) -> Result<ServerPacket> {
let packet = recv_packet(&mut self.stream, Some(self.crypto.decrypter()))?;
// `SMSG_ADDON_INFO` can reach any of the handshake's read loops, so it is caught here.
if let ServerPacket::AddonInfo { records } = &packet {
self.link.addon_info = Some(records.clone());
match &packet {
ServerPacket::AddonInfo { records } => self.link.addon_info = Some(records.clone()),
// Deviation: benilla runs no Warden module and answers nothing, where the reference
// hands `SMSG_WARDEN_DATA` to the module its connect loads (`0x6ca2f0`, `0x6ca5c0`)
// and sends that module's answer as `CMSG_WARDEN_DATA` (`0x6ca6a0`). The message is
// read past like any stray and the login goes on; what follows is the server's policy
// (vmangos kicks after `Warden.ClientResponseDelay`, `Warden.cpp:686-691`).
ServerPacket::Other {
opcode: opcode::SMSG_WARDEN_DATA,
} => self.link.warden_asked = true,
_ => {}
}
Ok(packet)
}
/// Whether the server sent `SMSG_WARDEN_DATA` on this link before the world entry, which
/// was read past unanswered ([`Self::recv`]).
pub fn warden_asked(&self) -> bool {
self.link.warden_asked
}
/// The next packet a request at character select reads past, or `None` for one whose body did
/// not parse: skipped, as the world stream skips it ([`WorldReader::poll`]), since back from
/// the world the link still carries what the world session left in flight (a pong, a reply
@@ -276,7 +271,7 @@ impl WorldSession {
self.link.roster_races = characters.iter().map(|c| (c.guid, c.race)).collect();
return Ok(characters);
}
other => self.note_stray(other)?,
other => self.note_stray(other),
}
}
}
@@ -295,10 +290,12 @@ impl WorldSession {
.context("restoring the world socket")?;
match peeked {
Ok(0) => bail!("world stream closed: the server ended the connection"),
Ok(_) => match self.recv_parsed()? {
Some(packet) => self.note_stray(packet),
None => Ok(()),
},
Ok(_) => {
if let Some(packet) = self.recv_parsed()? {
self.note_stray(packet);
}
Ok(())
}
Err(e)
if matches!(
e.kind(),
@@ -311,20 +308,12 @@ impl WorldSession {
}
}
/// A packet at character select that is not the answer being waited for. Warden can arm on
/// either side of SMSG_AUTH_RESPONSE, so this step refuses it too; the tutorial bank is kept
/// for the world entry when the server sends it this early; the account-data / cache packets
/// the server interleaves here are skipped.
fn note_stray(&mut self, packet: ServerPacket) -> Result<()> {
match packet {
ServerPacket::Other {
opcode: opcode::SMSG_WARDEN_DATA,
} => Err(WardenRequired.into()),
ServerPacket::TutorialFlags(flags) => {
self.tutorial_flags = Some(flags.bytes);
Ok(())
}
_ => Ok(()),
/// A packet at character select that is not the answer being waited for: the tutorial bank
/// is kept for the world entry when the server sends it this early; the account-data, cache
/// and Warden packets the server interleaves here are skipped.
fn note_stray(&mut self, packet: ServerPacket) {
if let ServerPacket::TutorialFlags(flags) = packet {
self.tutorial_flags = Some(flags.bytes);
}
}
+7 -11
View File
@@ -1,13 +1,12 @@
//! The world handshake over a real socket against a fake server: packets may precede
//! `SMSG_AUTH_RESPONSE`. Deviation: `SMSG_WARDEN_DATA` refuses the login, because benilla cannot
//! run a Warden module (`WardenRequired` says why) and the server kicks a silent client 30 s later.
//! `SMSG_AUTH_RESPONSE`, `SMSG_WARDEN_DATA` among them, which benilla reads past unanswered.
use std::io::{Read, Write};
use std::net::{TcpListener, TcpStream};
use std::thread;
use benilla_protocol::messages::opcode;
use benilla_protocol::{messages, WardenRequired, WorldSession};
use benilla_protocol::{messages, WorldSession};
use benilla_srp::vanilla_header::HeaderCrypto;
use benilla_srp::SESSION_KEY_LENGTH;
@@ -83,16 +82,13 @@ fn packets_ahead_of_the_auth_response_are_skipped() {
assert!(WorldSession::connect(&addr, "one", SESSION_KEY).is_ok());
}
/// A Warden request ahead of the auth response is read past, unanswered, and the connect
/// completes; the session remembers it was asked.
#[test]
fn a_warden_server_is_refused_at_the_handshake() {
fn warden_data_ahead_of_the_auth_response_is_read_past() {
let addr = fake_server(vec![(opcode::SMSG_WARDEN_DATA, vec![0u8; 16])]);
let Err(err) = WorldSession::connect(&addr, "one", SESSION_KEY) else {
panic!("a Warden server must not yield a session");
};
assert!(
err.downcast_ref::<WardenRequired>().is_some(),
"expected WardenRequired, got: {err:#}"
);
let session = WorldSession::connect(&addr, "one", SESSION_KEY).expect("the connect completes");
assert!(session.warden_asked());
}
/// Every packet the observer saw, with the thread that wrote it: the tests of this file share one
+9 -10
View File
@@ -34,7 +34,7 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
- [benilla-blp](#benilla-blp): 1
- [benilla-formats](#benilla-formats): 17
- [benilla-lua](#benilla-lua): 3
- [benilla-protocol](#benilla-protocol): 21
- [benilla-protocol](#benilla-protocol): 20
- [benilla-srp](#benilla-srp): 2
- [benilla-ui](#benilla-ui): 112
- [benilla-world](#benilla-world): 46
@@ -164,8 +164,8 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
#### net
- The reference loads the world first and logs in after: the entry's first frame starts the load at the record's map and position (`0x401570`, called at `0x46c236`), and a later one, once its file reader is idle (`0x46c247`), sends the login (`0x46c272`). ([`src/net/io.rs:10`](../crates/benilla-app/src/net/io.rs#L10))
- The reference re-dials only from `RequestRealmList`, and only when the link is down (`[CLoginMgr+5]` clear, `0x5ab857` → `0x5b2200`), with the reconnect challenge (`0x5b2134`, `[Logon+0xc]`); the connect's query sends only on a link in state 6 (`0x5bc14c`) and otherwise nothing, leaving the screen on its connecting dialog for good. ([`src/net/io.rs:399`](../crates/benilla-app/src/net/io.rs#L399))
- The reference's guard at `0x537e85` sends 0 whenever the write index is 0, one ping in sixteen; we send 0 only before the first pong, because the rest is an artefact of its index arithmetic that only the server stores. ([`src/net/io.rs:1169`](../crates/benilla-app/src/net/io.rs#L1169))
- The reference re-dials only from `RequestRealmList`, and only when the link is down (`[CLoginMgr+5]` clear, `0x5ab857` → `0x5b2200`), with the reconnect challenge (`0x5b2134`, `[Logon+0xc]`); the connect's query sends only on a link in state 6 (`0x5bc14c`) and otherwise nothing, leaving the screen on its connecting dialog for good. ([`src/net/io.rs:397`](../crates/benilla-app/src/net/io.rs#L397))
- The reference's guard at `0x537e85` sends 0 whenever the write index is 0, one ping in sixteen; we send 0 only before the first pong, because the rest is an artefact of its index arithmetic that only the server stores. ([`src/net/io.rs:1158`](../crates/benilla-app/src/net/io.rs#L1158))
- The reference places collision and culling by the raw facing, ours follow the display facing, because a capsule and a sphere barely change under rotation. ([`src/net/motion/facing.rs:9`](../crates/benilla-app/src/net/motion/facing.rs#L9))
- The reference paces a self move through the same replay chain as a remote's, which would only delay a correction to our own pose. ([`src/net/motion/remote.rs:55`](../crates/benilla-app/src/net/motion/remote.rs#L55))
- Its rate-limited hover climb (`0x636fa1`, 7 yd/s) is not reproduced, because the cache gate needs a pure function; it converges to this answer. ([`src/net/motion/spline.rs:568`](../crates/benilla-app/src/net/motion/spline.rs#L568))
@@ -412,7 +412,7 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
- The reference then re-reads the aspect (`0x492f13`), and on a change of 0.001 or more calls `0x491380`, which sets the reload trigger (`[0xb4b3f4]`) when the script-context check `0x494a50(0xa)` allows it; here a resize re-lays out the live UI, the chat bubbles' window-derived `BubbleGeometry` with it, because the window resizes freely and a reload on each resize would tear down every addon's state mid-play. ([`src/ui_script/extract/mod.rs:522`](../crates/benilla-app/src/ui_script/extract/mod.rs#L522))
- The V-plate border is resampled sharp to the quad's physical size rather than GPU-magnified, so its 1 px bevel stays crisp; keyed by that size, so only a resize re-rasterises it. ([`src/ui_script/extract/mod.rs:1390`](../crates/benilla-app/src/ui_script/extract/mod.rs#L1390))
- No signature or digest check (`0x46a90b`, `0x46a9d3`, `0x401560(9)`), so the chain's toc always loads and `FRAMES_LOADED` follows, because the check verifies Blizzard's signature with a key carried in the client binary, which benilla does not ship, and a modified interface file is loaded rather than refused. ([`src/ui_script/glue.rs:14`](../crates/benilla-app/src/ui_script/glue.rs#L14))
- The reference's handler completes whichever operation is current; here only the character list's does, in state 3, and a reply of another cause (a roster nothing of the screen asked for) or of another link (before a realm change) completes nothing. ([`src/ui_script/glue_mgr.rs:1386`](../crates/benilla-app/src/ui_script/glue_mgr.rs#L1386))
- The reference's handler completes whichever operation is current; here only the character list's does, in state 3, and a reply of another cause (a roster nothing of the screen asked for) or of another link (before a realm change) completes nothing. ([`src/ui_script/glue_mgr.rs:1362`](../crates/benilla-app/src/ui_script/glue_mgr.rs#L1362))
- The files are under `benilla-config/Logs/`, since the install is read-only. ([`src/ui_script/load_log.rs:5`](../crates/benilla-app/src/ui_script/load_log.rs#L5))
- `FULLSCREEN_QUADS_RESEAT` re-sizes the full-screen quads, which the stock files size only in their OnLoads, because a resize here keeps the loaded UI and the blackout would stop short of the new screen. ([`src/ui_script/manifest.rs:64`](../crates/benilla-app/src/ui_script/manifest.rs#L64))
- No `FrameXML.toc` signature check, where `UI_Init` loads on a failed one and then quits (`0x401560(0xa)` at `0x48ff90`), because the check verifies Blizzard's signature with a key carried in the client binary, which benilla does not ship, and a modified interface file is loaded rather than refused. ([`src/ui_script/manifest.rs:161`](../crates/benilla-app/src/ui_script/manifest.rs#L161))
@@ -559,7 +559,7 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
#### events
- `benilla::spell_mods` refuses an out-of-range pair, because the reference would overrun it. ([`src/events.rs:671`](../crates/benilla-protocol/src/events.rs#L671))
- `benilla::spell_mods` refuses an out-of-range pair, because the reference would overrun it. ([`src/events.rs:669`](../crates/benilla-protocol/src/events.rs#L669))
#### examples
@@ -575,8 +575,7 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
- Zone and position are kept, not set to the viewer's zone and the object's position, because nothing in benilla reads them. ([`src/messages/group.rs:255`](../crates/benilla-protocol/src/messages/group.rs#L255))
- String reads are unbounded. The reference `0x4191b0` caps each field, counting the NUL (roster name `0x30`, notes `0x80`, MOTD `0x200`, info `0x7d0`, guild name `0x60`, rank name `0x40`), and on overflow empties it and no-ops every later read in the packet. ([`src/messages/guild.rs:4`](../crates/benilla-protocol/src/messages/guild.rs#L4))
- A reason of 3 or more is silent, where the reference prints an uninitialized stack buffer, because 3 is the server's `INSTANCERESET_FAIL_SILENTLY`. ([`src/messages/instance.rs:70`](../crates/benilla-protocol/src/messages/instance.rs#L70))
- Benilla cannot run a Warden module, so the connect refuses such a server; `crate::WardenRequired` says why. ([`src/messages/opcode.rs:73`](../crates/benilla-protocol/src/messages/opcode.rs#L73))
- 2 or more prints nothing, because the reference prints an uninitialized buffer. ([`src/messages/opcode.rs:1003`](../crates/benilla-protocol/src/messages/opcode.rs#L1003))
- 2 or more prints nothing, because the reference prints an uninitialized buffer. ([`src/messages/opcode.rs:1002`](../crates/benilla-protocol/src/messages/opcode.rs#L1002))
- The consumer refuses 64 and up, because there the reference's store overruns its table. ([`src/messages/packet.rs:607`](../crates/benilla-protocol/src/messages/packet.rs#L607))
- A body too short for the position gives `None` where the client redisplays a stale global, because showing a stale queue position as current is a client bug. ([`src/messages/parse.rs:295`](../crates/benilla-protocol/src/messages/parse.rs#L295))
- A type outside 1-7 reads as nothing rather than the reference's default arm, which under-pushes its returns. ([`src/messages/pet.rs:75`](../crates/benilla-protocol/src/messages/pet.rs#L75))
@@ -585,9 +584,9 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
#### world
- The reference waits forever; a bound tells a server that died mid-queue from a long wait. ([`src/world/session.rs:17`](../crates/benilla-protocol/src/world/session.rs#L17))
- Benilla cannot answer it. The answers come from a module, native Win32 x86 code the server sends, which the client maps, links and runs in its own process (`0x7a79d0`); the client itself parses none of the payload (`0x6ca5c0`). benilla runs no such code on any platform, so it has nothing that could answer. vmangos ships Warden off (`Warden.WinEnabled`, `Warden.OSXEnabled`) and kicks a client that leaves a request unanswered for 30 s (`Warden.cpp`), so the connect refuses rather than log in to be kicked. ([`src/world/session.rs:21`](../crates/benilla-protocol/src/world/session.rs#L21))
- `0` when the body is too short, where the reference leaves its global as it was; this field lives per connection, with nothing earlier to keep. ([`src/world/session.rs:78`](../crates/benilla-protocol/src/world/session.rs#L78))
- Checked per queue packet where the reference checks each tick, so a cancel can lag one server update. ([`src/world/session.rs:111`](../crates/benilla-protocol/src/world/session.rs#L111))
- `0` when the body is too short, where the reference leaves its global as it was; this field lives per connection, with nothing earlier to keep. ([`src/world/session.rs:58`](../crates/benilla-protocol/src/world/session.rs#L58))
- Checked per queue packet where the reference checks each tick, so a cancel can lag one server update. ([`src/world/session.rs:94`](../crates/benilla-protocol/src/world/session.rs#L94))
- Benilla runs no Warden module and answers nothing, where the reference hands `SMSG_WARDEN_DATA` to the module its connect loads (`0x6ca2f0`, `0x6ca5c0`) and sends that module's answer as `CMSG_WARDEN_DATA` (`0x6ca6a0`). ([`src/world/session.rs:215`](../crates/benilla-protocol/src/world/session.rs#L215))
### benilla-srp
#### (crate root)