OperServ: SHUN and CHANKILL
- SHUN <user@host> silences a matching user network-wide without
disconnecting them — another kind ("SHUN") in the generalized X-line
handler (m_shun is loaded), same event-sourced list and lazy expiry as
AKILL/SQLINE/SNLINE.
- CHANKILL <#channel> [reason] AKILLs every distinct member host in one
shot to clear a spam or attack channel; the G-lines the ircd applies
also kill the sessions. Deduped by host, and never bans the operator who
ran it. Both admin-only.
This commit is contained in:
parent
1daebc94a5
commit
1f7591778f
4 changed files with 93 additions and 1 deletions
38
operserv/src/chankill.rs
Normal file
38
operserv/src/chankill.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use fedserv_api::{NetView, Priv, Sender, ServiceCtx, Store};
|
||||
use std::collections::HashSet;
|
||||
|
||||
// CHANKILL <#channel> [reason]: AKILL every user in a channel by host, clearing
|
||||
// a spam or attack channel in one shot. The G-lines the ircd applies also kill
|
||||
// the matching sessions. Admin-only, and never bans the operator running it.
|
||||
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, net: &dyn NetView, db: &mut dyn Store) {
|
||||
if !from.privs.has(Priv::Admin) {
|
||||
ctx.notice(me, from.uid, "Access denied — CHANKILL needs the \x02admin\x02 privilege.");
|
||||
return;
|
||||
}
|
||||
let Some(&chan) = args.get(1).filter(|c| c.starts_with('#') || c.starts_with('&')) else {
|
||||
ctx.notice(me, from.uid, "Syntax: CHANKILL <#channel> [reason]");
|
||||
return;
|
||||
};
|
||||
let members = net.channel_members(chan);
|
||||
if members.is_empty() {
|
||||
ctx.notice(me, from.uid, format!("No one is in \x02{chan}\x02 (or it isn't tracked)."));
|
||||
return;
|
||||
}
|
||||
let reason = if args.len() > 2 { args[2..].join(" ") } else { "Channel cleared by services".to_string() };
|
||||
let setter = from.account.unwrap_or(from.nick);
|
||||
let mut seen: HashSet<String> = HashSet::new();
|
||||
let mut banned = 0;
|
||||
for uid in &members {
|
||||
if uid.as_str() == from.uid {
|
||||
continue; // never ban yourself
|
||||
}
|
||||
let Some(host) = net.host_of(uid) else { continue };
|
||||
if seen.insert(host.to_string()) {
|
||||
let mask = format!("*@{host}");
|
||||
let _ = db.akill_add("G", &mask, setter, &reason, None);
|
||||
ctx.add_line("G", &mask, from.nick, 0, &reason);
|
||||
banned += 1;
|
||||
}
|
||||
}
|
||||
ctx.notice(me, from.uid, format!("CHANKILL on \x02{chan}\x02: \x02{banned}\x02 host(s) AKILL'd."));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue