Track login state and nick changes in NickServ

This commit is contained in:
Jean Chevronnet 2026-07-12 05:45:33 +00:00
parent 60fc687162
commit 65729a62b8
No known key found for this signature in database
6 changed files with 150 additions and 5 deletions

View file

@ -6,6 +6,7 @@ use std::collections::HashMap;
pub struct Network {
pub users: HashMap<String, User>, // keyed by UID
pub channels: HashMap<String, Channel>,
accounts: HashMap<String, String>, // UID -> logged-in account, until logout/quit
}
pub struct User {
@ -24,11 +25,32 @@ impl Network {
self.users.insert(uid.clone(), User { uid, nick });
}
pub fn user_nick_change(&mut self, uid: &str, nick: String) {
if let Some(user) = self.users.get_mut(uid) {
user.nick = nick;
}
}
pub fn user_quit(&mut self, uid: &str) {
self.users.remove(uid);
self.accounts.remove(uid);
}
pub fn nick_of(&self, uid: &str) -> Option<&str> {
self.users.get(uid).map(|u| u.nick.as_str())
}
// A user's currently identified account, if any. Kept in step with the
// accountname metadata the engine emits (login sets it, logout clears it).
pub fn account_of(&self, uid: &str) -> Option<&str> {
self.accounts.get(uid).map(String::as_str)
}
pub fn set_account(&mut self, uid: &str, account: &str) {
self.accounts.insert(uid.to_string(), account.to_string());
}
pub fn clear_account(&mut self, uid: &str) {
self.accounts.remove(uid);
}
}