diff options
| author | Fuwn <[email protected]> | 2024-06-03 15:23:14 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-06-03 15:23:14 -0700 |
| commit | 19010055c88fd7aac23f3ce39fa6a5ec1cbf9a52 (patch) | |
| tree | 22353b8c7a78b83c992b7bfb60c024fee6f78e3e | |
| parent | chore(rustfmt): add new rules (diff) | |
| download | whirl-19010055c88fd7aac23f3ce39fa6a5ec1cbf9a52.tar.xz whirl-19010055c88fd7aac23f3ce39fa6a5ec1cbf9a52.zip | |
format: rustfmt with new rules
38 files changed, 339 insertions, 419 deletions
diff --git a/crates/whirl/Cargo.toml b/crates/whirl/Cargo.toml index 5a373fe..71b99e9 100644 --- a/crates/whirl/Cargo.toml +++ b/crates/whirl/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "whirl" version = "0.1.0" -authors = ["Fuwn <[email protected]>"] +authors = ["Fuwn <[email protected]>"] edition = "2018" description = "The Open-Source WorldServer." documentation = "https://whirlsplash.org/docs/" diff --git a/crates/whirl/src/cli.rs b/crates/whirl/src/cli.rs index d13b14b..bd0caa3 100644 --- a/crates/whirl/src/cli.rs +++ b/crates/whirl/src/cli.rs @@ -1,10 +1,11 @@ // Copyright (C) 2021-2021 The Whirlsplash Collective // SPDX-License-Identifier: GPL-3.0-only -use std::{io::Write, str::FromStr}; - -use structopt::clap::{App, AppSettings, Arg, SubCommand}; -use whirl_config::Config; +use { + std::{io::Write, str::FromStr}, + structopt::clap::{App, AppSettings, Arg, SubCommand}, + whirl_config::Config, +}; enum RunType { Distributor, @@ -99,36 +100,37 @@ impl Cli { run_types }) .await, - ("config", Some(s_matches)) => - match s_matches.subcommand() { - ("show", _) => println!("{:#?}", Config::get()), - ("generate", Some(s_s_matches)) => { - if std::path::Path::new(".whirl/Config.toml").exists() - && !s_s_matches.is_present("force") - { - info!( - "a configuration file is already present, if you would like to regenerate the \ - configuration file, execute this sub-command with the `--force` (`-f`) flag" + ("config", Some(s_matches)) => match s_matches.subcommand() { + ("show", _) => println!("{:#?}", Config::get()), + ("generate", Some(s_s_matches)) => { + if std::path::Path::new(".whirl/Config.toml").exists() + && !s_s_matches.is_present("force") + { + info!( + "a configuration file is already present, if you would like to \ + regenerate the configuration file, execute this sub-command \ + with the `--force` (`-f`) flag" + ); + } else { + let mut file = std::fs::File::create(".whirl/Config.toml") + .expect("unable to create configuration file"); + file + .write_all(include_bytes!( + "../../whirl_config/Config.default.toml" + )) + .expect( + "unable to write default configuration to generated \ + configuration file", ); - } else { - let mut file = std::fs::File::create(".whirl/Config.toml") - .expect("unable to create configuration file"); - file - .write_all(include_bytes!("../../whirl_config/Config.default.toml")) - .expect("unable to write default configuration to generated configuration file"); - info!("successfully generated a new configuration file"); - } + info!("successfully generated a new configuration file"); } - _ => unreachable!(), - }, + } + _ => unreachable!(), + }, ("clean", _) => { let cleanable_directories = vec![".whirl/log/"]; for dir in cleanable_directories { - let file_type = if dir.ends_with('/') { - "directory" - } else { - "file" - }; + let file_type = if dir.ends_with('/') { "directory" } else { "file" }; info!("cleaning {}: {}", file_type, dir); if let Err(e) = std::fs::remove_dir_all(dir) { warn!("cannot delete {}: {}: {}", file_type, dir, e); @@ -149,8 +151,9 @@ impl Cli { SubCommand::with_name("run") .about("Start the WorldServer or a selection of sub-servers.") .long_about( - "Start the WorldServer by executing this sub-command WITHOUT any arguments, start a \ - selection of sub-servers by passing a comma-separated list of sub-server types.", + "Start the WorldServer by executing this sub-command WITHOUT any \ + arguments, start a selection of sub-servers by passing a \ + comma-separated list of sub-server types.", ) .arg( Arg::with_name("type") @@ -169,7 +172,8 @@ impl Cli { .arg(Arg::with_name("force").short("f").long("force")), ]), SubCommand::with_name("clean").about( - "Delete Whirl-generated files/ directories which are NOT critical. E.g., .whirl/logs/", + "Delete Whirl-generated files/ directories which are NOT critical. \ + E.g., .whirl/logs/", ), ]) .args(&[ @@ -190,7 +194,8 @@ impl Cli { server_type.pop(); } - if std::env::var("DISABLE_PROMPT").unwrap_or_else(|_| "false".to_string()) == "true" + if std::env::var("DISABLE_PROMPT").unwrap_or_else(|_| "false".to_string()) + == "true" || !Config::get().whirlsplash.prompt.enable { info!("starting with prompt disabled"); diff --git a/crates/whirl/src/lib.rs b/crates/whirl/src/lib.rs index ee68a02..3bdbe0d 100644 --- a/crates/whirl/src/lib.rs +++ b/crates/whirl/src/lib.rs @@ -17,8 +17,7 @@ html_favicon_url = "https://raw.githubusercontent.com/Whirlsplash/assets/master/Whirl.png" )] -#[macro_use] -extern crate log; +#[macro_use] extern crate log; // #[macro_use] // extern crate simple_error; @@ -32,8 +31,7 @@ static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc; pub mod cli; -#[cfg(unix)] -use signal_hook::consts::signal::{SIGINT, SIGTERM}; +#[cfg(unix)] use signal_hook::consts::signal::{SIGINT, SIGTERM}; use whirl_config::Config; pub struct Whirl; @@ -51,25 +49,26 @@ impl Whirl { dotenv::dotenv().ok(); human_panic::setup_panic!(); if Config::get().whirlsplash.log.enable { - let logger = - flexi_logger::Logger::try_with_str(whirl_common::log::calculate_log_level()).unwrap(); - if std::env::var("LOG_FILE").unwrap_or_else(|_| "true".to_string()) == "false" + let logger = flexi_logger::Logger::try_with_str( + whirl_common::log::calculate_log_level(), + ) + .unwrap(); + if std::env::var("LOG_FILE").unwrap_or_else(|_| "true".to_string()) + == "false" || !whirl_config::Config::get().whirlsplash.log.file || ({ // Cheeky as all hell. let args = std::env::args().collect::<Vec<_>>(); - if args.len() == 2 { - args[1] == "clean" - } else { - false - } + if args.len() == 2 { args[1] == "clean" } else { false } }) { logger.start()?; } else { logger .print_message() - .log_to_file(flexi_logger::FileSpec::default().directory(".whirl/log")) + .log_to_file( + flexi_logger::FileSpec::default().directory(".whirl/log"), + ) .start()?; } } diff --git a/crates/whirl/src/main.rs b/crates/whirl/src/main.rs index bf921d1..fe7ab1a 100644 --- a/crates/whirl/src/main.rs +++ b/crates/whirl/src/main.rs @@ -2,4 +2,6 @@ // SPDX-License-Identifier: GPL-3.0-only #[tokio::main] -async fn main() -> Result<(), Box<dyn std::error::Error>> { whirl::Whirl::splash().await } +async fn main() -> Result<(), Box<dyn std::error::Error>> { + whirl::Whirl::splash().await +} diff --git a/crates/whirl_api/Cargo.toml b/crates/whirl_api/Cargo.toml index 7c0dc8a..04456ed 100644 --- a/crates/whirl_api/Cargo.toml +++ b/crates/whirl_api/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "whirl_api" version = "0.1.0" -authors = ["Fuwn <[email protected]>"] +authors = ["Fuwn <[email protected]>"] edition = "2018" description = "Enables for remote interaction" documentation = "https://whirlsplash.org/docs/" diff --git a/crates/whirl_api/src/lib.rs b/crates/whirl_api/src/lib.rs index 9051f4c..589fda0 100644 --- a/crates/whirl_api/src/lib.rs +++ b/crates/whirl_api/src/lib.rs @@ -19,10 +19,8 @@ html_favicon_url = "https://raw.githubusercontent.com/Whirlsplash/assets/master/Whirl.png" )] -#[macro_use] -extern crate log; -#[macro_use] -extern crate serde_derive; +#[macro_use] extern crate log; +#[macro_use] extern crate serde_derive; use axum::routing::get; diff --git a/crates/whirl_api/src/routes/stats/mod.rs b/crates/whirl_api/src/routes/stats/mod.rs index 05b9bc7..0898902 100644 --- a/crates/whirl_api/src/routes/stats/mod.rs +++ b/crates/whirl_api/src/routes/stats/mod.rs @@ -3,12 +3,14 @@ pub mod structures; -use std::convert::TryFrom; - -use axum::response; -use sysinfo::{get_current_pid, ProcessExt, System, SystemExt}; - -use crate::routes::stats::structures::{Statistics, StatisticsProcess, StatisticsSystem}; +use { + crate::routes::stats::structures::{ + Statistics, StatisticsProcess, StatisticsSystem, + }, + axum::response, + std::convert::TryFrom, + sysinfo::{get_current_pid, ProcessExt, System, SystemExt}, +}; // This is mostly for developmental testing, it consumes more CPU than it's // worth. @@ -25,13 +27,17 @@ pub async fn statistics() -> impl response::IntoResponse { system: StatisticsSystem { os_type: sys.name().unwrap(), release: sys.kernel_version().unwrap(), - uptime: whirl_common::system::unixts_to_hrtime(usize::try_from(sys.uptime()).unwrap()), + uptime: whirl_common::system::unixts_to_hrtime( + usize::try_from(sys.uptime()).unwrap(), + ), }, process: StatisticsProcess { // (process.cpu_usage() * 100.0).round() / 100.0 memory_usage: (process.memory() / 1000).to_string(), - cpu_usage: (process.cpu_usage() / sys.processors().len() as f32).to_string(), - // uptime: seconds_to_hrtime((sys.get_uptime() - process.start_time()) as usize), + cpu_usage: (process.cpu_usage() / sys.processors().len() as f32) + .to_string(), + // uptime: seconds_to_hrtime((sys.get_uptime() - process.start_time()) + // as usize), }, }), ) diff --git a/crates/whirl_api/src/routes/worlds/info/mod.rs b/crates/whirl_api/src/routes/worlds/info/mod.rs index ea04112..382c07f 100644 --- a/crates/whirl_api/src/routes/worlds/info/mod.rs +++ b/crates/whirl_api/src/routes/worlds/info/mod.rs @@ -7,7 +7,9 @@ pub struct Parameters { } #[allow(clippy::needless_pass_by_value, clippy::unused_async)] -pub async fn info(axum::extract::Query(req): axum::extract::Query<Parameters>) -> &'static str { +pub async fn info( + axum::extract::Query(req): axum::extract::Query<Parameters>, +) -> &'static str { let mut easy = curl::easy::Easy::new(); easy diff --git a/crates/whirl_api/src/routes/worlds/vip/mod.rs b/crates/whirl_api/src/routes/worlds/vip/mod.rs index 7b7aee0..f53be55 100644 --- a/crates/whirl_api/src/routes/worlds/vip/mod.rs +++ b/crates/whirl_api/src/routes/worlds/vip/mod.rs @@ -3,11 +3,10 @@ mod structures; -use std::str::from_utf8; - -use axum::response; - -use crate::routes::worlds::vip::structures::Vip; +use { + crate::routes::worlds::vip::structures::Vip, axum::response, + std::str::from_utf8, +}; #[derive(Serialize, Deserialize)] pub struct Parameters { @@ -23,11 +22,10 @@ pub async fn vip( let username = req.username; if username.is_none() - || username - .as_ref() - .map_or(false, std::string::String::is_empty) + || username.as_ref().map_or(false, std::string::String::is_empty) { - error = "no username query parameter provided, defaulting to 'null'".to_string(); + error = + "no username query parameter provided, defaulting to 'null'".to_string(); } easy diff --git a/crates/whirl_common/Cargo.toml b/crates/whirl_common/Cargo.toml index 41db320..e8bd4a6 100644 --- a/crates/whirl_common/Cargo.toml +++ b/crates/whirl_common/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "whirl_common" version = "0.1.0" -authors = ["Fuwn <[email protected]>"] +authors = ["Fuwn <[email protected]>"] edition = "2018" description = "Provides assorted utilities for global use" documentation = "https://whirlsplash.org/docs/" @@ -16,17 +16,3 @@ publish = false # Config whirl_config = { path = "../whirl_config" } -[dev-dependencies] -# Benchmark -iai = "0.1.1" -criterion = { version = "0.3.5", features = ["html_reports"] } - -[[bench]] -name = "whirl_common" -path = "../../benches/whirl_common_iai.rs" -harness = false - -[[bench]] -name = "whirl_common_criterion" -path = "../../benches/whirl_common_criterion.rs" -harness = false diff --git a/crates/whirl_config/Cargo.toml b/crates/whirl_config/Cargo.toml index 7bfd7e3..6372da4 100644 --- a/crates/whirl_config/Cargo.toml +++ b/crates/whirl_config/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "whirl_config" version = "0.1.0" -authors = ["Fuwn <[email protected]>"] +authors = ["Fuwn <[email protected]>"] edition = "2018" description = "Provides abstractions to interact with the configuration system" documentation = "https://whirlsplash.org/docs/" diff --git a/crates/whirl_config/src/lib.rs b/crates/whirl_config/src/lib.rs index fbcdee2..3c9274d 100644 --- a/crates/whirl_config/src/lib.rs +++ b/crates/whirl_config/src/lib.rs @@ -19,22 +19,17 @@ html_favicon_url = "https://raw.githubusercontent.com/Whirlsplash/assets/master/Whirl.png" )] -#[macro_use] -extern crate serde_derive; -#[macro_use] -extern crate log; +#[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, +use { + crate::structures::{ + DistributorConfig, HubConfig, WhirlsplashApiConfig, WhirlsplashConfig, + WhirlsplashLogConfig, WhirlsplashPromptConfig, + }, + config::{ConfigError, File}, }; #[derive(Serialize, Deserialize, Debug)] @@ -49,10 +44,9 @@ impl Config { /// /// # Panics /// - May panic if the configuration is unable to be refreshed. - #[deprecated( - note = "the current implementation of the configurations system automatically performs \ - refreshes, this method has no effects" - )] + #[deprecated(note = "the current implementation of the configurations \ + system automatically performs refreshes, this method \ + has no effects")] pub fn refresh() { let _ = config::Config::new().refresh().unwrap(); } fn load() -> Result<Self, ConfigError> { @@ -74,7 +68,8 @@ impl Config { why ); warn!( - "you should probably generate yourself a configuration file with `whirl config generate`!" + "you should probably generate yourself a configuration file with \ + `whirl config generate`!" ); Self::default() @@ -90,9 +85,7 @@ impl Default for Config { whirlsplash: WhirlsplashConfig { worldsmaster_username: "WORLDSMASTER".to_string(), ip: "127.0.0.1".to_string(), - api: WhirlsplashApiConfig { - port: 80 - }, + api: WhirlsplashApiConfig { port: 80 }, prompt: WhirlsplashPromptConfig { enable: false, ps1: "[WORLDSMASTER@Whirlsplash ~]$".to_string(), @@ -109,9 +102,7 @@ impl Default for Config { worldsmaster_greeting: "Welcome to Whirlsplash!".to_string(), port: 6650, }, - hub: HubConfig { - port: 5673 - }, + hub: HubConfig { port: 5673 }, } } } diff --git a/crates/whirl_db/Cargo.toml b/crates/whirl_db/Cargo.toml index d5a5071..5a39d1a 100644 --- a/crates/whirl_db/Cargo.toml +++ b/crates/whirl_db/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "whirl_db" version = "0.1.0" -authors = ["Fuwn <[email protected]>"] +authors = ["Fuwn <[email protected]>"] edition = "2018" description = "Provides abstractions to interact with the database layer" documentation = "https://whirlsplash.org/docs/" diff --git a/crates/whirl_prompt/Cargo.toml b/crates/whirl_prompt/Cargo.toml index 6586acc..9fe2737 100644 --- a/crates/whirl_prompt/Cargo.toml +++ b/crates/whirl_prompt/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "whirl_prompt" version = "0.1.0" -authors = ["Fuwn <[email protected]>"] +authors = ["Fuwn <[email protected]>"] edition = "2018" description = "Enables for local interaction" documentation = "https://whirlsplash.org/docs/" diff --git a/crates/whirl_prompt/src/builtins/mod.rs b/crates/whirl_prompt/src/builtins/mod.rs index 047046b..b7f98b3 100644 --- a/crates/whirl_prompt/src/builtins/mod.rs +++ b/crates/whirl_prompt/src/builtins/mod.rs @@ -4,11 +4,15 @@ pub mod constants; pub mod structures; -use std::io::Write; - -use constants::{FILES, HELPABLES_BUILTINS, HELPABLES_BUILTIN_CONFIG, HELPABLES_BUILTIN_FETCH}; -use sysinfo::SystemExt; -use whirl_config::Config; +use { + constants::{ + FILES, HELPABLES_BUILTINS, HELPABLES_BUILTIN_CONFIG, + HELPABLES_BUILTIN_FETCH, + }, + std::io::Write, + sysinfo::SystemExt, + whirl_config::Config, +}; pub fn builtin_echo(args: &[String]) -> i32 { println!("{}", args.join(" ")); @@ -76,16 +80,15 @@ pub fn builtin_cat(args: &[String]) -> i32 { pub fn builtin_config(args: &[String]) -> i32 { match args.get(0) { - Some(sub) => - match sub.as_str() { - "show" => println!("{:#?}", Config::get()), - "help" | "--help" | "-h" => - for help in &HELPABLES_BUILTIN_CONFIG { - println!("{}", help); - }, - // "refresh" => Config::refresh(), - _ => println!("invalid arguments provided"), - }, + Some(sub) => match sub.as_str() { + "show" => println!("{:#?}", Config::get()), + "help" | "--help" | "-h" => + for help in &HELPABLES_BUILTIN_CONFIG { + println!("{}", help); + }, + // "refresh" => Config::refresh(), + _ => println!("invalid arguments provided"), + }, None => println!("invalid amount arguments provided"), } 0 @@ -100,17 +103,16 @@ pub fn builtin_fetch(args: &[String]) -> i32 { #[allow(clippy::single_match)] match args.get(0) { - Some(sub) => - match sub.as_str() { - "--whirl" | "-w" => whirl_image = true, - "help" | "--help" | "-h" => { - for help in &HELPABLES_BUILTIN_FETCH { - println!("{}", help); - } - return 0; + Some(sub) => match sub.as_str() { + "--whirl" | "-w" => whirl_image = true, + "help" | "--help" | "-h" => { + for help in &HELPABLES_BUILTIN_FETCH { + println!("{}", help); } - _ => println!("invalid arguments provided"), - }, + return 0; + } + _ => println!("invalid arguments provided"), + }, _ => (), } diff --git a/crates/whirl_prompt/src/lib.rs b/crates/whirl_prompt/src/lib.rs index 0c5c717..692282f 100644 --- a/crates/whirl_prompt/src/lib.rs +++ b/crates/whirl_prompt/src/lib.rs @@ -28,23 +28,16 @@ mod builtins; mod structure; -use std::{io, io::Write, str::FromStr}; - -use whirl_config::Config; - -use crate::{ - builtins::{ - builtin_cat, - builtin_clear, - builtin_config, - builtin_echo, - builtin_fetch, - builtin_help, - builtin_history, - builtin_ls, - structures::BuiltIn, +use { + crate::{ + builtins::{ + builtin_cat, builtin_clear, builtin_config, builtin_echo, builtin_fetch, + builtin_help, builtin_history, builtin_ls, structures::BuiltIn, + }, + structure::Command, }, - structure::Command, + std::{io, io::Write, str::FromStr}, + whirl_config::Config, }; pub struct Prompt { @@ -53,9 +46,7 @@ pub struct Prompt { impl Prompt { /// Begin handling user input as the prompt. pub async fn handle() -> ! { - let mut prompt = Self { - history: vec![] - }; + let mut prompt = Self { history: vec![] }; loop { Self::write_prompt(); @@ -83,15 +74,10 @@ impl Prompt { } fn tokenize_command(c: &str) -> Command { - let mut command_split: Vec<String> = c - .split_whitespace() - .map(std::string::ToString::to_string) - .collect(); - - Command { - keyword: command_split.remove(0), - args: command_split, - } + let mut command_split: Vec<String> = + c.split_whitespace().map(std::string::ToString::to_string).collect(); + + Command { keyword: command_split.remove(0), args: command_split } } // TODO: Find a way to make this access itself `history` doesn't have to be @@ -131,25 +117,26 @@ mod tokenize_command { fn empty_command() { assert_eq!("", Prompt::tokenize_command("").keyword) } #[test] - fn test_keyword() { assert_eq!("test", Prompt::tokenize_command("test").keyword) } + fn test_keyword() { + assert_eq!("test", Prompt::tokenize_command("test").keyword) + } #[test] fn no_arg() { assert_eq!(0, Prompt::tokenize_command("test").args.len()) } #[test] - fn one_arg() { assert_eq!(1, Prompt::tokenize_command("test one").args.len()) } + fn one_arg() { + assert_eq!(1, Prompt::tokenize_command("test one").args.len()) + } #[test] - fn multi_arg() { assert_eq!(3, Prompt::tokenize_command("test one two three").args.len()) } + fn multi_arg() { + assert_eq!(3, Prompt::tokenize_command("test one two three").args.len()) + } #[test] #[ignore] fn quotes() { - assert_eq!( - 2, - Prompt::tokenize_command("test \"one two\" three") - .args - .len() - ) + assert_eq!(2, Prompt::tokenize_command("test \"one two\" three").args.len()) } } diff --git a/crates/whirl_prompt/src/structure.rs b/crates/whirl_prompt/src/structure.rs index 9914385..16eccc4 100644 --- a/crates/whirl_prompt/src/structure.rs +++ b/crates/whirl_prompt/src/structure.rs @@ -6,5 +6,7 @@ pub struct Command { pub args: Vec<String>, } impl Command { - pub fn to_line(&self) -> String { format!("{} {}", self.keyword, self.args.join(" ")) } + pub fn to_line(&self) -> String { + format!("{} {}", self.keyword, self.args.join(" ")) + } } diff --git a/crates/whirl_server/Cargo.toml b/crates/whirl_server/Cargo.toml index 179fdbd..4a900c7 100644 --- a/crates/whirl_server/Cargo.toml +++ b/crates/whirl_server/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "whirl_server" version = "0.1.0" -authors = ["Fuwn <[email protected]>"] +authors = ["Fuwn <[email protected]>"] edition = "2018" description = "Instantiates the sub-servers which a WorldServer *should* accommodate." documentation = "https://whirlsplash.org/docs/" diff --git a/crates/whirl_server/src/cmd/commands/action.rs b/crates/whirl_server/src/cmd/commands/action.rs index 6303528..d7574ea 100644 --- a/crates/whirl_server/src/cmd/commands/action.rs +++ b/crates/whirl_server/src/cmd/commands/action.rs @@ -13,8 +13,8 @@ pub fn create() -> Vec<u8> { let mut command = BytesMut::new(); command.put_slice(&[ - 0x01, 0x11, 0x00, 0x05, 0x54, 0x52, 0x41, 0x44, 0x45, 0x07, 0x26, 0x7c, 0x2b, 0x69, 0x6e, 0x76, - 0x3e, + 0x01, 0x11, 0x00, 0x05, 0x54, 0x52, 0x41, 0x44, 0x45, 0x07, 0x26, 0x7c, + 0x2b, 0x69, 0x6e, 0x76, 0x3e, ]); // Convert to vector and insert the length diff --git a/crates/whirl_server/src/cmd/commands/appear_actor.rs b/crates/whirl_server/src/cmd/commands/appear_actor.rs index efdfb6d..836c681 100644 --- a/crates/whirl_server/src/cmd/commands/appear_actor.rs +++ b/crates/whirl_server/src/cmd/commands/appear_actor.rs @@ -1,9 +1,10 @@ // Copyright (C) 2021-2021 The Whirlsplash Collective // SPDX-License-Identifier: GPL-3.0-only -use bytes::{BufMut, BytesMut}; - -use crate::cmd::{constants::Command, extendable::Creatable}; +use { + crate::cmd::{constants::Command, extendable::Creatable}, + bytes::{BufMut, BytesMut}, +}; #[derive(Debug)] pub struct AppearActor { diff --git a/crates/whirl_server/src/cmd/commands/buddy_list.rs b/crates/whirl_server/src/cmd/commands/buddy_list.rs index 05aae6d..f8c76f6 100644 --- a/crates/whirl_server/src/cmd/commands/buddy_list.rs +++ b/crates/whirl_server/src/cmd/commands/buddy_list.rs @@ -1,11 +1,11 @@ // Copyright (C) 2021-2021 The Whirlsplash Collective // SPDX-License-Identifier: GPL-3.0-only -use std::str::from_utf8; - -use bytes::{BufMut, BytesMut}; - -use crate::cmd::extendable::{Creatable, Parsable}; +use { + crate::cmd::extendable::{Creatable, Parsable}, + bytes::{BufMut, BytesMut}, + std::str::from_utf8, +}; pub struct BuddyList { pub buddy: String, @@ -14,9 +14,7 @@ pub struct BuddyList { impl Parsable for BuddyList { fn parse(data: Vec<u8>) -> Self { Self { - buddy: from_utf8(&data[4..data[0] as usize - 1]) - .unwrap() - .to_string(), + buddy: from_utf8(&data[4..data[0] as usize - 1]).unwrap().to_string(), // Get the last byte add: data[data[0] as usize - 1] as i8, @@ -30,7 +28,8 @@ impl Creatable for BuddyList { // Header command.put_u8(0x01); // ObjId #[allow(clippy::cast_possible_truncation)] - command.put_i8(crate::cmd::constants::Command::BuddyListNotify as i32 as i8); // Type + command + .put_i8(crate::cmd::constants::Command::BuddyListNotify as i32 as i8); // Type // Content command.put_u8(self.buddy.len() as u8); // Buddy (name) length diff --git a/crates/whirl_server/src/cmd/commands/property/create.rs b/crates/whirl_server/src/cmd/commands/property/create.rs index 4d59521..c2afd59 100644 --- a/crates/whirl_server/src/cmd/commands/property/create.rs +++ b/crates/whirl_server/src/cmd/commands/property/create.rs @@ -3,28 +3,20 @@ // TODO: of2m-ify? -use whirl_config::Config; - -use crate::{ - cmd::constants::Command, - 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, +use { + crate::{ + cmd::constants::Command, + 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, + }, + network_property::NetworkProperty, + property_list::PropertyList, }, - network_property::NetworkProperty, - property_list::PropertyList, }, + whirl_config::Config, }; pub fn property_update_as_distributor() -> Vec<u8> { @@ -45,14 +37,8 @@ pub fn property_update_as_distributor() -> Vec<u8> { prop_id: VAR_EXTERNAL_HTTP_SERVER, value: "http://www-static.us.worlds.net".to_string(), }, - NetworkProperty { - prop_id: VAR_SERVERTYPE, - value: "1".to_string(), - }, - NetworkProperty { - prop_id: VAR_PROTOCOL, - value: "24".to_string(), - }, + NetworkProperty { prop_id: VAR_SERVERTYPE, value: "1".to_string() }, + NetworkProperty { prop_id: VAR_PROTOCOL, value: "24".to_string() }, NetworkProperty { prop_id: VAR_APPNAME, value: Config::get().whirlsplash.worldsmaster_username, @@ -63,10 +49,7 @@ pub fn property_update_as_distributor() -> Vec<u8> { pub fn property_update_as_hub() -> Vec<u8> { PropertyList(vec![ - NetworkProperty { - prop_id: VAR_UPDATETIME, - value: "1000000".to_string(), - }, + NetworkProperty { prop_id: VAR_UPDATETIME, value: "1000000".to_string() }, NetworkProperty { prop_id: VAR_MAIL_DOMAIN, value: "worlds3d.com".to_string(), @@ -83,14 +66,8 @@ pub fn property_update_as_hub() -> Vec<u8> { prop_id: VAR_EXTERNAL_HTTP_SERVER, value: "http://www-static.us.worlds.net".to_string(), }, - NetworkProperty { - prop_id: VAR_SERVERTYPE, - value: "3".to_string(), - }, - NetworkProperty { - prop_id: VAR_PROTOCOL, - value: "24".to_string(), - }, + NetworkProperty { prop_id: VAR_SERVERTYPE, value: "3".to_string() }, + NetworkProperty { prop_id: VAR_PROTOCOL, value: "24".to_string() }, NetworkProperty { prop_id: VAR_APPNAME, value: Config::get().whirlsplash.worldsmaster_username, @@ -101,30 +78,18 @@ pub fn property_update_as_hub() -> Vec<u8> { pub fn property_request_as_distributor() -> Vec<u8> { PropertyList(vec![ - NetworkProperty { - prop_id: VAR_ERROR, - value: "0".to_string(), - }, + NetworkProperty { prop_id: VAR_ERROR, value: "0".to_string() }, NetworkProperty { prop_id: VAR_APPNAME, value: Config::get().whirlsplash.worldsmaster_username, }, - NetworkProperty { - prop_id: VAR_PROTOCOL, - value: "24".to_string(), - }, - NetworkProperty { - prop_id: VAR_SERVERTYPE, - value: "1".to_string(), - }, + NetworkProperty { prop_id: VAR_PROTOCOL, value: "24".to_string() }, + NetworkProperty { prop_id: VAR_SERVERTYPE, value: "1".to_string() }, NetworkProperty { prop_id: VAR_SERIAL, value: "DWLV000000000000".to_string(), }, - NetworkProperty { - prop_id: VAR_PRIV, - value: "0".to_string(), - }, + NetworkProperty { prop_id: VAR_PRIV, value: "0".to_string() }, NetworkProperty { prop_id: VAR_CHANNEL, value: "dimension-1".to_string(), @@ -135,22 +100,10 @@ pub fn property_request_as_distributor() -> Vec<u8> { pub fn property_request_as_hub() -> Vec<u8> { PropertyList(vec![ - NetworkProperty { - prop_id: VAR_ERROR, - value: "0".to_string(), - }, - NetworkProperty { - prop_id: VAR_SERVERTYPE, - value: "3".to_string(), - }, - NetworkProperty { - prop_id: VAR_UPDATETIME, - value: "1000000".to_string(), - }, - NetworkProperty { - prop_id: VAR_PROTOCOL, - value: "24".to_string(), - }, + NetworkProperty { prop_id: VAR_ERROR, value: "0".to_string() }, + NetworkProperty { prop_id: VAR_SERVERTYPE, value: "3".to_string() }, + NetworkProperty { prop_id: VAR_UPDATETIME, value: "1000000".to_string() }, + NetworkProperty { prop_id: VAR_PROTOCOL, value: "24".to_string() }, ]) .as_bytes(Command::SessInit as i32, 0x01) } diff --git a/crates/whirl_server/src/cmd/commands/redirect_id.rs b/crates/whirl_server/src/cmd/commands/redirect_id.rs index 0771fa7..fe380d0 100644 --- a/crates/whirl_server/src/cmd/commands/redirect_id.rs +++ b/crates/whirl_server/src/cmd/commands/redirect_id.rs @@ -1,10 +1,11 @@ // Copyright (C) 2021-2021 The Whirlsplash Collective // SPDX-License-Identifier: GPL-3.0-only -use bytes::{BufMut, BytesMut}; -use whirl_config::Config; - -use crate::cmd::{constants::Command, extendable::Creatable}; +use { + crate::cmd::{constants::Command, extendable::Creatable}, + bytes::{BufMut, BytesMut}, + whirl_config::Config, +}; #[derive(Debug)] pub struct RedirectId { @@ -23,8 +24,8 @@ impl Creatable for RedirectId { // Content command.put_u8(self.room_name.len() as u8); // Room name length command.put_slice(self.room_name.as_bytes()); // Room name - // command.put_u8(0x00); // Unimplemented byte (?) - // command.put_u8(room_id); // Room ID + // command.put_u8(0x00); // Unimplemented byte (?) + // command.put_u8(room_id); // Room ID command.put_u16(self.room_number as u16); // Room ID // IP diff --git a/crates/whirl_server/src/cmd/commands/register_object_id.rs b/crates/whirl_server/src/cmd/commands/register_object_id.rs index 8e4cec7..7791ae2 100644 --- a/crates/whirl_server/src/cmd/commands/register_object_id.rs +++ b/crates/whirl_server/src/cmd/commands/register_object_id.rs @@ -1,9 +1,10 @@ // Copyright (C) 2021-2021 The Whirlsplash Collective // SPDX-License-Identifier: GPL-3.0-only -use bytes::{BufMut, BytesMut}; - -use crate::cmd::{constants::Command, extendable::Creatable}; +use { + crate::cmd::{constants::Command, extendable::Creatable}, + bytes::{BufMut, BytesMut}, +}; #[derive(Debug)] pub struct RegisterObjectId { diff --git a/crates/whirl_server/src/cmd/commands/room_id_request.rs b/crates/whirl_server/src/cmd/commands/room_id_request.rs index d6d269b..d90d26d 100644 --- a/crates/whirl_server/src/cmd/commands/room_id_request.rs +++ b/crates/whirl_server/src/cmd/commands/room_id_request.rs @@ -1,9 +1,7 @@ // Copyright (C) 2021-2021 The Whirlsplash Collective // SPDX-License-Identifier: GPL-3.0-only -use std::str::from_utf8; - -use crate::cmd::extendable::Parsable; +use {crate::cmd::extendable::Parsable, std::str::from_utf8}; #[derive(Debug)] pub struct RoomIdRequest { diff --git a/crates/whirl_server/src/cmd/commands/session_exit.rs b/crates/whirl_server/src/cmd/commands/session_exit.rs index 47048ab..330f9bb 100644 --- a/crates/whirl_server/src/cmd/commands/session_exit.rs +++ b/crates/whirl_server/src/cmd/commands/session_exit.rs @@ -8,5 +8,7 @@ use crate::{ pub struct SessionExit(pub PropertyList); impl Creatable for SessionExit { - fn create(&self) -> Vec<u8> { self.0.clone().as_bytes(Command::SessExit as i32, 0x01) } + fn create(&self) -> Vec<u8> { + self.0.clone().as_bytes(Command::SessExit as i32, 0x01) + } } diff --git a/crates/whirl_server/src/cmd/commands/subscribe_distance.rs b/crates/whirl_server/src/cmd/commands/subscribe_distance.rs index cbf0269..9877a5d 100644 --- a/crates/whirl_server/src/cmd/commands/subscribe_distance.rs +++ b/crates/whirl_server/src/cmd/commands/subscribe_distance.rs @@ -1,10 +1,11 @@ // Copyright (C) 2021-2021 The Whirlsplash Collective // SPDX-License-Identifier: GPL-3.0-only -use byteorder::{BigEndian, ReadBytesExt}; -use bytes::{Buf, BytesMut}; - -use crate::cmd::extendable::Parsable; +use { + crate::cmd::extendable::Parsable, + byteorder::{BigEndian, ReadBytesExt}, + bytes::{Buf, BytesMut}, +}; #[derive(Debug)] pub struct SubscribeDistance { diff --git a/crates/whirl_server/src/cmd/commands/subscribe_room.rs b/crates/whirl_server/src/cmd/commands/subscribe_room.rs index 667ae7f..2ed92a4 100644 --- a/crates/whirl_server/src/cmd/commands/subscribe_room.rs +++ b/crates/whirl_server/src/cmd/commands/subscribe_room.rs @@ -1,10 +1,11 @@ // Copyright (C) 2021-2021 The Whirlsplash Collective // SPDX-License-Identifier: GPL-3.0-only -use byteorder::{BigEndian, ReadBytesExt}; -use bytes::{Buf, BytesMut}; - -use crate::cmd::extendable::Parsable; +use { + crate::cmd::extendable::Parsable, + byteorder::{BigEndian, ReadBytesExt}, + bytes::{Buf, BytesMut}, +}; #[derive(Debug)] pub struct SubscribeRoom { @@ -24,7 +25,7 @@ impl Parsable for SubscribeRoom { x: f32::from(data.read_i16::<BigEndian>().unwrap() as i8), y: f32::from(data.read_i16::<BigEndian>().unwrap() as i8), z: f32::from(data.read_i16::<BigEndian>().unwrap() as i8), - distance: f32::from(data.read_i16::<BigEndian>().unwrap() as i8), // + 100 + distance: f32::from(data.read_i16::<BigEndian>().unwrap() as i8), /* + 100 */ } } } diff --git a/crates/whirl_server/src/cmd/commands/teleport.rs b/crates/whirl_server/src/cmd/commands/teleport.rs index 0493033..aa4b7dd 100644 --- a/crates/whirl_server/src/cmd/commands/teleport.rs +++ b/crates/whirl_server/src/cmd/commands/teleport.rs @@ -1,10 +1,11 @@ // Copyright (C) 2021-2021 The Whirlsplash Collective // SPDX-License-Identifier: GPL-3.0-only -use byteorder::{BigEndian, ReadBytesExt}; -use bytes::{Buf, BytesMut}; - -use crate::cmd::extendable::Parsable; +use { + crate::cmd::extendable::Parsable, + byteorder::{BigEndian, ReadBytesExt}, + bytes::{Buf, BytesMut}, +}; #[derive(Debug)] pub struct Teleport { diff --git a/crates/whirl_server/src/cmd/commands/text.rs b/crates/whirl_server/src/cmd/commands/text.rs index 9a36521..dac13b6 100644 --- a/crates/whirl_server/src/cmd/commands/text.rs +++ b/crates/whirl_server/src/cmd/commands/text.rs @@ -1,13 +1,13 @@ // Copyright (C) 2021-2021 The Whirlsplash Collective // SPDX-License-Identifier: GPL-3.0-only -use std::str::from_utf8; - -use bytes::{BufMut, BytesMut}; - -use crate::cmd::{ - constants::Command, - extendable::{Creatable, ParsableWithArguments}, +use { + crate::cmd::{ + constants::Command, + extendable::{Creatable, ParsableWithArguments}, + }, + bytes::{BufMut, BytesMut}, + std::str::from_utf8, }; pub struct Text { diff --git a/crates/whirl_server/src/cmd/structure.rs b/crates/whirl_server/src/cmd/structure.rs index 82cb226..54d47ed 100644 --- a/crates/whirl_server/src/cmd/structure.rs +++ b/crates/whirl_server/src/cmd/structure.rs @@ -45,12 +45,5 @@ impl Command { } } impl Default for Command { - fn default() -> Self { - Self { - length: 0, - obj_id: 0, - id: 0, - body: vec![], - } - } + fn default() -> Self { Self { length: 0, obj_id: 0, id: 0, body: vec![] } } } diff --git a/crates/whirl_server/src/distributor.rs b/crates/whirl_server/src/distributor.rs index 1213090..cf9acbf 100644 --- a/crates/whirl_server/src/distributor.rs +++ b/crates/whirl_server/src/distributor.rs @@ -11,35 +11,37 @@ //! This is not meant to be a high focus module as the Distributor is only //! meant to handle the initial and brief session initialization of the client. -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::{ - cmd::{ - commands::{ - action::create, - buddy_list::BuddyList, - property::create::{property_request_as_distributor, property_update_as_distributor}, - redirect_id::RedirectId, - room_id_request::RoomIdRequest, - session_exit::SessionExit, - text::Text, +use { + crate::{ + cmd::{ + commands::{ + action::create, + buddy_list::BuddyList, + property::create::{ + property_request_as_distributor, property_update_as_distributor, + }, + redirect_id::RedirectId, + room_id_request::RoomIdRequest, + session_exit::SessionExit, + text::Text, + }, + constants::Command, + extendable::{Creatable, Parsable}, }, - constants::Command, - extendable::{Creatable, Parsable}, - }, - interaction::{peer::Peer, shared::Shared}, - net::{ - constants::{VAR_ERROR, VAR_USERNAME}, - network_property::NetworkProperty, - property_list::PropertyList, + interaction::{peer::Peer, shared::Shared}, + net::{ + constants::{VAR_ERROR, VAR_USERNAME}, + network_property::NetworkProperty, + property_list::PropertyList, + }, + packet_parser::parse_commands_from_packet, + Server, }, - packet_parser::parse_commands_from_packet, - Server, + std::{error::Error, net::SocketAddr, sync::Arc}, + tokio::{io::AsyncWriteExt, net::TcpStream, sync::Mutex}, + tokio_stream::StreamExt, + tokio_util::codec::{BytesCodec, Decoder}, + whirl_config::Config, }; /// Spawn a Distributor. diff --git a/crates/whirl_server/src/hub.rs b/crates/whirl_server/src/hub.rs index f271c28..af4e656 100644 --- a/crates/whirl_server/src/hub.rs +++ b/crates/whirl_server/src/hub.rs @@ -8,38 +8,38 @@ //! client after they have been redirected to a room (Hub) and finished their //! business with the Distributor (`AutoServer`). -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::{ - cmd::{ - commands::{ - action::create, - appear_actor::AppearActor, - buddy_list::BuddyList, - property::create::{property_request_as_hub, property_update_as_hub}, - register_object_id::RegisterObjectId, - session_exit::SessionExit, - subscribe_distance::SubscribeDistance, - subscribe_room::SubscribeRoom, - teleport::Teleport, - text::Text, +use { + crate::{ + cmd::{ + commands::{ + action::create, + appear_actor::AppearActor, + buddy_list::BuddyList, + property::create::{property_request_as_hub, property_update_as_hub}, + register_object_id::RegisterObjectId, + session_exit::SessionExit, + subscribe_distance::SubscribeDistance, + subscribe_room::SubscribeRoom, + teleport::Teleport, + text::Text, + }, + constants::Command, + extendable::{Creatable, Parsable, ParsableWithArguments}, }, - constants::Command, - extendable::{Creatable, Parsable, ParsableWithArguments}, - }, - interaction::{peer::Peer, shared::Shared}, - net::{ - constants::{VAR_ERROR, VAR_USERNAME}, - network_property::NetworkProperty, - property_list::PropertyList, + interaction::{peer::Peer, shared::Shared}, + net::{ + constants::{VAR_ERROR, VAR_USERNAME}, + network_property::NetworkProperty, + property_list::PropertyList, + }, + packet_parser::parse_commands_from_packet, + Server, }, - packet_parser::parse_commands_from_packet, - Server, + std::{error::Error, net::SocketAddr, sync::Arc}, + tokio::{io::AsyncWriteExt, net::TcpStream, sync::Mutex}, + tokio_stream::StreamExt, + tokio_util::codec::{BytesCodec, Decoder}, + whirl_config::Config, }; /// Spawn a Hub. diff --git a/crates/whirl_server/src/interaction/peer.rs b/crates/whirl_server/src/interaction/peer.rs index e12c075..9993c7b 100644 --- a/crates/whirl_server/src/interaction/peer.rs +++ b/crates/whirl_server/src/interaction/peer.rs @@ -1,15 +1,15 @@ // Copyright (C) 2021-2021 The Whirlsplash Collective // SPDX-License-Identifier: GPL-3.0-only -use std::sync::Arc; - -use tokio::{ - net::TcpStream, - sync::{mpsc, Mutex}, +use { + crate::interaction::shared::Shared, + std::sync::Arc, + tokio::{ + net::TcpStream, + sync::{mpsc, Mutex}, + }, + tokio_util::codec::{BytesCodec, Framed}, }; -use tokio_util::codec::{BytesCodec, Framed}; - -use crate::interaction::shared::Shared; pub struct Peer { pub bytes: Framed<TcpStream, BytesCodec>, @@ -24,10 +24,7 @@ impl Peer { let (tx, rx) = mpsc::unbounded_channel(); state.lock().await.peers.insert(username, tx); - Ok(Self { - bytes, - rx, - }) + Ok(Self { bytes, rx }) } pub async fn _change_username( @@ -42,8 +39,6 @@ impl Peer { } // Add the peer back with the new username - Self::new(state, self.bytes, new_username.to_string()) - .await - .unwrap(); + Self::new(state, self.bytes, new_username.to_string()).await.unwrap(); } } diff --git a/crates/whirl_server/src/interaction/shared.rs b/crates/whirl_server/src/interaction/shared.rs index eb712b4..fc8674e 100644 --- a/crates/whirl_server/src/interaction/shared.rs +++ b/crates/whirl_server/src/interaction/shared.rs @@ -1,19 +1,13 @@ // Copyright (C) 2021-2021 The Whirlsplash Collective // SPDX-License-Identifier: GPL-3.0-only -use std::collections::HashMap; - -use bytes::BytesMut; +use {bytes::BytesMut, std::collections::HashMap}; pub struct Shared { pub peers: HashMap<String, tokio::sync::mpsc::UnboundedSender<BytesMut>>, } impl Shared { - pub fn new() -> Self { - Self { - peers: HashMap::new(), - } - } + pub fn new() -> Self { Self { peers: HashMap::new() } } pub async fn broadcast(&mut self, message: &[u8]) { for peer in &mut self.peers { diff --git a/crates/whirl_server/src/lib.rs b/crates/whirl_server/src/lib.rs index 2567cf7..e8fdb6f 100644 --- a/crates/whirl_server/src/lib.rs +++ b/crates/whirl_server/src/lib.rs @@ -20,10 +20,8 @@ )] #![allow(non_local_definitions, dead_code)] -#[macro_use] -extern crate log; -#[macro_use] -extern crate async_trait; +#[macro_use] extern crate log; +#[macro_use] extern crate async_trait; mod cmd; mod interaction; @@ -33,15 +31,15 @@ mod distributor; mod hub; mod packet_parser; -use std::{error::Error, fmt, net::SocketAddr, sync::Arc}; - -use tokio::{ - net::{TcpListener, TcpStream}, - sync::Mutex, +use { + crate::interaction::shared::Shared, + std::{error::Error, fmt, net::SocketAddr, sync::Arc}, + tokio::{ + net::{TcpListener, TcpStream}, + sync::Mutex, + }, }; -use crate::interaction::shared::Shared; - /// The type of server the `listen` method of the `Server` trait will /// implemented for. #[derive(Debug)] @@ -54,12 +52,17 @@ pub enum ServerType { } // https://stackoverflow.com/a/32712140/14452787 impl fmt::Display for ServerType { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}", self) } + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{:?}", self) + } } #[async_trait] pub trait Server { - async fn listen(address: &str, server_type: ServerType) -> Result<(), Box<dyn Error>> { + async fn listen( + address: &str, + server_type: ServerType, + ) -> Result<(), Box<dyn Error>> { let listener = TcpListener::bind(address).await?; let state = Arc::new(Mutex::new(Shared::new())); let mut counter = 0; @@ -86,7 +89,8 @@ pub trait Server { error!("an error occurred: {}", e); } - if std::env::var("EXIT_ON_CLIENT_DISCONNECT").unwrap_or_else(|_| "false".to_string()) + if std::env::var("EXIT_ON_CLIENT_DISCONNECT") + .unwrap_or_else(|_| "false".to_string()) == "true" { std::process::exit(0); @@ -104,10 +108,11 @@ pub trait Server { } pub mod make { - use tokio::task::JoinHandle; - use whirl_config::Config; - - use crate::{Server, ServerType}; + use { + crate::{Server, ServerType}, + tokio::task::JoinHandle, + whirl_config::Config, + }; /// Spawn and return a thread handle for a Distributor sub-server. /// @@ -158,8 +163,7 @@ pub mod make { /// - A panic may occur if the TCP server is unable to bind the specified /// port. #[must_use] - #[deprecated( - note = "The `distributor` and `hub` functions are more extensible, use them instead." - )] + #[deprecated(note = "The `distributor` and `hub` functions are more \ + extensible, use them instead.")] pub fn all() -> Vec<JoinHandle<()>> { vec![distributor(), hub()] } } diff --git a/crates/whirl_server/src/net/network_property.rs b/crates/whirl_server/src/net/network_property.rs index c8d9046..ef793bc 100644 --- a/crates/whirl_server/src/net/network_property.rs +++ b/crates/whirl_server/src/net/network_property.rs @@ -10,10 +10,5 @@ impl NetworkProperty { pub fn _new() -> Self { Self::default() } } impl Default for NetworkProperty { - fn default() -> Self { - Self { - prop_id: 0, - value: "".to_string(), - } - } + fn default() -> Self { Self { prop_id: 0, value: "".to_string() } } } diff --git a/crates/whirl_server/src/net/property_list.rs b/crates/whirl_server/src/net/property_list.rs index 554f344..37fd1e2 100644 --- a/crates/whirl_server/src/net/property_list.rs +++ b/crates/whirl_server/src/net/property_list.rs @@ -1,14 +1,15 @@ // Copyright (C) 2021-2021 The Whirlsplash Collective // SPDX-License-Identifier: GPL-3.0-only -use bytes::{BufMut, BytesMut}; - -use crate::{ - cmd::constants::Command, - net::{ - constants::{PROPACCESS_POSSESS, PROPFLAG_DBSTORE}, - network_property::NetworkProperty, +use { + crate::{ + cmd::constants::Command, + net::{ + constants::{PROPACCESS_POSSESS, PROPFLAG_DBSTORE}, + network_property::NetworkProperty, + }, }, + bytes::{BufMut, BytesMut}, }; #[derive(Clone)] |