diff options
Diffstat (limited to 'mumd/src/state.rs')
| -rw-r--r-- | mumd/src/state.rs | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 1c964b3..55fd8ae 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -6,7 +6,7 @@ use mumble_protocol::control::msgs; use mumble_protocol::control::ControlPacket; use mumble_protocol::voice::Serverbound; use mumlib::command::{Command, CommandResponse}; -use mumlib::error::Error; +use mumlib::error::{ChannelIdentifierError, Error}; use serde::{Deserialize, Serialize}; use std::collections::hash_map::Entry; use std::collections::HashMap; @@ -50,18 +50,38 @@ impl State { command: Command, ) -> (bool, mumlib::error::Result<Option<CommandResponse>>) { match command { - Command::ChannelJoin { channel_id } => { + Command::ChannelJoin { channel_identifier } => { if !matches!(*self.phase_receiver().borrow(), StatePhase::Connected) { return (false, Err(Error::DisconnectedError)); } - let server = self.server.as_ref().unwrap(); - if !server.channels().contains_key(&channel_id) { - return (false, Err(Error::InvalidChannelIdError(channel_id))); - } + + let channels = self.server() + .unwrap() + .channels(); + + let matches = channels.iter() + .map(|e| (e.0, e.1.path(channels))) + .filter(|e| e.1.ends_with(&channel_identifier)) + .collect::<Vec<_>>(); + let id = match matches.len() { + 0 => { + let soft_matches = channels.iter() + .map(|e| (e.0, e.1.path(channels).to_lowercase())) + .filter(|e| e.1.ends_with(&channel_identifier.to_lowercase())) + .collect::<Vec<_>>(); + match soft_matches.len() { + 0 => return (false, Err(Error::ChannelIdentifierError(channel_identifier, ChannelIdentifierError::Invalid))), + 1 => *soft_matches.get(0).unwrap().0, + _ => return (false, Err(Error::ChannelIdentifierError(channel_identifier, ChannelIdentifierError::Invalid))), + } + }, + 1 => *matches.get(0).unwrap().0, + _ => return (false, Err(Error::ChannelIdentifierError(channel_identifier, ChannelIdentifierError::Ambiguous))), + }; let mut msg = msgs::UserState::new(); - msg.set_session(server.session_id.unwrap()); - msg.set_channel_id(channel_id); + msg.set_session(self.server.as_ref().unwrap().session_id.unwrap()); + msg.set_channel_id(id); self.packet_sender.send(msg.into()).unwrap(); (false, Ok(None)) } @@ -141,6 +161,10 @@ impl State { .unwrap(); (false, Ok(None)) } + Command::InputVolumeSet(volume) => { + self.audio.set_input_volume(volume); + (false, Ok(None)) + } } } @@ -192,6 +216,9 @@ impl State { pub fn phase_receiver(&self) -> watch::Receiver<StatePhase> { self.phase_watcher.1.clone() } + pub fn server(&self) -> Option<&Server> { + self.server.as_ref() + } pub fn server_mut(&mut self) -> Option<&mut Server> { self.server.as_mut() } @@ -347,6 +374,13 @@ impl Channel { pub fn name(&self) -> &str { &self.name } + + pub fn path(&self, channels: &HashMap<u32, Channel>) -> String { + match &self.parent { + Some(t) => format!("{}/{}", channels.get(t).unwrap().path(channels), self.name), + None => self.name.clone(), + } + } } #[derive(Debug)] |
