diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/bot/master.rs | 20 | ||||
| -rw-r--r-- | src/teamspeak/mod.rs | 8 |
2 files changed, 23 insertions, 5 deletions
diff --git a/src/bot/master.rs b/src/bot/master.rs index 7612c68..dad2bed 100644 --- a/src/bot/master.rs +++ b/src/bot/master.rs @@ -88,11 +88,19 @@ impl MasterBot { let msg_loop = async move { 'outer: loop { while let Some(msg) = rx.recv().await { - if let MusicBotMessage::Quit(reason) = msg { - cbot.teamspeak.disconnect(&reason); - break 'outer; + match msg { + MusicBotMessage::Quit(reason) => { + cbot.teamspeak.disconnect(&reason); + break 'outer; + } + MusicBotMessage::ClientDisconnected { id, .. } => { + if id == cbot.my_id() { + // TODO Reconnect since quit was not called + break 'outer; + } + }, + _ => cbot.on_message(msg).await.unwrap(), } - cbot.on_message(msg).await.unwrap(); } } }; @@ -204,6 +212,10 @@ impl MasterBot { Ok(()) } + fn my_id(&self) -> ClientId { + self.teamspeak.my_id() + } + pub fn bot_data(&self, name: String) -> Option<crate::web_server::BotData> { let music_bots = self.music_bots.read().unwrap(); let bot = music_bots.connected_bots.get(&name)?; diff --git a/src/teamspeak/mod.rs b/src/teamspeak/mod.rs index 66d973c..fc10116 100644 --- a/src/teamspeak/mod.rs +++ b/src/teamspeak/mod.rs @@ -19,6 +19,7 @@ mod bbcode; pub use bbcode::*; pub struct TeamSpeakConnection { + id: ClientId, conn: Connection, } @@ -104,7 +105,8 @@ impl TeamSpeakConnection { }), ); - Ok(TeamSpeakConnection { conn }) + let id = conn.lock().own_client; + Ok(TeamSpeakConnection { conn, id }) } pub fn send_audio_packet(&self, samples: &[u8]) { @@ -167,6 +169,10 @@ impl TeamSpeakConnection { .channel } + pub fn my_id(&self) -> ClientId { + self.id + } + pub fn user_count(&self, channel: ChannelId) -> u32 { let conn = self.conn.lock(); let mut count = 0; |
