diff options
| author | Fuwn <[email protected]> | 2021-05-20 17:05:59 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-20 17:05:59 +0000 |
| commit | 9dbc613765de8ab7dfa8e1374cf6661dcfd56bc8 (patch) | |
| tree | 8cfff6a23bb72db2660e68c63a8cf9d0539a061f /crates/whirl_config | |
| parent | feat(readme): add sqlfluff as a dev dep (diff) | |
| download | whirl-9dbc613765de8ab7dfa8e1374cf6661dcfd56bc8.tar.xz whirl-9dbc613765de8ab7dfa8e1374cf6661dcfd56bc8.zip | |
refactor(global): move crates around, stricter module isolation
Diffstat (limited to 'crates/whirl_config')
| -rw-r--r-- | crates/whirl_config/.license_template | 2 | ||||
| -rw-r--r-- | crates/whirl_config/Cargo.toml | 25 | ||||
| -rw-r--r-- | crates/whirl_config/Whirl.default.toml | 24 | ||||
| -rw-r--r-- | crates/whirl_config/src/lib.rs | 90 | ||||
| -rw-r--r-- | crates/whirl_config/src/structures.rs | 37 |
5 files changed, 178 insertions, 0 deletions
diff --git a/crates/whirl_config/.license_template b/crates/whirl_config/.license_template new file mode 100644 index 0000000..1fda769 --- /dev/null +++ b/crates/whirl_config/.license_template @@ -0,0 +1,2 @@ +// Copyleft (ɔ) {20\d{2}(-20\d{2})?} The Whirlsplash Collective +// SPDX-License-Identifier: GPL-3.0-only diff --git a/crates/whirl_config/Cargo.toml b/crates/whirl_config/Cargo.toml new file mode 100644 index 0000000..64100d1 --- /dev/null +++ b/crates/whirl_config/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "whirl_config" +version = "0.1.0" +authors = ["Fuwn <[email protected]>"] +edition = "2018" +description = "Whirl, an open-source WorldServer implementation in Rust." +documentation = "https://whirlsplash.org/docs/" +readme = "../../README.rst" +homepage = "https://whirlsplash.org" +repository = "https://github.com/Whirlsplash/whirl" +license = "GPL-3.0-only" +# license-file = "LICENSE" +keywords = ["rust", "worldserver", "whirl", "whirlsplash"] +publish = false + +[dependencies] +# Config +config = "0.11.0" + +# Serialization +serde = "1.0.126" +serde_derive = "1.0.126" + +# Logging +log = "0.4.14" diff --git a/crates/whirl_config/Whirl.default.toml b/crates/whirl_config/Whirl.default.toml new file mode 100644 index 0000000..aa2d684 --- /dev/null +++ b/crates/whirl_config/Whirl.default.toml @@ -0,0 +1,24 @@ +# See more keys and their definitions at https://whirlsplash.org/docs/whirl/configuration + +[whirlsplash] +worldsmaster_username = "WORLDSMASTER" +ip = "0.0.0.0" +api.port = 8080 + +[whirlsplash.prompt] +enable = false +ps1 = "[WORLDSMASTER@Whirlsplash ~]$" + +[whirlsplash.log] +enable = true +level = 1 +everything = false +test = false +file = true + +[distributor] +worldsmaster_greeting = "Welcome to Whirlsplash!" +port = 6650 + +[hub] +port = 5673 diff --git a/crates/whirl_config/src/lib.rs b/crates/whirl_config/src/lib.rs new file mode 100644 index 0000000..8f312cd --- /dev/null +++ b/crates/whirl_config/src/lib.rs @@ -0,0 +1,90 @@ +// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective +// SPDX-License-Identifier: GPL-3.0-only + +#![feature( + type_ascription, + hash_set_entry, + type_name_of_val, + decl_macro, + proc_macro_hygiene +)] +#![warn(rust_2018_idioms)] +#![recursion_limit = "128"] + +#[macro_use] +extern crate serde_derive; +#[macro_use] +extern crate log; + +mod structures; + +use config::{ConfigError, File}; + +use crate::structures::{ + DistributorConfig, + HubConfig, + WhirlsplashApiConfig, + WhirlsplashConfig, + WhirlsplashLogConfig, + WhirlsplashPromptConfig, +}; + +#[derive(Serialize, Deserialize, Debug)] +pub struct Config { + pub whirlsplash: WhirlsplashConfig, + pub distributor: DistributorConfig, + pub hub: HubConfig, +} +impl Config { + pub fn refresh() { let _ = config::Config::new().refresh(); } + + fn load() -> Result<Self, ConfigError> { + let mut s = config::Config::new(); + + s.merge(File::with_name("./Whirl.toml").required(false))?; + s.try_into() + } + + pub fn get() -> Config { + return if let Err(why) = Self::load() { + error!( + "unable to load configuration file, reverting to default value: {}", + why + ); + Self::default() + } else { + Self::load().unwrap() + }; + } +} +impl Default for Config { + fn default() -> Self { + Config { + whirlsplash: WhirlsplashConfig { + worldsmaster_username: "WORLDSMASTER".to_string(), + ip: "0.0.0.0".to_string(), + api: WhirlsplashApiConfig { + port: 80 + }, + prompt: WhirlsplashPromptConfig { + enable: false, + ps1: "[WORLDSMASTER@Whirlsplash ~]$".to_string(), + }, + log: WhirlsplashLogConfig { + enable: true, + level: 1, + everything: false, + test: false, + file: true, + }, + }, + distributor: DistributorConfig { + worldsmaster_greeting: "Welcome to Whirlsplash!".to_string(), + port: 6650, + }, + hub: HubConfig { + port: 5673 + }, + } + } +} diff --git a/crates/whirl_config/src/structures.rs b/crates/whirl_config/src/structures.rs new file mode 100644 index 0000000..4f1d62e --- /dev/null +++ b/crates/whirl_config/src/structures.rs @@ -0,0 +1,37 @@ +// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective +// SPDX-License-Identifier: GPL-3.0-only + +#[derive(Serialize, Deserialize, Debug)] +pub struct WhirlsplashConfig { + pub worldsmaster_username: String, + pub ip: String, + pub api: WhirlsplashApiConfig, + pub prompt: WhirlsplashPromptConfig, + pub log: WhirlsplashLogConfig, +} +#[derive(Serialize, Deserialize, Debug)] +pub struct WhirlsplashApiConfig { + pub port: i64, +} +#[derive(Serialize, Deserialize, Debug)] +pub struct WhirlsplashPromptConfig { + pub enable: bool, + pub ps1: String, +} +#[derive(Serialize, Deserialize, Debug)] +pub struct WhirlsplashLogConfig { + pub enable: bool, + pub level: i64, + pub everything: bool, + pub test: bool, + pub file: bool, +} +#[derive(Serialize, Deserialize, Debug)] +pub struct DistributorConfig { + pub worldsmaster_greeting: String, + pub port: i64, +} +#[derive(Serialize, Deserialize, Debug)] +pub struct HubConfig { + pub port: i64, +} |