Extend WHOIS info
Diff
src/connection.rs | 19 +++++++++++++++++++
src/server/response.rs | 44 +++++++++++++++++++++++++++++++++++++++++---
2 files changed, 57 insertions(+), 6 deletions(-)
@@ -1,9 +1,10 @@
#![allow(clippy::iter_without_into_iter)]
mod authenticate;
pub mod sasl;
use std::{
fmt::{Display, Formatter},
io::{Error, ErrorKind},
net::SocketAddr,
str::FromStr,
@@ -98,7 +99,7 @@
Ok(Self {
host,
cloak: host.ip().to_string(),
cloak: format!("0{}", host.ip()),
nick,
user,
mode: UserMode::empty(),
@@ -295,6 +296,22 @@
const WALLOPS = 0b0000_0000_0000_0000_0000_0000_0000_0001;
const OPER = 0b0000_0000_0000_0000_0000_0000_0000_0010;
}
}
impl Display for UserMode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "+")?;
if self.contains(Self::WALLOPS) {
write!(f, "w")?;
}
if self.contains(Self::OPER) {
write!(f, "o")?;
}
Ok(())
}
}
@@ -25,6 +25,16 @@
),
}
};
($response:literal, $($payload:expr),*) => {
Message {
tags: None,
prefix: Some(Prefix::ServerName(SERVER_NAME.to_string())),
command: Command::Raw(
format!("{:03}", $response),
vec![for_user.to_string(), $($payload),*],
),
}
};
}
let Some(conn) = self.conn else {
@@ -42,11 +52,16 @@
let mut out = vec![
msg!(
307,
conn.nick.to_string(),
"has identified for this nick".to_string()
),
msg!(
RPL_WHOISUSER,
conn.nick.to_string(),
conn.user,
conn.user.to_string(),
conn.cloak,
"*".to_string(),
conn.real_name
),
@@ -64,10 +79,29 @@
"seconds idle, signon time".to_string()
),
msg!(RPL_WHOISCHANNELS, conn.nick.to_string(), channels),
msg!(
330,
conn.nick.to_string(),
conn.user.to_string(),
"is logged in as".to_string()
),
msg!(
378,
conn.nick.to_string(),
format!(
"is connecting from {}@{} {}",
conn.user, conn.host, conn.host
)
),
];
if !conn.mode.is_empty() {
out.push(msg!(
379,
conn.nick.to_string(),
format!("is using modes {}", conn.mode)
));
}
if let Some(msg) = conn.away {
out.push(msg!(RPL_AWAY, conn.nick.to_string(), msg));