names: fold the member list across multiple 353 replies to stay under 512 bytes

This commit is contained in:
Jean Chevronnet 2026-08-16 18:45:12 +00:00
parent 94f57608f7
commit e57e4c3a6a

View file

@ -1019,7 +1019,7 @@ impl Server {
// +u auditorium: a non-op viewer only sees ops (plus themselves) // +u auditorium: a non-op viewer only sees ops (plus themselves)
let hide = let hide =
ch.modes.auditorium && ch.members.get(&uid).map(|m| m.rank()).unwrap_or(0) < RANK_OP; ch.modes.auditorium && ch.members.get(&uid).map(|m| m.rank()).unwrap_or(0) < RANK_OP;
let mut names = String::new(); let mut toks: Vec<String> = Vec::new();
for (m, flags) in &ch.members { for (m, flags) in &ch.members {
if hide && *m != uid && flags.rank() < RANK_OP { if hide && *m != uid && flags.rank() < RANK_OP {
continue; continue;
@ -1034,10 +1034,8 @@ impl Server {
flags.prefix_char().to_string() flags.prefix_char().to_string()
}; };
if let Some(u) = self.users.get(m) { if let Some(u) = self.users.get(m) {
names.push_str(&p);
let shown = if uhost { u.prefix() } else { u.nick.clone() }; let shown = if uhost { u.prefix() } else { u.nick.clone() };
names.push_str(&shown); toks.push(format!("{p}{shown}"));
names.push(' ');
} }
} }
// remote members (users on linked servers) // remote members (users on linked servers)
@ -1051,10 +1049,8 @@ impl Server {
} else { } else {
mem.prefix_char().to_string() mem.prefix_char().to_string()
}; };
names.push_str(&p);
let shown = if uhost { ru.prefix() } else { ru.nick.clone() }; let shown = if uhost { ru.prefix() } else { ru.nick.clone() };
names.push_str(&shown); toks.push(format!("{p}{shown}"));
names.push(' ');
} }
} }
// visibility symbol: @ secret (+s), * private (+p), = public // visibility symbol: @ secret (+s), * private (+p), = public
@ -1065,11 +1061,23 @@ impl Server {
} else { } else {
'=' '='
}; };
self.numeric( // fold members across multiple 353 lines so a big channel stays under 512 bytes
uid, let askern = self.users.get(&uid).map(|u| u.nick.len()).unwrap_or(1);
RPL_NAMREPLY, let budget = 500usize.saturating_sub(self.name.len() + askern + ch.name.len() + 12);
&format!("{vis} {} :{}", ch.name, names.trim_end()), let mut line = String::new();
); for t in &toks {
if !line.is_empty() && line.len() + 1 + t.len() > budget {
self.numeric(uid, RPL_NAMREPLY, &format!("{vis} {} :{line}", ch.name));
line.clear();
}
if !line.is_empty() {
line.push(' ');
}
line.push_str(t);
}
if !line.is_empty() {
self.numeric(uid, RPL_NAMREPLY, &format!("{vis} {} :{line}", ch.name));
}
self.numeric( self.numeric(
uid, uid,
RPL_ENDOFNAMES, RPL_ENDOFNAMES,