NickServ: add SET HIDE STATUS for last-seen privacy

Lets an account keep its last-seen/online line in INFO visible only to
itself and to opers. Default stays public (Anope's default). Accepts
STATUS (with USERMASK as an alias) per Anope's SET HIDE <field> grammar.
This commit is contained in:
Jean Chevronnet 2026-07-16 02:33:55 +00:00
parent 39d7421c06
commit 053f8cf832
No known key found for this signature in database
12 changed files with 116 additions and 19 deletions

View file

@ -21,7 +21,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,
greet: String::new(), no_autoop: false, no_protect: false, hide_status: false,
vhost: None,
vhost_request: None,
last_seen: now(),
@ -60,7 +60,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,
greet: String::new(), no_autoop: false, no_protect: false, hide_status: false,
vhost: None,
vhost_request: None,
last_seen: now(),
@ -450,6 +450,22 @@ impl Db {
self.accounts.get(&key(account)).is_none_or(|a| !a.no_protect)
}
/// Set whether `account` hides its last-seen/online line from other users.
pub fn set_account_hide_status(&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::AccountHideStatusSet { account: account.to_string(), on }).map_err(|_| RegError::Internal)?;
self.accounts.get_mut(&k).unwrap().hide_status = on;
Ok(())
}
/// Whether `account` hides its last-seen/online line from others (default false).
pub fn account_hides_status(&self, account: &str) -> bool {
self.accounts.get(&key(account)).is_some_and(|a| a.hide_status)
}
/// Replace `account`'s password with freshly derived credentials.
pub fn set_credentials(&mut self, account: &str, creds: Credentials) -> Result<(), RegError> {
let k = key(account);

View file

@ -17,6 +17,7 @@ pub enum Event {
AccountGreetSet { account: String, greet: String },
AccountAutoOpSet { account: String, on: bool },
AccountKillSet { account: String, on: bool },
AccountHideStatusSet { account: String, on: bool },
AccountPasswordSet { account: String, scram256: String, scram512: String },
AccountDropped { account: String },
AccountVerified { account: String },
@ -151,6 +152,7 @@ impl Event {
| Event::AccountGreetSet { .. }
| Event::AccountAutoOpSet { .. }
| Event::AccountKillSet { .. }
| Event::AccountHideStatusSet { .. }
| Event::AccountPasswordSet { .. }
| Event::AccountDropped { .. }
| Event::AccountVerified { .. }
@ -287,6 +289,11 @@ pub(crate) fn apply(accounts: &mut HashMap<String, Account>, channels: &mut Hash
a.no_protect = !on;
}
}
Event::AccountHideStatusSet { account, on } => {
if let Some(a) = accounts.get_mut(&key(&account)) {
a.hide_status = on;
}
}
Event::AccountPasswordSet { account, scram256, scram512 } => {
if let Some(a) = accounts.get_mut(&key(&account)) {
a.scram256 = Some(scram256);

View file

@ -101,6 +101,11 @@ pub struct Account {
// inverted so the default (protection enabled) is the zero value.
#[serde(default)]
pub no_protect: bool,
// NickServ SET HIDE STATUS: when set, the last-seen / online line in INFO is
// shown only to the account's owner and to opers, not to other users. Default
// (visible) is the zero value.
#[serde(default)]
pub hide_status: bool,
// Assigned vhost (HostServ), applied to the displayed host on identify.
#[serde(default)]
pub vhost: Option<Vhost>,

View file

@ -12,6 +12,7 @@ impl Store for Db {
verified: a.verified,
greet: a.greet.clone(),
last_seen: a.last_seen,
hide_status: a.hide_status,
})
}
fn resolve_account(&self, name: &str) -> Option<&str> {
@ -20,7 +21,7 @@ impl Store for Db {
fn accounts_matching(&self, pattern: &str) -> Vec<AccountView> {
self.accounts()
.filter(|a| super::glob_match(pattern, &a.name))
.map(|a| AccountView { name: a.name.clone(), email: a.email.clone(), ts: a.ts, verified: a.verified, greet: a.greet.clone(), last_seen: a.last_seen })
.map(|a| AccountView { name: a.name.clone(), email: a.email.clone(), ts: a.ts, verified: a.verified, greet: a.greet.clone(), last_seen: a.last_seen, hide_status: a.hide_status })
.collect()
}
fn accounts_by_email(&self, pattern: &str) -> Vec<String> {
@ -95,6 +96,12 @@ impl Store for Db {
fn account_wants_protect(&self, account: &str) -> bool {
Db::account_wants_protect(self, account)
}
fn set_account_hide_status(&mut self, account: &str, on: bool) -> Result<(), RegError> {
Db::set_account_hide_status(self, account, on)
}
fn account_hides_status(&self, account: &str) -> bool {
Db::account_hides_status(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)
}

View file

@ -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, 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, 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());
@ -329,7 +329,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, 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, 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();