From ad7d17d2d8bda0778c953727e893612ac7a3a3c2 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Tue, 5 Aug 2014 23:10:59 +0200
Subject: kike: implement the ISON command
---
src/kike.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
(limited to 'src')
diff --git a/src/kike.c b/src/kike.c
index 020e8c3..82b3385 100644
--- a/src/kike.c
+++ b/src/kike.c
@@ -808,6 +808,7 @@ enum
IRC_RPL_AWAY = 301,
IRC_RPL_USERHOST = 302,
+ IRC_RPL_ISON = 303,
IRC_RPL_UNAWAY = 305,
IRC_RPL_NOWAWAY = 306,
IRC_RPL_ENDOFWHO = 315,
@@ -876,6 +877,7 @@ static const char *g_default_replies[] =
[IRC_RPL_AWAY] = "%s :%s",
[IRC_RPL_USERHOST] = ":%s",
+ [IRC_RPL_ISON] = ":%s",
[IRC_RPL_UNAWAY] = ":You are no longer marked as being away",
[IRC_RPL_NOWAWAY] = ":You have been marked as being away",
[IRC_RPL_ENDOFWHO] = "%s :End of WHO list",
@@ -1837,6 +1839,26 @@ irc_handle_away (const struct irc_message *msg, struct client *c)
}
}
+static void
+irc_handle_ison (const struct irc_message *msg, struct client *c)
+{
+ if (msg->params.len < 1)
+ RETURN_WITH_REPLY (c, IRC_ERR_NEEDMOREPARAMS, msg->command);
+
+ struct str result;
+ str_init (&result);
+
+ const char *nick;
+ if (str_map_find (&c->ctx->users, (nick = msg->params.vector[0])))
+ str_append (&result, nick);
+ for (size_t i = 1; i < msg->params.len; i++)
+ if (str_map_find (&c->ctx->users, (nick = msg->params.vector[i])))
+ str_append_printf (&result, " %s", nick);
+
+ irc_send_reply (c, IRC_RPL_ISON, result.str);
+ str_free (&result);
+}
+
// -----------------------------------------------------------------------------
struct irc_command
@@ -1879,6 +1901,7 @@ irc_register_handlers (struct server_context *ctx)
{ "LIST", true, irc_handle_list },
{ "NAMES", true, irc_handle_names },
{ "WHO", true, irc_handle_who },
+ { "ISON", true, irc_handle_ison },
};
for (size_t i = 0; i < N_ELEMENTS (message_handlers); i++)
--
cgit v1.2.3-70-g09d2