summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2014-08-05 01:04:21 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2014-08-05 01:04:21 +0200
commitc386592d70836e4ba755520a75c7577ad7028912 (patch)
tree596ed02226f1804674393003e8d450e7b7678d1e
parent17fdf0d4bf3cd77b46ff71987407475c3f94ff54 (diff)
downloadxK-c386592d70836e4ba755520a75c7577ad7028912.tar.gz
xK-c386592d70836e4ba755520a75c7577ad7028912.tar.xz
xK-c386592d70836e4ba755520a75c7577ad7028912.zip
kike: implement NOTICE
-rw-r--r--src/kike.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/kike.c b/src/kike.c
index 8e2b00a..a6ca384 100644
--- a/src/kike.c
+++ b/src/kike.c
@@ -1287,7 +1287,8 @@ irc_handle_mode (const struct irc_message *msg, struct client *c)
}
static void
-irc_handle_privmsg (const struct irc_message *msg, struct client *c)
+irc_handle_user_message (const struct irc_message *msg, struct client *c,
+ const char *command, bool allow_away_reply)
{
if (msg->params.len < 1)
RETURN_WITH_REPLY (c, IRC_ERR_NORECIPIENT, msg->command);
@@ -1299,9 +1300,9 @@ irc_handle_privmsg (const struct irc_message *msg, struct client *c)
struct client *client = str_map_find (&c->ctx->users, target);
if (client)
{
- irc_send (client, ":%s!%s@%s PRIVMSG %s :%s",
- c->nickname, c->username, c->hostname, target, text);
- if (client->away_message)
+ irc_send (client, ":%s!%s@%s %s %s :%s",
+ c->nickname, c->username, c->hostname, command, target, text);
+ if (allow_away_reply && client->away_message)
irc_send_reply (c, IRC_RPL_AWAY, target, client->away_message);
return;
}
@@ -1319,8 +1320,8 @@ irc_handle_privmsg (const struct irc_message *msg, struct client *c)
&& !client_in_mask_list (c, &chan->exception_list))
RETURN_WITH_REPLY (c, IRC_ERR_CANNOTSENDTOCHAN, target);
- char *message = xstrdup_printf (":%s!%s@%s PRIVMSG %s :%s",
- c->nickname, c->username, c->hostname, target, text);
+ char *message = xstrdup_printf (":%s!%s@%s %s %s :%s",
+ c->nickname, c->username, c->hostname, command, target, text);
irc_channel_multicast (chan, message);
free (message);
return;
@@ -1330,6 +1331,18 @@ irc_handle_privmsg (const struct irc_message *msg, struct client *c)
}
static void
+irc_handle_privmsg (const struct irc_message *msg, struct client *c)
+{
+ irc_handle_user_message (msg, c, "PRIVMSG", true);
+}
+
+static void
+irc_handle_notice (const struct irc_message *msg, struct client *c)
+{
+ irc_handle_user_message (msg, c, "NOTICE", false);
+}
+
+static void
irc_send_rpl_list (struct client *c, const struct channel *chan)
{
int visible = 0;
@@ -1768,7 +1781,6 @@ irc_register_handlers (struct server_context *ctx)
{
// TODO: add an index for IRC_ERR_NOSUCHSERVER validation?
// TODO: add a minimal parameter count?
- // TODO: more commands, see RFC 2812 :!
static const struct irc_command message_handlers[] =
{
{ "PASS", false, irc_handle_pass },
@@ -1789,6 +1801,7 @@ irc_register_handlers (struct server_context *ctx)
{ "MODE", true, irc_handle_mode },
{ "PRIVMSG", true, irc_handle_privmsg },
+ { "NOTICE", true, irc_handle_notice },
{ "JOIN", true, irc_handle_join },
{ "PART", true, irc_handle_part },
{ "TOPIC", true, irc_handle_topic },