Skip to content

Commit

Permalink
fix(net): remove reference to io mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
bigspeedfpv committed Nov 28, 2024
1 parent d50cf02 commit 3657072
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/net/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* <https://www.gnu.org/licenses/>.
*/

use std::{cmp::Ordering, sync::Arc};
use std::cmp::Ordering;

use rayon::prelude::*;

Expand Down
37 changes: 16 additions & 21 deletions src/net/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ use thiserror::Error;
use tokio::{
net::TcpStream,
sync::{Mutex, OwnedSemaphorePermit, RwLock},
time::{self, timeout, Instant},
time::{timeout, Instant},
};
use tokio_util::sync::CancellationToken;
use uuid::Uuid;

use crate::{
Expand Down Expand Up @@ -271,8 +270,7 @@ impl SharedPlayer {
data: Bounded(Bytes(&[3])),
};

let mut io = self.0.io.lock().await;
io.tx(&req).await?;
self.0.io.tx(&req).await?;

Ok(())
}
Expand Down Expand Up @@ -503,10 +501,13 @@ impl SharedPlayer {
let mut queue = player.0.frame_queue.lock().await;
queue.push(frame);
}
Err(why) => match why.downcast_ref::<tokio::io::Error>().map(|e| e.kind()) {
Some(tokio::io::ErrorKind::UnexpectedEof) => return,
_ => (),
},
Err(why) => {
if let Some(tokio::io::ErrorKind::UnexpectedEof) =
why.downcast_ref::<tokio::io::Error>().map(|e| e.kind())
{
return;
}
}
}
}
});
Expand All @@ -518,26 +519,20 @@ impl SharedPlayer {
let packet: SetPlayerPositionS = frame.decode()?;

let tp_state = self.0.tp_state.read().await;
match *tp_state {
TeleportState::Clear => {
let mut entity = self.0.entity.write().await;
entity.reposition(packet.x, packet.feet_y, packet.z);
}
_ => (),
if *tp_state == TeleportState::Clear {
let mut entity = self.0.entity.write().await;
entity.reposition(packet.x, packet.feet_y, packet.z);
}
}

SetPlayerPositionAndRotationS::ID => {
let packet: SetPlayerPositionAndRotationS = frame.decode()?;

let tp_state = self.0.tp_state.read().await;
match *tp_state {
TeleportState::Clear => {
let mut entity = self.0.entity.write().await;
entity.reposition(packet.x, packet.feet_y, packet.z);
entity.rotate(packet.yaw, packet.pitch);
}
_ => (),
if *tp_state == TeleportState::Clear {
let mut entity = self.0.entity.write().await;
entity.reposition(packet.x, packet.feet_y, packet.z);
entity.rotate(packet.yaw, packet.pitch);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub mod datatypes {

pub use impls::*;
pub use position::*;
pub use slot::*;

pub use string::*;
pub use text_component::*;
pub use variable::*;
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/packets/play/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* <https://www.gnu.org/licenses/>.
*/

use std::{collections::HashMap, sync::Arc};
use std::collections::HashMap;

use bit_vec::BitVec;
use bytes::BufMut;
Expand Down
2 changes: 1 addition & 1 deletion src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Server {
}

{
if player.0.io.connected().await == false {
if !player.0.io.connected().await {
invalid_players.insert(*id);
}
}
Expand Down

0 comments on commit 3657072

Please sign in to comment.