Send LUSERS output upon registration

This commit is contained in:
Přemysl Eric Janouch 2014-07-17 23:16:49 +02:00
parent 081b9f6bd2
commit 057a01e2e5

View File

@ -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);