aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/raw_connection.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-02-23 17:10:47 +0000
committermat <git@matdoes.dev>2025-02-23 17:10:47 +0000
commit2be4f0f2b66eb7181badec0134c3c3565e3cbd7f (patch)
tree1365332b5ba2ef7e4a6b0e2b187ea1889b2572a3 /azalea-client/src/raw_connection.rs
parent21acf4c84687eb40cb52746bdf40c2bbe9ab325a (diff)
downloadazalea-drasl-2be4f0f2b66eb7181badec0134c3c3565e3cbd7f.tar.xz
make run_schedule a bounded channel
Diffstat (limited to 'azalea-client/src/raw_connection.rs')
-rw-r--r--azalea-client/src/raw_connection.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/azalea-client/src/raw_connection.rs b/azalea-client/src/raw_connection.rs
index 4a6587be..97e93f16 100644
--- a/azalea-client/src/raw_connection.rs
+++ b/azalea-client/src/raw_connection.rs
@@ -10,7 +10,10 @@ use azalea_protocol::{
use bevy_ecs::prelude::*;
use parking_lot::Mutex;
use thiserror::Error;
-use tokio::sync::mpsc::{self, error::SendError};
+use tokio::sync::mpsc::{
+ self,
+ error::{SendError, TrySendError},
+};
use tracing::error;
/// A component for clients that can read and write packets to the server. This
@@ -34,7 +37,7 @@ pub struct RawConnection {
#[derive(Clone)]
pub struct RawConnectionReader {
pub incoming_packet_queue: Arc<Mutex<Vec<Box<[u8]>>>>,
- pub run_schedule_sender: mpsc::UnboundedSender<()>,
+ pub run_schedule_sender: mpsc::Sender<()>,
}
#[derive(Clone)]
pub struct RawConnectionWriter {
@@ -60,7 +63,7 @@ pub enum WritePacketError {
impl RawConnection {
pub fn new(
- run_schedule_sender: mpsc::UnboundedSender<()>,
+ run_schedule_sender: mpsc::Sender<()>,
connection_protocol: ConnectionProtocol,
raw_read_connection: RawReadConnection,
raw_write_connection: RawWriteConnection,
@@ -145,6 +148,9 @@ impl RawConnectionReader {
let mut incoming_packet_queue = self.incoming_packet_queue.lock();
incoming_packet_queue.push(raw_packet);
+ // this makes it so packets received at the same time are guaranteed to be
+ // handled in the same tick. this is also an attempt at making it so we can't
+ // receive any packets in the ticks/updates after being disconnected.
loop {
let raw_packet = match read_conn.try_read() {
Ok(p) => p,
@@ -158,7 +164,7 @@ impl RawConnectionReader {
}
// tell the client to run all the systems
- if self.run_schedule_sender.send(()).is_err() {
+ if self.run_schedule_sender.try_send(()) == Err(TrySendError::Closed(())) {
// the client was dropped
break;
}