user modes +W showwhois / +c commonchans

This commit is contained in:
Jean Chevronnet 2026-08-09 00:54:56 +00:00
parent 37ea5d277d
commit 835c1cf099
5 changed files with 65 additions and 2 deletions

View file

@ -119,6 +119,7 @@ impl Command for Whois {
signon,
certfp,
swhois,
showwhois,
) = {
let u = &s.users[&tuid];
(
@ -140,6 +141,7 @@ impl Command for Whois {
u.ext
.get::<crate::coremods::core_oper::Swhois>()
.map(|w| w.0.clone()),
u.flags.showwhois,
)
};
let chans: Vec<String> = keys
@ -221,6 +223,14 @@ impl Command for Whois {
RPL_WHOISIDLE,
&format!("{nick} {idle} {signon} :seconds idle, signon time"),
);
// +W showwhois — tell the target that someone looked them up
if showwhois && !is_self {
let by = s.users.get(&uid).map(|u| u.prefix()).unwrap_or_default();
s.send(
tuid,
format!(":{} NOTICE {nick} :*** {by} did a /WHOIS on you", s.name),
);
}
s.numeric(uid, RPL_ENDOFWHOIS, &format!("{nick} :End of /WHOIS list"));
CmdResult::Ok
}

View file

@ -360,6 +360,34 @@ pub(crate) fn deliver(s: &mut Server, uid: Uid, params: &[String], notice: bool)
// propagate to linked servers that have members in this channel
s.send_channel_to_links(uid, &key, target, cmd, &body);
} else if let Some(tuid) = s.find_nick(target) {
// user +c (commonchans): only users sharing a channel may PM them (opers exempt)
if s.users
.get(&tuid)
.map(|u| u.flags.deny_uncommon)
.unwrap_or(false)
&& uid != tuid
&& !s.is_oper(uid)
{
let common = match (s.users.get(&uid), s.users.get(&tuid)) {
(Some(a), Some(b)) => a.channels.intersection(&b.channels).next().is_some(),
_ => false,
};
if !common {
if !notice {
let tn = s
.users
.get(&tuid)
.map(|u| u.nick.clone())
.unwrap_or_default();
s.numeric(
uid,
ERR_CANTSENDTOUSER,
&format!("{tn} :You must share a channel to message this user (+c)"),
);
}
return CmdResult::Fail;
}
}
// user +R (regdeaf): drop messages from users not logged into an account
if s.users
.get(&tuid)