Skip to content

Commit

Permalink
run spamfilters against NICK
Browse files Browse the repository at this point in the history
  • Loading branch information
jesopo committed Apr 15, 2022
1 parent 48a06ae commit 3c68c0c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
25 changes: 25 additions & 0 deletions extensions/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ static const char filter_desc[] = "Filter messages using a precompiled Hyperscan
static void filter_msg_user(void *data);
static void filter_msg_channel(void *data);
static void filter_client_quit(void *data);
static void filter_client_nick(void *data);
static void on_client_exit(void *data);

static void mo_setfilter(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
Expand Down Expand Up @@ -93,6 +94,7 @@ mapi_hfn_list_av1 filter_hfnlist[] = {
{ "privmsg_user", filter_msg_user },
{ "privmsg_channel", filter_msg_channel },
{ "client_quit", filter_client_quit },
{ "local_nick_change", filter_client_nick },
{ "client_exit", on_client_exit },
{ NULL, NULL }
};
Expand Down Expand Up @@ -483,6 +485,29 @@ filter_client_quit(void *data_)
/* No point in doing anything with ACT_KILL */
}

void
filter_client_nick(void *data_)
{
hook_cdata *data = data_;
struct Client *s = data->client;
if (IsOper(s)) {
return;
}

unsigned r = match_message("0", s, "NICK", NULL, data->arg2);
if (r & ACT_DROP) {
data->arg2 = NULL;
}
if (r & ACT_ALARM) {
sendto_realops_snomask(SNO_GENERAL, L_ALL | L_NETWIDE,
"FILTER: %s!%s@%s [%s]",
s->name, s->username, s->host, s->sockhost);
}
if (r & ACT_KILL) {
exit_client(NULL, s, s, FILTER_EXIT_MSG);
}
}

void
on_client_exit(void *data_)
{
Expand Down
6 changes: 6 additions & 0 deletions modules/core/m_nick.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,12 @@ change_local_nick(struct Client *client_p, struct Client *source_p,
hook_info.arg2 = nick;
call_hook(h_local_nick_change, &hook_info);

if (!hook_info.arg2) {
sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME),
me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick);
return;
}

sendto_realops_snomask(SNO_NCHANGE, L_ALL,
"Nick change: From %s to %s [%s@%s]",
source_p->name, nick, source_p->username, source_p->host);
Expand Down

0 comments on commit 3c68c0c

Please sign in to comment.