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
All checks were successful
CI / check (push) Successful in 3m47s
This commit is contained in:
parent
3230cdd9db
commit
6429b82fc4
12 changed files with 90 additions and 11 deletions
|
|
@ -22,7 +22,7 @@ impl Db {
|
|||
ajoin: Vec::new(),
|
||||
suspension: 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_request: None,
|
||||
last_seen: ts,
|
||||
|
|
@ -78,7 +78,7 @@ impl Db {
|
|||
ajoin: Vec::new(),
|
||||
suspension: 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_request: None,
|
||||
last_seen: ts,
|
||||
|
|
@ -563,6 +563,22 @@ impl Db {
|
|||
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.
|
||||
pub fn set_credentials(&mut self, account: &str, creds: Credentials) -> Result<(), RegError> {
|
||||
let k = key(account);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ pub enum Event {
|
|||
AccountAutoOpSet { account: String, on: bool },
|
||||
AccountKillSet { account: String, on: bool },
|
||||
AccountHideStatusSet { account: String, on: bool },
|
||||
AccountSnoticeSet { account: String, on: bool },
|
||||
AccountPasswordSet { account: String, scram256: String, scram512: String },
|
||||
AccountDropped { account: String },
|
||||
AccountVerified { account: String },
|
||||
|
|
@ -176,6 +177,7 @@ impl Event {
|
|||
| Event::AccountAutoOpSet { .. }
|
||||
| Event::AccountKillSet { .. }
|
||||
| Event::AccountHideStatusSet { .. }
|
||||
| Event::AccountSnoticeSet { .. }
|
||||
| Event::AccountPasswordSet { .. }
|
||||
| Event::AccountDropped { .. }
|
||||
| Event::AccountVerified { .. }
|
||||
|
|
@ -352,6 +354,11 @@ pub(crate) fn apply(accounts: &mut HashMap<String, Account>, channels: &mut Hash
|
|||
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 } => {
|
||||
if let Some(a) = accounts.get_mut(&key(&account)) {
|
||||
a.scram256 = Some(scram256);
|
||||
|
|
|
|||
|
|
@ -106,6 +106,11 @@ pub struct Account {
|
|||
// (visible) is the zero value.
|
||||
#[serde(default)]
|
||||
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.
|
||||
#[serde(default)]
|
||||
pub vhost: Option<Vhost>,
|
||||
|
|
|
|||
|
|
@ -123,6 +123,12 @@ impl Store for Db {
|
|||
fn account_hides_status(&self, account: &str) -> bool {
|
||||
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> {
|
||||
Db::set_vhost(self, account, host, setter, ttl)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
// which of the two competing registrations we're looking at.
|
||||
let alice = |tag: &str, ts: u64, home: &str| Account {
|
||||
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 (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,
|
||||
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,
|
||||
hide_status: false, snotice: false, vhost: None, vhost_request: None, last_seen: ts, noexpire: false,
|
||||
expiry_warned: false, oper_note: None,
|
||||
};
|
||||
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());
|
||||
}
|
||||
|
||||
// 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.
|
||||
#[test]
|
||||
fn levels_grant_is_additive_and_tier_gated() {
|
||||
|
|
@ -410,7 +422,7 @@
|
|||
db.register("alice", "pw", None).unwrap();
|
||||
let bob = Account {
|
||||
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)) };
|
||||
db.ingest(entry).unwrap();
|
||||
|
|
@ -477,7 +489,7 @@
|
|||
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: 1,
|
||||
hide_status: false, snotice: false, vhost: None, vhost_request: None, last_seen: 1,
|
||||
noexpire: false, expiry_warned: false, oper_note: None,
|
||||
}))).unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,9 +67,27 @@ impl Engine {
|
|||
out.extend(self.reconcile_bots());
|
||||
// Announce whatever this command changed to the staff audit channel.
|
||||
out.extend(self.audit_feed(audit_mark, &nick, account.as_deref()));
|
||||
self.apply_msg_style(&mut 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
|
||||
// argument — then re-source the resulting actions from the bot, so the bot is
|
||||
// the visible actor.
|
||||
|
|
|
|||
|
|
@ -1776,7 +1776,7 @@ fn audit_summary(event: &db::Event) -> Option<String> {
|
|||
format!("{verb} channel \x02{channel}\x02 against expiry")
|
||||
}
|
||||
// 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 { .. }
|
||||
| MemoIgnoreAdd { .. } | MemoIgnoreDel { .. } | MemoPrefsSet { .. }
|
||||
| ChannelMlock { .. } | ChannelDescSet { .. } | ChannelEntryMsgSet { .. } | ChannelUrlSet { .. } | ChannelEmailSet { .. } | ChannelSettingsSet { .. }
|
||||
|
|
|
|||
|
|
@ -850,7 +850,7 @@
|
|||
// An earlier claim from another node wins and takes the name over.
|
||||
let winner = db::Account {
|
||||
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)));
|
||||
e.gossip_ingest(entry).unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue