nickserv: SET SNOTICE — opt-in server-notice-style service replies (*** NickServ: ...) sourced from the server instead of the pseudoclient
All checks were successful
CI / check (push) Successful in 3m47s

This commit is contained in:
Jean Chevronnet 2026-07-18 03:40:22 +00:00
parent 3230cdd9db
commit 6429b82fc4
No known key found for this signature in database
12 changed files with 90 additions and 11 deletions

View file

@ -1814,6 +1814,8 @@ pub trait Store {
// NickServ SET HIDE STATUS: whether this account hides its last-seen line. // NickServ SET HIDE STATUS: whether this account hides its last-seen line.
fn set_account_hide_status(&mut self, account: &str, on: bool) -> Result<(), RegError>; fn set_account_hide_status(&mut self, account: &str, on: bool) -> Result<(), RegError>;
fn account_hides_status(&self, account: &str) -> bool; fn account_hides_status(&self, account: &str) -> bool;
fn set_account_snotice(&mut self, account: &str, on: bool) -> Result<(), RegError>;
fn account_wants_snotice(&self, account: &str) -> bool;
// HostServ vhosts. // HostServ vhosts.
fn set_vhost(&mut self, account: &str, host: &str, setter: &str, ttl: Option<u64>) -> Result<(), RegError>; fn set_vhost(&mut self, account: &str, host: &str, setter: &str, ttl: Option<u64>) -> Result<(), RegError>;
fn del_vhost(&mut self, account: &str) -> Result<bool, RegError>; fn del_vhost(&mut self, account: &str) -> Result<bool, RegError>;

View file

@ -92,6 +92,18 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db:
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."), Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
} }
} }
Some("SNOTICE") | Some("SNOTICES") => {
let Some(on) = args.get(2).and_then(|s| parse_toggle(s)) else {
let state = if db.account_wants_snotice(account) { "ON" } else { "OFF" };
ctx.notice(me, from.uid, format!("SNOTICE is \x02{state}\x02. Syntax: SET SNOTICE {{ON|OFF}}"));
return;
};
match db.set_account_snotice(account, on) {
Ok(()) if on => ctx.notice(me, from.uid, "Service replies now arrive as server notices (\x02*** NickServ: …\x02)."),
Ok(()) => ctx.notice(me, from.uid, "Service replies now arrive as normal notices from the service."),
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
}
}
Some("GREET") => { Some("GREET") => {
// A bot shows this when you join a greet-enabled channel; no arg clears it. // A bot shows this when you join a greet-enabled channel; no arg clears it.
let greet = if args.len() > 2 { args[2..].join(" ") } else { String::new() }; let greet = if args.len() > 2 { args[2..].join(" ") } else { String::new() };
@ -102,7 +114,7 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db:
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."), Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
} }
} }
_ => ctx.notice(me, from.uid, "Syntax: SET PASSWORD <newpassword> | SET EMAIL [address] | SET GREET [message] | SET AUTOOP {ON|OFF} | SET KILL {ON|OFF} | SET HIDE STATUS {ON|OFF}"), _ => ctx.notice(me, from.uid, "Syntax: SET PASSWORD <newpassword> | SET EMAIL [address] | SET GREET [message] | SET AUTOOP {ON|OFF} | SET KILL {ON|OFF} | SET HIDE STATUS {ON|OFF} | SET SNOTICE {ON|OFF}"),
} }
} }

View file

@ -22,7 +22,7 @@ impl Db {
ajoin: Vec::new(), ajoin: Vec::new(),
suspension: None, suspension: None,
memos: Vec::new(), memo_ignore: Vec::new(), memo_notify: true, memo_limit: None, memos: Vec::new(), memo_ignore: Vec::new(), memo_notify: true, memo_limit: None,
greet: String::new(), no_autoop: false, no_protect: false, hide_status: false, greet: String::new(), no_autoop: false, no_protect: false, hide_status: false, snotice: false,
vhost: None, vhost: None,
vhost_request: None, vhost_request: None,
last_seen: ts, last_seen: ts,
@ -78,7 +78,7 @@ impl Db {
ajoin: Vec::new(), ajoin: Vec::new(),
suspension: None, suspension: None,
memos: Vec::new(), memo_ignore: Vec::new(), memo_notify: true, memo_limit: None, memos: Vec::new(), memo_ignore: Vec::new(), memo_notify: true, memo_limit: None,
greet: String::new(), no_autoop: false, no_protect: false, hide_status: false, greet: String::new(), no_autoop: false, no_protect: false, hide_status: false, snotice: false,
vhost: None, vhost: None,
vhost_request: None, vhost_request: None,
last_seen: ts, last_seen: ts,
@ -563,6 +563,22 @@ impl Db {
self.accounts.get(&key(account)).is_some_and(|a| a.hide_status) self.accounts.get(&key(account)).is_some_and(|a| a.hide_status)
} }
/// NickServ SET SNOTICE: whether service replies come as a server notice.
pub fn set_account_snotice(&mut self, account: &str, on: bool) -> Result<(), RegError> {
let k = key(account);
if !self.accounts.contains_key(&k) {
return Err(RegError::Internal);
}
self.log.append(Event::AccountSnoticeSet { account: account.to_string(), on }).map_err(|_| RegError::Internal)?;
self.accounts.get_mut(&k).unwrap().snotice = on;
Ok(())
}
/// Whether `account` wants server-notice-style service replies (default false).
pub fn account_wants_snotice(&self, account: &str) -> bool {
self.accounts.get(&key(account)).is_some_and(|a| a.snotice)
}
/// Replace `account`'s password with freshly derived credentials. /// Replace `account`'s password with freshly derived credentials.
pub fn set_credentials(&mut self, account: &str, creds: Credentials) -> Result<(), RegError> { pub fn set_credentials(&mut self, account: &str, creds: Credentials) -> Result<(), RegError> {
let k = key(account); let k = key(account);

View file

@ -18,6 +18,7 @@ pub enum Event {
AccountAutoOpSet { account: String, on: bool }, AccountAutoOpSet { account: String, on: bool },
AccountKillSet { account: String, on: bool }, AccountKillSet { account: String, on: bool },
AccountHideStatusSet { account: String, on: bool }, AccountHideStatusSet { account: String, on: bool },
AccountSnoticeSet { account: String, on: bool },
AccountPasswordSet { account: String, scram256: String, scram512: String }, AccountPasswordSet { account: String, scram256: String, scram512: String },
AccountDropped { account: String }, AccountDropped { account: String },
AccountVerified { account: String }, AccountVerified { account: String },
@ -176,6 +177,7 @@ impl Event {
| Event::AccountAutoOpSet { .. } | Event::AccountAutoOpSet { .. }
| Event::AccountKillSet { .. } | Event::AccountKillSet { .. }
| Event::AccountHideStatusSet { .. } | Event::AccountHideStatusSet { .. }
| Event::AccountSnoticeSet { .. }
| Event::AccountPasswordSet { .. } | Event::AccountPasswordSet { .. }
| Event::AccountDropped { .. } | Event::AccountDropped { .. }
| Event::AccountVerified { .. } | Event::AccountVerified { .. }
@ -352,6 +354,11 @@ pub(crate) fn apply(accounts: &mut HashMap<String, Account>, channels: &mut Hash
a.hide_status = on; a.hide_status = on;
} }
} }
Event::AccountSnoticeSet { account, on } => {
if let Some(a) = accounts.get_mut(&key(&account)) {
a.snotice = on;
}
}
Event::AccountPasswordSet { account, scram256, scram512 } => { Event::AccountPasswordSet { account, scram256, scram512 } => {
if let Some(a) = accounts.get_mut(&key(&account)) { if let Some(a) = accounts.get_mut(&key(&account)) {
a.scram256 = Some(scram256); a.scram256 = Some(scram256);

View file

@ -106,6 +106,11 @@ pub struct Account {
// (visible) is the zero value. // (visible) is the zero value.
#[serde(default)] #[serde(default)]
pub hide_status: bool, pub hide_status: bool,
// NickServ SET SNOTICE: when set, service replies to this user come as a
// server notice ("*** NickServ: …") instead of a normal notice from the
// pseudoclient. Default (normal notice) is the zero value.
#[serde(default)]
pub snotice: bool,
// Assigned vhost (HostServ), applied to the displayed host on identify. // Assigned vhost (HostServ), applied to the displayed host on identify.
#[serde(default)] #[serde(default)]
pub vhost: Option<Vhost>, pub vhost: Option<Vhost>,

View file

@ -123,6 +123,12 @@ impl Store for Db {
fn account_hides_status(&self, account: &str) -> bool { fn account_hides_status(&self, account: &str) -> bool {
Db::account_hides_status(self, account) Db::account_hides_status(self, account)
} }
fn set_account_snotice(&mut self, account: &str, on: bool) -> Result<(), RegError> {
Db::set_account_snotice(self, account, on)
}
fn account_wants_snotice(&self, account: &str) -> bool {
Db::account_wants_snotice(self, account)
}
fn set_vhost(&mut self, account: &str, host: &str, setter: &str, ttl: Option<u64>) -> Result<(), RegError> { fn set_vhost(&mut self, account: &str, host: &str, setter: &str, ttl: Option<u64>) -> Result<(), RegError> {
Db::set_vhost(self, account, host, setter, ttl) Db::set_vhost(self, account, host, setter, ttl)
} }

View file

@ -32,7 +32,7 @@
// which of the two competing registrations we're looking at. // which of the two competing registrations we're looking at.
let alice = |tag: &str, ts: u64, home: &str| Account { let alice = |tag: &str, ts: u64, home: &str| Account {
name: "alice".into(), email: Some(tag.into()), name: "alice".into(), email: Some(tag.into()),
ts, home: home.into(), scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![], suspension: None, memos: vec![], memo_ignore: vec![], memo_notify: true, memo_limit: None, greet: String::new(), no_autoop: false, no_protect: false, hide_status: false, vhost: None, vhost_request: None, last_seen: ts, noexpire: false, expiry_warned: false, oper_note: None, ts, home: home.into(), scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![], suspension: None, memos: vec![], memo_ignore: vec![], memo_notify: true, memo_limit: None, greet: String::new(), no_autoop: false, no_protect: false, hide_status: false, snotice: false, vhost: None, vhost_request: None, last_seen: ts, noexpire: false, expiry_warned: false, oper_note: None,
}; };
let converge = |first: &Account, second: &Account| { let converge = |first: &Account, second: &Account| {
let (mut acc, mut ch, mut gr, mut bo, mut hc, mut nd) = (HashMap::new(), HashMap::new(), HashMap::new(), HashMap::new(), HostConfig::default(), NetData::default()); let (mut acc, mut ch, mut gr, mut bo, mut hc, mut nd) = (HashMap::new(), HashMap::new(), HashMap::new(), HashMap::new(), HostConfig::default(), NetData::default());
@ -64,7 +64,7 @@
scram256: Some(verifier.into()), scram512: None, certfps: vec![], verified: true, scram256: Some(verifier.into()), scram512: None, certfps: vec![], verified: true,
ajoin: vec![], suspension: None, memos: vec![], memo_ignore: vec![], memo_notify: true, ajoin: vec![], suspension: None, memos: vec![], memo_ignore: vec![], memo_notify: true,
memo_limit: None, greet: String::new(), no_autoop: false, no_protect: false, memo_limit: None, greet: String::new(), no_autoop: false, no_protect: false,
hide_status: false, vhost: None, vhost_request: None, last_seen: ts, noexpire: false, hide_status: false, snotice: false, vhost: None, vhost_request: None, last_seen: ts, noexpire: false,
expiry_warned: false, oper_note: None, expiry_warned: false, oper_note: None,
}; };
let reg = |origin: &str, a: Account| LogEntry::for_test(origin, 1, 1, Event::AccountRegistered(Box::new(a))); let reg = |origin: &str, a: Account| LogEntry::for_test(origin, 1, 1, Event::AccountRegistered(Box::new(a)));
@ -134,6 +134,18 @@
assert!(!db.akick_del("#c", "*!*@bad.host").unwrap()); assert!(!db.akick_del("#c", "*!*@bad.host").unwrap());
} }
// SET SNOTICE toggles the per-account server-notice preference (default off).
#[test]
fn snotice_pref_toggles() {
let mut db = Db::open(tmp("snotice"), "N1");
db.register("bob", "pw", None).unwrap();
assert!(!db.account_wants_snotice("bob"), "default is a normal notice");
db.set_account_snotice("bob", true).unwrap();
assert!(db.account_wants_snotice("bob"));
db.set_account_snotice("bob", false).unwrap();
assert!(!db.account_wants_snotice("bob"));
}
// LEVELS grants are additive (default = unchanged), tier-gated, and reversible. // LEVELS grants are additive (default = unchanged), tier-gated, and reversible.
#[test] #[test]
fn levels_grant_is_additive_and_tier_gated() { fn levels_grant_is_additive_and_tier_gated() {
@ -410,7 +422,7 @@
db.register("alice", "pw", None).unwrap(); db.register("alice", "pw", None).unwrap();
let bob = Account { let bob = Account {
name: "bob".into(), email: None, name: "bob".into(), email: None,
ts: 0, home: "peer".into(), scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![], suspension: None, memos: vec![], memo_ignore: vec![], memo_notify: true, memo_limit: None, greet: String::new(), no_autoop: false, no_protect: false, hide_status: false, vhost: None, vhost_request: None, last_seen: 0, noexpire: false, expiry_warned: false, oper_note: None, ts: 0, home: "peer".into(), scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![], suspension: None, memos: vec![], memo_ignore: vec![], memo_notify: true, memo_limit: None, greet: String::new(), no_autoop: false, no_protect: false, hide_status: false, snotice: false, vhost: None, vhost_request: None, last_seen: 0, noexpire: false, expiry_warned: false, oper_note: None,
}; };
let entry = LogEntry { origin: "peer".into(), seq: 0, lamport: 1, event: Event::AccountRegistered(Box::new(bob)) }; let entry = LogEntry { origin: "peer".into(), seq: 0, lamport: 1, event: Event::AccountRegistered(Box::new(bob)) };
db.ingest(entry).unwrap(); db.ingest(entry).unwrap();
@ -477,7 +489,7 @@
scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![], scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![],
suspension: None, memos: vec![], memo_ignore: vec![], memo_notify: true, suspension: None, memos: vec![], memo_ignore: vec![], memo_notify: true,
memo_limit: None, greet: String::new(), no_autoop: false, no_protect: false, memo_limit: None, greet: String::new(), no_autoop: false, no_protect: false,
hide_status: false, vhost: None, vhost_request: None, last_seen: 1, hide_status: false, snotice: false, vhost: None, vhost_request: None, last_seen: 1,
noexpire: false, expiry_warned: false, oper_note: None, noexpire: false, expiry_warned: false, oper_note: None,
}))).unwrap(); }))).unwrap();
} }

View file

@ -67,9 +67,27 @@ impl Engine {
out.extend(self.reconcile_bots()); out.extend(self.reconcile_bots());
// Announce whatever this command changed to the staff audit channel. // Announce whatever this command changed to the staff audit channel.
out.extend(self.audit_feed(audit_mark, &nick, account.as_deref())); out.extend(self.audit_feed(audit_mark, &nick, account.as_deref()));
self.apply_msg_style(&mut out);
out out
} }
// Rewrite each service→user NOTICE to a server-notice ("*** NickServ: …",
// sourced from our server) for users who opted into SET SNOTICE. Everyone
// else's reply is left as a normal notice from the pseudoclient. Per target,
// so notices to channels or to users who didn't opt in are untouched.
fn apply_msg_style(&self, out: &mut [NetAction]) {
for a in out.iter_mut() {
let NetAction::Notice { from, to, text } = a else { continue };
let Some(account) = self.network.account_of(to) else { continue };
if !self.db.account_wants_snotice(account) {
continue;
}
let Some(nick) = self.services.iter().find(|s| s.uid() == *from).map(|s| s.nick()) else { continue };
*text = format!("*** {nick}: {text}");
*from = self.sid.clone();
}
}
// fantasy word becomes the command and the channel is injected as its first // fantasy word becomes the command and the channel is injected as its first
// argument — then re-source the resulting actions from the bot, so the bot is // argument — then re-source the resulting actions from the bot, so the bot is
// the visible actor. // the visible actor.

View file

@ -1776,7 +1776,7 @@ fn audit_summary(event: &db::Event) -> Option<String> {
format!("{verb} channel \x02{channel}\x02 against expiry") format!("{verb} channel \x02{channel}\x02 against expiry")
} }
// Private, self-service, or cosmetic — not surfaced. // Private, self-service, or cosmetic — not surfaced.
AjoinAdded { .. } | AjoinRemoved { .. } | AccountGreetSet { .. } | AccountAutoOpSet { .. } | AccountKillSet { .. } | AccountHideStatusSet { .. } | VhostRequested { .. } AjoinAdded { .. } | AjoinRemoved { .. } | AccountGreetSet { .. } | AccountAutoOpSet { .. } | AccountKillSet { .. } | AccountHideStatusSet { .. } | AccountSnoticeSet { .. } | VhostRequested { .. }
| VhostRequestCleared { .. } | MemoSent { .. } | MemoRead { .. } | MemoDeleted { .. } | VhostRequestCleared { .. } | MemoSent { .. } | MemoRead { .. } | MemoDeleted { .. }
| MemoIgnoreAdd { .. } | MemoIgnoreDel { .. } | MemoPrefsSet { .. } | MemoIgnoreAdd { .. } | MemoIgnoreDel { .. } | MemoPrefsSet { .. }
| ChannelMlock { .. } | ChannelDescSet { .. } | ChannelEntryMsgSet { .. } | ChannelUrlSet { .. } | ChannelEmailSet { .. } | ChannelSettingsSet { .. } | ChannelMlock { .. } | ChannelDescSet { .. } | ChannelEntryMsgSet { .. } | ChannelUrlSet { .. } | ChannelEmailSet { .. } | ChannelSettingsSet { .. }

View file

@ -850,7 +850,7 @@
// An earlier claim from another node wins and takes the name over. // An earlier claim from another node wins and takes the name over.
let winner = db::Account { let winner = db::Account {
name: "alice".into(), email: None, name: "alice".into(), email: None,
ts: 0, home: "peer".into(), scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![], suspension: None, memos: vec![], memo_ignore: vec![], memo_notify: true, memo_limit: None, greet: String::new(), no_autoop: false, no_protect: false, hide_status: false, vhost: None, vhost_request: None, last_seen: 0, noexpire: false, expiry_warned: false, oper_note: None, ts: 0, home: "peer".into(), scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![], suspension: None, memos: vec![], memo_ignore: vec![], memo_notify: true, memo_limit: None, greet: String::new(), no_autoop: false, no_protect: false, hide_status: false, snotice: false, vhost: None, vhost_request: None, last_seen: 0, noexpire: false, expiry_warned: false, oper_note: None,
}; };
let entry = LogEntry::for_test("peer", 0, 1, db::Event::AccountRegistered(Box::new(winner))); let entry = LogEntry::for_test("peer", 0, 1, db::Event::AccountRegistered(Box::new(winner)));
e.gossip_ingest(entry).unwrap(); e.gossip_ingest(entry).unwrap();

View file

@ -131,6 +131,7 @@ fn to_wire(entry: &LogEntry) -> Option<ReplicationEvent> {
| Event::AccountAutoOpSet { .. } | Event::AccountAutoOpSet { .. }
| Event::AccountKillSet { .. } | Event::AccountKillSet { .. }
| Event::AccountHideStatusSet { .. } | Event::AccountHideStatusSet { .. }
| Event::AccountSnoticeSet { .. }
| Event::AjoinAdded { .. } | Event::AjoinAdded { .. }
| Event::AjoinRemoved { .. } | Event::AjoinRemoved { .. }
| Event::VhostSet { .. } | Event::VhostSet { .. }
@ -486,7 +487,7 @@ mod tests {
memo_ignore: vec![], memo_ignore: vec![],
memo_notify: true, memo_notify: true,
memo_limit: None, memo_limit: None,
greet: String::new(), no_autoop: false, no_protect: false, hide_status: false, greet: String::new(), no_autoop: false, no_protect: false, hide_status: false, snotice: false,
vhost: None, vhost: None,
vhost_request: None, vhost_request: None,
last_seen: 111, last_seen: 111,

View file

@ -200,7 +200,7 @@ pub fn import_anope(anope_path: &str, out_path: &str, node: &str) -> std::io::Re
greet: String::new(), greet: String::new(),
no_autoop: !flag(nc, "AUTOOP"), no_autoop: !flag(nc, "AUTOOP"),
no_protect: !flag(nc, "PROTECT"), no_protect: !flag(nc, "PROTECT"),
hide_status: flag(nc, "HIDE_MASK"), hide_status: flag(nc, "HIDE_MASK"), snotice: false,
vhost, vhost,
vhost_request: None, vhost_request: None,
last_seen: last_seen_of.get(name).copied().unwrap_or(ts), last_seen: last_seen_of.get(name).copied().unwrap_or(ts),