Group the module crates under modules/

The service pseudo-clients and the ircd protocol link sat flat at the
repo root, mixed in with the daemon core and the SDK. Move them all
under modules/ so the tree separates concerns cleanly: the daemon in
src/, the SDK every module links against in api/, and the loadable
modules — the pseudo-clients plus the protocol link — in modules/.

Workspace members, the daemon's per-crate dependency paths, and each
module's api path are updated to match; the docs follow. No code change.
This commit is contained in:
Jean Chevronnet 2026-07-14 14:19:43 +00:00
parent 6f76f9722c
commit ad2a623120
No known key found for this signature in database
116 changed files with 69 additions and 46 deletions

View file

@ -0,0 +1,8 @@
[package]
name = "fedserv-statserv"
version = "0.0.1"
edition = "2021"
description = "StatServ: surface the shared stats registry and per-channel activity."
[dependencies]
fedserv-api = { path = "../../api" }

View file

@ -0,0 +1,21 @@
use fedserv_api::{NetView, Sender, ServiceCtx, Store};
// <#channel>: the lines seen in a channel this session and its top talkers.
// Founder-or-admin.
pub fn handle(me: &str, from: &Sender, chan: &str, ctx: &mut ServiceCtx, net: &dyn NetView, db: &mut dyn Store) {
if !super::require_channel_admin(me, from, chan, ctx, db) {
return;
}
let Some((lines, top)) = net.channel_activity(chan) else {
ctx.notice(me, from.uid, format!("No activity recorded for \x02{chan}\x02 yet."));
return;
};
ctx.notice(me, from.uid, format!("\x02{chan}\x02\x02{lines}\x02 line(s) seen this session."));
if top.is_empty() {
return;
}
ctx.notice(me, from.uid, "Top talkers:");
for (i, (nick, count)) in top.iter().enumerate() {
ctx.notice(me, from.uid, format!(" {}. \x02{nick}\x02{count}", i + 1));
}
}

View file

@ -0,0 +1,21 @@
use fedserv_api::{NetView, Priv, Sender, ServiceCtx, Store};
// SERVER: the shared, cross-service counter registry plus a couple of live
// gauges. Operators only (Priv::Auspex), since it is network-wide.
pub fn handle(me: &str, from: &Sender, ctx: &mut ServiceCtx, net: &dyn NetView, db: &dyn Store) {
if !from.privs.has(Priv::Auspex) {
ctx.notice(me, from.uid, "Network statistics are for services operators.");
return;
}
ctx.notice(me, from.uid, "Network statistics:");
ctx.notice(me, from.uid, format!(" channels.total: {}", db.channels().len()));
ctx.notice(me, from.uid, format!(" bots.total: {}", db.bots().len()));
let counters = net.stat_counters();
if counters.is_empty() {
ctx.notice(me, from.uid, " (no activity counters yet)");
return;
}
for (key, value) in counters {
ctx.notice(me, from.uid, format!(" {key}: {value}"));
}
}

View file

@ -0,0 +1,56 @@
//! StatServ surfaces statistics: the shared, cross-service counter registry
//! (SERVER, operators only) and per-channel activity the bots have seen
//! (a #channel argument, for its founder). `lib.rs` holds the dispatcher; each
//! view lives in its own file.
use fedserv_api::{NetView, Priv, Sender, Service, ServiceCtx, Store};
#[path = "global.rs"]
mod global;
#[path = "channel.rs"]
mod channel;
pub struct StatServ {
pub uid: String,
}
impl Service for StatServ {
fn nick(&self) -> &str {
"StatServ"
}
fn uid(&self) -> &str {
&self.uid
}
fn gecos(&self) -> &str {
"Statistics Service"
}
fn on_command(&mut self, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, net: &dyn NetView, db: &mut dyn Store) {
let me = self.uid.as_str();
match args.first().copied() {
Some(chan) if chan.starts_with('#') => channel::handle(me, from, chan, ctx, net, db),
Some(cmd) if cmd.eq_ignore_ascii_case("SERVER") || cmd.eq_ignore_ascii_case("GLOBAL") => global::handle(me, from, ctx, net, db),
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 \x02SERVER\x02, a \x02#channel\x02, or \x02HELP\x02.")),
}
}
}
fn help(me: &str, from: &Sender, ctx: &mut ServiceCtx) {
ctx.notice(me, from.uid, "StatServ reports statistics: \x02SERVER\x02 for network-wide counters (operators), or \x02<#channel>\x02 for a channel's activity (its founder).");
}
// Shared gate: the sender may see a channel's stats only as its founder or a
// services admin.
fn require_channel_admin(me: &str, from: &Sender, chan: &str, ctx: &mut ServiceCtx, db: &dyn Store) -> bool {
let Some(founder) = db.channel(chan).map(|c| c.founder) else {
ctx.notice(me, from.uid, format!("\x02{chan}\x02 isn't registered."));
return false;
};
if from.account != Some(founder.as_str()) && !from.privs.has(Priv::Admin) {
ctx.notice(me, from.uid, format!("Only \x02{chan}\x02's founder can see its stats."));
return false;
}
true
}