Add DiceServ: dice-roll and math-expression service

A stateless service for tabletop games over IRC. ROLL/CALC evaluate a dice
+ math expression (ROLL rounds to a whole number, CALC keeps decimals);
EXROLL/EXCALC also show each die. Supports NdM / dM / d% dice, + - * / ^ %,
parentheses, implicit multiplication, unary minus, pi/e, a set of functions
(sqrt, floor, sin, min, …), and N~expr to repeat a roll.

Modernises the C++ original: it ships its own Mersenne-Twister RNG in C
and parses via shunting-yard with a variadic-argument hack; this is a
typed AST from a small recursive-descent parser plus the rand crate —
shorter, and the dice/sides/total caps make abuse (999999d6) a clean error
instead of a hang. Opt-in (add "diceserv" to [modules].services).
This commit is contained in:
Jean Chevronnet 2026-07-14 03:46:34 +00:00
parent 3f8649414f
commit 1e8a5eab36
No known key found for this signature in database
6 changed files with 528 additions and 1 deletions

View file

@ -21,6 +21,7 @@ use fedserv_memoserv::MemoServ;
use fedserv_statserv::StatServ;
use fedserv_hostserv::HostServ;
use fedserv_operserv::OperServ;
use fedserv_diceserv::DiceServ;
use fedserv_example::ExampleServ;
use fedserv_inspircd::InspIrcd;
use fedserv_nickserv::NickServ;
@ -89,6 +90,11 @@ async fn main() -> Result<()> {
uid: format!("{}AAAAAH", cfg.server.sid),
}));
}
if enabled("diceserv") {
services.push(Box::new(DiceServ {
uid: format!("{}AAAAAI", cfg.server.sid),
}));
}
if enabled("example") {
services.push(Box::new(ExampleServ {
uid: format!("{}AAAAAC", cfg.server.sid),