OPERMOTD, self-service VHOST, and command aliases (config-driven)

This commit is contained in:
Jean Chevronnet 2026-08-09 01:19:24 +00:00
parent 6be8e5ebcb
commit f4c01e1bf8
6 changed files with 138 additions and 0 deletions

View file

@ -52,9 +52,47 @@ pub fn commands() -> Vec<Box<dyn Command>> {
Box::new(SetIdle),
Box::new(NickLock),
Box::new(NickUnlock),
Box::new(OperMotd),
]
}
/// OPERMOTD — show the IRC-operators' message of the day (InspIRCd `m_opermotd`),
/// configured with repeated `opermotd = <line>` entries.
struct OperMotd;
impl Command for OperMotd {
fn name(&self) -> &'static str {
"OPERMOTD"
}
fn handle(&self, s: &mut Server, uid: Uid, _params: &[String]) -> CmdResult {
if !require_oper(s, uid) {
return CmdResult::Fail;
}
let nick = oper_nick(s, uid);
if s.opermotd.is_empty() {
s.send(
uid,
format!(":{} NOTICE {nick} :No OPERMOTD is set", s.name),
);
return CmdResult::Ok;
}
s.send(
uid,
format!(
":{} NOTICE {nick} :- IRC Operators Message of the Day -",
s.name
),
);
for line in s.opermotd.clone() {
s.send(uid, format!(":{} NOTICE {nick} :- {line}", s.name));
}
s.send(
uid,
format!(":{} NOTICE {nick} :- End of OPERMOTD -", s.name),
);
CmdResult::Ok
}
}
/// An oper-set WHOIS line, stored per-user in `User.ext` and rendered by WHOIS
/// (RPL_WHOISSPECIAL 320). InspIRCd `m_swhois`.
pub struct Swhois(pub String);

View file

@ -22,9 +22,52 @@ pub fn commands() -> Vec<Box<dyn Command>> {
Box::new(Away),
Box::new(SetName),
Box::new(WebIrc),
Box::new(Vhost),
]
}
/// VHOST — claim a self-service virtual host with `VHOST <user> <pass>` matching a
/// configured `vhost = <user> <pass> <host>` block (InspIRCd `m_vhost`).
struct Vhost;
impl Command for Vhost {
fn name(&self) -> &'static str {
"VHOST"
}
fn min_params(&self) -> usize {
2
}
fn handle(&self, s: &mut Server, uid: Uid, params: &[String]) -> CmdResult {
let (user, pass) = (&params[0], &params[1]);
let host = s
.vhosts
.iter()
.find(|(u, p, _)| u == user && p == pass)
.map(|(_, _, h)| h.clone());
let nick = s
.users
.get(&uid)
.map(|u| u.nick.clone())
.unwrap_or_else(|| "*".to_string());
match host {
Some(h) => {
s.change_host_ident(uid, None, Some(&h));
s.send(
uid,
format!(":{} NOTICE {nick} :Your vhost is now {h}", s.name),
);
}
None => {
s.send(
uid,
format!(":{} NOTICE {nick} :Invalid vhost credentials", s.name),
);
return CmdResult::Fail;
}
}
CmdResult::Ok
}
}
/// WEBIRC — a trusted web gateway declares the real client's host + IP, so users
/// behind it don't all share the gateway's address. `WEBIRC <password> <gateway>
/// <hostname> <ip> [:flags]`; must precede registration and the password must