Skip to content

Commit 3657072

Browse files
committed
fix(net): remove reference to io mutex
1 parent d50cf02 commit 3657072

File tree

5 files changed

+20
-25
lines changed

5 files changed

+20
-25
lines changed

src/net/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* <https://www.gnu.org/licenses/>.
1818
*/
1919

20-
use std::{cmp::Ordering, sync::Arc};
20+
use std::cmp::Ordering;
2121

2222
use rayon::prelude::*;
2323

src/net/player.rs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ use thiserror::Error;
3232
use tokio::{
3333
net::TcpStream,
3434
sync::{Mutex, OwnedSemaphorePermit, RwLock},
35-
time::{self, timeout, Instant},
35+
time::{timeout, Instant},
3636
};
37-
use tokio_util::sync::CancellationToken;
3837
use uuid::Uuid;
3938

4039
use crate::{
@@ -271,8 +270,7 @@ impl SharedPlayer {
271270
data: Bounded(Bytes(&[3])),
272271
};
273272

274-
let mut io = self.0.io.lock().await;
275-
io.tx(&req).await?;
273+
self.0.io.tx(&req).await?;
276274

277275
Ok(())
278276
}
@@ -503,10 +501,13 @@ impl SharedPlayer {
503501
let mut queue = player.0.frame_queue.lock().await;
504502
queue.push(frame);
505503
}
506-
Err(why) => match why.downcast_ref::<tokio::io::Error>().map(|e| e.kind()) {
507-
Some(tokio::io::ErrorKind::UnexpectedEof) => return,
508-
_ => (),
509-
},
504+
Err(why) => {
505+
if let Some(tokio::io::ErrorKind::UnexpectedEof) =
506+
why.downcast_ref::<tokio::io::Error>().map(|e| e.kind())
507+
{
508+
return;
509+
}
510+
}
510511
}
511512
}
512513
});
@@ -518,26 +519,20 @@ impl SharedPlayer {
518519
let packet: SetPlayerPositionS = frame.decode()?;
519520

520521
let tp_state = self.0.tp_state.read().await;
521-
match *tp_state {
522-
TeleportState::Clear => {
523-
let mut entity = self.0.entity.write().await;
524-
entity.reposition(packet.x, packet.feet_y, packet.z);
525-
}
526-
_ => (),
522+
if *tp_state == TeleportState::Clear {
523+
let mut entity = self.0.entity.write().await;
524+
entity.reposition(packet.x, packet.feet_y, packet.z);
527525
}
528526
}
529527

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

533531
let tp_state = self.0.tp_state.read().await;
534-
match *tp_state {
535-
TeleportState::Clear => {
536-
let mut entity = self.0.entity.write().await;
537-
entity.reposition(packet.x, packet.feet_y, packet.z);
538-
entity.rotate(packet.yaw, packet.pitch);
539-
}
540-
_ => (),
532+
if *tp_state == TeleportState::Clear {
533+
let mut entity = self.0.entity.write().await;
534+
entity.reposition(packet.x, packet.feet_y, packet.z);
535+
entity.rotate(packet.yaw, packet.pitch);
541536
}
542537
}
543538

src/protocol/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub mod datatypes {
2727

2828
pub use impls::*;
2929
pub use position::*;
30-
pub use slot::*;
30+
3131
pub use string::*;
3232
pub use text_component::*;
3333
pub use variable::*;

src/protocol/packets/play/world.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* <https://www.gnu.org/licenses/>.
1818
*/
1919

20-
use std::{collections::HashMap, sync::Arc};
20+
use std::collections::HashMap;
2121

2222
use bit_vec::BitVec;
2323
use bytes::BufMut;

src/server/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl Server {
8686
}
8787

8888
{
89-
if player.0.io.connected().await == false {
89+
if !player.0.io.connected().await {
9090
invalid_players.insert(*id);
9191
}
9292
}

0 commit comments

Comments
 (0)