diff --git a/pumpkin-config/src/lib.rs b/pumpkin-config/src/lib.rs index 94feda0b..4e6625cc 100644 --- a/pumpkin-config/src/lib.rs +++ b/pumpkin-config/src/lib.rs @@ -1,7 +1,6 @@ use log::warn; use logging::LoggingConfig; use pumpkin_core::{Difficulty, GameMode, PermissionLvl}; -use query::QueryConfig; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use std::{ @@ -12,29 +11,26 @@ use std::{ sync::LazyLock, }; -pub mod auth; pub mod logging; -pub mod proxy; -pub mod query; +pub mod networking; + pub mod resource_pack; -pub use auth::AuthenticationConfig; pub use commands::CommandsConfig; -pub use compression::CompressionConfig; -pub use lan_broadcast::LANBroadcastConfig; +pub use networking::auth::AuthenticationConfig; +pub use networking::compression::CompressionConfig; +pub use networking::lan_broadcast::LANBroadcastConfig; +pub use networking::rcon::RCONConfig; pub use pvp::PVPConfig; -pub use rcon::RCONConfig; pub use server_links::ServerLinksConfig; mod commands; -pub mod compression; -mod lan_broadcast; + pub mod op; mod pvp; -mod rcon; mod server_links; -use proxy::ProxyConfig; +use networking::NetworkingConfig; use resource_pack::ResourcePackConfig; const CONFIG_ROOT_FOLDER: &str = "config/"; @@ -52,17 +48,12 @@ pub static BASIC_CONFIG: LazyLock = LazyLock::new(BasicConfi #[derive(Deserialize, Serialize, Default)] #[serde(default)] pub struct AdvancedConfiguration { - pub proxy: ProxyConfig, - pub authentication: AuthenticationConfig, - pub packet_compression: CompressionConfig, + pub logging: LoggingConfig, pub resource_pack: ResourcePackConfig, + pub networking: NetworkingConfig, pub commands: CommandsConfig, - pub rcon: RCONConfig, pub pvp: PVPConfig, - pub logging: LoggingConfig, - pub query: QueryConfig, pub server_links: ServerLinksConfig, - pub lan_broadcast: LANBroadcastConfig, } #[derive(Serialize, Deserialize)] diff --git a/pumpkin-config/src/auth.rs b/pumpkin-config/src/networking/auth.rs similarity index 100% rename from pumpkin-config/src/auth.rs rename to pumpkin-config/src/networking/auth.rs diff --git a/pumpkin-config/src/compression.rs b/pumpkin-config/src/networking/compression.rs similarity index 100% rename from pumpkin-config/src/compression.rs rename to pumpkin-config/src/networking/compression.rs diff --git a/pumpkin-config/src/lan_broadcast.rs b/pumpkin-config/src/networking/lan_broadcast.rs similarity index 100% rename from pumpkin-config/src/lan_broadcast.rs rename to pumpkin-config/src/networking/lan_broadcast.rs diff --git a/pumpkin-config/src/networking/mod.rs b/pumpkin-config/src/networking/mod.rs new file mode 100644 index 00000000..2d4b837f --- /dev/null +++ b/pumpkin-config/src/networking/mod.rs @@ -0,0 +1,24 @@ +use auth::AuthenticationConfig; +use proxy::ProxyConfig; +use query::QueryConfig; +use rcon::RCONConfig; +use serde::{Deserialize, Serialize}; + +use crate::{CompressionConfig, LANBroadcastConfig}; + +pub mod auth; +pub mod compression; +pub mod lan_broadcast; +pub mod proxy; +pub mod query; +pub mod rcon; + +#[derive(Deserialize, Serialize, Default)] +pub struct NetworkingConfig { + pub authentication: AuthenticationConfig, + pub query: QueryConfig, + pub rcon: RCONConfig, + pub proxy: ProxyConfig, + pub packet_compression: CompressionConfig, + pub lan_broadcast: LANBroadcastConfig, +} diff --git a/pumpkin-config/src/proxy.rs b/pumpkin-config/src/networking/proxy.rs similarity index 100% rename from pumpkin-config/src/proxy.rs rename to pumpkin-config/src/networking/proxy.rs diff --git a/pumpkin-config/src/query.rs b/pumpkin-config/src/networking/query.rs similarity index 100% rename from pumpkin-config/src/query.rs rename to pumpkin-config/src/networking/query.rs diff --git a/pumpkin-config/src/rcon.rs b/pumpkin-config/src/networking/rcon.rs similarity index 100% rename from pumpkin-config/src/rcon.rs rename to pumpkin-config/src/networking/rcon.rs diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index 3dec495f..5a2ec8f4 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -161,7 +161,7 @@ async fn main() { .expect("Unable to get the address of server!"); let use_console = ADVANCED_CONFIG.commands.use_console; - let rcon = ADVANCED_CONFIG.rcon.clone(); + let rcon = ADVANCED_CONFIG.networking.rcon.clone(); let server = Arc::new(Server::new()); let mut ticker = Ticker::new(BASIC_CONFIG.tps); @@ -179,12 +179,12 @@ async fn main() { }); } - if ADVANCED_CONFIG.query.enabled { + if ADVANCED_CONFIG.networking.query.enabled { log::info!("Query protocol enabled. Starting..."); tokio::spawn(query::start_query_handler(server.clone(), addr)); } - if ADVANCED_CONFIG.lan_broadcast.enabled { + if ADVANCED_CONFIG.networking.lan_broadcast.enabled { log::info!("LAN broadcast enabled. Starting..."); tokio::spawn(lan_broadcast::start_lan_broadcast(addr)); } diff --git a/pumpkin/src/net/authentication.rs b/pumpkin/src/net/authentication.rs index 0069228e..c485a950 100644 --- a/pumpkin/src/net/authentication.rs +++ b/pumpkin/src/net/authentication.rs @@ -1,7 +1,7 @@ use std::{collections::HashMap, net::IpAddr}; use base64::{engine::general_purpose, Engine}; -use pumpkin_config::{auth::TextureConfig, ADVANCED_CONFIG}; +use pumpkin_config::{networking::auth::TextureConfig, ADVANCED_CONFIG}; use pumpkin_protocol::Property; use reqwest::{StatusCode, Url}; use serde::Deserialize; @@ -50,8 +50,13 @@ pub async fn authenticate( ip: &IpAddr, auth_client: &reqwest::Client, ) -> Result { - let address = if ADVANCED_CONFIG.authentication.prevent_proxy_connections { + let address = if ADVANCED_CONFIG + .networking + .authentication + .prevent_proxy_connections + { let auth_url = ADVANCED_CONFIG + .networking .authentication .prevent_proxy_connection_auth_url .as_deref() @@ -63,6 +68,7 @@ pub async fn authenticate( .replace("{ip}", &ip.to_string()) } else { let auth_url = ADVANCED_CONFIG + .networking .authentication .auth_url .as_deref() diff --git a/pumpkin/src/net/lan_broadcast.rs b/pumpkin/src/net/lan_broadcast.rs index 3afb23fa..187fd431 100644 --- a/pumpkin/src/net/lan_broadcast.rs +++ b/pumpkin/src/net/lan_broadcast.rs @@ -10,7 +10,7 @@ const BROADCAST_ADDRESS: SocketAddr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(224, 0, 2, 60)), 4445); pub async fn start_lan_broadcast(bound_addr: SocketAddr) { - let port = ADVANCED_CONFIG.lan_broadcast.port.unwrap_or(0); + let port = ADVANCED_CONFIG.networking.lan_broadcast.port.unwrap_or(0); let socket = UdpSocket::bind(format!("0.0.0.0:{port}")) .await @@ -22,6 +22,7 @@ pub async fn start_lan_broadcast(bound_addr: SocketAddr) { let motd: String; let advanced_motd = &ADVANCED_CONFIG + .networking .lan_broadcast .motd .clone() diff --git a/pumpkin/src/net/mod.rs b/pumpkin/src/net/mod.rs index 53b25e92..36d890dc 100644 --- a/pumpkin/src/net/mod.rs +++ b/pumpkin/src/net/mod.rs @@ -14,7 +14,7 @@ use crate::{ }; use crossbeam::atomic::AtomicCell; -use pumpkin_config::compression::CompressionInfo; +use pumpkin_config::networking::compression::CompressionInfo; use pumpkin_core::{text::TextComponent, ProfileAction}; use pumpkin_protocol::{ bytebuf::{packet_id::Packet, ReadingError}, diff --git a/pumpkin/src/net/packet/login.rs b/pumpkin/src/net/packet/login.rs index 585413d6..d7ac97e0 100644 --- a/pumpkin/src/net/packet/login.rs +++ b/pumpkin/src/net/packet/login.rs @@ -105,7 +105,7 @@ impl Client { // default game profile, when no online mode // TODO: make offline uuid let mut gameprofile = self.gameprofile.lock().await; - let proxy = &ADVANCED_CONFIG.proxy; + let proxy = &ADVANCED_CONFIG.networking.proxy; if proxy.enabled { if proxy.velocity.enabled { velocity::velocity_login(self).await; @@ -146,7 +146,7 @@ impl Client { ) .await; } else { - if ADVANCED_CONFIG.packet_compression.enabled { + if ADVANCED_CONFIG.networking.packet_compression.enabled { self.enable_compression().await; } self.finish_login(&profile).await; @@ -205,14 +205,18 @@ impl Client { return; } - if ADVANCED_CONFIG.packet_compression.enabled { + if ADVANCED_CONFIG.networking.packet_compression.enabled { self.enable_compression().await; } self.finish_login(profile).await; } async fn enable_compression(&self) { - let compression = ADVANCED_CONFIG.packet_compression.compression_info.clone(); + let compression = ADVANCED_CONFIG + .networking + .packet_compression + .compression_info + .clone(); self.send_packet(&CSetCompression::new(compression.threshold.into())) .await; self.set_compression(Some(compression)).await; @@ -237,11 +241,13 @@ impl Client { // Check if player should join if let Some(actions) = &profile.profile_actions { if ADVANCED_CONFIG + .networking .authentication .player_profile .allow_banned_players { for allowed in &ADVANCED_CONFIG + .networking .authentication .player_profile .allowed_actions @@ -261,7 +267,7 @@ impl Client { for property in &profile.properties { authentication::validate_textures( property, - &ADVANCED_CONFIG.authentication.textures, + &ADVANCED_CONFIG.networking.authentication.textures, ) .map_err(AuthError::TextureError)?; } @@ -281,7 +287,7 @@ impl Client { } pub async fn handle_plugin_response(&self, plugin_response: SLoginPluginResponse) { log::debug!("Handling plugin"); - let velocity_config = &ADVANCED_CONFIG.proxy.velocity; + let velocity_config = &ADVANCED_CONFIG.networking.proxy.velocity; if velocity_config.enabled { let mut address = self.address.lock().await; match velocity::receive_velocity_plugin_response( diff --git a/pumpkin/src/net/proxy/velocity.rs b/pumpkin/src/net/proxy/velocity.rs index 461c9e0f..4394e1fe 100644 --- a/pumpkin/src/net/proxy/velocity.rs +++ b/pumpkin/src/net/proxy/velocity.rs @@ -5,7 +5,7 @@ use std::net::{IpAddr, SocketAddr}; use bytes::{BufMut, BytesMut}; use hmac::{Hmac, Mac}; -use pumpkin_config::proxy::VelocityConfig; +use pumpkin_config::networking::proxy::VelocityConfig; use pumpkin_protocol::{ bytebuf::ByteBuf, client::login::CLoginPluginRequest, server::login::SLoginPluginResponse, Property, diff --git a/pumpkin/src/net/query.rs b/pumpkin/src/net/query.rs index 0968c58c..ccfb9aae 100644 --- a/pumpkin/src/net/query.rs +++ b/pumpkin/src/net/query.rs @@ -17,7 +17,7 @@ use crate::server::{Server, CURRENT_MC_VERSION}; pub async fn start_query_handler(server: Arc, bound_addr: SocketAddr) { let mut query_addr = bound_addr; - if let Some(port) = ADVANCED_CONFIG.query.port { + if let Some(port) = ADVANCED_CONFIG.networking.query.port { query_addr.set_port(port); } diff --git a/pumpkin/src/net/rcon/mod.rs b/pumpkin/src/net/rcon/mod.rs index 1f36d827..87a81578 100644 --- a/pumpkin/src/net/rcon/mod.rs +++ b/pumpkin/src/net/rcon/mod.rs @@ -83,7 +83,7 @@ impl RCONClient { let Some(packet) = self.receive_packet().await? else { return Ok(()); }; - let config = &ADVANCED_CONFIG.rcon; + let config = &ADVANCED_CONFIG.networking.rcon; match packet.get_type() { ServerboundPacket::Auth => { if packet.get_body() == password {