|
@@ -119,7 +119,7 @@ impl<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> IrcClient<C> {
|
|
|
|
|
|
|
|
self.irc_config.channels.extend(new_config.channels);
|
|
self.irc_config.channels.extend(new_config.channels);
|
|
|
self.irc_config.contacts.extend(new_config.contacts);
|
|
self.irc_config.contacts.extend(new_config.contacts);
|
|
|
- self.irc_config.password = new_config.password;
|
|
|
|
|
|
|
+ self.irc_config.pass = new_config.pass;
|
|
|
|
|
|
|
|
if self.on_receive_join(self.irc_config.channels.keys().cloned().collect()).await.is_err() {
|
|
if self.on_receive_join(self.irc_config.channels.keys().cloned().collect()).await.is_err() {
|
|
|
warn!("Error to join updated channels");
|
|
warn!("Error to join updated channels");
|
|
@@ -253,7 +253,7 @@ impl<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> IrcClient<C> {
|
|
|
{
|
|
{
|
|
|
debug!("Initializing peer connection");
|
|
debug!("Initializing peer connection");
|
|
|
let register_reply =
|
|
let register_reply =
|
|
|
- format!(":darkfi 001 {} :Let there be dark\r\n", self.irc_config.nickname);
|
|
|
|
|
|
|
+ format!(":darkfi 001 {} :Let there be dark\r\n", self.irc_config.nick);
|
|
|
self.reply(®ister_reply).await?;
|
|
self.reply(®ister_reply).await?;
|
|
|
self.irc_config.is_registered = true;
|
|
self.irc_config.is_registered = true;
|
|
|
|
|
|
|
@@ -288,8 +288,8 @@ impl<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> IrcClient<C> {
|
|
|
Ok(())
|
|
Ok(())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async fn on_receive_pass(&mut self, password: &str) -> Result<()> {
|
|
|
|
|
- if self.irc_config.password == password {
|
|
|
|
|
|
|
+ async fn on_receive_pass(&mut self, pass: &str) -> Result<()> {
|
|
|
|
|
+ if self.irc_config.pass == pass {
|
|
|
self.irc_config.is_pass_init = true
|
|
self.irc_config.is_pass_init = true
|
|
|
} else {
|
|
} else {
|
|
|
// Close the connection
|
|
// Close the connection
|
|
@@ -336,28 +336,20 @@ impl<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> IrcClient<C> {
|
|
|
let chan_info = self.irc_config.channels.get_mut(channel).unwrap();
|
|
let chan_info = self.irc_config.channels.get_mut(channel).unwrap();
|
|
|
chan_info.topic = Some(topic.to_string());
|
|
chan_info.topic = Some(topic.to_string());
|
|
|
|
|
|
|
|
- let topic_reply = format!(
|
|
|
|
|
- ":{}!anon@dark.fi TOPIC {} :{}\r\n",
|
|
|
|
|
- self.irc_config.nickname, channel, topic
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ let topic_reply =
|
|
|
|
|
+ format!(":{}!anon@dark.fi TOPIC {} :{}\r\n", self.irc_config.nick, channel, topic);
|
|
|
self.reply(&topic_reply).await?;
|
|
self.reply(&topic_reply).await?;
|
|
|
} else {
|
|
} else {
|
|
|
// Client is asking or the topic
|
|
// Client is asking or the topic
|
|
|
let chan_info = self.irc_config.channels.get(channel).unwrap();
|
|
let chan_info = self.irc_config.channels.get(channel).unwrap();
|
|
|
let topic_reply = if let Some(topic) = &chan_info.topic {
|
|
let topic_reply = if let Some(topic) = &chan_info.topic {
|
|
|
- format!(
|
|
|
|
|
- "{} {} {} :{}\r\n",
|
|
|
|
|
- RPL::Topic as u32,
|
|
|
|
|
- self.irc_config.nickname,
|
|
|
|
|
- channel,
|
|
|
|
|
- topic
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ format!("{} {} {} :{}\r\n", RPL::Topic as u32, self.irc_config.nick, channel, topic)
|
|
|
} else {
|
|
} else {
|
|
|
const TOPIC: &str = "No topic is set";
|
|
const TOPIC: &str = "No topic is set";
|
|
|
format!(
|
|
format!(
|
|
|
"{} {} {} :{}\r\n",
|
|
"{} {} {} :{}\r\n",
|
|
|
RPL::NoTopic as u32,
|
|
RPL::NoTopic as u32,
|
|
|
- self.irc_config.nickname,
|
|
|
|
|
|
|
+ self.irc_config.nick,
|
|
|
channel,
|
|
channel,
|
|
|
TOPIC
|
|
TOPIC
|
|
|
)
|
|
)
|
|
@@ -375,14 +367,14 @@ impl<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> IrcClient<C> {
|
|
|
async fn on_receive_cap(&mut self, line: &str, subcommand: &str) -> Result<()> {
|
|
async fn on_receive_cap(&mut self, line: &str, subcommand: &str) -> Result<()> {
|
|
|
self.irc_config.is_cap_end = false;
|
|
self.irc_config.is_cap_end = false;
|
|
|
|
|
|
|
|
- let capabilities_keys: Vec<String> = self.irc_config.capabilities.keys().cloned().collect();
|
|
|
|
|
|
|
+ let caps_keys: Vec<String> = self.irc_config.caps.keys().cloned().collect();
|
|
|
|
|
|
|
|
match subcommand {
|
|
match subcommand {
|
|
|
"LS" => {
|
|
"LS" => {
|
|
|
let cap_ls_reply = format!(
|
|
let cap_ls_reply = format!(
|
|
|
":{}!anon@dark.fi CAP * LS :{}\r\n",
|
|
":{}!anon@dark.fi CAP * LS :{}\r\n",
|
|
|
- self.irc_config.nickname,
|
|
|
|
|
- capabilities_keys.join(" ")
|
|
|
|
|
|
|
+ self.irc_config.nick,
|
|
|
|
|
+ caps_keys.join(" ")
|
|
|
);
|
|
);
|
|
|
self.reply(&cap_ls_reply).await?;
|
|
self.reply(&cap_ls_reply).await?;
|
|
|
}
|
|
}
|
|
@@ -400,8 +392,8 @@ impl<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> IrcClient<C> {
|
|
|
let mut nak_list = vec![];
|
|
let mut nak_list = vec![];
|
|
|
|
|
|
|
|
for c in cap {
|
|
for c in cap {
|
|
|
- if self.irc_config.capabilities.contains_key(c) {
|
|
|
|
|
- self.irc_config.capabilities.insert(c.to_string(), true);
|
|
|
|
|
|
|
+ if self.irc_config.caps.contains_key(c) {
|
|
|
|
|
+ self.irc_config.caps.insert(c.to_string(), true);
|
|
|
ack_list.push(c);
|
|
ack_list.push(c);
|
|
|
} else {
|
|
} else {
|
|
|
nak_list.push(c);
|
|
nak_list.push(c);
|
|
@@ -410,13 +402,13 @@ impl<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> IrcClient<C> {
|
|
|
|
|
|
|
|
let cap_ack_reply = format!(
|
|
let cap_ack_reply = format!(
|
|
|
":{}!anon@dark.fi CAP * ACK :{}\r\n",
|
|
":{}!anon@dark.fi CAP * ACK :{}\r\n",
|
|
|
- self.irc_config.nickname,
|
|
|
|
|
|
|
+ self.irc_config.nick,
|
|
|
ack_list.join(" ")
|
|
ack_list.join(" ")
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
let cap_nak_reply = format!(
|
|
let cap_nak_reply = format!(
|
|
|
":{}!anon@dark.fi CAP * NAK :{}\r\n",
|
|
":{}!anon@dark.fi CAP * NAK :{}\r\n",
|
|
|
- self.irc_config.nickname,
|
|
|
|
|
|
|
+ self.irc_config.nick,
|
|
|
nak_list.join(" ")
|
|
nak_list.join(" ")
|
|
|
);
|
|
);
|
|
|
|
|
|
|
@@ -425,9 +417,9 @@ impl<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> IrcClient<C> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
"LIST" => {
|
|
"LIST" => {
|
|
|
- let enabled_capabilities: Vec<String> = self
|
|
|
|
|
|
|
+ let enabled_caps: Vec<String> = self
|
|
|
.irc_config
|
|
.irc_config
|
|
|
- .capabilities
|
|
|
|
|
|
|
+ .caps
|
|
|
.clone()
|
|
.clone()
|
|
|
.into_iter()
|
|
.into_iter()
|
|
|
.filter(|(_, v)| *v)
|
|
.filter(|(_, v)| *v)
|
|
@@ -436,8 +428,8 @@ impl<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> IrcClient<C> {
|
|
|
|
|
|
|
|
let cap_list_reply = format!(
|
|
let cap_list_reply = format!(
|
|
|
":{}!anon@dark.fi CAP * LIST :{}\r\n",
|
|
":{}!anon@dark.fi CAP * LIST :{}\r\n",
|
|
|
- self.irc_config.nickname,
|
|
|
|
|
- enabled_capabilities.join(" ")
|
|
|
|
|
|
|
+ self.irc_config.nick,
|
|
|
|
|
+ enabled_caps.join(" ")
|
|
|
);
|
|
);
|
|
|
self.reply(&cap_list_reply).await?;
|
|
self.reply(&cap_list_reply).await?;
|
|
|
}
|
|
}
|
|
@@ -464,7 +456,7 @@ impl<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> IrcClient<C> {
|
|
|
|
|
|
|
|
let names_reply = format!(
|
|
let names_reply = format!(
|
|
|
":{}!anon@dark.fi {} = {} : {}\r\n",
|
|
":{}!anon@dark.fi {} = {} : {}\r\n",
|
|
|
- self.irc_config.nickname,
|
|
|
|
|
|
|
+ self.irc_config.nick,
|
|
|
RPL::NameReply as u32,
|
|
RPL::NameReply as u32,
|
|
|
chan,
|
|
chan,
|
|
|
chan_info.names()
|
|
chan_info.names()
|
|
@@ -475,7 +467,7 @@ impl<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> IrcClient<C> {
|
|
|
let end_of_names = format!(
|
|
let end_of_names = format!(
|
|
|
":DarkFi {:03} {} {} :End of NAMES list\r\n",
|
|
":DarkFi {:03} {} {} :End of NAMES list\r\n",
|
|
|
RPL::EndOfNames as u32,
|
|
RPL::EndOfNames as u32,
|
|
|
- self.irc_config.nickname,
|
|
|
|
|
|
|
+ self.irc_config.nick,
|
|
|
chan
|
|
chan
|
|
|
);
|
|
);
|
|
|
|
|
|
|
@@ -498,7 +490,7 @@ impl<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> IrcClient<C> {
|
|
|
|
|
|
|
|
let mut privmsg = PrivMsgEvent::new();
|
|
let mut privmsg = PrivMsgEvent::new();
|
|
|
|
|
|
|
|
- privmsg.nick = self.irc_config.nickname.clone();
|
|
|
|
|
|
|
+ privmsg.nick = self.irc_config.nick.clone();
|
|
|
privmsg.target = target.to_string();
|
|
privmsg.target = target.to_string();
|
|
|
privmsg.msg = message.clone();
|
|
privmsg.msg = message.clone();
|
|
|
|
|
|
|
@@ -541,31 +533,32 @@ impl<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> IrcClient<C> {
|
|
|
if !chan.starts_with('#') {
|
|
if !chan.starts_with('#') {
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
if !self.irc_config.channels.contains_key(chan) {
|
|
if !self.irc_config.channels.contains_key(chan) {
|
|
|
let mut chan_info = ChannelInfo::new()?;
|
|
let mut chan_info = ChannelInfo::new()?;
|
|
|
chan_info.topic = Some("n/a".to_string());
|
|
chan_info.topic = Some("n/a".to_string());
|
|
|
self.irc_config.channels.insert(chan.to_string(), chan_info);
|
|
self.irc_config.channels.insert(chan.to_string(), chan_info);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- let chan_info = self.irc_config.channels.get_mut(chan).unwrap();
|
|
|
|
|
- if chan_info.joined {
|
|
|
|
|
|
|
+ if !self.channels_joined.insert(chan.to_string()) {
|
|
|
return Ok(())
|
|
return Ok(())
|
|
|
}
|
|
}
|
|
|
- chan_info.joined = true;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ let chan_info = self.irc_config.channels.get_mut(chan).unwrap();
|
|
|
|
|
|
|
|
let topic =
|
|
let topic =
|
|
|
if let Some(topic) = chan_info.topic.clone() { topic } else { "n/a".to_string() };
|
|
if let Some(topic) = chan_info.topic.clone() { topic } else { "n/a".to_string() };
|
|
|
chan_info.topic = Some(topic.to_string());
|
|
chan_info.topic = Some(topic.to_string());
|
|
|
|
|
|
|
|
{
|
|
{
|
|
|
- let j = format!(":{}!anon@dark.fi JOIN {}\r\n", self.irc_config.nickname, chan);
|
|
|
|
|
|
|
+ let j = format!(":{}!anon@dark.fi JOIN {}\r\n", self.irc_config.nick, chan);
|
|
|
let t = format!(":DarkFi TOPIC {} :{}\r\n", chan, topic);
|
|
let t = format!(":DarkFi TOPIC {} :{}\r\n", chan, topic);
|
|
|
self.reply(&j).await?;
|
|
self.reply(&j).await?;
|
|
|
self.reply(&t).await?;
|
|
self.reply(&t).await?;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if *self.irc_config.capabilities.get("no-history").unwrap() {
|
|
|
|
|
|
|
+ if *self.irc_config.caps.get("no-history").unwrap() {
|
|
|
return Ok(())
|
|
return Ok(())
|
|
|
}
|
|
}
|
|
|
|
|
|