mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
backtraces + fix clientbound chat message
This commit is contained in:
parent
fb158bab4b
commit
c6d2d41807
11 changed files with 59 additions and 40 deletions
|
@ -9,10 +9,10 @@ version = "0.3.0"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
azalea-buf-macros = {path = "./azalea-buf-macros", version = "^0.3.0" }
|
||||
azalea-buf-macros = {path = "./azalea-buf-macros", version = "^0.3.0"}
|
||||
byteorder = "^1.4.3"
|
||||
serde_json = {version = "^1.0", optional = true}
|
||||
thiserror = "^1.0.34"
|
||||
thiserror = "1.0.37"
|
||||
tokio = {version = "^1.19.2", features = ["io-util", "net", "macros"]}
|
||||
uuid = "^1.1.2"
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use super::{UnsizedByteArray, MAX_STRING_LENGTH};
|
||||
use byteorder::{ReadBytesExt, BE};
|
||||
use std::{
|
||||
backtrace::Backtrace,
|
||||
collections::HashMap,
|
||||
hash::Hash,
|
||||
io::{Cursor, Read},
|
||||
|
@ -17,12 +18,12 @@ pub enum BufReadError {
|
|||
CouldNotReadBytes,
|
||||
#[error("The received encoded string buffer length is longer than maximum allowed ({length} > {max_length})")]
|
||||
StringLengthTooLong { length: u32, max_length: u32 },
|
||||
#[error("{0}")]
|
||||
Io(
|
||||
#[error("{source}")]
|
||||
Io {
|
||||
#[from]
|
||||
#[backtrace]
|
||||
std::io::Error,
|
||||
),
|
||||
source: std::io::Error,
|
||||
backtrace: Backtrace,
|
||||
},
|
||||
#[error("Invalid UTF-8")]
|
||||
InvalidUtf8,
|
||||
#[error("Unexpected enum variant {id}")]
|
||||
|
@ -37,8 +38,12 @@ pub enum BufReadError {
|
|||
#[error("{0}")]
|
||||
Custom(String),
|
||||
#[cfg(feature = "serde_json")]
|
||||
#[error("{0}")]
|
||||
Deserialization(#[from] serde_json::Error),
|
||||
#[error("{source}")]
|
||||
Deserialization {
|
||||
#[from]
|
||||
source: serde_json::Error,
|
||||
backtrace: Backtrace,
|
||||
},
|
||||
}
|
||||
|
||||
fn read_bytes<'a>(buf: &'a mut Cursor<&[u8]>, length: usize) -> Result<&'a [u8], BufReadError> {
|
||||
|
|
|
@ -257,6 +257,7 @@ impl<'de> Deserialize<'de> for Component {
|
|||
impl McBufReadable for Component {
|
||||
fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
|
||||
let string = String::read_from(buf)?;
|
||||
println!("string: {}", string);
|
||||
let json: serde_json::Value = serde_json::from_str(string.as_str())?;
|
||||
let component = Component::deserialize(json)?;
|
||||
Ok(component)
|
||||
|
|
|
@ -3,23 +3,23 @@ description = "A headless Minecraft client."
|
|||
edition = "2021"
|
||||
license = "MIT"
|
||||
name = "azalea-client"
|
||||
version = "0.3.0"
|
||||
repository = "https://github.com/mat-1/azalea/tree/main/azalea-client"
|
||||
version = "0.3.0"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.59"
|
||||
azalea-auth = { path = "../azalea-auth", version = "0.3.0" }
|
||||
azalea-block = { path = "../azalea-block", version = "0.3.0" }
|
||||
azalea-chat = { path = "../azalea-chat", version = "0.3.0" }
|
||||
azalea-core = { path = "../azalea-core", version = "0.3.0" }
|
||||
azalea-crypto = { path = "../azalea-crypto", version = "0.3.0" }
|
||||
azalea-physics = { path = "../azalea-physics", version = "0.3.0" }
|
||||
azalea-protocol = { path = "../azalea-protocol", version = "0.3.0" }
|
||||
azalea-world = { path = "../azalea-world", version = "0.3.0" }
|
||||
azalea-auth = {path = "../azalea-auth", version = "0.3.0"}
|
||||
azalea-block = {path = "../azalea-block", version = "0.3.0"}
|
||||
azalea-chat = {path = "../azalea-chat", version = "0.3.0"}
|
||||
azalea-core = {path = "../azalea-core", version = "0.3.0"}
|
||||
azalea-crypto = {path = "../azalea-crypto", version = "0.3.0"}
|
||||
azalea-physics = {path = "../azalea-physics", version = "0.3.0"}
|
||||
azalea-protocol = {path = "../azalea-protocol", version = "0.3.0"}
|
||||
azalea-world = {path = "../azalea-world", version = "0.3.0"}
|
||||
log = "0.4.17"
|
||||
parking_lot = "0.12.1"
|
||||
thiserror = "^1.0.34"
|
||||
tokio = { version = "^1.19.2", features = ["sync"] }
|
||||
thiserror = "1.0.37"
|
||||
tokio = {version = "^1.19.2", features = ["sync"]}
|
||||
uuid = "^1.1.2"
|
||||
|
|
|
@ -32,6 +32,8 @@ use azalea_world::{
|
|||
use log::{debug, error, warn};
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use std::{
|
||||
any,
|
||||
backtrace::Backtrace,
|
||||
fmt::Debug,
|
||||
io::{self, Cursor},
|
||||
sync::Arc,
|
||||
|
@ -299,14 +301,19 @@ impl Client {
|
|||
}
|
||||
},
|
||||
Err(e) => {
|
||||
let default_backtrace = Backtrace::capture();
|
||||
if IGNORE_ERRORS {
|
||||
warn!("{}", e);
|
||||
let backtrace =
|
||||
any::request_ref::<Backtrace>(&e).unwrap_or(&default_backtrace);
|
||||
warn!("{e}\n{backtrace}");
|
||||
match e {
|
||||
ReadPacketError::FrameSplitter { .. } => panic!("Error: {e:?}"),
|
||||
_ => continue,
|
||||
}
|
||||
} else {
|
||||
panic!("{}", e);
|
||||
let backtrace =
|
||||
any::request_ref::<Backtrace>(&e).unwrap_or(&default_backtrace);
|
||||
panic!("{e}\n{backtrace}")
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
//! [`azalea_protocol`]: https://crates.io/crates/azalea-protocol
|
||||
//! [`azalea`]: https://crates.io/crates/azalea
|
||||
|
||||
#![feature(provide_any)]
|
||||
|
||||
mod account;
|
||||
mod chat;
|
||||
mod client;
|
||||
|
|
|
@ -3,25 +3,25 @@ description = "Send and receive Minecraft packets."
|
|||
edition = "2021"
|
||||
license = "MIT"
|
||||
name = "azalea-protocol"
|
||||
version = "0.3.0"
|
||||
repository = "https://github.com/mat-1/azalea/tree/main/azalea-protocol"
|
||||
version = "0.3.0"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
async-compression = {version = "^0.3.8", features = ["tokio", "zlib"], optional = true}
|
||||
async-recursion = "1.0.0"
|
||||
azalea-auth = {path = "../azalea-auth", version = "^0.3.0" }
|
||||
azalea-block = {path = "../azalea-block", default-features = false, version = "^0.3.0" }
|
||||
azalea-brigadier = {path = "../azalea-brigadier", version = "^0.3.0" }
|
||||
azalea-buf = {path = "../azalea-buf", version = "^0.3.0" }
|
||||
azalea-chat = {path = "../azalea-chat", version = "^0.3.0" }
|
||||
azalea-core = {path = "../azalea-core", optional = true, version = "^0.3.0" }
|
||||
azalea-crypto = {path = "../azalea-crypto", version = "^0.3.0" }
|
||||
azalea-nbt = {path = "../azalea-nbt", version = "^0.3.0" }
|
||||
azalea-protocol-macros = {path = "./azalea-protocol-macros", version = "^0.3.0" }
|
||||
azalea-registry = {path = "../azalea-registry", version = "^0.3.0" }
|
||||
azalea-world = {path = "../azalea-world", version = "^0.3.0" }
|
||||
azalea-auth = {path = "../azalea-auth", version = "^0.3.0"}
|
||||
azalea-block = {path = "../azalea-block", default-features = false, version = "^0.3.0"}
|
||||
azalea-brigadier = {path = "../azalea-brigadier", version = "^0.3.0"}
|
||||
azalea-buf = {path = "../azalea-buf", version = "^0.3.0"}
|
||||
azalea-chat = {path = "../azalea-chat", version = "^0.3.0"}
|
||||
azalea-core = {path = "../azalea-core", optional = true, version = "^0.3.0"}
|
||||
azalea-crypto = {path = "../azalea-crypto", version = "^0.3.0"}
|
||||
azalea-nbt = {path = "../azalea-nbt", version = "^0.3.0"}
|
||||
azalea-protocol-macros = {path = "./azalea-protocol-macros", version = "^0.3.0"}
|
||||
azalea-registry = {path = "../azalea-registry", version = "^0.3.0"}
|
||||
azalea-world = {path = "../azalea-world", version = "^0.3.0"}
|
||||
byteorder = "^1.4.3"
|
||||
bytes = "^1.1.0"
|
||||
flate2 = "1.0.23"
|
||||
|
@ -30,7 +30,7 @@ futures-util = "0.3.24"
|
|||
log = "0.4.17"
|
||||
serde = {version = "1.0.130", features = ["serde_derive"]}
|
||||
serde_json = "^1.0.72"
|
||||
thiserror = "^1.0.34"
|
||||
thiserror = "1.0.37"
|
||||
tokio = {version = "^1.19.2", features = ["io-util", "net", "macros"]}
|
||||
tokio-util = {version = "0.7.4", features = ["codec"]}
|
||||
trust-dns-resolver = "^0.20.3"
|
||||
|
|
|
@ -224,6 +224,7 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
|
|||
let data = #module::#name::read(buf).map_err(|e| crate::read::ReadPacketError::Parse {
|
||||
source: e,
|
||||
packet_id: #id,
|
||||
backtrace: std::backtrace::Backtrace::capture(),
|
||||
packet_name: #name_litstr.to_string(),
|
||||
})?;
|
||||
#[cfg(debug_assertions)]
|
||||
|
@ -256,6 +257,7 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
|
|||
let data = #module::#name::read(buf).map_err(|e| crate::read::ReadPacketError::Parse {
|
||||
source: e,
|
||||
packet_id: #id,
|
||||
backtrace: std::backtrace::Backtrace::capture(),
|
||||
packet_name: #name_litstr.to_string(),
|
||||
})?;
|
||||
#[cfg(debug_assertions)]
|
||||
|
|
|
@ -33,7 +33,7 @@ pub struct PackedSignedMessageBody {
|
|||
|
||||
#[derive(Clone, Debug, McBuf)]
|
||||
pub struct PackedLastSeenMessages {
|
||||
pub entries: PackedMessageSignature,
|
||||
pub entries: Vec<PackedMessageSignature>,
|
||||
}
|
||||
|
||||
/// Messages can be deleted by either their signature or message id.
|
||||
|
|
|
@ -22,7 +22,7 @@ pub enum ReadPacketError {
|
|||
Parse {
|
||||
packet_id: u32,
|
||||
packet_name: String,
|
||||
#[backtrace]
|
||||
backtrace: Backtrace,
|
||||
source: BufReadError,
|
||||
},
|
||||
#[error("Unknown packet id {id} in state {state_name}")]
|
||||
|
@ -63,8 +63,8 @@ pub enum FrameSplitterError {
|
|||
#[error("Io error")]
|
||||
Io {
|
||||
#[from]
|
||||
#[backtrace]
|
||||
source: std::io::Error,
|
||||
backtrace: Backtrace,
|
||||
},
|
||||
#[error("Packet is longer than {max} bytes (is {size})")]
|
||||
BadLength { max: usize, size: usize },
|
||||
|
@ -84,7 +84,9 @@ fn parse_frame(buffer: &mut BytesMut) -> Result<BytesMut, FrameSplitterError> {
|
|||
let length = match u32::var_read_from(&mut buffer_copy) {
|
||||
Ok(length) => length as usize,
|
||||
Err(err) => match err {
|
||||
BufReadError::Io(io_err) => return Err(FrameSplitterError::Io { source: io_err }),
|
||||
BufReadError::Io { source, backtrace } => {
|
||||
return Err(FrameSplitterError::Io { source, backtrace })
|
||||
}
|
||||
_ => return Err(err.into()),
|
||||
},
|
||||
};
|
||||
|
|
|
@ -14,7 +14,7 @@ async-trait = "^0.1.57"
|
|||
azalea-client = {version = "0.3.0", path = "../azalea-client"}
|
||||
azalea-protocol = {version = "0.3.0", path = "../azalea-protocol"}
|
||||
parking_lot = "^0.12.1"
|
||||
thiserror = "^1.0.37"
|
||||
thiserror = "1.0.37"
|
||||
tokio = "^1.21.1"
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
Loading…
Add table
Reference in a new issue