commit
4682079dd9
3 changed files with 61 additions and 10 deletions
|
@ -55,6 +55,7 @@ static const char filter_desc[] = "Filter messages using a precompiled Hyperscan
|
||||||
|
|
||||||
static void filter_msg_user(void *data);
|
static void filter_msg_user(void *data);
|
||||||
static void filter_msg_channel(void *data);
|
static void filter_msg_channel(void *data);
|
||||||
|
static void filter_client_quit(void *data);
|
||||||
static void on_client_exit(void *data);
|
static void on_client_exit(void *data);
|
||||||
|
|
||||||
static void mo_setfilter(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
static void mo_setfilter(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
||||||
|
@ -91,6 +92,7 @@ static unsigned filter_chmode, filter_umode;
|
||||||
mapi_hfn_list_av1 filter_hfnlist[] = {
|
mapi_hfn_list_av1 filter_hfnlist[] = {
|
||||||
{ "privmsg_user", (hookfn) filter_msg_user },
|
{ "privmsg_user", (hookfn) filter_msg_user },
|
||||||
{ "privmsg_channel", (hookfn) filter_msg_channel },
|
{ "privmsg_channel", (hookfn) filter_msg_channel },
|
||||||
|
{ "client_quit", (hookfn) filter_client_quit },
|
||||||
{ "client_exit", (hookfn) on_client_exit },
|
{ "client_exit", (hookfn) on_client_exit },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
@ -346,7 +348,7 @@ unsigned match_message(const char *prefix,
|
||||||
return 0;
|
return 0;
|
||||||
if (!command)
|
if (!command)
|
||||||
return 0;
|
return 0;
|
||||||
snprintf(check_buffer, sizeof check_buffer, "%s:%s!%s@%s#%c %s %s :%s",
|
snprintf(check_buffer, sizeof check_buffer, "%s:%s!%s@%s#%c %s%s%s :%s",
|
||||||
prefix,
|
prefix,
|
||||||
#if FILTER_NICK
|
#if FILTER_NICK
|
||||||
source->name,
|
source->name,
|
||||||
|
@ -364,7 +366,10 @@ unsigned match_message(const char *prefix,
|
||||||
"*",
|
"*",
|
||||||
#endif
|
#endif
|
||||||
source->user && source->user->suser[0] != '\0' ? '1' : '0',
|
source->user && source->user->suser[0] != '\0' ? '1' : '0',
|
||||||
command, target, msg);
|
command,
|
||||||
|
target ? " " : "",
|
||||||
|
target ? target : "",
|
||||||
|
msg);
|
||||||
hs_error_t r = hs_scan(filter_db, check_buffer, strlen(check_buffer), 0, filter_scratch, match_callback, &state);
|
hs_error_t r = hs_scan(filter_db, check_buffer, strlen(check_buffer), 0, filter_scratch, match_callback, &state);
|
||||||
if (r != HS_SUCCESS && r != HS_SCAN_TERMINATED)
|
if (r != HS_SUCCESS && r != HS_SCAN_TERMINATED)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -454,6 +459,30 @@ filter_msg_channel(void *data_)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
filter_client_quit(void *data_)
|
||||||
|
{
|
||||||
|
hook_data_client_quit *data = data_;
|
||||||
|
struct Client *s = data->client;
|
||||||
|
if (IsOper(s)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
char *text = strcpy(clean_buffer, data->orig_reason);
|
||||||
|
strip_colour(text);
|
||||||
|
strip_unprintable(text);
|
||||||
|
unsigned r = match_message("0", s, "QUIT", NULL, data->orig_reason) |
|
||||||
|
match_message("1", s, "QUIT", NULL, text);
|
||||||
|
if (r & ACT_DROP) {
|
||||||
|
data->reason = 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);
|
||||||
|
}
|
||||||
|
/* No point in doing anything with ACT_KILL */
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
on_client_exit(void *data_)
|
on_client_exit(void *data_)
|
||||||
{
|
{
|
||||||
|
|
|
@ -124,6 +124,13 @@ typedef struct
|
||||||
const char *comment;
|
const char *comment;
|
||||||
} hook_data_client_exit;
|
} hook_data_client_exit;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
struct Client *client;
|
||||||
|
const char *reason;
|
||||||
|
const char *orig_reason;
|
||||||
|
} hook_data_client_quit;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
struct Client *client;
|
struct Client *client;
|
||||||
|
|
|
@ -39,6 +39,8 @@ static const char quit_desc[] = "Provides the QUIT command to allow a user to le
|
||||||
static void m_quit(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
static void m_quit(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
||||||
static void ms_quit(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
static void ms_quit(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
||||||
|
|
||||||
|
static int h_client_quit;
|
||||||
|
|
||||||
struct Message quit_msgtab = {
|
struct Message quit_msgtab = {
|
||||||
"QUIT", 0, 0, 0, 0,
|
"QUIT", 0, 0, 0, 0,
|
||||||
{{m_quit, 0}, {m_quit, 0}, {ms_quit, 0}, mg_ignore, mg_ignore, {m_quit, 0}}
|
{{m_quit, 0}, {m_quit, 0}, {ms_quit, 0}, mg_ignore, mg_ignore, {m_quit, 0}}
|
||||||
|
@ -46,7 +48,12 @@ struct Message quit_msgtab = {
|
||||||
|
|
||||||
mapi_clist_av1 quit_clist[] = { &quit_msgtab, NULL };
|
mapi_clist_av1 quit_clist[] = { &quit_msgtab, NULL };
|
||||||
|
|
||||||
DECLARE_MODULE_AV2(quit, NULL, NULL, quit_clist, NULL, NULL, NULL, NULL, quit_desc);
|
mapi_hlist_av1 quit_hlist[] = {
|
||||||
|
{ "client_quit", &h_client_quit },
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
DECLARE_MODULE_AV2(quit, NULL, NULL, quit_clist, quit_hlist, NULL, NULL, NULL, quit_desc);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** m_quit
|
** m_quit
|
||||||
|
@ -55,25 +62,33 @@ DECLARE_MODULE_AV2(quit, NULL, NULL, quit_clist, NULL, NULL, NULL, NULL, quit_de
|
||||||
static void
|
static void
|
||||||
m_quit(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
m_quit(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
||||||
{
|
{
|
||||||
char *comment = LOCAL_COPY((parc > 1 && parv[1]) ? parv[1] : client_p->name);
|
char *comment_copy = LOCAL_COPY((parc > 1 && parv[1]) ? parv[1] : client_p->name);
|
||||||
|
const char *comment = comment_copy;
|
||||||
char reason[REASONLEN + 1];
|
char reason[REASONLEN + 1];
|
||||||
|
hook_data_client_quit hdata;
|
||||||
|
|
||||||
source_p->flags |= FLAGS_NORMALEX;
|
source_p->flags |= FLAGS_NORMALEX;
|
||||||
|
|
||||||
if(strlen(comment) > (size_t) REASONLEN)
|
if (strlen(comment_copy) > (size_t) REASONLEN)
|
||||||
comment[REASONLEN] = '\0';
|
comment_copy[REASONLEN] = '\0';
|
||||||
|
|
||||||
strip_colour(comment);
|
strip_colour(comment_copy);
|
||||||
|
|
||||||
if(ConfigFileEntry.client_exit && comment[0])
|
hdata.client = client_p;
|
||||||
|
hdata.reason = hdata.orig_reason = comment;
|
||||||
|
call_hook(h_client_quit, &hdata);
|
||||||
|
comment = hdata.reason;
|
||||||
|
|
||||||
|
/* don't add Quit: if the reason comes from a module */
|
||||||
|
if (ConfigFileEntry.client_exit && hdata.reason == hdata.orig_reason && comment[0])
|
||||||
{
|
{
|
||||||
snprintf(reason, sizeof(reason), "Quit: %s", comment);
|
snprintf(reason, sizeof(reason), "Quit: %s", comment);
|
||||||
comment = reason;
|
comment = reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!IsOper(source_p) &&
|
if (comment == NULL || (!IsOper(source_p) && hdata.reason == hdata.orig_reason &&
|
||||||
(source_p->localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time) >
|
(source_p->localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time) >
|
||||||
rb_current_time())
|
rb_current_time()))
|
||||||
{
|
{
|
||||||
exit_client(client_p, source_p, source_p, "Client Quit");
|
exit_client(client_p, source_p, source_p, "Client Quit");
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue