From 767ecb347105a98979aafcb4a78bbc106ec3d748 Mon Sep 17 00:00:00 2001 From: reverse Date: Sun, 16 Aug 2026 18:46:07 +0000 Subject: [PATCH] whois: fold the channel list across multiple 319 lines to stay under 512 bytes --- src/coremods/core_info.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/coremods/core_info.rs b/src/coremods/core_info.rs index 4ce88db..1411609 100644 --- a/src/coremods/core_info.rs +++ b/src/coremods/core_info.rs @@ -258,11 +258,23 @@ impl Command for Whois { } // +I hides the channel list from everyone but the user themselves + opers if !chans.is_empty() && (is_self || asker_oper || !hidechans) { - s.numeric( - uid, - RPL_WHOISCHANNELS, - &format!("{nick} :{}", chans.join(" ")), - ); + // fold across multiple 319 lines so a user in many channels stays under 512 + let askern = s.users.get(&uid).map(|u| u.nick.len()).unwrap_or(1); + let budget = 500usize.saturating_sub(s.name.len() + askern + nick.len() + 12); + let mut line = String::new(); + for c in &chans { + if !line.is_empty() && line.len() + 1 + c.len() > budget { + s.numeric(uid, RPL_WHOISCHANNELS, &format!("{nick} :{line}")); + line.clear(); + } + if !line.is_empty() { + line.push(' '); + } + line.push_str(c); + } + if !line.is_empty() { + s.numeric(uid, RPL_WHOISCHANNELS, &format!("{nick} :{line}")); + } } // 313: is an IRC operator (hidden by +H unless the asker is an oper) if oper && (!hideoper || asker_oper) {