aboutsummaryrefslogtreecommitdiffstats
path: root/mumd
diff options
context:
space:
mode:
Diffstat (limited to 'mumd')
-rw-r--r--mumd/src/state.rs80
1 files changed, 35 insertions, 45 deletions
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))