Skip to content

Commit

Permalink
fixes unwrap on write_raw_packet(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
1zun4 committed Jan 20, 2024
1 parent fd1c99e commit a8fad57
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions azalea-client/src/raw_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use azalea_protocol::{
use bevy_ecs::prelude::*;
use parking_lot::Mutex;
use thiserror::Error;
use tokio::sync::mpsc;
use tokio::sync::mpsc::{self, error::SendError};
use tracing::error;

/// A component for clients that can read and write packets to the server. This
Expand Down Expand Up @@ -51,6 +51,12 @@ pub enum WritePacketError {
},
#[error(transparent)]
Encoding(#[from] azalea_protocol::write::PacketEncodeError),
#[error(transparent)]
SendError {
#[from]
#[backtrace]
source: SendError<Vec<u8>>,
},
}

impl RawConnection {
Expand Down Expand Up @@ -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
.outgoing_packets_sender
.send(raw_packet)
.unwrap();
.map_err(WritePacketError::from)?;
Ok(())
}

/// Write the packet with the given state to the server.
Expand All @@ -106,7 +113,8 @@ impl RawConnection {
packet: P,
) -> Result<(), WritePacketError> {
let raw_packet = serialize_packet(&packet)?;
self.write_raw_packet(raw_packet);
self.write_raw_packet(raw_packet)?;

Ok(())
}

Expand Down

0 comments on commit a8fad57

Please sign in to comment.