diff --git a/protocol/src/lib.rs b/protocol/src/lib.rs index 68c8d09..b1ff03b 100644 --- a/protocol/src/lib.rs +++ b/protocol/src/lib.rs @@ -140,7 +140,12 @@ unsafe impl Send for PlayerNet {} unsafe impl Sync for PlayerNet {} impl PlayerNet { - pub fn new(mut read: OwnedReadHalf, mut write: OwnedWriteHalf, shit: mpsc::Sender<()>) -> Self { + pub fn new( + mut read: OwnedReadHalf, + mut write: OwnedWriteHalf, + shit: mpsc::Sender<()>, + compression: Option, + ) -> Self { let peer_addr = read.peer_addr().expect("no peer address"); let local_addr = read.local_addr().expect("no local address"); diff --git a/protocol/src/model/packets.rs b/protocol/src/model/packets.rs index 7ad8080..1c4e5ce 100644 --- a/protocol/src/model/packets.rs +++ b/protocol/src/model/packets.rs @@ -165,8 +165,8 @@ pub fn err_with_source( ) -> impl FnOnce(Error) -> Error { move |e| match e { Error::Ser(error) => Error::SerSrc(WithSource { - source: BytesSource::new(source(), name), - error, + src: BytesSource::new(source(), name), + errors: vec![error], }), e => e, } diff --git a/protocol/src/ser.rs b/protocol/src/ser.rs index ae23971..13ec04e 100644 --- a/protocol/src/ser.rs +++ b/protocol/src/ser.rs @@ -51,6 +51,20 @@ pub fn any_of(things: &[T]) -> String { } } +pub fn any_of_display(things: &[T]) -> String { + match things { + [el] => format!("{el}"), + elements => format!( + "any of [{}]", + elements + .iter() + .map(ToString::to_string) + .collect::>() + .join(", ") + ), + } +} + #[derive(thiserror::Error, miette::Diagnostic, Debug)] pub enum SerializationError { #[error("expected {}, found {found}", any_of(.expected))] @@ -114,14 +128,12 @@ pub enum SerializationError { } #[derive(thiserror::Error, miette::Diagnostic, Debug)] -#[error("{error}")] +#[error("{}", any_of_display(.errors))] pub struct WithSource { #[source_code] - pub source: BytesSource, - #[diagnostic(transparent)] - #[source] - #[diagnostic_source] - pub error: SerializationError, + pub src: BytesSource, + #[related] + pub errors: Vec>, } #[derive(Debug, Clone)] diff --git a/server/src/main.rs b/server/src/main.rs index a465bff..ef6a986 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -276,7 +276,11 @@ fn listen(net: Res, rt: Res) { let (read, write) = tcp.into_split(); let (shit, mut shit_r) = mpsc::channel(1); - let player = PlayerNet::new(read, write, shit.clone()); + let CompressionThreshold(compress) = t + .run_on_main_thread(|tcx| *tcx.world.resource::()) + .await; + + let player = PlayerNet::new(read, write, shit.clone(), compress); let entity = t .clone() .run_on_main_thread(move |cx| { @@ -372,6 +376,9 @@ fn init_registries( info!(dimension_types=?dimension_types.0, worldgen_biomes=?worldgen_biomes.0, damage_types=?damage_types.0, "successfully initialized registries."); } +#[derive(Resource, Debug, Clone, Copy)] +pub struct CompressionThreshold(pub Option); + #[tokio::main] async fn main() -> Result<(), Report> { tracing_subscriber::registry() @@ -410,6 +417,7 @@ That was my warning, now I wish you good luck debugging your issue."# .init_resource::>() .init_resource::>() .init_resource::>() + .insert_resource(CompressionThreshold(None)) .add_systems(Startup, (init_registries, listen)) .add_systems(Update, on_login) .run();