kike: implement NOTICE

This commit is contained in:
Přemysl Eric Janouch 2014-08-05 01:04:21 +02:00
parent 17fdf0d4bf
commit c386592d70

View File

@ -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;
@ -1329,6 +1330,18 @@ irc_handle_privmsg (const struct irc_message *msg, struct client *c)
irc_send_reply (c, IRC_ERR_NOSUCHNICK, target);
}
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)
{
@ -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 },