echo/modules/hostserv/src/default.rs
Jean 993f5b2eea
Rename the project to Echo (was fedserv)
Rebrand the daemon and workspace: the binary is now `echo`, every crate
is `echo-*` (`echo-api` and the module crates), Rust imports use
`echo_*`, the gRPC proto is `proto/echo.proto` with package `echo.v1`,
and the log filter, gossip peer-name default, and on-disk store default
(`echo.db.jsonl`) follow. Docs updated throughout. No behaviour change;
crate directories and the config schema are untouched.
2026-07-14 15:24:41 +00:00

35 lines
1.5 KiB
Rust

use echo_api::{Sender, ServiceCtx, Store};
// DEFAULT: give yourself the auto-vhost from the network template, with your
// account name substituted for $account.
pub fn handle(me: &str, from: &Sender, ctx: &mut ServiceCtx, db: &mut dyn Store) {
let Some(account) = from.account else {
ctx.notice(me, from.uid, "You need to identify to NickServ first.");
return;
};
let Some(template) = db.vhost_template() else {
ctx.notice(me, from.uid, "This network has no auto-vhost template.");
return;
};
// Sanitise the account into a host-safe label (lowercase, alphanumerics only).
let label: String = account.to_ascii_lowercase().chars().filter(|c| c.is_ascii_alphanumeric()).collect();
if label.is_empty() {
ctx.notice(me, from.uid, "Your account name has no usable characters for a vhost.");
return;
}
let generated = template.replace("$account", &label);
let host = match super::prepare_vhost(&generated, account, db) {
Ok(h) if !db.vhost_is_forbidden(&h) => h,
_ => {
ctx.notice(me, from.uid, "Sorry, a vhost couldn't be generated for your account.");
return;
}
};
match db.set_vhost(account, &host, "template", None) {
Ok(()) => {
ctx.apply_vhost(from.uid, &host);
ctx.notice(me, from.uid, format!("You now have the vhost \x02{host}\x02."));
}
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
}
}