Sfoglia il codice sorgente

bin/ircd: fix part command

Dastan-glitch 4 anni fa
parent
commit
f6de14bea1
3 ha cambiato i file con 34 aggiunte e 27 eliminazioni
  1. 3 0
      bin/ircd/src/main.rs
  2. 28 26
      bin/ircd/src/server.rs
  3. 3 1
      bin/ircd/src/settings.rs

+ 3 - 0
bin/ircd/src/main.rs

@@ -120,6 +120,9 @@ async fn process(
                 // Try to potentially decrypt the incoming message.
                 if conn.configured_chans.contains_key(&msg.channel) {
                     let chan_info = conn.configured_chans.get(&msg.channel).unwrap();
+                    if !chan_info.joined {
+                        continue
+                    }
                     if let Some(salt_box) = &chan_info.salt_box {
                         if let Some(decrypted_msg) = try_decrypt_message(salt_box, &msg.message) {
                             msg.message = decrypted_msg;

+ 28 - 26
bin/ircd/src/server.rs

@@ -83,6 +83,8 @@ impl IrcServerConnection {
                 for chan in channels.split(',') {
                     let part_reply = format!(":{}!anon@dark.fi PART {}\r\n", self.nickname, chan);
                     self.reply(&part_reply).await?;
+                    let chan_info = self.configured_chans.get_mut(chan).unwrap();
+                    chan_info.joined = false;
                 }
             }
             "TOPIC" => {
@@ -131,34 +133,34 @@ impl IrcServerConnection {
                 let message = &line[substr_idx + 1..];
                 info!("(Plain) PRIVMSG {} :{}", channel, message);
 
-                let message = if self.configured_chans.contains_key(channel) {
+                if self.configured_chans.contains_key(channel) {
                     let channel_info = self.configured_chans.get(channel).unwrap();
-                    if let Some(salt_box) = &channel_info.salt_box {
-                        let encrypted = encrypt_message(salt_box, message);
-                        info!("(Encrypted) PRIVMSG {} :{}", channel, encrypted);
-                        encrypted
-                    } else {
-                        message.to_string()
+                    if channel_info.joined {
+                        let message = if let Some(salt_box) = &channel_info.salt_box {
+                            let encrypted = encrypt_message(salt_box, message);
+                            info!("(Encrypted) PRIVMSG {} :{}", channel, encrypted);
+                            encrypted
+                        } else {
+                            message.to_string()
+                        };
+
+                        let random_id = OsRng.next_u32();
+
+                        let protocol_msg = Privmsg {
+                            id: random_id,
+                            nickname: self.nickname.clone(),
+                            channel: channel.to_string(),
+                            message,
+                        };
+
+                        let mut smi = self.seen_msg_id.lock().await;
+                        smi.push(random_id);
+                        drop(smi);
+
+                        debug!(target: "ircd", "PRIVMSG to be sent: {:?}", protocol_msg);
+                        self.p2p_sender.send(protocol_msg).await?;
                     }
-                } else {
-                    message.to_string()
-                };
-
-                let random_id = OsRng.next_u32();
-
-                let protocol_msg = Privmsg {
-                    id: random_id,
-                    nickname: self.nickname.clone(),
-                    channel: channel.to_string(),
-                    message,
-                };
-
-                let mut smi = self.seen_msg_id.lock().await;
-                smi.push(random_id);
-                drop(smi);
-
-                debug!(target: "ircd", "PRIVMSG to be sent: {:?}", protocol_msg);
-                self.p2p_sender.send(protocol_msg).await?;
+                }
             }
             "QUIT" => {
                 // Close the connection

+ 3 - 1
bin/ircd/src/settings.rs

@@ -68,11 +68,13 @@ pub struct ChannelInfo {
     pub topic: Option<String>,
     /// Optional NaCl box for the channel, used for {en,de}cryption.
     pub salt_box: Option<crypto_box::Box>,
+    ///
+    pub joined: bool,
 }
 
 impl ChannelInfo {
     pub fn new() -> Result<Self> {
-        Ok(Self { topic: None, salt_box: None })
+        Ok(Self { topic: None, salt_box: None, joined: true })
     }
 }