From 21ea94dd3e13c65736693e385a20b764579b86af Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Wed, 31 Jan 2024 02:03:03 +0000 Subject: [PATCH] Extend WHOIS info --- src/connection.rs | 19 +++++++++++++++++++ src/server/response.rs | 44 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/connection.rs b/src/connection.rs index e5c4c7d..c8cf981 100644 --- a/src/connection.rs +++ a/src/connection.rs @@ -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; /// o - operator flag 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(()) } } diff --git a/src/server/response.rs b/src/server/response.rs index 8c38ce7..f22bbbb 100644 --- a/src/server/response.rs +++ a/src/server/response.rs @@ -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 @@ // TODO: RPL_WHOISSECURE // TODO: fix missing rpl variants let mut out = vec![ - // msg!(RPL_WHOISREGNICK, self.conn.nick.to_string(), "has identified for this nick".to_string()), msg!( + 307, + conn.nick.to_string(), + "has identified for this nick".to_string() + ), // RPL_WHOISREGNICK + 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() ), // TODO msg!(RPL_WHOISCHANNELS, conn.nick.to_string(), channels), - // msg!(RPL_WHOISACCOUNT, self.conn.nick.to_string(), self.conn.user.to_string(), "is logged in as".to_string()), - // msg!(RPL_WHOISHOST, self.conn.nick.to_string(), format!("is connecting from {}@{} {}", self.conn.user, self.conn.host, self.conn.host)), - // msg!(RPL_WHOISMODES, self.conn.nick.to_string(), format!("is using modes {}", self.conn.mode)), + msg!( + 330, + conn.nick.to_string(), + conn.user.to_string(), + "is logged in as".to_string() + ), // RPL_WHOISACCOUNT + msg!( + 378, + conn.nick.to_string(), + format!( + "is connecting from {}@{} {}", + conn.user, conn.host, conn.host + ) + ), // RPL_WHOISHOST ]; + + if !conn.mode.is_empty() { + out.push(msg!( + 379, + conn.nick.to_string(), + format!("is using modes {}", conn.mode) + )); // RPL_WHOISMODES + } if let Some(msg) = conn.away { out.push(msg!(RPL_AWAY, conn.nick.to_string(), msg)); -- rgit 0.1.5