]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Merge.
authorsplidge <redacted>
Sat, 15 Mar 2008 12:42:20 +0000 (12:42 +0000)
committersplidge <redacted>
Sat, 15 Mar 2008 12:42:20 +0000 (12:42 +0000)
newsearch/Makefile
newsearch/newsearch.c
newsearch/newsearch.h
newsearch/ns-notice.c [new file with mode: 0644]

index d506b41080931b184b38beab9d7764150ecedb5f..86f16d26941632363a9f9b83c5bcde9bb208d58d 100644 (file)
@@ -2,5 +2,5 @@
 .PHONY: all
 all: newsearch.so
 
-newsearch.so: newsearch.o formats.o ns-not.o ns-and.o ns-or.o ns-eq.o ns-match.o ns-hostmask.o ns-realname.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-hostpct.o ns-authedpct.o ns-length.o ns-kick.o ns-authts.o ns-channels.o ns-server.o ns-authid.o
+newsearch.so: newsearch.o formats.o ns-not.o ns-and.o ns-or.o ns-eq.o ns-match.o ns-hostmask.o ns-realname.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-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
        ld -shared -Bdynamic $(LIBPCRE) -o $@ $^
index 479433824774c6347b61d9b606801f69991125ed..9d16814cc7fc6511c7839785c3e908ca9618c4a3 100644 (file)
@@ -101,6 +101,9 @@ void _init() {
   /* Kill / gline parameters */
   registersearchterm("kill",kill_parse);
   registersearchterm("gline",gline_parse);
+
+  /* Notice functionality */
+  registersearchterm("notice",notice_parse);
   
   /* Nick output filters */
   regnickdisp("default",printnick);
index 5c1c190e8e2056bb9e715ef4e14142671dc77273..44bb09760e400aa873c0da872f706374de7dd352 100644 (file)
@@ -18,6 +18,7 @@
 #define    NSGLINE_DURATION       3600
 
 #define    NSMAX_REASON_LEN       120
+#define    NSMAX_NOTICE_LEN       250
 
 
 #define    RETURNTYPE_BOOL        0x01
@@ -56,6 +57,9 @@ struct searchNode *length_parse(int type, int argc, char **argv);
 struct searchNode *kill_parse(int type, int argc, char **argv);
 struct searchNode *gline_parse(int type, int argc, char **argv);
 
+/* notice action (BOOL) */
+struct searchNode *notice_parse(int type, int argc, char **argv);
+
 /* Nick/Channel functions (various types) */
 struct searchNode *nick_parse(int type, int argc, char **argv);
 struct searchNode *modes_parse(int type, int argc, char **argv);
diff --git a/newsearch/ns-notice.c b/newsearch/ns-notice.c
new file mode 100644 (file)
index 0000000..dfd0121
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * NOTICE functionality
+ * ---------
+ * Use of markers allows us to use notice in both channel and nick searches so we can have newserv notice everyone on a channel and/or
+ * everyone matching a certain nick_search pattern.
+ */
+
+#include "newsearch.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "../control/control.h" /* controlreply() */
+#include "../lib/irc_string.h" /* IPtostr() */
+#include "../lib/strlfunc.h"
+
+extern nick *senderNSExtern;
+
+void *notice_exe(struct searchNode *thenode, void *theinput);
+void notice_free(struct searchNode *thenode);
+
+struct notice_localdata {
+  unsigned int marker;
+  int count;
+  int type;
+  char message[NSMAX_NOTICE_LEN];
+};
+
+struct searchNode *notice_parse(int type, int argc, char **argv) {
+  struct notice_localdata *localdata;
+  struct searchNode *thenode;
+  int len;
+
+  if (!(localdata = (struct notice_localdata *) malloc(sizeof(struct notice_localdata)))) {
+    parseError = "malloc: could not allocate memory for this search.";
+    return NULL;
+  }
+  localdata->count = 0;
+  localdata->type = type;
+  if (type == SEARCHTYPE_CHANNEL)
+    localdata->marker = nextchanmarker();
+  else
+    localdata->marker = nextnickmarker();
+
+  if (argc==1) {
+    char *p = argv[0];
+    if(*p == '\"')
+      p++;
+    len = strlcpy(localdata->message, p, sizeof(localdata->message));
+    if(len >= sizeof(localdata->message)) {
+      localdata->message[sizeof(localdata->message)-1] = '\0';
+    } else {
+      localdata->message[len-1] = '\0';
+    }
+  }
+  else {
+    /* no notice to send out ... */
+    parseError = "Warning: you did not specify a message to notice out.";
+    free(localdata);
+    return NULL;
+  }
+
+  if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
+    /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
+    parseError = "malloc: could not allocate memory for this search.";
+    free(localdata);
+    return NULL;
+  }
+
+  thenode->returntype = RETURNTYPE_BOOL;
+  thenode->localdata = localdata;
+  thenode->exe = notice_exe;
+  thenode->free = notice_free;
+
+  return thenode;
+}
+
+void *notice_exe(struct searchNode *thenode, void *theinput) {
+  struct notice_localdata *localdata;
+  nick *np;
+  chanindex *cip;
+
+  localdata = thenode->localdata;
+
+  if (localdata->type == SEARCHTYPE_CHANNEL) {
+    cip = (chanindex *)theinput;
+    cip->marker = localdata->marker;
+    localdata->count += cip->channel->users->totalusers;
+  }
+  else {
+    np = (nick *)theinput;
+    np->marker = localdata->marker;
+    localdata->count++;
+  }
+
+  return (void *)1;
+}
+
+void notice_free(struct searchNode *thenode) {
+  struct notice_localdata *localdata;
+  nick *np, *nnp;
+  chanindex *cip, *ncip;
+  int i, j;
+  unsigned int nickmarker;
+
+  localdata = thenode->localdata;
+
+  if (localdata->type == SEARCHTYPE_CHANNEL) {
+    nickmarker=nextnickmarker();
+    for (i=0;i<CHANNELHASHSIZE;i++) {
+      for (cip=chantable[i];cip;cip=ncip) {
+        ncip = cip->next;
+        if (cip != NULL && cip->channel != NULL && cip->marker == localdata->marker) {
+          for (j=0;j<cip->channel->users->hashsize;j++) {
+            if (cip->channel->users->content[j]==nouser)
+              continue;
+    
+            if ((np=getnickbynumeric(cip->channel->users->content[j])))
+              np->marker=nickmarker;
+          }
+        }
+      }
+    }
+    for (i=0;i<NICKHASHSIZE;i++) {
+      for(np=nicktable[i];np;np=nnp) {
+        nnp = np->next;
+        if (np->marker == nickmarker)
+          controlnotice(np, localdata->message);
+      }
+    }
+  }
+  else {
+    for (i=0;i<NICKHASHSIZE;i++) {
+      for (np=nicktable[i];np;np=nnp) {
+        nnp = np->next;
+        if (np->marker == localdata->marker)
+         controlnotice(np, localdata->message);
+      }
+    }
+  }
+  /* notify opers of the action */
+  controlwall(NO_OPER, NL_BROADCASTS, "%s/%s sent the following message to %d %s: %s", senderNSExtern->nick, senderNSExtern->authname, localdata->count, localdata->count != 1 ? "users" : "user", localdata->message);
+  free(localdata);
+  free(thenode);
+}