aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJokler <jokler@protonmail.com>2020-09-01 18:14:17 +0200
committerGitHub <noreply@github.com>2020-09-01 18:14:17 +0200
commit130cde033795382b70a312846a8f2704a15d11e3 (patch)
tree9464e08f4e15906418f40ebef76bc150d3162bbe
parent161c8ab648036cf0999b248fab4bf57e3a55cb61 (diff)
parent1beccb77e57c53051160d664ccbb087835ac015a (diff)
downloadpokebot-130cde033795382b70a312846a8f2704a15d11e3.tar.gz
pokebot-130cde033795382b70a312846a8f2704a15d11e3.zip
Merge pull request #60 from Mavulp/auto-reconnect
Shut down on disconnect
-rw-r--r--src/bot/master.rs20
-rw-r--r--src/teamspeak/mod.rs8
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;