Skip to content

Commit

Permalink
Cleaned up and fixed some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ReCore-sys committed Jun 26, 2024
1 parent 2667abf commit 9db498e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 24 deletions.
16 changes: 6 additions & 10 deletions src/crates/ferrumc_net/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,25 @@ 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 {
static CONNECTIONS: OnceLock<ConnectionList> = OnceLock::new();
CONNECTIONS.get_or_init(|| ConnectionList {
connections: DashMap::new(),
connection_count: AtomicU32::new(0),
purge_queue: Lariv::new(1024),
})
}

Expand Down Expand Up @@ -65,8 +63,6 @@ pub struct ConnectionList {
pub connections: DashMap<u32, Arc<RwLock<Connection>>>,
// 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<u32>,
}

#[derive()]
Expand Down
3 changes: 1 addition & 2 deletions src/crates/ferrumc_net/src/packets/incoming/handshake.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
3 changes: 2 additions & 1 deletion src/crates/ferrumc_net/src/packets/incoming/ping.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
13 changes: 7 additions & 6 deletions src/crates/ferrumc_net/src/packets/incoming/status.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions src/crates/ferrumc_net/src/packets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Connection>) -> Result<(), Error>;
}

Expand Down
5 changes: 0 additions & 5 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 9db498e

Please sign in to comment.