From: Gunnar Beutner Date: Tue, 13 Aug 2013 01:28:37 +0000 (+0200) Subject: nickwatch: Implement hook for messages/notices. X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/commitdiff_plain/80e32fcd996025093c28b304d91d376b72c1496e?hp=474d3d6240df2349196a8982194d27421a127656 nickwatch: Implement hook for messages/notices. --- diff --git a/core/hooks.h b/core/hooks.h index de800e35..d362cf61 100644 --- a/core/hooks.h +++ b/core/hooks.h @@ -42,6 +42,7 @@ #define HOOK_NICK_KILL 308 /* Argument is void*[2] (nick, reason) */ #define HOOK_NICK_MASKPRIVMSG 309 /* Argument is void*[3] (nick, target, message) ** NICK COULD BE NULL ** */ #define HOOK_NICK_MODECHANGE 310 /* Argument is void*[2] (nick *, oldmodes) */ +#define HOOK_NICK_MESSAGE 311 /* Argument is void*[3] (nick *, message, isnotice) */ #define HOOK_CHANNEL_BURST 400 /* Argument is channel pointer */ #define HOOK_CHANNEL_CREATE 401 /* Argument is void*[2] (channel, nick) */ diff --git a/localuser/localuser.c b/localuser/localuser.c index c75e31ea..9e056b95 100644 --- a/localuser/localuser.c +++ b/localuser/localuser.c @@ -364,7 +364,7 @@ int handlemessageornotice(void *source, int cargc, char **cargv, int isnotice) { char *ch; char targetnick[NICKLEN+1]; int foundat; - void *nargs[2]; + void *nargs[3]; int i; /* Should have target and message */ @@ -372,15 +372,23 @@ int handlemessageornotice(void *source, int cargc, char **cargv, int isnotice) { return CMD_OK; } - if (cargv[0][0]=='#' || cargv[0][0]=='+') { - /* Channel message/notice */ - return CMD_OK; - } - if ((sender=getnickbynumericstr((char *)source))==NULL) { Error("localuser",ERR_WARNING,"PRIVMSG from non existant user %s",(char *)source); return CMD_OK; } + + freesstring(sender->message); + sender->message = getsstring(cargv[1], 512); + + nargs[0] = sender; + nargs[1] = cargv[1]; + nargs[2] = (void *)(uintptr_t)isnotice; + triggerhook(HOOK_NICK_MESSAGE, nargs); + + if (cargv[0][0]=='#' || cargv[0][0]=='+') { + /* Channel message/notice */ + return CMD_OK; + } /* Check for a "secure" message (foo@bar) */ foundat=0; diff --git a/newsearch/Makefile b/newsearch/Makefile index 58663674..f2c97bae 100644 --- a/newsearch/Makefile +++ b/newsearch/Makefile @@ -6,7 +6,7 @@ LDFLAGS+=$(LIBPCRE) .PHONY: all clean distclean all: newsearch.so -NSCOMMANDS=ns-not.o ns-and.o ns-or.o ns-eq.o ns-match.o ns-hostmask.o ns-realname.o ns-away.o ns-modes.o ns-nick.o ns-ident.o ns-regex.o ns-host.o ns-channel.o ns-lt.o ns-gt.o ns-timestamp.o ns-country.o ns-authname.o ns-ip.o ns-kill.o ns-gline.o ns-exists.o ns-services.o ns-size.o ns-name.o ns-topic.o ns-oppct.o ns-cumodecount.o ns-cumodepct.o ns-hostpct.o ns-authedpct.o ns-length.o ns-kick.o ns-authts.o ns-channels.o ns-server.o ns-authid.o ns-notice.o newsearch_ast.o ns-any.o ns-channeliter.o ns-var.o ns-all.o ns-cumodes.o ns-cidr.o ns-nickiter.o ns-ipv6.o ns-away.o ns-quit.o ns-killed.o ns-renamed.o ns-age.o ns-newnick.o ns-reason.o +NSCOMMANDS=ns-not.o ns-and.o ns-or.o ns-eq.o ns-match.o ns-hostmask.o ns-realname.o ns-away.o ns-modes.o ns-nick.o ns-ident.o ns-regex.o ns-host.o ns-channel.o ns-lt.o ns-gt.o ns-timestamp.o ns-country.o ns-authname.o ns-ip.o ns-kill.o ns-gline.o ns-exists.o ns-services.o ns-size.o ns-name.o ns-topic.o ns-oppct.o ns-cumodecount.o ns-cumodepct.o ns-hostpct.o ns-authedpct.o ns-length.o ns-kick.o ns-authts.o ns-channels.o ns-server.o ns-authid.o ns-notice.o newsearch_ast.o ns-any.o ns-channeliter.o ns-var.o ns-all.o ns-cumodes.o ns-cidr.o ns-nickiter.o ns-ipv6.o ns-away.o ns-quit.o ns-killed.o ns-renamed.o ns-age.o ns-newnick.o ns-reason.o ns-message.o newsearch.so: newsearch.o formats.o y.tab.o lex.yy.o parser.o ${NSCOMMANDS} diff --git a/newsearch/newsearch.c b/newsearch/newsearch.c index d8a9b87c..0b08bdfb 100644 --- a/newsearch/newsearch.c +++ b/newsearch/newsearch.c @@ -211,6 +211,7 @@ void _init() { registersearchterm(reg_whowassearch, "cidr",cidr_parse, 0, "CIDR matching"); registersearchterm(reg_nicksearch, "ipvsix",ipv6_parse, 0, "IPv6 user"); registersearchterm(reg_whowassearch, "ipvsix",ipv6_parse, 0, "IPv6 user"); + registersearchterm(reg_nicksearch, "message",message_parse, 0, "Last message"); /* Whowas operations */ registersearchterm(reg_whowassearch, "quit",quit_parse, 0, "User quit"); diff --git a/newsearch/newsearch.h b/newsearch/newsearch.h index 7e14e030..e8d66936 100644 --- a/newsearch/newsearch.h +++ b/newsearch/newsearch.h @@ -142,6 +142,7 @@ struct searchNode *server_parse(searchCtx *ctx, int argc, char **argv); struct searchNode *authid_parse(searchCtx *ctx, int argc, char **argv); struct searchNode *cidr_parse(searchCtx *ctx, int argc, char **argv); struct searchNode *ipv6_parse(searchCtx *ctx, int argc, char **argv); +struct searchNode *message_parse(searchCtx *ctx, int argc, char **argv); /* Whowas functions (various types) */ struct searchNode *quit_parse(searchCtx *ctx, int argc, char **argv); diff --git a/nick/nick.c b/nick/nick.c index b08e854a..1b7dcadf 100644 --- a/nick/nick.c +++ b/nick/nick.c @@ -218,6 +218,7 @@ void deletenick(nick *np) { freesstring(np->shident); /* freesstring(NULL) is OK */ freesstring(np->sethost); freesstring(np->opername); + freesstring(np->message); node_decrement_usercount(np->ipnode); derefnode(iptree, np->ipnode); diff --git a/nick/nick.h b/nick/nick.h index 2efadf30..d3bae4e2 100644 --- a/nick/nick.h +++ b/nick/nick.h @@ -164,6 +164,7 @@ typedef struct nick { struct nick *nextbyauthname; /* These are extensions only used by other modules */ array *channels; + sstring *message; void *exts[MAXNICKEXTS]; } nick; diff --git a/nickwatch/nickwatch.c b/nickwatch/nickwatch.c index beb9167a..d53bfb15 100644 --- a/nickwatch/nickwatch.c +++ b/nickwatch/nickwatch.c @@ -104,6 +104,14 @@ static void nw_hook_umodechange(int hooknum, void *arg) { scheduleoneshot(0, nw_sched_processevent, nwe); } +static void nw_hook_message(int hooknum, void *arg) { + void **args = arg; + nick *np = args[0]; + int isnotice = (uintptr_t)args[2]; + nickwatchevent *nwe = nwe_new(np, isnotice ? "notice" : "message"); + scheduleoneshot(0, nw_sched_processevent, nwe); +} + static void nw_hook_joinchannel(int hooknum, void *arg) { void **args = arg; channel *cp = args[0]; @@ -190,6 +198,7 @@ void _init(void) { registerhook(HOOK_NICK_NEWNICK, &nw_hook_newnick); registerhook(HOOK_NICK_RENAME, &nw_hook_rename); registerhook(HOOK_NICK_MODECHANGE, &nw_hook_umodechange); + registerhook(HOOK_NICK_MESSAGE, &nw_hook_message); registerhook(HOOK_CHANNEL_CREATE, &nw_hook_joinchannel); registerhook(HOOK_CHANNEL_JOIN, &nw_hook_joinchannel); } @@ -204,6 +213,7 @@ void _fini(void) { deregisterhook(HOOK_NICK_NEWNICK, &nw_hook_newnick); deregisterhook(HOOK_NICK_RENAME, &nw_hook_rename); deregisterhook(HOOK_NICK_MODECHANGE, &nw_hook_umodechange); + deregisterhook(HOOK_NICK_MESSAGE, &nw_hook_message); deregisterhook(HOOK_CHANNEL_CREATE, &nw_hook_joinchannel); deregisterhook(HOOK_CHANNEL_JOIN, &nw_hook_joinchannel);