diff options
| author | Fuwn <[email protected]> | 2021-05-17 09:43:26 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-17 09:43:26 +0000 |
| commit | 34101185feeebca00b4f142a9b13ff0d0e28531a (patch) | |
| tree | b341ddaed17fe05d001536d3d5ec03f8941c236d | |
| parent | perf(builtins): help commands to constants (diff) | |
| download | whirl-34101185feeebca00b4f142a9b13ff0d0e28531a.tar.xz whirl-34101185feeebca00b4f142a9b13ff0d0e28531a.zip | |
refactor(global): whirl_config modulized
The config module has now become it's own crate.
| -rw-r--r-- | Cargo.toml | 9 | ||||
| -rw-r--r-- | src/cli.rs | 3 | ||||
| -rw-r--r-- | src/lib.rs | 1 | ||||
| -rw-r--r-- | src/main.rs | 3 | ||||
| -rw-r--r-- | src/prompt/builtins.rs | 3 | ||||
| -rw-r--r-- | src/prompt/mod.rs | 27 | ||||
| -rw-r--r-- | src/server/cmd/commands/property/create.rs | 41 | ||||
| -rw-r--r-- | src/server/cmd/commands/redirect_id.rs | 6 | ||||
| -rw-r--r-- | src/server/distributor.rs | 38 | ||||
| -rw-r--r-- | src/server/hub.rs | 40 | ||||
| -rw-r--r-- | src/subs.rs | 3 | ||||
| -rw-r--r-- | src/utils/log.rs | 2 | ||||
| -rw-r--r-- | whirl_config/Cargo.toml | 25 | ||||
| -rw-r--r-- | whirl_config/Whirl.default.toml (renamed from src/config/Whirl.default.toml) | 0 | ||||
| -rw-r--r-- | whirl_config/src/lib.rs (renamed from src/config/mod.rs) | 5 |
15 files changed, 117 insertions, 89 deletions
@@ -15,6 +15,9 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[workspace] +members = ["whirl_config"] + [dependencies] # Environment dotenv = "0.15.0" @@ -32,15 +35,17 @@ simple-error = "0.2.3" # Byte Manipulation bytes = "1.0.1" +byteorder = "1.4.3" + +# Serialization serde = "1.0.126" serde_derive = "1.0.126" -byteorder = "1.4.3" # CLI structopt = "0.3.21" # Config -config = "0.11.0" +whirl_config = { path = "./whirl_config" } # TCP tokio = { version = "1.6.0", features = ["full"] } @@ -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 { @@ -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; diff --git a/whirl_config/Cargo.toml b/whirl_config/Cargo.toml new file mode 100644 index 0000000..55de1e2 --- /dev/null +++ b/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.md" +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/src/config/Whirl.default.toml b/whirl_config/Whirl.default.toml index aa2d684..aa2d684 100644 --- a/src/config/Whirl.default.toml +++ b/whirl_config/Whirl.default.toml diff --git a/src/config/mod.rs b/whirl_config/src/lib.rs index bc350ea..a4d23e5 100644 --- a/src/config/mod.rs +++ b/whirl_config/src/lib.rs @@ -1,6 +1,11 @@ // Copyleft (ɔ) 2021-2021 The Whirlsplash Collective // SPDX-License-Identifier: GPL-3.0-only +#[macro_use] +extern crate serde_derive; +#[macro_use] +extern crate log; + use config::{ConfigError, File}; #[derive(Serialize, Deserialize, Debug)] |