aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/bot/master.rs49
-rw-r--r--src/bot/music.rs6
-rw-r--r--src/teamspeak.rs10
3 files changed, 56 insertions, 9 deletions
diff --git a/src/bot/master.rs b/src/bot/master.rs
index 1f1ddfb..3e56b1a 100644
--- a/src/bot/master.rs
+++ b/src/bot/master.rs
@@ -82,7 +82,40 @@ impl MasterBot {
}
async fn spawn_bot(&self, id: ClientId) {
- let channel = self.teamspeak.channel_path_of_user(id);
+ let channel = self
+ .teamspeak
+ .channel_of_user(id)
+ .expect("Can find poke sender");
+
+ if channel == self.teamspeak.my_channel() {
+ self.teamspeak.send_message_to_user(
+ id,
+ &format!(
+ "Joining the channel of \"{}\" is not allowed",
+ self.config.master_name
+ ),
+ );
+ return;
+ }
+
+ for (_, bot) in &*self.connected_bots.lock().expect("Mutex was not poisoned") {
+ if bot.my_channel() == channel {
+ self.teamspeak.send_message_to_user(
+ id,
+ &format!(
+ "\"{}\" is already in this channel. \
+ Multiple bots in one channel are not allowed.",
+ bot.name()
+ ),
+ );
+ return;
+ }
+ }
+
+ let channel_path = self
+ .teamspeak
+ .channel_path_of_user(id)
+ .expect("can find poke sender");
let (name, name_index) = {
let mut available_names = self.available_names.lock().expect("Mutex was not poisoned");
@@ -126,11 +159,17 @@ impl MasterBot {
let disconnect_cb = Box::new(move |n, name_index, id_index| {
let mut bots = cconnected_bots.lock().expect("Mutex was not poisoned");
bots.remove(&n);
- cavailable_names.lock().expect("Mutex was not poisoned").push(name_index);
- cavailable_ids.lock().expect("Mutex was not poisoned").push(id_index);
+ cavailable_names
+ .lock()
+ .expect("Mutex was not poisoned")
+ .push(name_index);
+ cavailable_ids
+ .lock()
+ .expect("Mutex was not poisoned")
+ .push(id_index);
});
- info!("Connecting to {} on {}", channel, self.config.address);
+ info!("Connecting to {} on {}", channel_path, self.config.address);
let bot_args = MusicBotArgs {
name: name.clone(),
name_index,
@@ -138,7 +177,7 @@ impl MasterBot {
local: self.config.local,
address: self.config.address.clone(),
id,
- channel,
+ channel: channel_path,
verbose: self.config.verbose,
disconnect_cb,
};
diff --git a/src/bot/music.rs b/src/bot/music.rs
index 0bb5274..821087c 100644
--- a/src/bot/music.rs
+++ b/src/bot/music.rs
@@ -190,7 +190,11 @@ impl MusicBot {
}
}
- fn my_channel(&self) -> ChannelId {
+ pub fn name(&self) -> &str {
+ &self.name
+ }
+
+ pub fn my_channel(&self) -> ChannelId {
self.teamspeak
.as_ref()
.map(|ts| ts.my_channel())
diff --git a/src/teamspeak.rs b/src/teamspeak.rs
index 5dd80ba..b429869 100644
--- a/src/teamspeak.rs
+++ b/src/teamspeak.rs
@@ -115,10 +115,14 @@ impl TeamSpeakConnection {
tokio::run(send_packet);
}
- pub fn channel_path_of_user(&self, id: ClientId) -> String {
+ pub fn channel_of_user(&self, id: ClientId) -> Option<ChannelId> {
+ Some(self.conn.lock().clients.get(&id)?.channel)
+ }
+
+ pub fn channel_path_of_user(&self, id: ClientId) -> Option<String> {
let conn = self.conn.lock();
- let channel_id = conn.clients.get(&id).expect("can find poke sender").channel;
+ let channel_id = conn.clients.get(&id)?.channel;
let mut channel = conn
.channels
@@ -142,7 +146,7 @@ impl TeamSpeakConnection {
path.push_str(name);
}
- path
+ Some(path)
}
pub fn my_channel(&self) -> ChannelId {