From 3535d2cda1ad29ab7e9536aac8e3aa868dab2a41 Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Thu, 29 Aug 2024 16:52:22 +0200 Subject: [PATCH 01/12] Fixed new clippy lint --- pumpkin/src/config/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pumpkin/src/config/mod.rs b/pumpkin/src/config/mod.rs index cc47d9772..d5e1876c5 100644 --- a/pumpkin/src/config/mod.rs +++ b/pumpkin/src/config/mod.rs @@ -14,10 +14,12 @@ pub mod resource_pack; /// Current Config version of the Base Config const CURRENT_BASE_VERSION: &str = "1.0.0"; -#[derive(Deserialize, Serialize)] -/// The idea is that Pumpkin should very customizable, You can Enable or Disable Features depending on your needs. +/// The idea is that Pumpkin should very customizable. +/// You can Enable or Disable Features depending on your needs. +/// /// This also allows you get some Performance or Resource boosts. /// Important: The Configuration should match Vanilla by default +#[derive(Deserialize, Serialize)] pub struct AdvancedConfiguration { pub proxy: ProxyConfig, pub authentication: AuthenticationConfig, From ff68b5cac503412a97d84982ded562f9d7b9167c Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sat, 31 Aug 2024 18:49:23 +0200 Subject: [PATCH 02/12] Removed manual Default implementation --- pumpkin/src/config/mod.rs | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/pumpkin/src/config/mod.rs b/pumpkin/src/config/mod.rs index d5e1876c5..e98b78dc7 100644 --- a/pumpkin/src/config/mod.rs +++ b/pumpkin/src/config/mod.rs @@ -19,7 +19,7 @@ const CURRENT_BASE_VERSION: &str = "1.0.0"; /// /// This also allows you get some Performance or Resource boosts. /// Important: The Configuration should match Vanilla by default -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Default)] pub struct AdvancedConfiguration { pub proxy: ProxyConfig, pub authentication: AuthenticationConfig, @@ -111,21 +111,6 @@ impl Default for CompressionConfig { } } -/// Important: The Configuration should match Vanilla by default -impl Default for AdvancedConfiguration { - fn default() -> Self { - Self { - proxy: ProxyConfig::default(), - authentication: AuthenticationConfig::default(), - commands: CommandsConfig::default(), - packet_compression: CompressionConfig::default(), - resource_pack: ResourcePackConfig::default(), - rcon: RCONConfig::default(), - pvp: PVPConfig::default(), - } - } -} - #[derive(Serialize, Deserialize)] pub struct BasicConfiguration { /// A version identifier for the configuration format. From d57d9ffdcc9b8a5843c5ed00b54d6102a0b10341 Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Thu, 29 Aug 2024 16:56:35 +0200 Subject: [PATCH 03/12] Use proper IP Address abstraction instead of using format!() --- pumpkin/src/config/mod.rs | 19 ++++++++----------- pumpkin/src/main.rs | 9 +-------- pumpkin/src/rcon/mod.rs | 5 +---- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/pumpkin/src/config/mod.rs b/pumpkin/src/config/mod.rs index e98b78dc7..fffe2c1a0 100644 --- a/pumpkin/src/config/mod.rs +++ b/pumpkin/src/config/mod.rs @@ -1,9 +1,11 @@ -use std::path::Path; - use auth_config::AuthenticationConfig; use proxy::ProxyConfig; use resource_pack::ResourcePackConfig; use serde::{Deserialize, Serialize}; +use std::{ + net::{Ipv4Addr, SocketAddr}, + path::Path, +}; use crate::{entity::player::GameMode, server::Difficulty}; @@ -33,8 +35,7 @@ pub struct AdvancedConfiguration { #[derive(Deserialize, Serialize, Clone)] pub struct RCONConfig { pub enabled: bool, - pub ip: String, - pub port: u16, + pub address: SocketAddr, pub password: String, } @@ -42,8 +43,7 @@ impl Default for RCONConfig { fn default() -> Self { Self { enabled: false, - ip: "0.0.0.0".to_string(), - port: 25575, + address: SocketAddr::new(Ipv4Addr::new(0, 0, 0, 0).into(), 25575), password: "".to_string(), } } @@ -116,9 +116,7 @@ pub struct BasicConfiguration { /// A version identifier for the configuration format. pub config_version: String, /// The address to bind the server to. - pub server_address: String, - /// The port to listen on. - pub server_port: u16, + pub server_address: SocketAddr, /// The seed for world generation. pub seed: String, /// The maximum number of players allowed on the server. @@ -147,8 +145,7 @@ impl Default for BasicConfiguration { fn default() -> Self { Self { config_version: CURRENT_BASE_VERSION.to_string(), - server_address: "0.0.0.0".to_string(), - server_port: 25565, + server_address: SocketAddr::new(Ipv4Addr::new(0, 0, 0, 0).into(), 25565), seed: "".to_string(), max_players: 100000, view_distance: 10, diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index 56281f274..d586b6040 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -74,14 +74,7 @@ fn main() -> io::Result<()> { let mut events = Events::with_capacity(128); // Setup the TCP server socket. - - let addr = format!( - "{}:{}", - basic_config.server_address, basic_config.server_port - ) - .parse() - .unwrap(); - + let addr = basic_config.server_address; let mut listener = TcpListener::bind(addr)?; // Register the server with poll we can receive events for it. diff --git a/pumpkin/src/rcon/mod.rs b/pumpkin/src/rcon/mod.rs index e6a94fdf8..3f20ffd54 100644 --- a/pumpkin/src/rcon/mod.rs +++ b/pumpkin/src/rcon/mod.rs @@ -35,11 +35,8 @@ impl RCONServer { server: Arc>, ) -> Result { assert!(config.enabled, "RCON is not enabled"); - let addr = format!("{}:{}", config.ip, config.port) - .parse() - .expect("Failed to parse RCON address"); let mut poll = Poll::new().unwrap(); - let mut listener = TcpListener::bind(addr).unwrap(); + let mut listener = TcpListener::bind(config.address).unwrap(); poll.registry() .register(&mut listener, SERVER, Interest::READABLE) From d2924d463255b6638912fd68583801709205edfa Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Thu, 29 Aug 2024 19:02:10 +0200 Subject: [PATCH 04/12] Moved `auth_config` to `auth` Make it consistent with `proxy` and `resource_pack` --- pumpkin/src/client/authentication.rs | 2 +- pumpkin/src/config/{auth_config.rs => auth.rs} | 0 pumpkin/src/config/mod.rs | 5 +++-- 3 files changed, 4 insertions(+), 3 deletions(-) rename pumpkin/src/config/{auth_config.rs => auth.rs} (100%) diff --git a/pumpkin/src/client/authentication.rs b/pumpkin/src/client/authentication.rs index d841756a3..44f2054dd 100644 --- a/pumpkin/src/client/authentication.rs +++ b/pumpkin/src/client/authentication.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use thiserror::Error; use uuid::Uuid; -use crate::{config::auth_config::TextureConfig, server::Server}; +use crate::{config::auth::TextureConfig, server::Server}; #[derive(Deserialize, Clone, Debug)] #[allow(non_snake_case)] diff --git a/pumpkin/src/config/auth_config.rs b/pumpkin/src/config/auth.rs similarity index 100% rename from pumpkin/src/config/auth_config.rs rename to pumpkin/src/config/auth.rs diff --git a/pumpkin/src/config/mod.rs b/pumpkin/src/config/mod.rs index fffe2c1a0..68679b9b6 100644 --- a/pumpkin/src/config/mod.rs +++ b/pumpkin/src/config/mod.rs @@ -1,4 +1,3 @@ -use auth_config::AuthenticationConfig; use proxy::ProxyConfig; use resource_pack::ResourcePackConfig; use serde::{Deserialize, Serialize}; @@ -9,10 +8,12 @@ use std::{ use crate::{entity::player::GameMode, server::Difficulty}; -pub mod auth_config; +pub mod auth; pub mod proxy; pub mod resource_pack; +use auth::AuthenticationConfig; + /// Current Config version of the Base Config const CURRENT_BASE_VERSION: &str = "1.0.0"; From 003219d3e8faf093c4effd84639bf3acc582fa13 Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Thu, 29 Aug 2024 20:28:25 +0200 Subject: [PATCH 05/12] Sorted main.rs inputs --- pumpkin/src/main.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index d586b6040..aa57f5ed9 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -6,16 +6,13 @@ compile_error!("Compiling for WASI targets is not supported!"); use mio::net::TcpListener; use mio::{Events, Interest, Poll, Token}; -use std::io::{self}; - -use client::Client; -use commands::handle_command; -use config::AdvancedConfiguration; use std::collections::HashMap; +use std::io::{self}; -use client::interrupted; -use config::BasicConfiguration; +use client::{interrupted, Client}; +use commands::handle_command; +use config::{AdvancedConfiguration, BasicConfiguration}; use server::Server; // Setup some tokens to allow us to identify which event is for which socket. From a6cb88b48fb10a61979db142ea7b7220de18fed6 Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Thu, 29 Aug 2024 20:28:51 +0200 Subject: [PATCH 06/12] Added LoadConfiguration trait. De-duplicates code from both BasicConfiguration and AdvancedConfiguration. Allow config to fail writing. (On e.g. immutable linux distros) --- pumpkin/src/config/mod.rs | 82 ++++++++++++++++++++++++--------------- pumpkin/src/main.rs | 6 +-- 2 files changed, 54 insertions(+), 34 deletions(-) diff --git a/pumpkin/src/config/mod.rs b/pumpkin/src/config/mod.rs index 68679b9b6..9baa3fad4 100644 --- a/pumpkin/src/config/mod.rs +++ b/pumpkin/src/config/mod.rs @@ -1,7 +1,9 @@ +use log::warn; use proxy::ProxyConfig; use resource_pack::ResourcePackConfig; -use serde::{Deserialize, Serialize}; +use serde::{de::DeserializeOwned, Deserialize, Serialize}; use std::{ + fs, net::{Ipv4Addr, SocketAddr}, path::Path, }; @@ -162,44 +164,62 @@ impl Default for BasicConfiguration { } } -impl AdvancedConfiguration { - pub fn load>(path: P) -> AdvancedConfiguration { - if path.as_ref().exists() { - let toml = std::fs::read_to_string(path).expect("Couldn't read configuration"); - let config: AdvancedConfiguration = - toml::from_str(toml.as_str()).expect("Couldn't parse features.toml, Probably old config, Replacing with a new one or just delete it"); - config.validate(); - config +pub trait LoadConfiguration { + fn load() -> Self + where + Self: Sized + Default + Serialize + DeserializeOwned, + { + let path = Self::get_path(); + + let config = if path.exists() { + let file_content = fs::read_to_string(path) + .unwrap_or_else(|_| panic!("Couldn't read configuration file at {:?}", path)); + + toml::from_str(&file_content).unwrap_or_else(|err| { + panic!( + "Couldn't parse config at {:?}. Reason: {}", + path, + err.message() + ) + }) } else { - let config = AdvancedConfiguration::default(); - let toml = toml::to_string(&config).expect("Couldn't create toml!"); - std::fs::write(path, toml).expect("Couldn't save configuration"); - config.validate(); - config - } + let content = Self::default(); + + if let Err(err) = fs::write(path, toml::to_string(&content).unwrap()) { + warn!( + "Couldn't write default config to {:?}. Reason: {}", + path, err + ); + } + + content + }; + + config.validate(); + config + } + + fn get_path() -> &'static Path; + + fn validate(&self); +} + +impl LoadConfiguration for AdvancedConfiguration { + fn get_path() -> &'static Path { + Path::new("features.toml") } - pub fn validate(&self) { + + fn validate(&self) { self.resource_pack.validate() } } -impl BasicConfiguration { - pub fn load>(path: P) -> BasicConfiguration { - if path.as_ref().exists() { - let toml = std::fs::read_to_string(path).expect("Couldn't read configuration"); - let config: BasicConfiguration = toml::from_str(toml.as_str()).expect("Couldn't parse configuration.toml, Probably old config, Replacing with a new one or just delete it"); - config.validate(); - config - } else { - let config = BasicConfiguration::default(); - let toml = toml::to_string(&config).expect("Couldn't create toml!"); - std::fs::write(path, toml).expect("Couldn't save configuration"); - config.validate(); - config - } +impl LoadConfiguration for BasicConfiguration { + fn get_path() -> &'static Path { + Path::new("configuration.toml") } - pub fn validate(&self) { + fn validate(&self) { assert_eq!( self.config_version, CURRENT_BASE_VERSION, "Config version does not match used Config version. Please update your config" diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index aa57f5ed9..9f685a84a 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -12,7 +12,7 @@ use std::io::{self}; use client::{interrupted, Client}; use commands::handle_command; -use config::{AdvancedConfiguration, BasicConfiguration}; +use config::{AdvancedConfiguration, BasicConfiguration, LoadConfiguration}; use server::Server; // Setup some tokens to allow us to identify which event is for which socket. @@ -61,9 +61,9 @@ fn main() -> io::Result<()> { use std::time::Instant; let time = Instant::now(); - let basic_config = BasicConfiguration::load("configuration.toml"); + let basic_config = BasicConfiguration::load(); - let advanced_configuration = AdvancedConfiguration::load("features.toml"); + let advanced_configuration = AdvancedConfiguration::load(); // Create a poll instance. let mut poll = Poll::new()?; From e48ca3b99f66b6721579491747793ae755be41cb Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sat, 31 Aug 2024 13:58:42 +0200 Subject: [PATCH 07/12] Moved configuration structs into own files - PVPConfiguration - RCONConfiguration - CompressionConfiguration - CommandsConfiguration --- pumpkin/src/config/commands.rs | 14 +++++ pumpkin/src/config/compression.rs | 24 +++++++++ pumpkin/src/config/mod.rs | 90 ++++--------------------------- pumpkin/src/config/pvp.rs | 27 ++++++++++ pumpkin/src/config/rcon.rs | 20 +++++++ 5 files changed, 95 insertions(+), 80 deletions(-) create mode 100644 pumpkin/src/config/commands.rs create mode 100644 pumpkin/src/config/compression.rs create mode 100644 pumpkin/src/config/pvp.rs create mode 100644 pumpkin/src/config/rcon.rs diff --git a/pumpkin/src/config/commands.rs b/pumpkin/src/config/commands.rs new file mode 100644 index 000000000..94ee4d8c2 --- /dev/null +++ b/pumpkin/src/config/commands.rs @@ -0,0 +1,14 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Deserialize, Serialize)] +pub struct CommandsConfig { + /// Are commands from the Console accepted ? + pub use_console: bool, + // TODO: commands... +} + +impl Default for CommandsConfig { + fn default() -> Self { + Self { use_console: true } + } +} diff --git a/pumpkin/src/config/compression.rs b/pumpkin/src/config/compression.rs new file mode 100644 index 000000000..544c8d31d --- /dev/null +++ b/pumpkin/src/config/compression.rs @@ -0,0 +1,24 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Deserialize, Serialize)] +// Packet compression +pub struct CompressionConfig { + /// Is compression enabled ? + pub enabled: bool, + /// The compression threshold used when compression is enabled + pub compression_threshold: u32, + /// A value between 0..9 + /// 1 = Optimize for the best speed of encoding. + /// 9 = Optimize for the size of data being encoded. + pub compression_level: u32, +} + +impl Default for CompressionConfig { + fn default() -> Self { + Self { + enabled: true, + compression_threshold: 256, + compression_level: 4, + } + } +} diff --git a/pumpkin/src/config/mod.rs b/pumpkin/src/config/mod.rs index 9baa3fad4..50c40b977 100644 --- a/pumpkin/src/config/mod.rs +++ b/pumpkin/src/config/mod.rs @@ -14,7 +14,16 @@ pub mod auth; pub mod proxy; pub mod resource_pack; -use auth::AuthenticationConfig; +mod commands; +mod compression; +mod pvp; +mod rcon; + +pub use auth::AuthenticationConfig; +pub use commands::CommandsConfig; +pub use compression::CompressionConfig; +pub use pvp::PVPConfig; +pub use rcon::RCONConfig; /// Current Config version of the Base Config const CURRENT_BASE_VERSION: &str = "1.0.0"; @@ -35,85 +44,6 @@ pub struct AdvancedConfiguration { pub pvp: PVPConfig, } -#[derive(Deserialize, Serialize, Clone)] -pub struct RCONConfig { - pub enabled: bool, - pub address: SocketAddr, - pub password: String, -} - -impl Default for RCONConfig { - fn default() -> Self { - Self { - enabled: false, - address: SocketAddr::new(Ipv4Addr::new(0, 0, 0, 0).into(), 25575), - password: "".to_string(), - } - } -} - -#[derive(Deserialize, Serialize)] -pub struct CommandsConfig { - /// Are commands from the Console accepted ? - pub use_console: bool, - // TODO: commands... -} - -impl Default for CommandsConfig { - fn default() -> Self { - Self { use_console: true } - } -} - -#[derive(Deserialize, Serialize)] -pub struct PVPConfig { - /// Is PVP enabled ? - pub enabled: bool, - /// Do we want to have the Red hurt animation & fov bobbing - pub hurt_animation: bool, - /// Should players in creative be protected against PVP - pub protect_creative: bool, - /// Has PVP Knockback? - pub knockback: bool, - /// Should player swing when attacking? - pub swing: bool, -} - -impl Default for PVPConfig { - fn default() -> Self { - Self { - enabled: true, - hurt_animation: true, - protect_creative: true, - knockback: true, - swing: true, - } - } -} - -#[derive(Deserialize, Serialize)] -// Packet compression -pub struct CompressionConfig { - /// Is compression enabled ? - pub enabled: bool, - /// The compression threshold used when compression is enabled - pub compression_threshold: u32, - /// A value between 0..9 - /// 1 = Optimize for the best speed of encoding. - /// 9 = Optimize for the size of data being encoded. - pub compression_level: u32, -} - -impl Default for CompressionConfig { - fn default() -> Self { - Self { - enabled: true, - compression_threshold: 256, - compression_level: 4, - } - } -} - #[derive(Serialize, Deserialize)] pub struct BasicConfiguration { /// A version identifier for the configuration format. diff --git a/pumpkin/src/config/pvp.rs b/pumpkin/src/config/pvp.rs new file mode 100644 index 000000000..cfbddc6c4 --- /dev/null +++ b/pumpkin/src/config/pvp.rs @@ -0,0 +1,27 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Deserialize, Serialize)] +pub struct PVPConfig { + /// Is PVP enabled ? + pub enabled: bool, + /// Do we want to have the Red hurt animation & fov bobbing + pub hurt_animation: bool, + /// Should players in creative be protected against PVP + pub protect_creative: bool, + /// Has PVP Knockback? + pub knockback: bool, + /// Should player swing when attacking? + pub swing: bool, +} + +impl Default for PVPConfig { + fn default() -> Self { + Self { + enabled: true, + hurt_animation: true, + protect_creative: true, + knockback: true, + swing: true, + } + } +} diff --git a/pumpkin/src/config/rcon.rs b/pumpkin/src/config/rcon.rs new file mode 100644 index 000000000..af5aa6ac0 --- /dev/null +++ b/pumpkin/src/config/rcon.rs @@ -0,0 +1,20 @@ +use std::net::{Ipv4Addr, SocketAddr}; + +use serde::{Deserialize, Serialize}; + +#[derive(Deserialize, Serialize, Clone)] +pub struct RCONConfig { + pub enabled: bool, + pub address: SocketAddr, + pub password: String, +} + +impl Default for RCONConfig { + fn default() -> Self { + Self { + enabled: false, + address: SocketAddr::new(Ipv4Addr::new(0, 0, 0, 0).into(), 25575), + password: "".to_string(), + } + } +} From bb543b7178860bb297549f9c77403988d055ecae Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sat, 31 Aug 2024 17:24:36 +0200 Subject: [PATCH 08/12] Moved configuration to LazyLock --- pumpkin/src/client/authentication.rs | 13 ++++++------- pumpkin/src/client/client_packet.rs | 26 +++++++++++--------------- pumpkin/src/client/player_packet.rs | 5 +++-- pumpkin/src/config/mod.rs | 8 +++++++- pumpkin/src/main.rs | 18 ++++++------------ pumpkin/src/server.rs | 15 ++++++--------- 6 files changed, 39 insertions(+), 46 deletions(-) diff --git a/pumpkin/src/client/authentication.rs b/pumpkin/src/client/authentication.rs index 44f2054dd..13dc427fa 100644 --- a/pumpkin/src/client/authentication.rs +++ b/pumpkin/src/client/authentication.rs @@ -8,7 +8,10 @@ use serde::{Deserialize, Serialize}; use thiserror::Error; use uuid::Uuid; -use crate::{config::auth::TextureConfig, server::Server}; +use crate::{ + config::{auth::TextureConfig, ADVANCED_CONFIG}, + server::Server, +}; #[derive(Deserialize, Clone, Debug)] #[allow(non_snake_case)] @@ -52,13 +55,9 @@ pub async fn authenticate( ip: &IpAddr, server: &mut Server, ) -> Result { - assert!(server.advanced_config.authentication.enabled); + assert!(ADVANCED_CONFIG.authentication.enabled); assert!(server.auth_client.is_some()); - let address = if server - .advanced_config - .authentication - .prevent_proxy_connections - { + let address = if ADVANCED_CONFIG.authentication.prevent_proxy_connections { format!("https://sessionserver.mojang.com/session/minecraft/hasJoined?username={username}&serverId={server_hash}&ip={ip}") } else { format!("https://sessionserver.mojang.com/session/minecraft/hasJoined?username={username}&serverId={server_hash}") diff --git a/pumpkin/src/client/client_packet.rs b/pumpkin/src/client/client_packet.rs index 7ac629f5d..855c12d57 100644 --- a/pumpkin/src/client/client_packet.rs +++ b/pumpkin/src/client/client_packet.rs @@ -19,6 +19,7 @@ use sha1::{Digest, Sha1}; use crate::{ client::authentication::{self, GameProfile}, + config::{ADVANCED_CONFIG, BASIC_CONFIG}, entity::player::{ChatMode, Hand}, proxy::velocity::velocity_login, server::{Server, CURRENT_MC_VERSION}, @@ -81,7 +82,7 @@ impl Client { properties: vec![], profile_actions: None, }); - let proxy = &server.advanced_config.proxy; + let proxy = &ADVANCED_CONFIG.proxy; if proxy.enabled { if proxy.velocity.enabled { velocity_login(self) @@ -96,7 +97,7 @@ impl Client { "", public_key_der, &verify_token, - server.base_config.online_mode, // TODO + BASIC_CONFIG.online_mode, // TODO ); self.send_packet(&packet); } @@ -114,7 +115,7 @@ impl Client { self.enable_encryption(&shared_secret) .unwrap_or_else(|e| self.kick(&e.to_string())); - if server.base_config.online_mode { + if BASIC_CONFIG.online_mode { let hash = Sha1::new() .chain_update(&shared_secret) .chain_update(&server.public_key_der) @@ -132,8 +133,7 @@ impl Client { Ok(p) => { // Check if player should join if let Some(p) = &p.profile_actions { - if !server - .advanced_config + if !ADVANCED_CONFIG .authentication .player_profile .allow_banned_players @@ -142,8 +142,7 @@ impl Client { self.kick("Your account can't join"); } } else { - for allowed in server - .advanced_config + for allowed in ADVANCED_CONFIG .authentication .player_profile .allowed_actions @@ -162,16 +161,13 @@ impl Client { } for ele in self.gameprofile.as_ref().unwrap().properties.clone() { // todo, use this - unpack_textures(ele, &server.advanced_config.authentication.textures); + unpack_textures(ele, &ADVANCED_CONFIG.authentication.textures); } // enable compression - if server.advanced_config.packet_compression.enabled { - let threshold = server - .advanced_config - .packet_compression - .compression_threshold; - let level = server.advanced_config.packet_compression.compression_level; + if ADVANCED_CONFIG.packet_compression.enabled { + let threshold = ADVANCED_CONFIG.packet_compression.compression_threshold; + let level = ADVANCED_CONFIG.packet_compression.compression_level; self.send_packet(&CSetCompression::new(threshold.into())); self.set_compression(Some((threshold, level))); } @@ -199,7 +195,7 @@ impl Client { self.connection_state = ConnectionState::Config; server.send_brand(self); - let resource_config = &server.advanced_config.resource_pack; + let resource_config = &ADVANCED_CONFIG.resource_pack; if resource_config.enabled { let prompt_message = if resource_config.prompt_message.is_empty() { None diff --git a/pumpkin/src/client/player_packet.rs b/pumpkin/src/client/player_packet.rs index be6e08ccc..15fe31477 100644 --- a/pumpkin/src/client/player_packet.rs +++ b/pumpkin/src/client/player_packet.rs @@ -2,6 +2,7 @@ use std::f32::consts::PI; use crate::{ commands::{handle_command, CommandSender}, + config::ADVANCED_CONFIG, entity::player::{ChatMode, GameMode, Hand, Player}, server::Server, util::math::wrap_degrees, @@ -313,7 +314,7 @@ impl Player { } } - pub async fn handle_interact(&mut self, server: &mut Server, interact: SInteract) { + pub async fn handle_interact(&mut self, _: &mut Server, interact: SInteract) { let sneaking = interact.sneaking; if self.sneaking != sneaking { self.set_sneaking(sneaking).await; @@ -323,7 +324,7 @@ impl Player { ActionType::Attack => { let entity_id = interact.entity_id; // TODO: do validation and stuff - let config = &server.advanced_config.pvp; + let config = &ADVANCED_CONFIG.pvp; if config.enabled { let world = self.world.clone(); let world = world.lock().await; diff --git a/pumpkin/src/config/mod.rs b/pumpkin/src/config/mod.rs index 50c40b977..55369279f 100644 --- a/pumpkin/src/config/mod.rs +++ b/pumpkin/src/config/mod.rs @@ -6,6 +6,7 @@ use std::{ fs, net::{Ipv4Addr, SocketAddr}, path::Path, + sync::LazyLock, }; use crate::{entity::player::GameMode, server::Difficulty}; @@ -28,6 +29,11 @@ pub use rcon::RCONConfig; /// Current Config version of the Base Config const CURRENT_BASE_VERSION: &str = "1.0.0"; +pub static ADVANCED_CONFIG: LazyLock = + LazyLock::new(AdvancedConfiguration::load); + +pub static BASIC_CONFIG: LazyLock = LazyLock::new(BasicConfiguration::load); + /// The idea is that Pumpkin should very customizable. /// You can Enable or Disable Features depending on your needs. /// @@ -94,7 +100,7 @@ impl Default for BasicConfiguration { } } -pub trait LoadConfiguration { +trait LoadConfiguration { fn load() -> Self where Self: Sized + Default + Serialize + DeserializeOwned, diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index 9f685a84a..4acac485b 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -12,7 +12,6 @@ use std::io::{self}; use client::{interrupted, Client}; use commands::handle_command; -use config::{AdvancedConfiguration, BasicConfiguration, LoadConfiguration}; use server::Server; // Setup some tokens to allow us to identify which event is for which socket. @@ -30,6 +29,7 @@ pub mod world; fn main() -> io::Result<()> { use std::sync::{Arc, Mutex}; + use config::{ADVANCED_CONFIG, BASIC_CONFIG}; use entity::player::Player; use pumpkin_core::text::{color::NamedColor, TextComponent}; use rcon::RCONServer; @@ -61,9 +61,6 @@ fn main() -> io::Result<()> { use std::time::Instant; let time = Instant::now(); - let basic_config = BasicConfiguration::load(); - - let advanced_configuration = AdvancedConfiguration::load(); // Create a poll instance. let mut poll = Poll::new()?; @@ -71,7 +68,7 @@ fn main() -> io::Result<()> { let mut events = Events::with_capacity(128); // Setup the TCP server socket. - let addr = basic_config.server_address; + let addr = BASIC_CONFIG.server_address; let mut listener = TcpListener::bind(addr)?; // Register the server with poll we can receive events for it. @@ -81,16 +78,13 @@ fn main() -> io::Result<()> { // Unique token for each incoming connection. let mut unique_token = Token(SERVER.0 + 1); - let use_console = advanced_configuration.commands.use_console; - let rcon = advanced_configuration.rcon.clone(); + let use_console = ADVANCED_CONFIG.commands.use_console; + let rcon = ADVANCED_CONFIG.rcon.clone(); let mut clients: HashMap = HashMap::new(); let mut players: HashMap, Arc>> = HashMap::new(); - let server = Arc::new(tokio::sync::Mutex::new(Server::new(( - basic_config, - advanced_configuration, - )))); + let server = Arc::new(tokio::sync::Mutex::new(Server::new())); log::info!("Started Server took {}ms", time.elapsed().as_millis()); log::info!("You now can connect to the server, Listening on {}", addr); @@ -204,7 +198,7 @@ fn main() -> io::Result<()> { server.add_player(token.clone(), client).await; players.insert(token, player.clone()); let mut world = world.lock().await; - world.spawn_player(&server.base_config, player).await; + world.spawn_player(&BASIC_CONFIG, player).await; } } } diff --git a/pumpkin/src/server.rs b/pumpkin/src/server.rs index 582d4e992..8a2bb136a 100644 --- a/pumpkin/src/server.rs +++ b/pumpkin/src/server.rs @@ -25,7 +25,7 @@ use serde::{Deserialize, Serialize}; use crate::{ client::Client, - config::{AdvancedConfiguration, BasicConfiguration}, + config::{BasicConfiguration, BASIC_CONFIG}, entity::player::{GameMode, Player}, world::World, }; @@ -52,16 +52,15 @@ pub struct Server { pub cached_registry: Vec, entity_id: AtomicI32, - pub base_config: BasicConfiguration, - pub advanced_config: AdvancedConfiguration, /// Used for Authentication, None is Online mode is disabled pub auth_client: Option, } impl Server { - pub fn new(config: (BasicConfiguration, AdvancedConfiguration)) -> Self { - let status_response = Self::build_response(&config.0); + #[allow(clippy::new_without_default)] + pub fn new() -> Self { + let status_response = Self::build_response(&BASIC_CONFIG); let status_response_json = serde_json::to_string(&status_response) .expect("Failed to parse Status response into JSON"); let cached_server_brand = Self::build_brand(); @@ -75,7 +74,7 @@ impl Server { &private_key.e().to_bytes_be(), ) .into_boxed_slice(); - let auth_client = if config.0.online_mode { + let auth_client = if BASIC_CONFIG.online_mode { Some( reqwest::Client::builder() .timeout(Duration::from_millis(5000)) @@ -106,9 +105,7 @@ impl Server { status_response, status_response_json, public_key_der, - base_config: config.0, auth_client, - advanced_config: config.1, } } @@ -118,7 +115,7 @@ impl Server { client: Client, ) -> (Arc>, Arc>) { let entity_id = self.new_entity_id(); - let gamemode = match self.base_config.default_gamemode { + let gamemode = match BASIC_CONFIG.default_gamemode { GameMode::Undefined => GameMode::Survival, game_mode => game_mode, }; From 6740e717f7cf94c1d91dee9d647d9bea28d10e1e Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sat, 31 Aug 2024 17:38:49 +0200 Subject: [PATCH 09/12] Reordered Imports --- pumpkin/src/config/mod.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pumpkin/src/config/mod.rs b/pumpkin/src/config/mod.rs index 55369279f..5c854116d 100644 --- a/pumpkin/src/config/mod.rs +++ b/pumpkin/src/config/mod.rs @@ -1,7 +1,6 @@ use log::warn; -use proxy::ProxyConfig; -use resource_pack::ResourcePackConfig; use serde::{de::DeserializeOwned, Deserialize, Serialize}; + use std::{ fs, net::{Ipv4Addr, SocketAddr}, @@ -15,17 +14,20 @@ pub mod auth; pub mod proxy; pub mod resource_pack; -mod commands; -mod compression; -mod pvp; -mod rcon; - pub use auth::AuthenticationConfig; pub use commands::CommandsConfig; pub use compression::CompressionConfig; pub use pvp::PVPConfig; pub use rcon::RCONConfig; +mod commands; +mod compression; +mod pvp; +mod rcon; + +use proxy::ProxyConfig; +use resource_pack::ResourcePackConfig; + /// Current Config version of the Base Config const CURRENT_BASE_VERSION: &str = "1.0.0"; From 2fbf450ed35eb1cc16cdaeef6a8cf54e91f7368b Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sat, 31 Aug 2024 18:16:15 +0200 Subject: [PATCH 10/12] Moved GameMode into pumpkin-core --- Cargo.lock | 2 ++ pumpkin-core/Cargo.toml | 3 +++ pumpkin-core/src/gamemode.rs | 30 +++++++++++++++++++++++++ pumpkin-core/src/lib.rs | 3 +++ pumpkin/src/client/player_packet.rs | 4 ++-- pumpkin/src/commands/cmd_gamemode.rs | 2 +- pumpkin/src/config/mod.rs | 3 ++- pumpkin/src/entity/player.rs | 33 +++------------------------- pumpkin/src/server.rs | 3 ++- 9 files changed, 48 insertions(+), 35 deletions(-) create mode 100644 pumpkin-core/src/gamemode.rs diff --git a/Cargo.lock b/Cargo.lock index 990b46cf0..e2e6ed06c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1936,6 +1936,8 @@ dependencies = [ "colored", "fastnbt", "md5", + "num-derive", + "num-traits", "serde", "uuid", ] diff --git a/pumpkin-core/Cargo.toml b/pumpkin-core/Cargo.toml index 6bd39248b..8d7ae3900 100644 --- a/pumpkin-core/Cargo.toml +++ b/pumpkin-core/Cargo.toml @@ -9,3 +9,6 @@ fastnbt = { git = "https://github.com/owengage/fastnbt.git" } uuid.workspace = true colored = "2" md5 = "0.7.0" + +num-traits = "0.2.19" +num-derive = { version = "0.4.2" } diff --git a/pumpkin-core/src/gamemode.rs b/pumpkin-core/src/gamemode.rs new file mode 100644 index 000000000..6e996a6f9 --- /dev/null +++ b/pumpkin-core/src/gamemode.rs @@ -0,0 +1,30 @@ +use std::str::FromStr; + +use num_derive::{FromPrimitive, ToPrimitive}; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, PartialEq, Eq)] +pub struct ParseGameModeError; + +#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, FromPrimitive, ToPrimitive)] +pub enum GameMode { + Undefined = -1, + Survival, + Creative, + Adventure, + Spectator, +} + +impl FromStr for GameMode { + type Err = ParseGameModeError; + + fn from_str(s: &str) -> Result { + match s { + "survival" => Ok(Self::Survival), + "creative" => Ok(Self::Creative), + "adventure" => Ok(Self::Adventure), + "spectator" => Ok(Self::Spectator), + _ => Err(ParseGameModeError), + } + } +} diff --git a/pumpkin-core/src/lib.rs b/pumpkin-core/src/lib.rs index 4cfe1770b..d7f4f5837 100644 --- a/pumpkin-core/src/lib.rs +++ b/pumpkin-core/src/lib.rs @@ -1,2 +1,5 @@ +pub mod gamemode; pub mod random; pub mod text; + +pub use gamemode::GameMode; diff --git a/pumpkin/src/client/player_packet.rs b/pumpkin/src/client/player_packet.rs index 15fe31477..4323d0eda 100644 --- a/pumpkin/src/client/player_packet.rs +++ b/pumpkin/src/client/player_packet.rs @@ -3,12 +3,12 @@ use std::f32::consts::PI; use crate::{ commands::{handle_command, CommandSender}, config::ADVANCED_CONFIG, - entity::player::{ChatMode, GameMode, Hand, Player}, + entity::player::{ChatMode, Hand, Player}, server::Server, util::math::wrap_degrees, }; use num_traits::FromPrimitive; -use pumpkin_core::text::TextComponent; +use pumpkin_core::{text::TextComponent, GameMode}; use pumpkin_entity::EntityId; use pumpkin_inventory::WindowType; use pumpkin_protocol::server::play::{SCloseContainer, SSetPlayerGround, SUseItem}; diff --git a/pumpkin/src/commands/cmd_gamemode.rs b/pumpkin/src/commands/cmd_gamemode.rs index 375172f27..17e47fea4 100644 --- a/pumpkin/src/commands/cmd_gamemode.rs +++ b/pumpkin/src/commands/cmd_gamemode.rs @@ -2,6 +2,7 @@ use std::str::FromStr; use num_traits::FromPrimitive; use pumpkin_core::text::TextComponent; +use pumpkin_core::GameMode; use crate::commands::arg_player::{consume_arg_player, parse_arg_player}; @@ -13,7 +14,6 @@ use crate::commands::tree::{CommandTree, ConsumedArgs, RawArgs}; use crate::commands::tree_builder::{argument, require}; use crate::commands::CommandSender; use crate::commands::CommandSender::Player; -use crate::entity::player::GameMode; const NAMES: [&str; 1] = ["gamemode"]; diff --git a/pumpkin/src/config/mod.rs b/pumpkin/src/config/mod.rs index 5c854116d..6f2cb88d5 100644 --- a/pumpkin/src/config/mod.rs +++ b/pumpkin/src/config/mod.rs @@ -1,4 +1,5 @@ use log::warn; +use pumpkin_core::GameMode; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use std::{ @@ -8,7 +9,7 @@ use std::{ sync::LazyLock, }; -use crate::{entity::player::GameMode, server::Difficulty}; +use crate::server::Difficulty; pub mod auth; pub mod proxy; diff --git a/pumpkin/src/entity/player.rs b/pumpkin/src/entity/player.rs index 2ee561f41..1dd05cb50 100644 --- a/pumpkin/src/entity/player.rs +++ b/pumpkin/src/entity/player.rs @@ -1,8 +1,8 @@ -use std::{str::FromStr, sync::Arc}; +use std::sync::Arc; -use num_derive::{FromPrimitive, ToPrimitive}; +use num_derive::FromPrimitive; use num_traits::ToPrimitive; -use pumpkin_core::text::TextComponent; +use pumpkin_core::{text::TextComponent, GameMode}; use pumpkin_entity::{entity_type::EntityType, pose::EntityPose, Entity, EntityId}; use pumpkin_inventory::player::PlayerInventory; use pumpkin_protocol::{ @@ -21,7 +21,6 @@ use pumpkin_protocol::{ ConnectionState, RawPacket, ServerPacket, VarInt, }; use pumpkin_world::vector3::Vector3; -use serde::{Deserialize, Serialize}; use crate::{ client::{authentication::GameProfile, Client}, @@ -454,29 +453,3 @@ pub enum ChatMode { CommandsOnly, Hidden, } - -#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, FromPrimitive, ToPrimitive)] -pub enum GameMode { - Undefined = -1, - Survival, - Creative, - Adventure, - Spectator, -} - -#[derive(Debug, PartialEq, Eq)] -pub struct ParseGameModeError; - -impl FromStr for GameMode { - type Err = ParseGameModeError; - - fn from_str(s: &str) -> Result { - match s { - "survival" => Ok(Self::Survival), - "creative" => Ok(Self::Creative), - "adventure" => Ok(Self::Adventure), - "spectator" => Ok(Self::Spectator), - _ => Err(ParseGameModeError), - } - } -} diff --git a/pumpkin/src/server.rs b/pumpkin/src/server.rs index 8a2bb136a..00da103c9 100644 --- a/pumpkin/src/server.rs +++ b/pumpkin/src/server.rs @@ -11,6 +11,7 @@ use std::{ use base64::{engine::general_purpose, Engine}; use image::GenericImageView; use mio::Token; +use pumpkin_core::GameMode; use pumpkin_entity::EntityId; use pumpkin_plugin::PluginLoader; use pumpkin_protocol::{ @@ -26,7 +27,7 @@ use serde::{Deserialize, Serialize}; use crate::{ client::Client, config::{BasicConfiguration, BASIC_CONFIG}, - entity::player::{GameMode, Player}, + entity::player::Player, world::World, }; From a17ed23b00d6c899b124bb61ec7cd6779fbb1e02 Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sat, 31 Aug 2024 18:18:32 +0200 Subject: [PATCH 11/12] Moved Difficulty into pumpkin-core --- pumpkin-core/src/lib.rs | 10 ++++++++++ pumpkin/src/config/mod.rs | 4 +--- pumpkin/src/server.rs | 9 --------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/pumpkin-core/src/lib.rs b/pumpkin-core/src/lib.rs index d7f4f5837..ac5bdb4a5 100644 --- a/pumpkin-core/src/lib.rs +++ b/pumpkin-core/src/lib.rs @@ -3,3 +3,13 @@ pub mod random; pub mod text; pub use gamemode::GameMode; + +use serde::{Deserialize, Serialize}; + +#[derive(PartialEq, Serialize, Deserialize)] +pub enum Difficulty { + Peaceful, + Easy, + Normal, + Hard, +} diff --git a/pumpkin/src/config/mod.rs b/pumpkin/src/config/mod.rs index 6f2cb88d5..f24ca2810 100644 --- a/pumpkin/src/config/mod.rs +++ b/pumpkin/src/config/mod.rs @@ -1,5 +1,5 @@ use log::warn; -use pumpkin_core::GameMode; +use pumpkin_core::{Difficulty, GameMode}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use std::{ @@ -9,8 +9,6 @@ use std::{ sync::LazyLock, }; -use crate::server::Difficulty; - pub mod auth; pub mod proxy; pub mod resource_pack; diff --git a/pumpkin/src/server.rs b/pumpkin/src/server.rs index 00da103c9..e37f4ea0e 100644 --- a/pumpkin/src/server.rs +++ b/pumpkin/src/server.rs @@ -22,7 +22,6 @@ use pumpkin_world::dimension::Dimension; use pumpkin_registry::Registry; use rsa::{traits::PublicKeyParts, RsaPrivateKey, RsaPublicKey}; -use serde::{Deserialize, Serialize}; use crate::{ client::Client, @@ -214,11 +213,3 @@ impl Server { (pub_key, priv_key) } } - -#[derive(PartialEq, Serialize, Deserialize)] -pub enum Difficulty { - Peaceful, - Easy, - Normal, - Hard, -} From 070a50833bef0d668a014d926bed70665bb0e696 Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sat, 31 Aug 2024 18:32:48 +0200 Subject: [PATCH 12/12] Moved config into its own crate --- Cargo.lock | 11 +++++++++++ Cargo.toml | 2 +- pumpkin-config/Cargo.toml | 12 ++++++++++++ .../src/config => pumpkin-config/src}/auth.rs | 3 +-- .../config => pumpkin-config/src}/commands.rs | 0 .../src}/compression.rs | 0 .../config/mod.rs => pumpkin-config/src/lib.rs | 0 .../src/config => pumpkin-config/src}/proxy.rs | 0 .../src/config => pumpkin-config/src}/pvp.rs | 0 .../src/config => pumpkin-config/src}/rcon.rs | 0 .../src}/resource_pack.rs | 0 pumpkin-core/src/lib.rs | 7 +++++++ pumpkin/Cargo.toml | 1 + pumpkin/src/client/authentication.rs | 17 ++++------------- pumpkin/src/client/client_packet.rs | 2 +- pumpkin/src/client/player_packet.rs | 2 +- pumpkin/src/main.rs | 3 +-- pumpkin/src/proxy/velocity.rs | 3 ++- pumpkin/src/rcon/mod.rs | 3 ++- pumpkin/src/server.rs | 8 ++------ pumpkin/src/world/mod.rs | 3 ++- 21 files changed, 48 insertions(+), 29 deletions(-) create mode 100644 pumpkin-config/Cargo.toml rename {pumpkin/src/config => pumpkin-config/src}/auth.rs (97%) rename {pumpkin/src/config => pumpkin-config/src}/commands.rs (100%) rename {pumpkin/src/config => pumpkin-config/src}/compression.rs (100%) rename pumpkin/src/config/mod.rs => pumpkin-config/src/lib.rs (100%) rename {pumpkin/src/config => pumpkin-config/src}/proxy.rs (100%) rename {pumpkin/src/config => pumpkin-config/src}/pvp.rs (100%) rename {pumpkin/src/config => pumpkin-config/src}/rcon.rs (100%) rename {pumpkin/src/config => pumpkin-config/src}/resource_pack.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index e2e6ed06c..b204a8850 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1906,6 +1906,7 @@ dependencies = [ "num-bigint", "num-derive", "num-traits", + "pumpkin-config", "pumpkin-core", "pumpkin-entity", "pumpkin-inventory", @@ -1929,6 +1930,16 @@ dependencies = [ "uuid", ] +[[package]] +name = "pumpkin-config" +version = "0.1.0" +dependencies = [ + "log", + "pumpkin-core", + "serde", + "toml 0.8.19", +] + [[package]] name = "pumpkin-core" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 3fbea597f..abca231fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" -members = [ "pumpkin-core", "pumpkin-entity", "pumpkin-inventory", "pumpkin-macros/", "pumpkin-plugin", "pumpkin-protocol/", "pumpkin-registry/", "pumpkin-world", "pumpkin/"] +members = [ "pumpkin-config", "pumpkin-core", "pumpkin-entity", "pumpkin-inventory", "pumpkin-macros/", "pumpkin-plugin", "pumpkin-protocol/", "pumpkin-registry/", "pumpkin-world", "pumpkin/"] [workspace.package] version = "0.1.0" diff --git a/pumpkin-config/Cargo.toml b/pumpkin-config/Cargo.toml new file mode 100644 index 000000000..782294c9c --- /dev/null +++ b/pumpkin-config/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "pumpkin-config" +version.workspace = true +edition.workspace = true + +[dependencies] +pumpkin-core = { path = "../pumpkin-core" } + +serde = "1.0" +toml = "0.8" + +log.workspace = true diff --git a/pumpkin/src/config/auth.rs b/pumpkin-config/src/auth.rs similarity index 97% rename from pumpkin/src/config/auth.rs rename to pumpkin-config/src/auth.rs index 09c4188ff..c6606cd86 100644 --- a/pumpkin/src/config/auth.rs +++ b/pumpkin-config/src/auth.rs @@ -1,7 +1,6 @@ +use pumpkin_core::ProfileAction; use serde::{Deserialize, Serialize}; -use crate::client::authentication::ProfileAction; - #[derive(Deserialize, Serialize)] pub struct AuthenticationConfig { /// Whether to use Mojang authentication. diff --git a/pumpkin/src/config/commands.rs b/pumpkin-config/src/commands.rs similarity index 100% rename from pumpkin/src/config/commands.rs rename to pumpkin-config/src/commands.rs diff --git a/pumpkin/src/config/compression.rs b/pumpkin-config/src/compression.rs similarity index 100% rename from pumpkin/src/config/compression.rs rename to pumpkin-config/src/compression.rs diff --git a/pumpkin/src/config/mod.rs b/pumpkin-config/src/lib.rs similarity index 100% rename from pumpkin/src/config/mod.rs rename to pumpkin-config/src/lib.rs diff --git a/pumpkin/src/config/proxy.rs b/pumpkin-config/src/proxy.rs similarity index 100% rename from pumpkin/src/config/proxy.rs rename to pumpkin-config/src/proxy.rs diff --git a/pumpkin/src/config/pvp.rs b/pumpkin-config/src/pvp.rs similarity index 100% rename from pumpkin/src/config/pvp.rs rename to pumpkin-config/src/pvp.rs diff --git a/pumpkin/src/config/rcon.rs b/pumpkin-config/src/rcon.rs similarity index 100% rename from pumpkin/src/config/rcon.rs rename to pumpkin-config/src/rcon.rs diff --git a/pumpkin/src/config/resource_pack.rs b/pumpkin-config/src/resource_pack.rs similarity index 100% rename from pumpkin/src/config/resource_pack.rs rename to pumpkin-config/src/resource_pack.rs diff --git a/pumpkin-core/src/lib.rs b/pumpkin-core/src/lib.rs index ac5bdb4a5..9539acae3 100644 --- a/pumpkin-core/src/lib.rs +++ b/pumpkin-core/src/lib.rs @@ -13,3 +13,10 @@ pub enum Difficulty { Normal, Hard, } + +#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)] +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] +pub enum ProfileAction { + ForcedNameChange, + UsingBannedSkin, +} diff --git a/pumpkin/Cargo.toml b/pumpkin/Cargo.toml index 0494fc462..804506fd3 100644 --- a/pumpkin/Cargo.toml +++ b/pumpkin/Cargo.toml @@ -10,6 +10,7 @@ default = [] [dependencies] # pumpkin pumpkin-core = { path = "../pumpkin-core"} +pumpkin-config = { path = "../pumpkin-config" } pumpkin-plugin = { path = "../pumpkin-plugin"} pumpkin-inventory = { path = "../pumpkin-inventory"} pumpkin-world = { path = "../pumpkin-world"} diff --git a/pumpkin/src/client/authentication.rs b/pumpkin/src/client/authentication.rs index 13dc427fa..692cf266c 100644 --- a/pumpkin/src/client/authentication.rs +++ b/pumpkin/src/client/authentication.rs @@ -2,16 +2,15 @@ use std::{collections::HashMap, net::IpAddr}; use base64::{engine::general_purpose, Engine}; use num_bigint::BigInt; +use pumpkin_config::{auth::TextureConfig, ADVANCED_CONFIG}; +use pumpkin_core::ProfileAction; use pumpkin_protocol::Property; use reqwest::{StatusCode, Url}; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; use thiserror::Error; use uuid::Uuid; -use crate::{ - config::{auth::TextureConfig, ADVANCED_CONFIG}, - server::Server, -}; +use crate::server::Server; #[derive(Deserialize, Clone, Debug)] #[allow(non_snake_case)] @@ -32,14 +31,6 @@ pub struct Texture { metadata: Option>, } -#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)] -pub enum ProfileAction { - #[serde(rename = "FORCED_NAME_CHANGE")] - ForcedNameChange, - #[serde(rename = "USING_BANNED_SKIN")] - UsingBannedSkin, -} - #[derive(Deserialize, Clone, Debug)] pub struct GameProfile { pub id: Uuid, diff --git a/pumpkin/src/client/client_packet.rs b/pumpkin/src/client/client_packet.rs index 855c12d57..1c70b0e7c 100644 --- a/pumpkin/src/client/client_packet.rs +++ b/pumpkin/src/client/client_packet.rs @@ -1,4 +1,5 @@ use num_traits::FromPrimitive; +use pumpkin_config::{ADVANCED_CONFIG, BASIC_CONFIG}; use pumpkin_core::text::TextComponent; use pumpkin_protocol::{ client::{ @@ -19,7 +20,6 @@ use sha1::{Digest, Sha1}; use crate::{ client::authentication::{self, GameProfile}, - config::{ADVANCED_CONFIG, BASIC_CONFIG}, entity::player::{ChatMode, Hand}, proxy::velocity::velocity_login, server::{Server, CURRENT_MC_VERSION}, diff --git a/pumpkin/src/client/player_packet.rs b/pumpkin/src/client/player_packet.rs index 4323d0eda..1602a5d89 100644 --- a/pumpkin/src/client/player_packet.rs +++ b/pumpkin/src/client/player_packet.rs @@ -2,12 +2,12 @@ use std::f32::consts::PI; use crate::{ commands::{handle_command, CommandSender}, - config::ADVANCED_CONFIG, entity::player::{ChatMode, Hand, Player}, server::Server, util::math::wrap_degrees, }; use num_traits::FromPrimitive; +use pumpkin_config::ADVANCED_CONFIG; use pumpkin_core::{text::TextComponent, GameMode}; use pumpkin_entity::EntityId; use pumpkin_inventory::WindowType; diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index 4acac485b..79cd54053 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -18,7 +18,6 @@ use server::Server; pub mod client; pub mod commands; -pub mod config; pub mod entity; pub mod proxy; pub mod rcon; @@ -29,8 +28,8 @@ pub mod world; fn main() -> io::Result<()> { use std::sync::{Arc, Mutex}; - use config::{ADVANCED_CONFIG, BASIC_CONFIG}; use entity::player::Player; + use pumpkin_config::{ADVANCED_CONFIG, BASIC_CONFIG}; use pumpkin_core::text::{color::NamedColor, TextComponent}; use rcon::RCONServer; diff --git a/pumpkin/src/proxy/velocity.rs b/pumpkin/src/proxy/velocity.rs index 3b06ff97a..b2f753506 100644 --- a/pumpkin/src/proxy/velocity.rs +++ b/pumpkin/src/proxy/velocity.rs @@ -2,12 +2,13 @@ use std::net::SocketAddr; use bytes::{BufMut, BytesMut}; use hmac::{Hmac, Mac}; +use pumpkin_config::proxy::VelocityConfig; use pumpkin_protocol::{ bytebuf::ByteBuffer, client::login::CLoginPluginRequest, server::login::SLoginPluginResponse, }; use sha2::Sha256; -use crate::{client::Client, config::proxy::VelocityConfig}; +use crate::client::Client; type HmacSha256 = Hmac; diff --git a/pumpkin/src/rcon/mod.rs b/pumpkin/src/rcon/mod.rs index 3f20ffd54..19a5b17d6 100644 --- a/pumpkin/src/rcon/mod.rs +++ b/pumpkin/src/rcon/mod.rs @@ -9,9 +9,10 @@ use mio::{ Events, Interest, Poll, Token, }; use packet::{Packet, PacketError, PacketType}; +use pumpkin_config::RCONConfig; use thiserror::Error; -use crate::{commands::handle_command, config::RCONConfig, server::Server}; +use crate::{commands::handle_command, server::Server}; mod packet; diff --git a/pumpkin/src/server.rs b/pumpkin/src/server.rs index e37f4ea0e..8082b1daf 100644 --- a/pumpkin/src/server.rs +++ b/pumpkin/src/server.rs @@ -11,6 +11,7 @@ use std::{ use base64::{engine::general_purpose, Engine}; use image::GenericImageView; use mio::Token; +use pumpkin_config::{BasicConfiguration, BASIC_CONFIG}; use pumpkin_core::GameMode; use pumpkin_entity::EntityId; use pumpkin_plugin::PluginLoader; @@ -23,12 +24,7 @@ use pumpkin_world::dimension::Dimension; use pumpkin_registry::Registry; use rsa::{traits::PublicKeyParts, RsaPrivateKey, RsaPublicKey}; -use crate::{ - client::Client, - config::{BasicConfiguration, BASIC_CONFIG}, - entity::player::Player, - world::World, -}; +use crate::{client::Client, entity::player::Player, world::World}; pub const CURRENT_MC_VERSION: &str = "1.21.1"; diff --git a/pumpkin/src/world/mod.rs b/pumpkin/src/world/mod.rs index 337f6332b..77123a0ab 100644 --- a/pumpkin/src/world/mod.rs +++ b/pumpkin/src/world/mod.rs @@ -6,6 +6,7 @@ use std::{ use mio::Token; use num_traits::ToPrimitive; +use pumpkin_config::BasicConfiguration; use pumpkin_entity::{entity_type::EntityType, EntityId}; use pumpkin_protocol::{ client::play::{ @@ -19,7 +20,7 @@ use pumpkin_protocol::{ use pumpkin_world::{level::Level, radial_chunk_iterator::RadialIterator}; use tokio::sync::mpsc; -use crate::{config::BasicConfiguration, entity::player::Player}; +use crate::entity::player::Player; pub struct World { pub level: Arc>,