Skip to content

Commit

Permalink
more verbose login_disconnect error
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Dec 21, 2024
1 parent 78e5a65 commit 527333f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion azalea-protocol/src/packets/login/c_login_disconnect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError};
use azalea_chat::FormattedText;
use azalea_protocol_macros::ClientboundLoginPacket;
use serde::{Deserialize, Serialize};
use tracing::trace;

#[derive(Clone, Debug, ClientboundLoginPacket)]
pub struct ClientboundLoginDisconnect {
Expand All @@ -13,7 +14,16 @@ pub struct ClientboundLoginDisconnect {
impl AzaleaRead for ClientboundLoginDisconnect {
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<ClientboundLoginDisconnect, BufReadError> {
let disconnect_string = String::azalea_read(buf)?;
let disconnect_json: serde_json::Value = serde_json::from_str(disconnect_string.as_str())?;
trace!("Got disconnect packet with string: {disconnect_string:?}");
let disconnect_json =
match serde_json::from_str::<serde_json::Value>(disconnect_string.as_str()) {
Ok(json) => json,
Err(err) => {
return Err(BufReadError::Custom(format!(
"Failed to deserialize disconnect JSON {disconnect_string:?}: {err}"
)))
}
};

Ok(ClientboundLoginDisconnect {
reason: FormattedText::deserialize(disconnect_json)?,
Expand Down

0 comments on commit 527333f

Please sign in to comment.