From 97f35bedfd333dea7e46b535c8cf9093fecfad11 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Sat, 2 Aug 2014 22:58:18 +0200
Subject: kike: implement USERHOST
---
src/kike.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 47 insertions(+), 13 deletions(-)
(limited to 'src')
diff --git a/src/kike.c b/src/kike.c
index 73b6df1..b1f4f62 100644
--- a/src/kike.c
+++ b/src/kike.c
@@ -626,6 +626,7 @@ enum
IRC_RPL_LUSERCHANNELS = 254,
IRC_RPL_LUSERME = 255,
+ IRC_RPL_USERHOST = 302,
IRC_RPL_VERSION = 351,
IRC_RPL_MOTD = 372,
IRC_RPL_MOTDSTART = 375,
@@ -660,6 +661,7 @@ static const char *g_default_replies[] =
[IRC_RPL_LUSERCHANNELS] = "%d :channels formed",
[IRC_RPL_LUSERME] = ":I have %d clients and %d servers",
+ [IRC_RPL_USERHOST] = ":%s",
[IRC_RPL_VERSION] = "%s.%d %s :%s",
[IRC_RPL_MOTD] = ":- %s",
[IRC_RPL_MOTDSTART] = ":- %s Message of the day - ",
@@ -863,6 +865,37 @@ irc_handle_user (const struct irc_message *msg, struct client *c)
irc_try_finish_registration (c);
}
+static void
+irc_handle_userhost (const struct irc_message *msg, struct client *c)
+{
+ if (msg->params.len < 1)
+ {
+ irc_send_reply (c, IRC_ERR_NEEDMOREPARAMS, msg->command);
+ return;
+ }
+
+ struct str reply;
+ str_init (&reply);
+ for (size_t i = 0; i < 5 && i < msg->params.len; i++)
+ {
+ const char *nick = msg->params.vector[i];
+ struct client *target = str_map_find (&c->ctx->users, nick);
+ if (!target)
+ continue;
+
+ if (i)
+ str_append_c (&reply, ' ');
+ str_append (&reply, nick);
+ if (target->mode & IRC_USER_MODE_OPERATOR)
+ str_append_c (&reply, '*');
+ str_append_printf (&reply, "=%c%s@%s",
+ target->away_message ? '-' : '+',
+ target->username, target->hostname);
+ }
+ irc_send_reply (c, IRC_RPL_USERHOST, reply.str);
+ str_free (&reply);
+}
+
static void
irc_handle_lusers (const struct irc_message *msg, struct client *c)
{
@@ -981,19 +1014,20 @@ irc_register_handlers (struct server_context *ctx)
// TODO: more commands, see RFC 2812 :!
static const struct irc_command message_handlers[] =
{
- { "PASS", false, irc_handle_pass },
- { "NICK", false, irc_handle_nick },
- { "USER", false, irc_handle_user },
-
- { "LUSERS", true, irc_handle_lusers },
- { "MOTD", true, irc_handle_motd },
- { "PING", true, irc_handle_ping },
- { "PONG", false, irc_handle_pong },
- { "QUIT", false, irc_handle_quit },
- { "TIME", true, irc_handle_time },
- { "VERSION", true, irc_handle_version },
-
- { "PRIVMSG", true, irc_handle_privmsg },
+ { "PASS", false, irc_handle_pass },
+ { "NICK", false, irc_handle_nick },
+ { "USER", false, irc_handle_user },
+
+ { "USERHOST", true, irc_handle_userhost },
+ { "LUSERS", true, irc_handle_lusers },
+ { "MOTD", true, irc_handle_motd },
+ { "PING", true, irc_handle_ping },
+ { "PONG", false, irc_handle_pong },
+ { "QUIT", false, irc_handle_quit },
+ { "TIME", true, irc_handle_time },
+ { "VERSION", true, irc_handle_version },
+
+ { "PRIVMSG", true, irc_handle_privmsg },
};
for (size_t i = 0; i < N_ELEMENTS (message_handlers); i++)
--
cgit v1.2.3-70-g09d2