From 057a01e2e5ec4cb3721e16999af9b50df27b5429 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Thu, 17 Jul 2014 23:16:49 +0200
Subject: Send LUSERS output upon registration
---
src/kike.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 45 insertions(+), 1 deletion(-)
diff --git a/src/kike.c b/src/kike.c
index 07ebccd..3d3817a 100644
--- a/src/kike.c
+++ b/src/kike.c
@@ -508,6 +508,12 @@ enum
IRC_RPL_CREATED = 3,
IRC_RPL_MYINFO = 4,
+ IRC_RPL_LUSERCLIENT = 251,
+ IRC_RPL_LUSEROP = 252,
+ IRC_RPL_LUSERUNKNOWN = 253,
+ IRC_RPL_LUSERCHANNELS = 254,
+ IRC_RPL_LUSERME = 255,
+
IRC_RPL_MOTD = 372,
IRC_RPL_MOTDSTART = 375,
IRC_RPL_ENDOFMOTD = 376,
@@ -530,6 +536,12 @@ static const char *g_default_replies[] =
[IRC_RPL_CREATED] = ":This server was created %s",
[IRC_RPL_MYINFO] = "%s %s %s %s",
+ [IRC_RPL_LUSERCLIENT] = ":There are %d users and %d services on %d servers",
+ [IRC_RPL_LUSEROP] = "%d :operator(s) online",
+ [IRC_RPL_LUSERUNKNOWN] = "%d :unknown connection(s)",
+ [IRC_RPL_LUSERCHANNELS] = "%d :channels formed",
+ [IRC_RPL_LUSERME] = ":I have %d clients and %d servers",
+
[IRC_RPL_MOTD] = ":- %s",
[IRC_RPL_MOTDSTART] = ":- %s Message of the day - ",
[IRC_RPL_ENDOFMOTD] = ":End of MOTD command",
@@ -581,6 +593,38 @@ irc_send_motd (struct client *c)
}
static void
+irc_send_lusers (struct client *c)
+{
+ int n_users = 0, n_services = 0, n_opers = 0, n_unknown = 0;
+ for (struct client *link = c->ctx->clients; link; link = link->next)
+ {
+ if (link->registered)
+ n_users++;
+ else
+ n_unknown++;
+ if (link->mode & IRC_USER_MODE_OPERATOR)
+ n_opers++;
+ }
+
+ int n_channels = 0;
+ struct str_map_iter iter;
+ str_map_iter_init (&iter, &c->ctx->channels);
+ while (str_map_iter_next (&iter))
+ n_channels++;
+
+ irc_send_reply (c, IRC_RPL_LUSERCLIENT,
+ n_users, n_services, 1 /* servers total */);
+ if (n_opers)
+ irc_send_reply (c, IRC_RPL_LUSEROP, n_opers);
+ if (n_unknown)
+ irc_send_reply (c, IRC_RPL_LUSERUNKNOWN, n_unknown);
+ if (n_channels)
+ irc_send_reply (c, IRC_RPL_LUSERCHANNELS, n_channels);
+ irc_send_reply (c, IRC_RPL_LUSERME,
+ n_users + n_services + n_unknown, 0 /* peer servers */);
+}
+
+static bool
irc_try_finish_registration (struct client *c)
{
struct server_context *ctx = c->ctx;
@@ -596,7 +640,7 @@ irc_try_finish_registration (struct client *c)
irc_send_reply (c, IRC_RPL_MYINFO, ctx->server_name, PROGRAM_VERSION,
IRC_SUPPORTED_USER_MODES, IRC_SUPPORTED_CHAN_MODES);
- // Although not strictly required, bots often need this to work
+ irc_send_lusers (c);
irc_send_motd (c);
char *mode = client_get_mode (c);
--
cgit v1.2.3-70-g09d2