OperServ: MODE override and KICK

Two channel operator tools:

- MODE <#chan> <modes> [params] forces a channel mode change (TS 1, so it
  applies regardless of the current TS). A status-mode target may be given
  as a nick — it's resolved to the uid the ircd's FMODE expects.
- KICK <#chan> <nick> [reason] removes a user, sourced from OperServ and
  attributed to the operator.

Both admin-gated. To resolve status-mode params, channel-mode parameter
arity became one shared helper (chanmode_takes_param + STATUS_MODES in the
api): the ircd module now delegates to it instead of keeping its own copy,
so burst-parsing and MODE-building can never drift.
This commit is contained in:
Jean Chevronnet 2026-07-14 00:54:29 +00:00
parent 930198b826
commit c5d93f29c1
No known key found for this signature in database
6 changed files with 147 additions and 11 deletions

45
operserv/src/mode.rs Normal file
View file

@ -0,0 +1,45 @@
use fedserv_api::{chanmode_takes_param, NetView, Priv, Sender, ServiceCtx, STATUS_MODES};
// MODE <#channel> <modes> [params]: set channel modes as a services override
// (forced, so it applies regardless of the current TS). Admin-only. Status-mode
// targets may be given as nicks — they're resolved to uids for the ircd.
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, net: &dyn NetView) {
if !from.privs.has(Priv::Admin) {
ctx.notice(me, from.uid, "Access denied — MODE 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: MODE <#channel> <modes> [params]");
return;
};
let Some(&modes) = args.get(2) else {
ctx.notice(me, from.uid, "Syntax: MODE <#channel> <modes> [params]");
return;
};
let params = &args[3..];
// Walk the change alongside its params: each param-taking mode consumes one,
// and a status mode's param is a nick we translate to its uid.
let (mut adding, mut pi) = (true, 0);
let mut out_params: Vec<String> = Vec::new();
for m in modes.chars() {
match m {
'+' => adding = true,
'-' => adding = false,
_ if chanmode_takes_param(m, adding) => {
if let Some(&p) = params.get(pi) {
pi += 1;
if STATUS_MODES.contains(m) {
out_params.push(net.uid_by_nick(p).map(str::to_string).unwrap_or_else(|| p.to_string()));
} else {
out_params.push(p.to_string());
}
}
}
_ => {}
}
}
let full = if out_params.is_empty() { modes.to_string() } else { format!("{} {}", modes, out_params.join(" ")) };
ctx.channel_mode(me, chan, &full);
ctx.notice(me, from.uid, format!("Set \x02{modes}\x02 on \x02{chan}\x02."));
}