add oper SQUIT command to disconnect a linked server by name
This commit is contained in:
parent
d4a7043d10
commit
559a102e48
1 changed files with 31 additions and 0 deletions
|
|
@ -37,6 +37,7 @@ pub fn commands() -> Vec<Box<dyn Command>> {
|
||||||
Box::new(Cban),
|
Box::new(Cban),
|
||||||
Box::new(Rline),
|
Box::new(Rline),
|
||||||
Box::new(Connect),
|
Box::new(Connect),
|
||||||
|
Box::new(Squit),
|
||||||
Box::new(ChgHost),
|
Box::new(ChgHost),
|
||||||
Box::new(ChgIdent),
|
Box::new(ChgIdent),
|
||||||
Box::new(SetHost),
|
Box::new(SetHost),
|
||||||
|
|
@ -968,6 +969,36 @@ impl Command for Connect {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// SQUIT <server> — disconnect a linked server (and everything behind it).
|
||||||
|
struct Squit;
|
||||||
|
impl Command for Squit {
|
||||||
|
fn name(&self) -> &'static str {
|
||||||
|
"SQUIT"
|
||||||
|
}
|
||||||
|
fn min_params(&self) -> usize {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
fn handle(&self, s: &mut Server, uid: Uid, params: &[String]) -> CmdResult {
|
||||||
|
if !require_oper(s, uid) {
|
||||||
|
return CmdResult::Fail;
|
||||||
|
}
|
||||||
|
let name = ¶ms[0];
|
||||||
|
let Some(via) = s
|
||||||
|
.servers
|
||||||
|
.values()
|
||||||
|
.find(|sv| sv.name.eq_ignore_ascii_case(name))
|
||||||
|
.map(|sv| sv.via)
|
||||||
|
else {
|
||||||
|
s.numeric(uid, ERR_NOSUCHSERVER, &format!("{name} :No such server"));
|
||||||
|
return CmdResult::Fail;
|
||||||
|
};
|
||||||
|
let by = oper_nick(s, uid);
|
||||||
|
s.snotice_c('l', &format!("{by} used SQUIT on {name}"));
|
||||||
|
s.close_link(via, &format!("SQUIT from {by}"));
|
||||||
|
CmdResult::Ok
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Resolve a nick to a uid, sending ERR_NOSUCHNICK if it's unknown.
|
/// Resolve a nick to a uid, sending ERR_NOSUCHNICK if it's unknown.
|
||||||
fn oper_target(s: &mut Server, uid: Uid, nick: &str) -> Option<Uid> {
|
fn oper_target(s: &mut Server, uid: Uid, nick: &str) -> Option<Uid> {
|
||||||
match s.find_nick(nick) {
|
match s.find_nick(nick) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue