aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2014-07-17 23:16:49 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2014-07-17 23:48:38 +0200
commit057a01e2e5ec4cb3721e16999af9b50df27b5429 (patch)
treee7eceae3ef7eec8e91230d779c6b3ff675e95ffa /src
parent081b9f6bd20dc19edbed491c4e8d8cb24de0559d (diff)
downloadxK-057a01e2e5ec4cb3721e16999af9b50df27b5429.tar.gz
xK-057a01e2e5ec4cb3721e16999af9b50df27b5429.tar.xz
xK-057a01e2e5ec4cb3721e16999af9b50df27b5429.zip
Send LUSERS output upon registration
Diffstat (limited to 'src')
-rw-r--r--src/kike.c46
1 files changed, 45 insertions, 1 deletions
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);