mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
bin/ircd: fix part command
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user