diff options
| author | Fuwn <[email protected]> | 2024-06-03 15:23:14 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-06-03 15:23:14 +0000 |
| commit | 303ed249037821be0e947b790ecb6090c89cc832 (patch) | |
| tree | 07d1449bb77f12eae0bd90344eee37440291167b /crates/whirl_server/src | |
| parent | chore(rustfmt): add new rules (diff) | |
| download | whirl-303ed249037821be0e947b790ecb6090c89cc832.tar.xz whirl-303ed249037821be0e947b790ecb6090c89cc832.zip | |
format: rustfmt with new rules
Diffstat (limited to 'crates/whirl_server/src')
20 files changed, 183 insertions, 241 deletions
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)] |