From 11c823701b12f10933b40044a12cc4048ccf8bd2 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sat, 31 Oct 2020 02:27:26 +0100 Subject: add support for mumctl server list --- mumlib/src/command.rs | 10 ++++++++++ mumlib/src/config.rs | 11 +++++++++++ mumlib/src/lib.rs | 1 + 3 files changed, 22 insertions(+) (limited to 'mumlib/src') diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs index e404056..26071ac 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -18,6 +18,10 @@ pub enum Command { }, ServerDisconnect, Status, + ServerStatus { + host: String, + port: u16, + }, } #[derive(Debug, Deserialize, Serialize)] @@ -25,4 +29,10 @@ pub enum CommandResponse { ChannelList { channels: Channel }, ServerConnect { welcome_message: Option }, Status { server_state: Server }, + ServerStatus { + version: u32, + users: u32, + max_users: u32, + bandwidth: u32, + }, } diff --git a/mumlib/src/config.rs b/mumlib/src/config.rs index e6b97fd..e7d107a 100644 --- a/mumlib/src/config.rs +++ b/mumlib/src/config.rs @@ -4,6 +4,8 @@ use std::fs; use std::path::Path; use toml::value::Array; use toml::Value; +use std::net::{SocketAddr, ToSocketAddrs}; +use crate::DEFAULT_PORT; #[derive(Debug, Deserialize, Serialize)] struct TOMLConfig { @@ -58,6 +60,15 @@ pub struct ServerConfig { pub password: Option, } +impl ServerConfig { + pub fn to_socket_addr(&self) -> Option { + match (self.host.as_str(), self.port.unwrap_or(DEFAULT_PORT)).to_socket_addrs().map(|mut e| e.next()) { + Ok(Some(addr)) => Some(addr), + _ => None, + } + } +} + pub fn get_cfg_path() -> String { if let Ok(var) = std::env::var("XDG_CONFIG_HOME") { let path = format!("{}/mumdrc", var); diff --git a/mumlib/src/lib.rs b/mumlib/src/lib.rs index a54990e..439efa9 100644 --- a/mumlib/src/lib.rs +++ b/mumlib/src/lib.rs @@ -7,6 +7,7 @@ use colored::*; use log::*; pub const SOCKET_PATH: &str = "/var/tmp/mumd"; +pub const DEFAULT_PORT: u16 = 64738; pub fn setup_logger>(target: T, color: bool) { fern::Dispatch::new() -- cgit v1.2.1 From d72b0fe5862a99d9ce1a0ef37938f4517de36ed7 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sat, 31 Oct 2020 02:37:24 +0100 Subject: cargo fmt --- mumlib/src/command.rs | 12 +++++++++--- mumlib/src/config.rs | 9 ++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'mumlib/src') diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs index 26071ac..9b0c9ed 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -26,9 +26,15 @@ pub enum Command { #[derive(Debug, Deserialize, Serialize)] pub enum CommandResponse { - ChannelList { channels: Channel }, - ServerConnect { welcome_message: Option }, - Status { server_state: Server }, + ChannelList { + channels: Channel, + }, + ServerConnect { + welcome_message: Option, + }, + Status { + server_state: Server, + }, ServerStatus { version: u32, users: u32, diff --git a/mumlib/src/config.rs b/mumlib/src/config.rs index e7d107a..ae569aa 100644 --- a/mumlib/src/config.rs +++ b/mumlib/src/config.rs @@ -1,11 +1,11 @@ +use crate::DEFAULT_PORT; use serde::{Deserialize, Serialize}; use std::convert::TryFrom; use std::fs; +use std::net::{SocketAddr, ToSocketAddrs}; use std::path::Path; use toml::value::Array; use toml::Value; -use std::net::{SocketAddr, ToSocketAddrs}; -use crate::DEFAULT_PORT; #[derive(Debug, Deserialize, Serialize)] struct TOMLConfig { @@ -62,7 +62,10 @@ pub struct ServerConfig { impl ServerConfig { pub fn to_socket_addr(&self) -> Option { - match (self.host.as_str(), self.port.unwrap_or(DEFAULT_PORT)).to_socket_addrs().map(|mut e| e.next()) { + match (self.host.as_str(), self.port.unwrap_or(DEFAULT_PORT)) + .to_socket_addrs() + .map(|mut e| e.next()) + { Ok(Some(addr)) => Some(addr), _ => None, } -- cgit v1.2.1 From 46861ce465d6f1d86e80007742a850fd1cfa9bad Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Mon, 2 Nov 2020 20:31:50 +0100 Subject: add mumd support for volume adjustment --- mumlib/src/command.rs | 2 ++ mumlib/src/error.rs | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'mumlib/src') diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs index e404056..d2d5d53 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -10,6 +10,8 @@ pub enum Command { ChannelList, ConfigReload, InputVolumeSet(f32), + OutputVolumeSet(f32), + UserVolumeSet(String, f32), ServerConnect { host: String, port: u16, diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs index c6d9255..eaf517c 100644 --- a/mumlib/src/error.rs +++ b/mumlib/src/error.rs @@ -10,6 +10,7 @@ pub enum Error { AlreadyConnectedError, ChannelIdentifierError(String, ChannelIdentifierError), InvalidServerAddrError(String, u16), + InvalidUsernameError(String), } impl Display for Error { @@ -18,9 +19,8 @@ impl Display for Error { Error::DisconnectedError => write!(f, "Not connected to a server"), Error::AlreadyConnectedError => write!(f, "Already connected to a server"), Error::ChannelIdentifierError(id, kind) => write!(f, "{}: {}", kind, id), - Error::InvalidServerAddrError(addr, port) => { - write!(f, "Invalid server address: {}: {}", addr, port) - } + Error::InvalidServerAddrError(addr, port) => write!(f, "Invalid server address: {}: {}", addr, port), + Error::InvalidUsernameError(username) => write!(f, "Invalid username: {}", username), } } } -- cgit v1.2.1 From 0cb39d13bba3dc5ffa3231e6021066e4191a43a4 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Mon, 2 Nov 2020 21:47:47 +0100 Subject: refactor and add audio out config command --- mumlib/src/config.rs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'mumlib/src') diff --git a/mumlib/src/config.rs b/mumlib/src/config.rs index e6b97fd..a971b2d 100644 --- a/mumlib/src/config.rs +++ b/mumlib/src/config.rs @@ -13,7 +13,7 @@ struct TOMLConfig { #[derive(Clone, Debug, Default)] pub struct Config { - pub audio: Option, + pub audio: AudioConfig, pub servers: Option>, } @@ -44,9 +44,10 @@ impl Config { } } -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct AudioConfig { pub input_volume: Option, + pub output_volume: Option, } #[derive(Clone, Debug, Deserialize, Serialize)] @@ -113,7 +114,7 @@ impl TryFrom for Config { fn try_from(config: TOMLConfig) -> Result { Ok(Config { - audio: config.audio, + audio: config.audio.unwrap_or_default(), servers: config .servers .map(|servers| { @@ -130,7 +131,11 @@ impl TryFrom for Config { impl From for TOMLConfig { fn from(config: Config) -> Self { TOMLConfig { - audio: config.audio, + audio: if config.audio.output_volume.is_some() || config.audio.input_volume.is_some() { + Some(config.audio) + } else { + None + }, servers: config.servers.map(|servers| { servers .into_iter() @@ -141,15 +146,11 @@ impl From for TOMLConfig { } } -pub fn read_default_cfg() -> Option { - Some( - Config::try_from( - toml::from_str::(&match fs::read_to_string(get_cfg_path()) { - Ok(f) => f.to_string(), - Err(_) => return None, - }) - .expect("invalid TOML in config file"), //TODO - ) - .expect("invalid config in TOML"), - ) //TODO +pub fn read_default_cfg() -> Config { + Config::try_from( + toml::from_str::(&match fs::read_to_string(get_cfg_path()) { + Ok(f) => f, + Err(_) => return Config::default(), + }).expect("invalid TOML in config file"), //TODO + ).expect("invalid config in TOML") //TODO } -- cgit v1.2.1 From 9d60f06ae05c5de08a026c7f9067c1a339bc24be Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Mon, 2 Nov 2020 22:57:52 +0100 Subject: remove redundancy --- mumlib/src/config.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'mumlib/src') diff --git a/mumlib/src/config.rs b/mumlib/src/config.rs index a971b2d..210dc7b 100644 --- a/mumlib/src/config.rs +++ b/mumlib/src/config.rs @@ -14,7 +14,7 @@ struct TOMLConfig { #[derive(Clone, Debug, Default)] pub struct Config { pub audio: AudioConfig, - pub servers: Option>, + pub servers: Vec, } impl Config { @@ -123,7 +123,8 @@ impl TryFrom for Config { .map(|s| s.try_into::()) .collect() }) - .transpose()?, + .transpose()? + .unwrap_or(Vec::new()), }) } } @@ -136,12 +137,9 @@ impl From for TOMLConfig { } else { None }, - servers: config.servers.map(|servers| { - servers - .into_iter() - .map(|s| Value::try_from::(s).unwrap()) - .collect() - }), + servers: Some(config.servers.into_iter() + .map(|s| Value::try_from::(s).unwrap()) + .collect()), } } } -- cgit v1.2.1 From 36b5d69929d15212f5845f42d0239ba50e46a69c Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Mon, 2 Nov 2020 23:01:08 +0100 Subject: cargo fmt --- mumlib/src/config.rs | 16 +++++++++++----- mumlib/src/error.rs | 4 +++- 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'mumlib/src') diff --git a/mumlib/src/config.rs b/mumlib/src/config.rs index 210dc7b..2eca104 100644 --- a/mumlib/src/config.rs +++ b/mumlib/src/config.rs @@ -137,9 +137,13 @@ impl From for TOMLConfig { } else { None }, - servers: Some(config.servers.into_iter() - .map(|s| Value::try_from::(s).unwrap()) - .collect()), + servers: Some( + config + .servers + .into_iter() + .map(|s| Value::try_from::(s).unwrap()) + .collect(), + ), } } } @@ -149,6 +153,8 @@ pub fn read_default_cfg() -> Config { toml::from_str::(&match fs::read_to_string(get_cfg_path()) { Ok(f) => f, Err(_) => return Config::default(), - }).expect("invalid TOML in config file"), //TODO - ).expect("invalid config in TOML") //TODO + }) + .expect("invalid TOML in config file"), //TODO + ) + .expect("invalid config in TOML") //TODO } diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs index eaf517c..1e79b9c 100644 --- a/mumlib/src/error.rs +++ b/mumlib/src/error.rs @@ -19,7 +19,9 @@ impl Display for Error { Error::DisconnectedError => write!(f, "Not connected to a server"), Error::AlreadyConnectedError => write!(f, "Already connected to a server"), Error::ChannelIdentifierError(id, kind) => write!(f, "{}: {}", kind, id), - Error::InvalidServerAddrError(addr, port) => write!(f, "Invalid server address: {}: {}", addr, port), + Error::InvalidServerAddrError(addr, port) => { + write!(f, "Invalid server address: {}: {}", addr, port) + } Error::InvalidUsernameError(username) => write!(f, "Invalid username: {}", username), } } -- cgit v1.2.1