whois: fold the channel list across multiple 319 lines to stay under 512 bytes
This commit is contained in:
parent
e57e4c3a6a
commit
767ecb3471
1 changed files with 17 additions and 5 deletions
|
|
@ -258,11 +258,23 @@ impl Command for Whois {
|
||||||
}
|
}
|
||||||
// +I hides the channel list from everyone but the user themselves + opers
|
// +I hides the channel list from everyone but the user themselves + opers
|
||||||
if !chans.is_empty() && (is_self || asker_oper || !hidechans) {
|
if !chans.is_empty() && (is_self || asker_oper || !hidechans) {
|
||||||
s.numeric(
|
// fold across multiple 319 lines so a user in many channels stays under 512
|
||||||
uid,
|
let askern = s.users.get(&uid).map(|u| u.nick.len()).unwrap_or(1);
|
||||||
RPL_WHOISCHANNELS,
|
let budget = 500usize.saturating_sub(s.name.len() + askern + nick.len() + 12);
|
||||||
&format!("{nick} :{}", chans.join(" ")),
|
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)
|
// 313: is an IRC operator (hidden by +H unless the asker is an oper)
|
||||||
if oper && (!hideoper || asker_oper) {
|
if oper && (!hideoper || asker_oper) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue