Auto-reconnect: never after account session refusals, retry when session servers are down

Classifies the online-mode login outcomes from #161: invalid session,
banned from playing online, multiplayer disabled, no account signed in
and the server failing to verify the username are never retried;
unreachable session servers (the client's or the server's) are. A retry
of an online-mode server joins with the account held in memory for the
whole run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-14 22:41:14 +02:00
parent 5797cf2702
commit ce9c1d3a5c
3 changed files with 58 additions and 9 deletions
+4 -1
View File
@@ -129,7 +129,10 @@ impl Game<'_> {
*slot = Some(retry);
}
}
/// Auto-reconnect: connect again once the countdown is over.
/// Auto-reconnect: connect again once the countdown is over. An
/// online-mode server gets the signed-in account again: `connect_server`
/// takes it from `auth::current()`, held in memory for the whole run
/// (the launcher's session file is gone after the first read).
pub(super) fn extras_retry(&mut self) -> horizon_client::Result<()> {
if let Some(retry) = self.title.as_mut().and_then(|t| t.due_retry()) {
self.connect_server(&retry.address, &retry.name)?;
+46 -4
View File
@@ -13,8 +13,11 @@ pub const STABLE: Duration = Duration::from_secs(60);
/// permanent refusal) gave `reason`, rather than the connection failing.
pub fn allowed(reason: &str, from_server: bool) -> bool {
let r = reason.to_lowercase();
// Kicks, bans, whitelists, version and session refusals: never.
const NEVER: [&str; 9] = [
// Kicks, bans, whitelists, version refusals and the account's session
// refusals (`disconnect.loginFailedInfo.*` but the unreachable session
// servers, the server's failed username check, joining an online-mode
// server without an account): never.
const NEVER: [&str; 13] = [
"ban",
"kick",
"white-list",
@@ -24,6 +27,10 @@ pub fn allowed(reason: &str, from_server: bool) -> bool {
"another location",
"online mode",
"invalid server address",
"invalid session",
"multiplayer is disabled",
"failed to verify username",
"microsoft account",
];
if NEVER.iter().any(|w| r.contains(w)) {
return false;
@@ -32,12 +39,14 @@ pub fn allowed(reason: &str, from_server: bool) -> bool {
return true;
}
// The server going away for a while: vanilla's shutdown and time-out
// reasons, a full server, a slow login, and restart messages.
const RETRY: [&str; 5] = [
// reasons, a full server, a slow login, the server's own session
// servers being down, and restart messages.
const RETRY: [&str; 6] = [
"server closed",
"timed out",
"the server is full",
"took too long to log in",
"authentication servers",
"restart",
];
RETRY.iter().any(|w| r.contains(w))
@@ -157,6 +166,39 @@ mod tests {
assert!(!allowed("Kicked for spamming", false));
}
#[test]
fn online_mode_login_failures() {
// The client's join with the session service (net.rs: Err, with
// vanilla's disconnect.loginFailedInfo texts).
let failed = |why: &str| format!("Failed to log in: {why}");
assert!(!allowed(
&failed("Invalid session (Try restarting your game and the launcher)"),
false
));
assert!(!allowed(
&failed("You are banned from playing online"),
false
));
assert!(!allowed(
&failed("Multiplayer is disabled. Please check your Microsoft account settings."),
false
));
assert!(!allowed(crate::net::NOT_SIGNED_IN, false));
// Unreachable session servers are worth another try.
assert!(allowed(
&failed("The authentication servers are currently not reachable. Please try again."),
false
));
assert!(allowed(&failed("Connection timed out"), false));
// The server's side: its username check failed, or its session
// servers are down.
assert!(!allowed("Failed to verify username!", true));
assert!(allowed(
"Authentication servers are down. Please try again later. Sorry!",
true
));
}
#[test]
fn attempts_back_off_and_stop() {
let mut t = Tracker::default();
+8 -4
View File
@@ -85,10 +85,14 @@ Horizon category in Controls, and adding one would put a non-vanilla mapping int
- Backoff 5, 10, 20, 40, 60 s; at most 5 attempts, then it stops. The count
only resets after staying connected for a minute, so a server that drops
players at once never causes an endless loop.
- Never after a kick, a ban, a whitelist or version refusal, a duplicate login
or an online-mode refusal: only lost connections (errors, time-outs, refused
connections while the server restarts) and the server's own "Server closed"
shutdown reason.
- Never after a kick, a ban, a whitelist or version refusal, a duplicate login,
an online-mode refusal (no account signed in), or a session refusal from the
account's login (invalid session, banned from playing online, multiplayer
disabled, the server failing to verify the username). Unreachable session
servers, on either side, are retried with the same backoff.
- Online-mode servers: the retry joins with the account the game signed in
with, held in memory for the whole run (`auth::current()`); nothing is
written to disk.
## Shared rules