fixes unwrap on write_raw_packet(...) (#128)

This commit is contained in:
1zuna 2024-01-21 00:34:54 +01:00 committed by GitHub
parent fd1c99e74a
commit 73be589e7f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,7 +10,7 @@ use azalea_protocol::{
use bevy_ecs::prelude::*; use bevy_ecs::prelude::*;
use parking_lot::Mutex; use parking_lot::Mutex;
use thiserror::Error; use thiserror::Error;
use tokio::sync::mpsc; use tokio::sync::mpsc::{self, error::SendError};
use tracing::error; use tracing::error;
/// A component for clients that can read and write packets to the server. This /// A component for clients that can read and write packets to the server. This
@ -51,6 +51,12 @@ pub enum WritePacketError {
}, },
#[error(transparent)] #[error(transparent)]
Encoding(#[from] azalea_protocol::write::PacketEncodeError), Encoding(#[from] azalea_protocol::write::PacketEncodeError),
#[error(transparent)]
SendError {
#[from]
#[backtrace]
source: SendError<Vec<u8>>,
},
} }
impl RawConnection { impl RawConnection {
@ -88,11 +94,12 @@ impl RawConnection {
} }
} }
pub fn write_raw_packet(&self, raw_packet: Vec<u8>) { pub fn write_raw_packet(&self, raw_packet: Vec<u8>) -> Result<(), WritePacketError> {
self.writer self.writer
.outgoing_packets_sender .outgoing_packets_sender
.send(raw_packet) .send(raw_packet)
.unwrap(); .map_err(WritePacketError::from)?;
Ok(())
} }
/// Write the packet with the given state to the server. /// Write the packet with the given state to the server.
@ -106,7 +113,8 @@ impl RawConnection {
packet: P, packet: P,
) -> Result<(), WritePacketError> { ) -> Result<(), WritePacketError> {
let raw_packet = serialize_packet(&packet)?; let raw_packet = serialize_packet(&packet)?;
self.write_raw_packet(raw_packet); self.write_raw_packet(raw_packet)?;
Ok(()) Ok(())
} }