From 9db498e53eda7e654f147b6c2764058ff8142dd6 Mon Sep 17 00:00:00 2001 From: ReCore-sys Date: Wed, 26 Jun 2024 23:09:48 +0930 Subject: [PATCH] Cleaned up and fixed some warnings --- src/crates/ferrumc_net/src/lib.rs | 16 ++++++---------- .../src/packets/incoming/handshake.rs | 3 +-- .../ferrumc_net/src/packets/incoming/ping.rs | 3 ++- .../ferrumc_net/src/packets/incoming/status.rs | 13 +++++++------ src/crates/ferrumc_net/src/packets/mod.rs | 1 + src/tests.rs | 5 ----- 6 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/crates/ferrumc_net/src/lib.rs b/src/crates/ferrumc_net/src/lib.rs index 293e6c70..1b95feb7 100644 --- a/src/crates/ferrumc_net/src/lib.rs +++ b/src/crates/ferrumc_net/src/lib.rs @@ -7,19 +7,18 @@ use std::sync::{Arc, atomic, OnceLock}; use std::sync::atomic::AtomicU32; use dashmap::DashMap; -use ferrumc_utils::encoding::varint::read_varint; -use ferrumc_utils::prelude::*; -use lariv::Lariv; -use lazy_static::lazy_static; use log::{debug, trace}; use rand::random; use tokio::io::AsyncReadExt; use tokio::io::AsyncWriteExt; -use tokio::sync::{RwLock, RwLockWriteGuard}; +use tokio::sync::RwLock; + +use ferrumc_utils::encoding::varint::read_varint; +use ferrumc_utils::prelude::*; -use crate::packets::{handle_packet}; +use crate::packets::handle_packet; -mod packets; +pub mod packets; #[allow(non_snake_case)] pub fn CONNECTIONS() -> &'static ConnectionList { @@ -27,7 +26,6 @@ pub fn CONNECTIONS() -> &'static ConnectionList { CONNECTIONS.get_or_init(|| ConnectionList { connections: DashMap::new(), connection_count: AtomicU32::new(0), - purge_queue: Lariv::new(1024), }) } @@ -65,8 +63,6 @@ pub struct ConnectionList { pub connections: DashMap>>, // The number of connections. pub connection_count: AtomicU32, - // The queue of connections to be purged. This is used to store the connections to be dropped at the end of every tick. - pub purge_queue: Lariv, } #[derive()] diff --git a/src/crates/ferrumc_net/src/packets/incoming/handshake.rs b/src/crates/ferrumc_net/src/packets/incoming/handshake.rs index bc5f8cbb..494fc4ad 100644 --- a/src/crates/ferrumc_net/src/packets/incoming/handshake.rs +++ b/src/crates/ferrumc_net/src/packets/incoming/handshake.rs @@ -1,7 +1,6 @@ -use std::sync::Arc; -use log::{debug, info}; use ferrumc_macros::{Decode, packet}; use ferrumc_utils::encoding::varint::VarInt; + use crate::{Connection, State}; use crate::packets::IncomingPacket; diff --git a/src/crates/ferrumc_net/src/packets/incoming/ping.rs b/src/crates/ferrumc_net/src/packets/incoming/ping.rs index d7e21773..b6ecc796 100644 --- a/src/crates/ferrumc_net/src/packets/incoming/ping.rs +++ b/src/crates/ferrumc_net/src/packets/incoming/ping.rs @@ -1,8 +1,9 @@ -use std::sync::Arc; use log::info; use tokio::io::AsyncWriteExt; + use ferrumc_macros::{Decode, packet}; use ferrumc_utils::encoding::varint::VarInt; + use crate::Connection; use crate::packets::IncomingPacket; use crate::packets::outgoing::ping::OutgoingPing; diff --git a/src/crates/ferrumc_net/src/packets/incoming/status.rs b/src/crates/ferrumc_net/src/packets/incoming/status.rs index c056ce8c..2bc1314b 100644 --- a/src/crates/ferrumc_net/src/packets/incoming/status.rs +++ b/src/crates/ferrumc_net/src/packets/incoming/status.rs @@ -1,15 +1,16 @@ -use std::sync::Arc; -use tokio::sync::OnceCell; +use base64::Engine; use log::info; use serde::Serialize; +use tokio::io::{AsyncReadExt, AsyncWriteExt}; +use tokio::sync::OnceCell; + use ferrumc_macros::{Decode, packet}; +use ferrumc_utils::config; use ferrumc_utils::encoding::varint::VarInt; + use crate::Connection; use crate::packets::IncomingPacket; use crate::packets::outgoing::status::OutgoingStatusResponse; -use tokio::io::{AsyncReadExt, AsyncWriteExt}; -use ferrumc_utils::config; -use base64::{Engine}; #[derive(Decode)] #[packet(packet_id = 0x00, state = "status")] @@ -48,7 +49,7 @@ struct Description { } impl IncomingPacket for Status { - async fn handle(&self, conn: &mut tokio::sync::RwLockWriteGuard<'_, Connection>) -> Result<(), ferrumc_utils::error::Error> { + async fn handle(&self, conn: &mut tokio::sync::RwLockWriteGuard<'_, Connection>) -> Result<(), Error> { info!("Handling status request packet"); let config = config::get_global_config(); diff --git a/src/crates/ferrumc_net/src/packets/mod.rs b/src/crates/ferrumc_net/src/packets/mod.rs index 110a7e35..d427082e 100644 --- a/src/crates/ferrumc_net/src/packets/mod.rs +++ b/src/crates/ferrumc_net/src/packets/mod.rs @@ -11,6 +11,7 @@ pub mod incoming; pub mod outgoing; pub trait IncomingPacket { + #[allow(async_fn_in_trait)] async fn handle(&self, conn: &mut tokio::sync::RwLockWriteGuard) -> Result<(), Error>; } diff --git a/src/tests.rs b/src/tests.rs index cea89782..bb4183f8 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -3,13 +3,8 @@ mod tests { use std::io::Cursor; - use tokio::io::{AsyncRead, AsyncSeek}; - use ferrumc_macros::Decode; use ferrumc_utils::encoding::varint::VarInt; - use ferrumc_utils::type_impls::Decode; - - use crate::Error; #[tokio::test] async fn test_macro_decode() {