From dd17a2944585a33421f0d0f75ef5cf2d3e7bb046 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Sat, 13 Jun 2015 12:02:17 +0200 Subject: kike: implement CAP invite-notify --- kike.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/kike.c b/kike.c index 83aa659..824566a 100644 --- a/kike.c +++ b/kike.c @@ -296,6 +296,7 @@ enum enum { IRC_CAP_MULTI_PREFIX = (1 << 0), + IRC_CAP_INVITE_NOTIFY = (1 << 1) }; struct client @@ -1144,7 +1145,7 @@ irc_handle_cap_ls (struct client *c, struct irc_cap_args *a) a->subcommand, "Ignoring invalid protocol version number"); c->cap_negotiating = true; - client_send (c, "CAP %s LS :multi-prefix", a->target); + client_send (c, "CAP %s LS :multi-prefix invite-notify", a->target); } static void @@ -1155,6 +1156,8 @@ irc_handle_cap_list (struct client *c, struct irc_cap_args *a) if (c->caps_enabled & IRC_CAP_MULTI_PREFIX) str_vector_add (&caps, "multi-prefix"); + if (c->caps_enabled & IRC_CAP_INVITE_NOTIFY) + str_vector_add (&caps, "invite-notify"); char *caps_str = join_str_vector (&caps, ' '); str_vector_free (&caps); @@ -1167,6 +1170,8 @@ irc_decode_capability (const char *name) { if (!strcmp (name, "multi-prefix")) return IRC_CAP_MULTI_PREFIX; + if (!strcmp (name, "invite-notify")) + return IRC_CAP_INVITE_NOTIFY; return 0; } @@ -2481,6 +2486,17 @@ irc_handle_kick (const struct irc_message *msg, struct client *c) str_vector_free (&users); } +static void +irc_send_invite_notifications + (struct channel *chan, struct client *c, struct client *target) +{ + for (struct channel_user *iter = chan->users; iter; iter = iter->next) + if (iter->c != target && iter->c->caps_enabled & IRC_CAP_INVITE_NOTIFY) + client_send (iter->c, ":%s!%s@%s INVITE %s %s", + c->nickname, c->username, c->hostname, + target->nickname, chan->name); +} + static void irc_handle_invite (const struct irc_message *msg, struct client *c) { @@ -2507,6 +2523,10 @@ irc_handle_invite (const struct irc_message *msg, struct client *c) str_map_set (&client->invites, channel_name, (void *) 1); else if ((chan->modes & IRC_CHAN_MODE_INVITE_ONLY)) RETURN_WITH_REPLY (c, IRC_ERR_CHANOPRIVSNEEDED, channel_name); + + // It's not specified when and how we should send out invite-notify + if (chan->modes & IRC_CHAN_MODE_INVITE_ONLY) + irc_send_invite_notifications (chan, c, client); } client_send (client, ":%s!%s@%s INVITE %s %s", -- cgit v1.2.3-70-g09d2