From d3ab641be8c1d3e2f00fc2d7f84322ecb2cda16a Mon Sep 17 00:00:00 2001 From: Richard Robbins Date: Tue, 13 Oct 2020 22:12:26 -0700 Subject: [PATCH] add ircv3 CAP account-notify --- CHANGELOG | 2 ++ config.def.h | 3 ++- src/components/ircv3.h | 4 +++- src/handlers/irc_recv.c | 48 ++++++++++++++++++++++++++++++++----- src/handlers/irc_recv.gperf | 8 ++++--- 5 files changed, 54 insertions(+), 11 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 5d82efb3..6ed729c2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,8 @@ Summary of notable changes and features ## Unreleased (dev) +### Features + - add IRCv3 CAP account-notify ## [0.1.3] ### Features diff --git a/config.def.h b/config.def.h index b93d1513..6ff1dfef 100644 --- a/config.def.h +++ b/config.def.h @@ -16,12 +16,13 @@ #define DEFAULT_USERNAME "" #define DEFAULT_REALNAME "" -/* User count in channel before filtering JOIN/PART/QUIT messages +/* User count in channel before filtering message types * Integer * (0: no filtering) */ #define JOIN_THRESHOLD 0 #define PART_THRESHOLD 0 #define QUIT_THRESHOLD 0 +#define ACCOUNT_THRESHOLD 0 /* Message sent for PART and QUIT by default */ #define DEFAULT_QUIT_MESG "rirc v" VERSION diff --git a/src/components/ircv3.h b/src/components/ircv3.h index 346450e3..91e948dd 100644 --- a/src/components/ircv3.h +++ b/src/components/ircv3.h @@ -4,10 +4,12 @@ #define IRCV3_CAP_AUTO (1 << 0) #define IRCV3_CAP_NO_DEL (1 << 1) #define IRCV3_CAP_NO_REQ (1 << 2) + #define IRCV3_CAP_VERSION "302" #define IRCV3_CAPS_DEF \ - X("multi-prefix", multi_prefix, IRCV3_CAP_AUTO) + X("account-notify", account_notify, IRCV3_CAP_AUTO) \ + X("multi-prefix", multi_prefix, IRCV3_CAP_AUTO) /* Extended by testcases */ #ifndef IRCV3_CAPS_TEST diff --git a/src/handlers/irc_recv.c b/src/handlers/irc_recv.c index 89bde3c0..c892c035 100644 --- a/src/handlers/irc_recv.c +++ b/src/handlers/irc_recv.c @@ -24,6 +24,10 @@ #define QUIT_THRESHOLD 0 #endif +#ifndef ACCOUNT_THRESHOLD +#define ACCOUNT_THRESHOLD 0 +#endif + #define failf(S, ...) \ do { server_error((S), __VA_ARGS__); \ return 1; \ @@ -63,6 +67,7 @@ static int recv_mode_usermodes(struct irc_message*, const struct mode_cfg*, stru static const unsigned quit_threshold = QUIT_THRESHOLD; static const unsigned join_threshold = JOIN_THRESHOLD; static const unsigned part_threshold = PART_THRESHOLD; +static const unsigned account_threshold = ACCOUNT_THRESHOLD; static const irc_recv_f irc_numerics[] = { [1] = irc_001, /* RPL_WELCOME */ @@ -603,12 +608,6 @@ irc_recv_numeric(struct server *s, struct irc_message *m) failf(s, "Numeric type '%u' unknown", code); } -static int -recv_cap(struct server *s, struct irc_message *m) -{ - return ircv3_recv_CAP(s, m); -} - static int recv_error(struct server *s, struct irc_message *m) { @@ -1259,5 +1258,42 @@ recv_quit(struct server *s, struct irc_message *m) return 0; } +static int +recv_ircv3_cap(struct server *s, struct irc_message *m) +{ + return ircv3_recv_CAP(s, m); +} + +static int +recv_ircv3_account(struct server *s, struct irc_message *m) +{ + /* :nick!user@host ACCOUNT */ + + char *account; + struct channel *c = s->channel; + + if (!m->from) + failf(s, "ACCOUNT: sender's nick is null"); + + if (!irc_message_param(m, &account)) + failf(s, "ACCOUNT: account is null"); + + do { + if (!user_list_get(&(c->users), s->casemapping, m->from, 0)) + continue; + + if (account_threshold && account_threshold < c->users.count) + continue; + + if (!strcmp(account, "*")) + newlinef(c, 0, FROM_INFO, "%s has logged out", m->from); + else + newlinef(c, 0, FROM_INFO, "%s has logged in as %s", m->from, account); + + } while ((c = c->next) != s->channel); + + return 0; +} + #undef failf #undef sendf diff --git a/src/handlers/irc_recv.gperf b/src/handlers/irc_recv.gperf index 03b68c93..8cc6f218 100644 --- a/src/handlers/irc_recv.gperf +++ b/src/handlers/irc_recv.gperf @@ -2,7 +2,6 @@ #include #define RECV_HANDLERS \ - X(cap) \ X(error) \ X(invite) \ X(join) \ @@ -15,7 +14,9 @@ X(pong) \ X(privmsg) \ X(quit) \ - X(topic) + X(topic) \ + X(ircv3_cap) \ + X(ircv3_account) #define X(cmd) static int recv_##cmd(struct server*, struct irc_message*); RECV_HANDLERS @@ -41,7 +42,6 @@ struct recv_handler %define initializer-suffix ,(irc_recv_f)0 struct recv_handler; %% -CAP, recv_cap ERROR, recv_error INVITE, recv_invite JOIN, recv_join @@ -55,4 +55,6 @@ PONG, recv_pong PRIVMSG, recv_privmsg QUIT, recv_quit TOPIC, recv_topic +CAP, recv_ircv3_cap +ACCOUNT, recv_ircv3_account %%