chore: merge config files
This commit is contained in:
parent
6d63a72354
commit
c8633b78d7
3
.gitignore
vendored
3
.gitignore
vendored
@ -107,8 +107,7 @@ crash-reports/
|
|||||||
data/*
|
data/*
|
||||||
|
|
||||||
# project's configurations
|
# project's configurations
|
||||||
configuration.toml
|
pumpkin.toml
|
||||||
features.toml
|
|
||||||
|
|
||||||
|
|
||||||
*.local.nbt
|
*.local.nbt
|
||||||
|
|||||||
@ -45,6 +45,26 @@ use player_data::PlayerDataConfig;
|
|||||||
use resource_pack::ResourcePackConfig;
|
use resource_pack::ResourcePackConfig;
|
||||||
use world::LevelConfig;
|
use world::LevelConfig;
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, Default)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub struct PumpkinConfig {
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub basic: BasicConfiguration,
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub advanced: AdvancedConfiguration,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LoadConfiguration for PumpkinConfig {
|
||||||
|
fn get_path() -> &'static Path {
|
||||||
|
Path::new("pumpkin.toml")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn validate(&self) {
|
||||||
|
self.basic.validate();
|
||||||
|
self.advanced.validate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Advanced configuration for optional and feature-specific server settings.
|
/// Advanced configuration for optional and feature-specific server settings.
|
||||||
///
|
///
|
||||||
/// Allows enabling/disabling features, customizing behaviour, and
|
/// Allows enabling/disabling features, customizing behaviour, and
|
||||||
@ -179,6 +199,38 @@ impl BasicConfiguration {
|
|||||||
pub fn get_world_path(&self) -> PathBuf {
|
pub fn get_world_path(&self) -> PathBuf {
|
||||||
PathBuf::from(&self.default_level_name)
|
PathBuf::from(&self.default_level_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn validate(&self) {
|
||||||
|
let min = NonZeroU8::new(2).unwrap();
|
||||||
|
let max = NonZeroU8::new(64).unwrap();
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
self.view_distance.ge(&min),
|
||||||
|
"View distance must be at least 2"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
self.view_distance.le(&max),
|
||||||
|
"View distance must be less than 64"
|
||||||
|
);
|
||||||
|
if self.online_mode {
|
||||||
|
assert!(
|
||||||
|
self.encryption,
|
||||||
|
"When online mode is enabled, encryption must be enabled"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if self.allow_chat_reports {
|
||||||
|
assert!(
|
||||||
|
self.online_mode,
|
||||||
|
"When allow_chat_reports is enabled, online_mode must be enabled"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AdvancedConfiguration {
|
||||||
|
pub const fn validate(&self) {
|
||||||
|
//self.resource_pack.validate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait for loading and validating configuration from a TOML file.
|
/// Trait for loading and validating configuration from a TOML file.
|
||||||
@ -312,45 +364,3 @@ pub trait LoadConfiguration {
|
|||||||
/// Validates the configuration after loading or merging.
|
/// Validates the configuration after loading or merging.
|
||||||
fn validate(&self);
|
fn validate(&self);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LoadConfiguration for AdvancedConfiguration {
|
|
||||||
fn get_path() -> &'static Path {
|
|
||||||
Path::new("features.toml")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn validate(&self) {
|
|
||||||
//self.resource_pack.validate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LoadConfiguration for BasicConfiguration {
|
|
||||||
fn get_path() -> &'static Path {
|
|
||||||
Path::new("configuration.toml")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn validate(&self) {
|
|
||||||
let min = NonZeroU8::new(2).unwrap();
|
|
||||||
let max = NonZeroU8::new(64).unwrap();
|
|
||||||
|
|
||||||
assert!(
|
|
||||||
self.view_distance.ge(&min),
|
|
||||||
"View distance must be at least 2"
|
|
||||||
);
|
|
||||||
assert!(
|
|
||||||
self.view_distance.le(&max),
|
|
||||||
"View distance must be less than 64"
|
|
||||||
);
|
|
||||||
if self.online_mode {
|
|
||||||
assert!(
|
|
||||||
self.encryption,
|
|
||||||
"When online mode is enabled, encryption must be enabled"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if self.allow_chat_reports {
|
|
||||||
assert!(
|
|
||||||
self.online_mode,
|
|
||||||
"When allow_chat_reports is enabled, online_mode must be enabled"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -27,7 +27,7 @@ use pumpkin::{
|
|||||||
};
|
};
|
||||||
use pumpkin::{LoggerOption, PumpkinServer, SHOULD_STOP, STOP_INTERRUPT, stop_server};
|
use pumpkin::{LoggerOption, PumpkinServer, SHOULD_STOP, STOP_INTERRUPT, stop_server};
|
||||||
|
|
||||||
use pumpkin_config::{AdvancedConfiguration, BasicConfiguration, LoadConfiguration};
|
use pumpkin_config::{LoadConfiguration, PumpkinConfig};
|
||||||
use pumpkin_util::text::{
|
use pumpkin_util::text::{
|
||||||
TextComponent,
|
TextComponent,
|
||||||
color::{Color, NamedColor},
|
color::{Color, NamedColor},
|
||||||
@ -75,14 +75,12 @@ async fn main() {
|
|||||||
let time = Instant::now();
|
let time = Instant::now();
|
||||||
|
|
||||||
let exec_dir = std::env::current_dir().unwrap();
|
let exec_dir = std::env::current_dir().unwrap();
|
||||||
let config_dir = exec_dir.join("config");
|
|
||||||
|
|
||||||
let basic_config = BasicConfiguration::load(&config_dir);
|
let config = PumpkinConfig::load(&exec_dir);
|
||||||
let advanced_config = AdvancedConfiguration::load(&config_dir);
|
|
||||||
|
|
||||||
let vanilla_data = VanillaData::load();
|
let vanilla_data = VanillaData::load();
|
||||||
|
|
||||||
pumpkin::init_logger(&advanced_config);
|
pumpkin::init_logger(&config.advanced);
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
"{}",
|
"{}",
|
||||||
@ -120,7 +118,7 @@ async fn main() {
|
|||||||
.expect("Unable to setup signal handlers");
|
.expect("Unable to setup signal handlers");
|
||||||
});
|
});
|
||||||
|
|
||||||
let pumpkin_server = PumpkinServer::new(basic_config, advanced_config, vanilla_data).await;
|
let pumpkin_server = PumpkinServer::new(config.basic, config.advanced, vanilla_data).await;
|
||||||
let plugin_wait_time = pumpkin_server.init_plugins().await;
|
let plugin_wait_time = pumpkin_server.init_plugins().await;
|
||||||
|
|
||||||
let time_elapsed = time.elapsed().saturating_sub(plugin_wait_time);
|
let time_elapsed = time.elapsed().saturating_sub(plugin_wait_time);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user