]> jfr.im git - irc/quakenet/newserv.git/commitdiff
nickwatch: Implement hook for messages/notices.
authorGunnar Beutner <redacted>
Tue, 13 Aug 2013 01:28:37 +0000 (03:28 +0200)
committerGunnar Beutner <redacted>
Tue, 13 Aug 2013 01:28:37 +0000 (03:28 +0200)
core/hooks.h
localuser/localuser.c
newsearch/Makefile
newsearch/newsearch.c
newsearch/newsearch.h
nick/nick.c
nick/nick.h
nickwatch/nickwatch.c

index de800e3537fba4a559239b094116e2080f5edd46..d362cf61fd48a15eb10750f0c09019d3c1b3c481 100644 (file)
@@ -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) */
index c75e31eaef91eef2a24e8441915d50f481994de2..9e056b9581e5fec1bf28bc8babdc8e915ec6c381 100644 (file)
@@ -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;
index 5866367492cd37683abf40c5f7987f8153c71cd2..f2c97bae57192c8d7773f8ad0019c950649794dd 100644 (file)
@@ -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}
 
index d8a9b87c1d6b46850f0a8b833f56649a96df4ca6..0b08bdfb73daa5b7c574e1149f39b6a5646fc66a 100644 (file)
@@ -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");
index 7e14e030713f3c50dc57b0792f9da5f0aff5c646..e8d669364bc43fa6f92a927b36389f337a9a5d0d 100644 (file)
@@ -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);
index b08e854a732fd00dab86719bb33a11be453c3238..1b7dcadf85fe6d88334603ac7d3df421efc0933c 100644 (file)
@@ -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);
index 2efadf30dfb12ae7b28bfaadf7cd5e0abc734fb3..d3bae4e23b468ea52c6b8338f4e3990397675c6c 100644 (file)
@@ -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;
 
index beb9167ab1f7eedd9344ef11703e821921f5b8ea..d53bfb15ec47548c98d6acce393d9d2a73852444 100644 (file)
@@ -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);