aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2014-08-02 22:58:18 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2014-08-02 23:00:51 +0200
commit97f35bedfd333dea7e46b535c8cf9093fecfad11 (patch)
tree7c89766383386ddbce453cfaf07dd056ad384cfd
parent559bedad650796967f928e1d0b7fbdcf74a03f27 (diff)
downloadxK-97f35bedfd333dea7e46b535c8cf9093fecfad11.tar.gz
xK-97f35bedfd333dea7e46b535c8cf9093fecfad11.tar.xz
xK-97f35bedfd333dea7e46b535c8cf9093fecfad11.zip
kike: implement USERHOST
-rw-r--r--src/kike.c60
1 files changed, 47 insertions, 13 deletions
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 - ",
@@ -864,6 +866,37 @@ irc_handle_user (const struct irc_message *msg, struct client *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)
{
if (msg->params.len > 1 && !irc_is_this_me (c->ctx, msg->params.vector[1]))
@@ -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++)