diff options
| -rw-r--r-- | documentation/mumctl.1 | 28 | ||||
| -rw-r--r-- | documentation/mumctl.txt | 28 | ||||
| -rw-r--r-- | mumctl/src/main.rs | 25 | ||||
| -rw-r--r-- | mumd/src/state.rs | 68 | ||||
| -rw-r--r-- | mumd/src/state/server.rs | 9 | ||||
| -rw-r--r-- | mumlib/src/command.rs | 15 | ||||
| -rw-r--r-- | mumlib/src/error.rs | 2 |
7 files changed, 102 insertions, 73 deletions
diff --git a/documentation/mumctl.1 b/documentation/mumctl.1 index c50398f..8d8ba72 100644 --- a/documentation/mumctl.1 +++ b/documentation/mumctl.1 @@ -104,6 +104,21 @@ mumctl help Show a help message. .RE .sp +mumctl message channel [\-r|\-\-recursive] <message> [<channel>...] +Sends a message to all channels specified in the list of channels. +If the recursive flag is set, the message is also sent to all subchannels in a recursive manner. +If no channels are given the message is sent to the channel currently +connected to. +.sp +mumctl message user <message> <users> +Sends a message to all users specified in the list of users. +.sp +mumctl messages [\-f|\-\-follow] +Prints all received messages since mumd was started, or since this command last was issued, +whichever happens first. +If the follow flag is set, mumctl will instead wait for new messages to come in and print +them as they come in. To exit this loop, issue a Ctrl\-C. +.sp mumctl mute [user] .RS 4 Mute yourself or someone else. @@ -162,19 +177,6 @@ mumctl volume <user> set <volume> Set the volume of another user\(cqs incoming audio. 1.0 is the default. .RE -.sp -mumctl messages [\-f|\-\-follow] -Prints all received messages since mumd was started, or since this command last was issued, -whichever happens first. -If the follow flag is set, mumctl will instead wait for new messages to come in and print -them as they come in. To exit this loop, issue a Ctrl\-C. -.sp -mumctl message user <message> <users> -Sends a message to all users specified in the list of users. -.sp -mumctl message channel [\-r|\-\-recursive] <message> <channels> -Sends a message to all channels specified in the list of channels. -If the recursive flag is set, the message is also sent to all subchannels in a recursive manner. .SH "AUTHORS" .sp Gustav Sörnäs and Eskil Queseth. diff --git a/documentation/mumctl.txt b/documentation/mumctl.txt index 68e4c0e..1c8ee8f 100644 --- a/documentation/mumctl.txt +++ b/documentation/mumctl.txt @@ -64,6 +64,21 @@ mumctl events :: mumctl help :: Show a help message. +mumctl message channel [-r|--recursive] <message> [<channel>...] + Sends a message to all channels specified in the list of channels. + If the recursive flag is set, the message is also sent to all subchannels in a recursive manner. + If no channels are given the message is sent to the channel currently + connected to. + +mumctl message user <message> <users> + Sends a message to all users specified in the list of users. + +mumctl messages [-f|--follow] + Prints all received messages since mumd was started, or since this command last was issued, + whichever happens first. + If the follow flag is set, mumctl will instead wait for new messages to come in and print + them as they come in. To exit this loop, issue a Ctrl-C. + mumctl mute [user] :: Mute yourself or someone else. If user is omitted, you mute yourself. Otherwise, the user with the username [user] is muted. @@ -101,19 +116,6 @@ mumctl volume <user> set <volume> :: Set the volume of another user's incoming audio. 1.0 is the default. -mumctl messages [-f|--follow] - Prints all received messages since mumd was started, or since this command last was issued, - whichever happens first. - If the follow flag is set, mumctl will instead wait for new messages to come in and print - them as they come in. To exit this loop, issue a Ctrl-C. - -mumctl message user <message> <users> - Sends a message to all users specified in the list of users. - -mumctl message channel [-r|--recursive] <message> <channels> - Sends a message to all channels specified in the list of channels. - If the recursive flag is set, the message is also sent to all subchannels in a recursive manner. - Authors ------- diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 2f1063f..1fb2a45 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -1,6 +1,6 @@ use colored::Colorize; use log::*; -use mumlib::command::{Command as MumCommand, CommandResponse, MessageTarget}; +use mumlib::command::{ChannelTarget, Command as MumCommand, CommandResponse, MessageTarget}; use mumlib::config::{self, Config, ServerConfig}; use mumlib::state::Channel as MumChannel; use serde::de::DeserializeOwned; @@ -99,10 +99,10 @@ enum Target { Channel { /// The message to send message: String, - /// If the message should be sent recursivley to sub-channels + /// If the message should be sent recursively to sub-channels #[structopt(short = "r", long = "recursive")] recursive: bool, - /// Which channels to send to + /// Which channels to send to. Defaults to current channel if left empty names: Vec<String>, }, User { @@ -386,20 +386,23 @@ fn match_opt() -> Result<(), Error> { } => { let msg = MumCommand::SendMessage { message, - targets: names - .into_iter() - .map(|name| MessageTarget::Channel { name, recursive }) - .collect(), + targets: if names.is_empty() { + MessageTarget::Channel(vec![(ChannelTarget::Current, recursive)]) + } else { + MessageTarget::Channel( + names + .into_iter() + .map(|name| (ChannelTarget::Named(name), recursive)) + .collect() + ) + }, }; send_command(msg)??; } Target::User { message, names } => { let msg = MumCommand::SendMessage { message, - targets: names - .into_iter() - .map(|name| MessageTarget::User { name }) - .collect(), + targets: MessageTarget::User(names), }; send_command(msg)??; } diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 37dd6a2..d12b5b6 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -16,7 +16,7 @@ use mumble_protocol::control::msgs; use mumble_protocol::control::ControlPacket; use mumble_protocol::ping::PongPacket; use mumble_protocol::voice::Serverbound; -use mumlib::command::{Command, CommandResponse, MessageTarget, MumbleEvent, MumbleEventKind}; +use mumlib::command::{ChannelTarget, Command, CommandResponse, MessageTarget, MumbleEvent, MumbleEventKind}; use mumlib::config::Config; use mumlib::Error; use std::{ @@ -738,43 +738,45 @@ pub fn handle_command( msg.set_message(message); - for target in targets { - match target { - MessageTarget::Channel { recursive, name } => { - let channel_id = state.server().unwrap().channel_name(&name); - - let channel_id = match channel_id { - Ok(id) => id, + match targets { + MessageTarget::Channel(channels) => for (channel, recursive) in channels { + let channel_id = if let ChannelTarget::Named(name) = channel { + let channel = state.server().unwrap().channel_name(&name); + match channel { + Ok(channel) => channel.0, Err(e) => return now!(Err(Error::ChannelIdentifierError(name, e))), } - .0; - - if recursive { - msg.mut_tree_id() - } else { - msg.mut_channel_id() + } else { + match state.server().unwrap().current_channel() { + Some(channel) => channel.0, + None => return now!(Err(Error::NotConnectedToChannel)), } - .push(channel_id); - } - MessageTarget::User { name } => { - let id = state - .server() - .unwrap() - .users() - .iter() - .find(|(_, user)| user.name() == &name) - .map(|(e, _)| *e); - - let id = match id { - Some(id) => id, - None => return now!(Err(Error::InvalidUsername(name))), - }; - - msg.mut_session().push(id); - } + }; + + let ids = if recursive { + msg.mut_tree_id() + } else { + msg.mut_channel_id() + }; + ids.push(channel_id); + } + MessageTarget::User(names) => for name in names { + let id = state + .server() + .unwrap() + .users() + .iter() + .find(|(_, user)| user.name() == &name) + .map(|(e, _)| *e); + + let id = match id { + Some(id) => id, + None => return now!(Err(Error::InvalidUsername(name))), + }; + + msg.mut_session().push(id); } } - packet_sender.send(msg.into()).unwrap(); now!(Ok(None)) diff --git a/mumd/src/state/server.rs b/mumd/src/state/server.rs index 869940a..4abde49 100644 --- a/mumd/src/state/server.rs +++ b/mumd/src/state/server.rs @@ -132,6 +132,15 @@ impl Server { }) } + /// Returns the currenctly connected channel. + /// + /// Returns None if not connected. + pub fn current_channel(&self) -> Option<(u32, &Channel)> { + let channel_id = self.users().get(&self.session_id()?)?.channel(); + let channel = self.channels().get(&channel_id)?; + Some((channel_id, channel)) + } + pub fn host_mut(&mut self) -> &mut Option<String> { &mut self.host } diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs index c5d4676..8cb7cb9 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -77,7 +77,7 @@ pub enum Command { Ping, SendMessage { message: String, - targets: Vec<MessageTarget>, + targets: MessageTarget, }, ServerConnect { host: String, @@ -128,8 +128,17 @@ pub enum CommandResponse { }, } +/// Messages sent to channels can be sent either to a named channel or the +/// currently connected channel. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum ChannelTarget { + Current, + Named(String) +} + +/// Messages can be sent to either channels or specific users. #[derive(Clone, Debug, Deserialize, Serialize)] pub enum MessageTarget { - Channel { recursive: bool, name: String }, - User { name: String }, + Channel(Vec<(ChannelTarget, bool)>), // (target, recursive) + User(Vec<String>), } diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs index c492a5f..2cb3927 100644 --- a/mumlib/src/error.rs +++ b/mumlib/src/error.rs @@ -12,6 +12,7 @@ pub enum Error { InvalidUsername(String), InvalidServerPassword, Unimplemented, + NotConnectedToChannel, } impl std::error::Error for Error {} @@ -28,6 +29,7 @@ impl fmt::Display for Error { Error::InvalidUsername(username) => write!(f, "Invalid username: {}", username), Error::InvalidServerPassword => write!(f, "Invalid server password"), Error::Unimplemented => write!(f, "Unimplemented"), + Error::NotConnectedToChannel => write!(f, "Not connected to a channel"), } } } |
