snoop: drop needless clones in the connect notice (hold the &User borrow)

This commit is contained in:
Jean Chevronnet 2026-08-25 00:12:23 +00:00
parent 6e8d6c31fb
commit 37436d0306
No known key found for this signature in database
GPG key ID: 439666D63A9477E4

View file

@ -12,31 +12,25 @@ impl Module for Snoop {
"snoop" "snoop"
} }
fn on_user_connect(&mut self, srv: &mut Server, uid: Uid) { fn on_user_connect(&mut self, srv: &mut Server, uid: Uid) {
let info = srv.users.get(&uid).map(|u| { // `conf_bool`/`snotice_c` are `&self`, so we can hold the `&User` borrow and
( // reference its fields directly instead of cloning them out.
u.nick.clone(), let Some(u) = srv.users.get(&uid) else {
u.ident.clone(), return;
u.host.clone(), };
u.port,
u.sni.clone(),
u.account.clone(),
)
});
if let Some((nick, ident, host, port, sni, account)) = info {
if srv.conf_bool("snoop_stderr", false) { if srv.conf_bool("snoop_stderr", false) {
eprintln!("[snoop] connect {nick} ({ident}@{host})"); eprintln!("[snoop] connect {} ({}@{})", u.nick, u.ident, u.host);
} }
// port is always shown; sni/account only when present, so plaintext or // port is always shown; sni/account only when present, so plaintext or
// anonymous connects don't carry empty fields. // anonymous connects don't carry empty fields.
let mut extra = format!(", port: {port}"); let mut extra = format!(", port: {}", u.port);
if let Some(sni) = &sni { if let Some(sni) = &u.sni {
extra.push_str(&format!(", sni: {sni}")); extra.push_str(&format!(", sni: {sni}"));
} }
if let Some(acct) = &account { if let Some(acct) = &u.account {
extra.push_str(&format!(", account: {acct}")); extra.push_str(&format!(", account: {acct}"));
} }
srv.snotice_c('c', &format!("Client connecting: {nick} ({ident}@{host}){extra}")); let msg = format!("Client connecting: {} ({}@{}){extra}", u.nick, u.ident, u.host);
} srv.snotice_c('c', &msg);
} }
fn on_join(&mut self, srv: &mut Server, uid: Uid, chan: &str) { fn on_join(&mut self, srv: &mut Server, uid: Uid, chan: &str) {
if srv.conf_bool("snoop_stderr", false) { if srv.conf_bool("snoop_stderr", false) {