aboutsummaryrefslogtreecommitdiffstats
path: root/mumd/src/state.rs
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2020-10-21 01:01:33 +0200
committerGustav Sörnäs <gustav@sornas.net>2020-10-21 01:01:33 +0200
commitd58c2aad6844789c24b93387f9b61e4ab8d2a2d3 (patch)
treea6f43da526bf84f96f79f96199f0bca33deb66f8 /mumd/src/state.rs
parentec323df881c3aad82ed963fbfbdd9ade9f96e830 (diff)
parent6a136ac842dd601ce7f68566c27b5262d221872c (diff)
downloadmum-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/src/state.rs')
-rw-r--r--mumd/src/state.rs30
1 files changed, 27 insertions, 3 deletions
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