From c6d63f0b5c231bfc42128a670923a660fabd1835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 7 Jun 2021 17:58:06 +0200 Subject: default send message to current channel if no channel specified --- mumctl/src/main.rs | 12 ++++++++---- mumd/src/state.rs | 22 +++++++++++++++++----- mumd/src/state/server.rs | 6 ++++++ mumlib/src/command.rs | 1 + mumlib/src/error.rs | 2 ++ 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index bde24a1..7d02582 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -381,10 +381,14 @@ 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() { + names + .into_iter() + .map(|name| MessageTarget::Channel { name, recursive }) + .collect() + } else { + vec![MessageTarget::CurrentChannel { recursive }] + }, }; send_command(msg)??; } diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 84583e0..a57b53d 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -687,14 +687,26 @@ pub fn handle_command( for target in targets { match target { + MessageTarget::CurrentChannel { recursive } => { + let channel_id = match state.server().unwrap().current_channel() { + Some(channel)=> channel.0, + None => return now!(Err(Error::NotConnectedToChannel)), + }; + + if recursive { + msg.mut_tree_id() + } else { + msg.mut_channel_id() + } + .push(channel_id); + } MessageTarget::Channel { recursive, name } => { - let channel_id = state.server().unwrap().channel_name(&name); + let channel = state.server().unwrap().channel_name(&name); - let channel_id = match channel_id { - Ok(id) => id, + let channel_id = match channel { + Ok(channel) => channel.0, Err(e) => return now!(Err(Error::ChannelIdentifierError(name, e))), - } - .0; + }; if recursive { msg.mut_tree_id() diff --git a/mumd/src/state/server.rs b/mumd/src/state/server.rs index 869940a..58c614c 100644 --- a/mumd/src/state/server.rs +++ b/mumd/src/state/server.rs @@ -132,6 +132,12 @@ impl Server { }) } + 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 { &mut self.host } diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs index 351d7f6..f8a8fc8 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -69,6 +69,7 @@ pub enum CommandResponse { #[derive(Clone, Debug, Deserialize, Serialize)] pub enum MessageTarget { + CurrentChannel {recursive: bool }, Channel { recursive: bool, name: String }, User { name: String }, } diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs index e88bd97..83f97b8 100644 --- a/mumlib/src/error.rs +++ b/mumlib/src/error.rs @@ -11,6 +11,7 @@ pub enum Error { InvalidServerAddr(String, u16), InvalidUsername(String), InvalidServerPassword, + NotConnectedToChannel, } impl std::error::Error for Error {} @@ -26,6 +27,7 @@ impl fmt::Display for Error { } Error::InvalidUsername(username) => write!(f, "Invalid username: {}", username), Error::InvalidServerPassword => write!(f, "Invalid server password"), + Error::NotConnectedToChannel => write!(f, "Not connected to a channel"), } } } -- cgit v1.2.1 From 01e996ce32e13bd47be938dcb8db83778658b3a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 7 Jun 2021 17:59:18 +0200 Subject: send message documentation --- mumctl/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 7d02582..d1d0a62 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -94,10 +94,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, }, User { -- cgit v1.2.1 From 2f3ca41289de5cc275f19af5125557a175465d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 8 Jun 2021 10:12:13 +0200 Subject: manpage alphabetical order --- documentation/mumctl.1 | 30 +++++++++++++++--------------- documentation/mumctl.txt | 26 +++++++++++++------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/documentation/mumctl.1 b/documentation/mumctl.1 index e875fd7..b2badf6 100644 --- a/documentation/mumctl.1 +++ b/documentation/mumctl.1 @@ -2,12 +2,12 @@ .\" Title: mumd .\" Author: [see the "AUTHOR(S)" section] .\" Generator: Asciidoctor 2.0.15 -.\" Date: 2021-06-06 +.\" Date: 2021-06-08 .\" Manual: \ \& .\" Source: \ \& .\" Language: English .\" -.TH "MUMCTL" "1" "2021-06-06" "\ \&" "\ \&" +.TH "MUMCTL" "1" "2021-06-08" "\ \&" "\ \&" .ie \n(.g .ds Aq \(aq .el .ds Aq ' .ss \n[.ss] 0 @@ -99,6 +99,19 @@ mumctl help Show a help message. .RE .sp +mumctl message channel [\-r|\-\-recursive] +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. +.sp +mumctl message user +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. @@ -157,19 +170,6 @@ mumctl volume set 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 -Sends a message to all users specified in the list of users. -.sp -mumctl message channel [\-r|\-\-recursive] -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 e513255..af9e059 100644 --- a/documentation/mumctl.txt +++ b/documentation/mumctl.txt @@ -61,6 +61,19 @@ mumctl disconnect :: mumctl help :: Show a help message. +mumctl message channel [-r|--recursive] + 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. + +mumctl message user + 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. @@ -98,19 +111,6 @@ mumctl volume set :: 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 - Sends a message to all users specified in the list of users. - -mumctl message channel [-r|--recursive] - 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 ------- -- cgit v1.2.1 From 558b4e7cf74cba5b14b65819ceb190b073d7bb4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 8 Jun 2021 10:13:57 +0200 Subject: update manpage --- documentation/mumctl.1 | 4 +++- documentation/mumctl.txt | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/documentation/mumctl.1 b/documentation/mumctl.1 index b2badf6..01840d1 100644 --- a/documentation/mumctl.1 +++ b/documentation/mumctl.1 @@ -99,9 +99,11 @@ mumctl help Show a help message. .RE .sp -mumctl message channel [\-r|\-\-recursive] +mumctl message channel [\-r|\-\-recursive] [...] 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 Sends a message to all users specified in the list of users. diff --git a/documentation/mumctl.txt b/documentation/mumctl.txt index af9e059..888d847 100644 --- a/documentation/mumctl.txt +++ b/documentation/mumctl.txt @@ -61,9 +61,11 @@ mumctl disconnect :: mumctl help :: Show a help message. -mumctl message channel [-r|--recursive] +mumctl message channel [-r|--recursive] [...] 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 Sends a message to all users specified in the list of users. -- cgit v1.2.1 From 4aff5b39b0ca6e0594870e7545f720de8427392e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Fri, 11 Jun 2021 03:03:39 +0200 Subject: invert if --- mumctl/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index d1d0a62..9d87541 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -381,13 +381,13 @@ fn match_opt() -> Result<(), Error> { } => { let msg = MumCommand::SendMessage { message, - targets: if !names.is_empty() { + targets: if names.is_empty() { + vec![MessageTarget::CurrentChannel { recursive }] + } else { names .into_iter() .map(|name| MessageTarget::Channel { name, recursive }) .collect() - } else { - vec![MessageTarget::CurrentChannel { recursive }] }, }; send_command(msg)??; -- cgit v1.2.1 From b5805f7e72afcc53287b0e5ff52f131f99849784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Fri, 11 Jun 2021 03:21:27 +0200 Subject: clearer api for message targets --- mumctl/src/main.rs | 21 +++++++------- mumd/src/state.rs | 80 ++++++++++++++++++++++----------------------------- mumlib/src/command.rs | 13 ++++++--- 3 files changed, 54 insertions(+), 60 deletions(-) diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 9d87541..99e0608 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; @@ -381,13 +381,15 @@ fn match_opt() -> Result<(), Error> { } => { let msg = MumCommand::SendMessage { message, - targets: if names.is_empty() { - vec![MessageTarget::CurrentChannel { recursive }] + target: if names.is_empty() { + MessageTarget::Channel(vec![(ChannelTarget::Default, recursive)]) } else { - names - .into_iter() - .map(|name| MessageTarget::Channel { name, recursive }) - .collect() + MessageTarget::Channel( + names + .into_iter() + .map(|name| (ChannelTarget::Named(name), recursive)) + .collect() + ) }, }; send_command(msg)??; @@ -395,10 +397,7 @@ fn match_opt() -> Result<(), Error> { Target::User { message, names } => { let msg = MumCommand::SendMessage { message, - targets: names - .into_iter() - .map(|name| MessageTarget::User { name }) - .collect(), + target: MessageTarget::User(names), }; send_command(msg)??; } diff --git a/mumd/src/state.rs b/mumd/src/state.rs index a57b53d..942d320 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -15,7 +15,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}; +use mumlib::command::{ChannelTarget, Command, CommandResponse, MessageTarget}; use mumlib::config::Config; use mumlib::Error; use std::{ @@ -676,7 +676,7 @@ pub fn handle_command( ExecutionContext::Now(Box::new(move || Box::new(messages.into_iter()))) } } - Command::SendMessage { message, targets } => { + Command::SendMessage { message, target } => { if !matches!(*state.phase_receiver().borrow(), StatePhase::Connected(_)) { return now!(Err(Error::Disconnected)); } @@ -685,55 +685,45 @@ pub fn handle_command( msg.set_message(message); - for target in targets { - match target { - MessageTarget::CurrentChannel { recursive } => { - let channel_id = match state.server().unwrap().current_channel() { - Some(channel)=> channel.0, - None => return now!(Err(Error::NotConnectedToChannel)), - }; - - if recursive { - msg.mut_tree_id() - } else { - msg.mut_channel_id() - } - .push(channel_id); - } - MessageTarget::Channel { recursive, name } => { + match target { + 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); - - let channel_id = match channel { + match channel { Ok(channel) => channel.0, Err(e) => return now!(Err(Error::ChannelIdentifierError(name, e))), - }; - - if recursive { - msg.mut_tree_id() - } else { - msg.mut_channel_id() } - .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); - } + } else { + match state.server().unwrap().current_channel() { + Some(channel) => channel.0, + None => return now!(Err(Error::NotConnectedToChannel)), + } + }; + + 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/mumlib/src/command.rs b/mumlib/src/command.rs index f8a8fc8..79bbc8b 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -34,7 +34,7 @@ pub enum Command { }, SendMessage { message: String, - targets: Vec, + target: MessageTarget, }, } @@ -67,9 +67,14 @@ pub enum CommandResponse { }, } +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum ChannelTarget { + Default, + Named(String) +} + #[derive(Clone, Debug, Deserialize, Serialize)] pub enum MessageTarget { - CurrentChannel {recursive: bool }, - Channel { recursive: bool, name: String }, - User { name: String }, + Channel(Vec<(ChannelTarget, bool)>), // (target, recursive) + User(Vec), } -- cgit v1.2.1 From ebb9e206701ff3c538f34c58d8e7a4d6f9f314c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Fri, 11 Jun 2021 03:24:57 +0200 Subject: doc func --- mumd/src/state/server.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mumd/src/state/server.rs b/mumd/src/state/server.rs index 58c614c..4abde49 100644 --- a/mumd/src/state/server.rs +++ b/mumd/src/state/server.rs @@ -132,6 +132,9 @@ 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)?; -- cgit v1.2.1 From 3cfbfe7aab14e9a33c7d4e81289de40a60f19eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Fri, 11 Jun 2021 17:21:57 +0200 Subject: doc {Message,Channel}Target --- mumctl/src/main.rs | 2 +- mumlib/src/command.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 99e0608..84517d5 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -382,7 +382,7 @@ fn match_opt() -> Result<(), Error> { let msg = MumCommand::SendMessage { message, target: if names.is_empty() { - MessageTarget::Channel(vec![(ChannelTarget::Default, recursive)]) + MessageTarget::Channel(vec![(ChannelTarget::Current, recursive)]) } else { MessageTarget::Channel( names diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs index 79bbc8b..4f4cf3a 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -67,12 +67,15 @@ 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 { - Default, + Current, Named(String) } +/// Messages can be sent to either channels or specific users. #[derive(Clone, Debug, Deserialize, Serialize)] pub enum MessageTarget { Channel(Vec<(ChannelTarget, bool)>), // (target, recursive) -- cgit v1.2.1 From 726ec68532dc964d5eea878e664875aa01ca08f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Fri, 11 Jun 2021 17:26:12 +0200 Subject: update changelog --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 63c01a2..a8d2616 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -21,7 +21,7 @@ Added * Added tunneling audio through TCP if UDP connection goes down. * --version now includes the current commit hash. * Server passwords. Thanks @rbran! - * Added support for sending and receiving text messages + * Added support for sending and receiving text messages. Changed ~~~~~~~ -- cgit v1.2.1