protocol: learn channel-mode arity + prefix modes (incl custom Y/ojoin) from CAPAB CHANMODES; services MODE uses the authoritative set
This commit is contained in:
parent
d313ca3523
commit
e6f05a3ede
9 changed files with 163 additions and 26 deletions
|
|
@ -82,7 +82,7 @@ impl Service for OperServ {
|
|||
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("MODE") => mode::handle(me, from, args, ctx, net, db),
|
||||
Some(cmd) if cmd.eq_ignore_ascii_case("IGNORE") => ignore::handle(me, from, args, ctx, db),
|
||||
Some(cmd) if cmd.eq_ignore_ascii_case("STATS") => stats::handle(me, from, db, ctx),
|
||||
Some(cmd) if cmd.eq_ignore_ascii_case("SVSNICK") => svs::nick(me, from, args, ctx, net),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use echo_api::{chanmode_takes_param, NetView, Priv, Sender, ServiceCtx, STATUS_MODES};
|
||||
use echo_api::{NetView, Priv, Sender, ServiceCtx, Store};
|
||||
|
||||
// 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) {
|
||||
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, net: &dyn NetView, db: &dyn Store) {
|
||||
if !from.privs.has(Priv::Admin) {
|
||||
ctx.notice(me, from.uid, "Access denied — MODE needs the \x02admin\x02 privilege.");
|
||||
return;
|
||||
|
|
@ -19,17 +19,19 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, net:
|
|||
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.
|
||||
// and a status mode's param is a nick we translate to its uid. Both arity and
|
||||
// the prefix set come from the ircd's advertised CHANMODES (incl custom modes).
|
||||
let status_modes = db.status_modes();
|
||||
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 db.chanmode_takes_param(m, adding) => {
|
||||
if let Some(&p) = params.get(pi) {
|
||||
pi += 1;
|
||||
if STATUS_MODES.contains(m) {
|
||||
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());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue