Skip to content

Commit

Permalink
add ircv3 CAP account-notify
Browse files Browse the repository at this point in the history
  • Loading branch information
rcr committed Oct 14, 2020
1 parent 78453c9 commit d3ab641
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Summary of notable changes and features

## Unreleased (dev)
### Features
- add IRCv3 CAP account-notify

## [0.1.3]
### Features
Expand Down
3 changes: 2 additions & 1 deletion config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/components/ircv3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 42 additions & 6 deletions src/handlers/irc_recv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 <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
8 changes: 5 additions & 3 deletions src/handlers/irc_recv.gperf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <string.h>

#define RECV_HANDLERS \
X(cap) \
X(error) \
X(invite) \
X(join) \
Expand All @@ -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
Expand All @@ -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
Expand All @@ -55,4 +55,6 @@ PONG, recv_pong
PRIVMSG, recv_privmsg
QUIT, recv_quit
TOPIC, recv_topic
CAP, recv_ircv3_cap
ACCOUNT, recv_ircv3_account
%%

0 comments on commit d3ab641

Please sign in to comment.