From 0c30138d26e8192468507b12683daf32e8fdbc29 Mon Sep 17 00:00:00 2001 From: EightFactorial Date: Fri, 6 Jan 2023 16:30:55 -0800 Subject: [PATCH] Add reason for disconnect (#54) * Add reason for disconnect Handles messages like "The server is full!" and "Banned by an operator." Ban reasons are shown like "You are banned from this server.\nReason: foo" * keep the kick reason as a Component in the error Co-authored-by: mat --- azalea-client/src/client.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index 4282df46..dbb1b71e 100644 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -1,6 +1,7 @@ pub use crate::chat::ChatPacket; use crate::{movement::WalkDirection, plugins::PluginStates, Account, PlayerInfo}; use azalea_auth::{game_profile::GameProfile, sessionserver::SessionServerError}; +use azalea_chat::Component; use azalea_core::{ChunkPos, ResourceLocation, Vec3}; use azalea_protocol::{ connect::{Connection, ConnectionError, ReadConnection, WriteConnection}, @@ -145,6 +146,8 @@ pub enum JoinError { InvalidAddress, #[error("Couldn't refresh access token: {0}")] Auth(#[from] azalea_auth::AuthError), + #[error("Disconnected: {reason}")] + Disconnect { reason: Component }, } #[derive(Error, Debug)] @@ -346,6 +349,7 @@ impl Client { } ClientboundLoginPacket::LoginDisconnect(p) => { debug!("Got disconnect {:?}", p); + return Err(JoinError::Disconnect { reason: p.reason }); } ClientboundLoginPacket::CustomQuery(p) => { debug!("Got custom query {:?}", p);