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:
parent
930198b826
commit
c5d93f29c1
6 changed files with 147 additions and 11 deletions
26
operserv/src/kick.rs
Normal file
26
operserv/src/kick.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
use fedserv_api::{NetView, Priv, Sender, ServiceCtx};
|
||||
|
||||
// KICK <#channel> <nick> [reason]: remove a user from a channel, sourced from
|
||||
// OperServ so it's clearly a staff action. Admin-only.
|
||||
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 — KICK 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: KICK <#channel> <nick> [reason]");
|
||||
return;
|
||||
};
|
||||
let Some(&target) = args.get(2) else {
|
||||
ctx.notice(me, from.uid, "Syntax: KICK <#channel> <nick> [reason]");
|
||||
return;
|
||||
};
|
||||
let Some(uid) = net.uid_by_nick(target).map(str::to_string) else {
|
||||
ctx.notice(me, from.uid, format!("There's no \x02{target}\x02 online."));
|
||||
return;
|
||||
};
|
||||
let by = from.account.unwrap_or(from.nick);
|
||||
let reason = if args.len() > 3 { args[3..].join(" ") } else { "Removed by services".to_string() };
|
||||
ctx.kick(me, chan, &uid, &format!("({by}) {reason}"));
|
||||
ctx.notice(me, from.uid, format!("\x02{target}\x02 kicked from \x02{chan}\x02."));
|
||||
}
|
||||
|
|
@ -11,6 +11,10 @@ mod xline;
|
|||
mod global;
|
||||
#[path = "kill.rs"]
|
||||
mod kill;
|
||||
#[path = "kick.rs"]
|
||||
mod kick;
|
||||
#[path = "mode.rs"]
|
||||
mod mode;
|
||||
|
||||
pub struct OperServ {
|
||||
pub uid: String,
|
||||
|
|
@ -39,6 +43,8 @@ impl Service for OperServ {
|
|||
Some(cmd) if cmd.eq_ignore_ascii_case("SQLINE") => xline::SQLINE.handle(me, from, args, ctx, db),
|
||||
Some(cmd) if cmd.eq_ignore_ascii_case("GLOBAL") => global::handle(me, from, args, ctx),
|
||||
Some(cmd) if cmd.eq_ignore_ascii_case("KILL") => kill::handle(me, from, args, ctx, net),
|
||||
Some(cmd) if cmd.eq_ignore_ascii_case("KICK") => kick::handle(me, from, args, ctx, net),
|
||||
Some(cmd) if cmd.eq_ignore_ascii_case("MODE") => mode::handle(me, from, args, ctx, net),
|
||||
Some(cmd) if cmd.eq_ignore_ascii_case("HELP") => help(me, from, ctx),
|
||||
None => help(me, from, ctx),
|
||||
Some(other) => ctx.notice(me, from.uid, format!("I don't know \x02{other}\x02. Try \x02HELP\x02.")),
|
||||
|
|
@ -47,5 +53,5 @@ impl Service for OperServ {
|
|||
}
|
||||
|
||||
fn help(me: &str, from: &Sender, ctx: &mut ServiceCtx) {
|
||||
ctx.notice(me, from.uid, "OperServ holds network operator tools (Priv::Admin): \x02AKILL\x02 ADD|DEL|LIST (user@host bans), \x02SQLINE\x02 ADD|DEL|LIST (nick bans), \x02GLOBAL\x02 <message> (announce to everyone), \x02KILL\x02 <nick> [reason] (disconnect a user).");
|
||||
ctx.notice(me, from.uid, "OperServ holds network operator tools (Priv::Admin): \x02AKILL\x02 ADD|DEL|LIST (user@host bans), \x02SQLINE\x02 ADD|DEL|LIST (nick bans), \x02GLOBAL\x02 <message> (announce to everyone), \x02KILL\x02 <nick> [reason] (disconnect a user), \x02KICK\x02 <#chan> <nick> [reason], \x02MODE\x02 <#chan> <modes> [params].");
|
||||
}
|
||||
|
|
|
|||
45
operserv/src/mode.rs
Normal file
45
operserv/src/mode.rs
Normal 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."));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue