aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-17 09:43:26 +0000
committerFuwn <[email protected]>2021-05-17 09:43:26 +0000
commit34101185feeebca00b4f142a9b13ff0d0e28531a (patch)
treeb341ddaed17fe05d001536d3d5ec03f8941c236d /src
parentperf(builtins): help commands to constants (diff)
downloadwhirl-34101185feeebca00b4f142a9b13ff0d0e28531a.tar.xz
whirl-34101185feeebca00b4f142a9b13ff0d0e28531a.zip
refactor(global): whirl_config modulized
The config module has now become it's own crate.
Diffstat (limited to 'src')
-rw-r--r--src/cli.rs3
-rw-r--r--src/config/Whirl.default.toml24
-rw-r--r--src/config/mod.rs99
-rw-r--r--src/lib.rs1
-rw-r--r--src/main.rs3
-rw-r--r--src/prompt/builtins.rs3
-rw-r--r--src/prompt/mod.rs27
-rw-r--r--src/server/cmd/commands/property/create.rs41
-rw-r--r--src/server/cmd/commands/redirect_id.rs6
-rw-r--r--src/server/distributor.rs38
-rw-r--r--src/server/hub.rs40
-rw-r--r--src/subs.rs3
-rw-r--r--src/utils/log.rs2
13 files changed, 80 insertions, 210 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 02a6e1e..6565845 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -2,8 +2,9 @@
// SPDX-License-Identifier: GPL-3.0-only
use structopt::clap::{App, AppSettings, Arg, ArgMatches, Shell, SubCommand};
+use whirl_config::Config;
-use crate::{config::Config, subs::run};
+use crate::subs::run;
pub struct Cli;
impl Cli {
diff --git a/src/config/Whirl.default.toml b/src/config/Whirl.default.toml
deleted file mode 100644
index aa2d684..0000000
--- a/src/config/Whirl.default.toml
+++ /dev/null
@@ -1,24 +0,0 @@
-# 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/src/config/mod.rs b/src/config/mod.rs
deleted file mode 100644
index bc350ea..0000000
--- a/src/config/mod.rs
+++ /dev/null
@@ -1,99 +0,0 @@
-// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
-// SPDX-License-Identifier: GPL-3.0-only
-
-use config::{ConfigError, File};
-
-#[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,
-}
-
-#[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/src/lib.rs b/src/lib.rs
index 1c60e70..527647b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -23,7 +23,6 @@ extern crate async_trait;
extern crate simple_error;
pub mod cli;
-pub mod config;
pub mod prompt;
pub mod subs;
diff --git a/src/main.rs b/src/main.rs
index 0ec0796..e48fbbb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,7 +3,8 @@
use std::error::Error;
-use whirl::{cli::Cli, config::Config, utils::log::calculate_log_level};
+use whirl::{cli::Cli, utils::log::calculate_log_level};
+use whirl_config::Config;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
diff --git a/src/prompt/builtins.rs b/src/prompt/builtins.rs
index e8952bf..442aeb5 100644
--- a/src/prompt/builtins.rs
+++ b/src/prompt/builtins.rs
@@ -4,8 +4,7 @@
use std::{io::Write, str::FromStr};
use sysinfo::SystemExt;
-
-use crate::config::Config;
+use whirl_config::Config;
const FILES: [&str; 2] = ["README.rst", "Whirl.toml"];
const HELPABLES_BUILTINS: [&str; 8] = [
diff --git a/src/prompt/mod.rs b/src/prompt/mod.rs
index 990dd10..d142cb1 100644
--- a/src/prompt/mod.rs
+++ b/src/prompt/mod.rs
@@ -6,21 +6,20 @@ mod structure;
use std::{io, io::Write, str::FromStr};
-use crate::{
- config::Config,
- prompt::{
- builtins::{
- builtin_cat,
- builtin_config,
- builtin_echo,
- builtin_fetch,
- builtin_help,
- builtin_history,
- builtin_ls,
- BuiltIn,
- },
- structure::Command,
+use whirl_config::Config;
+
+use crate::prompt::{
+ builtins::{
+ builtin_cat,
+ builtin_config,
+ builtin_echo,
+ builtin_fetch,
+ builtin_help,
+ builtin_history,
+ builtin_ls,
+ BuiltIn,
},
+ structure::Command,
};
pub struct Prompt {
diff --git a/src/server/cmd/commands/property/create.rs b/src/server/cmd/commands/property/create.rs
index 9908b27..88a9293 100644
--- a/src/server/cmd/commands/property/create.rs
+++ b/src/server/cmd/commands/property/create.rs
@@ -3,28 +3,27 @@
// TODO: of2m-ify?
-use crate::{
- config::Config,
- server::{
- cmd::constants::{PROPUPD, SESSINIT},
- net::{
- constants::{
- VAR_APPNAME,
- VAR_CHANNEL,
- VAR_ERROR,
- VAR_EXTERNAL_HTTP_SERVER,
- VAR_MAIL_DOMAIN,
- VAR_PRIV,
- VAR_PROTOCOL,
- VAR_SCRIPT_SERVER,
- VAR_SERIAL,
- VAR_SERVERTYPE,
- VAR_SMTP_SERVER,
- VAR_UPDATETIME,
- },
- converter::property_list_to_bytes,
- structure::NetworkProperty,
+use whirl_config::Config;
+
+use crate::server::{
+ cmd::constants::{PROPUPD, SESSINIT},
+ net::{
+ constants::{
+ VAR_APPNAME,
+ VAR_CHANNEL,
+ VAR_ERROR,
+ VAR_EXTERNAL_HTTP_SERVER,
+ VAR_MAIL_DOMAIN,
+ VAR_PRIV,
+ VAR_PROTOCOL,
+ VAR_SCRIPT_SERVER,
+ VAR_SERIAL,
+ VAR_SERVERTYPE,
+ VAR_SMTP_SERVER,
+ VAR_UPDATETIME,
},
+ converter::property_list_to_bytes,
+ structure::NetworkProperty,
},
};
diff --git a/src/server/cmd/commands/redirect_id.rs b/src/server/cmd/commands/redirect_id.rs
index e6d3ddd..edaf46e 100644
--- a/src/server/cmd/commands/redirect_id.rs
+++ b/src/server/cmd/commands/redirect_id.rs
@@ -2,11 +2,9 @@
// SPDX-License-Identifier: GPL-3.0-only
use bytes::{BufMut, BytesMut};
+use whirl_config::Config;
-use crate::{
- config::Config,
- server::cmd::{constants::REDIRID, extendable::Creatable},
-};
+use crate::server::cmd::{constants::REDIRID, extendable::Creatable};
#[derive(Debug)]
pub struct RedirectId {
diff --git a/src/server/distributor.rs b/src/server/distributor.rs
index cfcaa63..4267a78 100644
--- a/src/server/distributor.rs
+++ b/src/server/distributor.rs
@@ -16,30 +16,28 @@ use std::{error::Error, net::SocketAddr, sync::Arc};
use tokio::{io::AsyncWriteExt, net::TcpStream, sync::Mutex};
use tokio_stream::StreamExt;
use tokio_util::codec::{BytesCodec, Decoder};
+use whirl_config::Config;
-use crate::{
- config::Config,
- server::{
- cmd::{
- commands::{
- action::create_action,
- buddy_list::BuddyList,
- property::{
- create::{create_property_request_as_distributor, create_property_update_as_distributor},
- parse::find_property_in_property_list,
- },
- redirect_id::RedirectId,
- room_id_request::RoomIdRequest,
- text::Text,
+use crate::server::{
+ cmd::{
+ commands::{
+ action::create_action,
+ buddy_list::BuddyList,
+ property::{
+ create::{create_property_request_as_distributor, create_property_update_as_distributor},
+ parse::find_property_in_property_list,
},
- constants::*,
- extendable::{Creatable, Parsable},
+ redirect_id::RedirectId,
+ room_id_request::RoomIdRequest,
+ text::Text,
},
- interaction::{peer::Peer, shared::Shared},
- net::{constants::VAR_USERNAME, property_parser::parse_network_property},
- packet_parser::parse_commands_from_packet,
- Server,
+ constants::*,
+ extendable::{Creatable, Parsable},
},
+ interaction::{peer::Peer, shared::Shared},
+ net::{constants::VAR_USERNAME, property_parser::parse_network_property},
+ packet_parser::parse_commands_from_packet,
+ Server,
};
pub struct Distributor;
diff --git a/src/server/hub.rs b/src/server/hub.rs
index c6e5be8..99ba600 100644
--- a/src/server/hub.rs
+++ b/src/server/hub.rs
@@ -12,31 +12,29 @@ use std::{error::Error, net::SocketAddr, sync::Arc};
use tokio::{io::AsyncWriteExt, net::TcpStream, sync::Mutex};
use tokio_stream::StreamExt;
use tokio_util::codec::{BytesCodec, Decoder};
+use whirl_config::Config;
-use crate::{
- config::Config,
- server::{
- cmd::{
- commands::{
- action::create_action,
- buddy_list::BuddyList,
- property::{
- create::{create_property_request_as_hub, create_property_update_as_hub},
- parse::find_property_in_property_list,
- },
- subscribe_distance::SubscribeDistance,
- subscribe_room::SubscribeRoom,
- teleport::Teleport,
- text::Text,
+use crate::server::{
+ cmd::{
+ commands::{
+ action::create_action,
+ buddy_list::BuddyList,
+ property::{
+ create::{create_property_request_as_hub, create_property_update_as_hub},
+ parse::find_property_in_property_list,
},
- constants::*,
- extendable::{Creatable, Parsable, ParsableWithArguments},
+ subscribe_distance::SubscribeDistance,
+ subscribe_room::SubscribeRoom,
+ teleport::Teleport,
+ text::Text,
},
- interaction::{peer::Peer, shared::Shared},
- net::{constants::VAR_USERNAME, property_parser::parse_network_property},
- packet_parser::parse_commands_from_packet,
- Server,
+ constants::*,
+ extendable::{Creatable, Parsable, ParsableWithArguments},
},
+ interaction::{peer::Peer, shared::Shared},
+ net::{constants::VAR_USERNAME, property_parser::parse_network_property},
+ packet_parser::parse_commands_from_packet,
+ Server,
};
pub struct Hub;
diff --git a/src/subs.rs b/src/subs.rs
index 18107bc..dbf9b21 100644
--- a/src/subs.rs
+++ b/src/subs.rs
@@ -1,9 +1,10 @@
// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
// SPDX-License-Identifier: GPL-3.0-only
+use whirl_config::Config;
+
use crate::{
api::Api,
- config::Config,
prompt::Prompt,
server::{
distributor::Distributor,
diff --git a/src/utils/log.rs b/src/utils/log.rs
index e4a45e9..39ceca0 100644
--- a/src/utils/log.rs
+++ b/src/utils/log.rs
@@ -1,7 +1,7 @@
// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
// SPDX-License-Identifier: GPL-3.0-only
-use crate::config::Config;
+use whirl_config::Config;
pub fn calculate_log_level() -> String {
let mut level;