diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-10-21 01:01:33 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-10-21 01:01:33 +0200 |
| commit | d58c2aad6844789c24b93387f9b61e4ab8d2a2d3 (patch) | |
| tree | a6f43da526bf84f96f79f96199f0bca33deb66f8 /mumd | |
| parent | ec323df881c3aad82ed963fbfbdd9ade9f96e830 (diff) | |
| parent | 6a136ac842dd601ce7f68566c27b5262d221872c (diff) | |
| download | mum-d58c2aad6844789c24b93387f9b61e4ab8d2a2d3.tar.gz | |
Merge branch 'config-file' into 'main'
Config file
Closes #1 and #27
See merge request gustav/mum!16
Diffstat (limited to 'mumd')
| -rw-r--r-- | mumd/Cargo.toml | 1 | ||||
| -rw-r--r-- | mumd/src/state.rs | 30 |
2 files changed, 27 insertions, 4 deletions
diff --git a/mumd/Cargo.toml b/mumd/Cargo.toml index 9101b43..ffb463a 100644 --- a/mumd/Cargo.toml +++ b/mumd/Cargo.toml @@ -27,6 +27,5 @@ tokio = { version = "0.2", features = ["full"] } tokio-tls = "0.3" tokio-util = { version = "0.3", features = ["codec", "udp"] } -#clap = "2.33" #compressor = "0.3" #daemonize = "0.4" diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 55fd8ae..0dbf9c5 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -6,6 +6,7 @@ use mumble_protocol::control::msgs; use mumble_protocol::control::ControlPacket; use mumble_protocol::voice::Serverbound; use mumlib::command::{Command, CommandResponse}; +use mumlib::config::Config; use mumlib::error::{ChannelIdentifierError, Error}; use serde::{Deserialize, Serialize}; use std::collections::hash_map::Entry; @@ -21,6 +22,7 @@ pub enum StatePhase { } pub struct State { + config: Option<Config>, server: Option<Server>, audio: Audio, @@ -35,13 +37,17 @@ impl State { packet_sender: mpsc::UnboundedSender<ControlPacket<Serverbound>>, connection_info_sender: watch::Sender<Option<ConnectionInfo>>, ) -> Self { - Self { + let audio = Audio::new(); + let mut state = Self { + config: mumlib::config::read_default_cfg(), server: None, - audio: Audio::new(), + audio, packet_sender, connection_info_sender, phase_watcher: watch::channel(StatePhase::Disconnected), - } + }; + state.reload_config(); + state } //TODO? move bool inside Result @@ -165,6 +171,10 @@ impl State { self.audio.set_input_volume(volume); (false, Ok(None)) } + Command::ConfigReload => { + self.reload_config(); + (false, Ok(None)) + } } } @@ -197,6 +207,20 @@ impl State { self.server.as_mut().unwrap().parse_user_state(msg); } + pub fn reload_config(&mut self) { + if let Some(config) = mumlib::config::read_default_cfg() { + self.config = Some(config); + let config = &self.config.as_ref().unwrap(); + if let Some(audio_config) = &config.audio { + if let Some(input_volume) = audio_config.input_volume { + self.audio.set_input_volume(input_volume); + } + } + } else { + warn!("config file not found"); + } + } + pub fn initialized(&self) { self.phase_watcher .0 |
