]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Added some things to chanserv_newsearch.
authorsplidge <redacted>
Sat, 22 Mar 2008 13:31:53 +0000 (13:31 +0000)
committersplidge <redacted>
Sat, 22 Mar 2008 13:31:53 +0000 (13:31 +0000)
Channel display format "qusers" displays a summary of the known users on that channel.
Channel search term "qusers" returns the number of known users on that channel.  Optional argument is the flags the user must have (all flags specified with + and none with - must be present for it to match).

chanserv/newsearch/Makefile.in
chanserv/newsearch/chanserv_newsearch.c [new file with mode: 0644]
chanserv/newsearch/cs-newsearch.c
chanserv/newsearch/csns-qusers.c [new file with mode: 0644]
chanserv/newsearch/formats.c

index 98f1ca0f79965fa06e8135a262e78bc28fc3d3bc..788abd12ad5e2103060cf2175eb8ca8cbbd688bd 100644 (file)
@@ -5,5 +5,5 @@ INCPATH=../../
 .PHONY: all
 all: chanserv_newsearch.so
 
-chanserv_newsearch.so: cs-newsearch.o formats.o 
+chanserv_newsearch.so: cs-newsearch.o formats.o chanserv_newsearch.o csns-qusers.o
         
diff --git a/chanserv/newsearch/chanserv_newsearch.c b/chanserv/newsearch/chanserv_newsearch.c
new file mode 100644 (file)
index 0000000..e69de29
index 0a01d25ef040a4a6fb860deed6c19ca844b79173..23cedb822ee06ab7aa71deff96be69dfabe211ed 100644 (file)
@@ -4,13 +4,20 @@
 /* formats.c */
 void printnick_auth(nick *, nick *);
 void printnick_authchans(nick *, nick *);
+void printchannel_qusers(nick *, chanindex *);
+
+struct searchNode *qusers_parse(int type, int argc, char **argv);
 
 void _init() {
   regnickdisp("auth", printnick_auth);
   regnickdisp("authchans", printnick_authchans);
+  regchandisp("qusers", printchannel_qusers);
+  registersearchterm("qusers", qusers_parse);
 }
 
 void _fini() {
   unregnickdisp("auth", printnick_auth);
   unregnickdisp("authchans", printnick_authchans);
+  unregchandisp("qusers", printchannel_qusers);
+  deregistersearchterm("qusers", qusers_parse);
 }
diff --git a/chanserv/newsearch/csns-qusers.c b/chanserv/newsearch/csns-qusers.c
new file mode 100644 (file)
index 0000000..9a573e1
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * exists functionality 
+ */
+
+#include "../../newsearch/newsearch.h"
+#include "../../lib/flags.h"
+#include "../chanserv.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+void *qusers_exe(struct searchNode *thenode, void *theinput);
+void qusers_free(struct searchNode *thenode);
+
+struct qusers_localdata {
+  flag_t setmodes;
+  flag_t clearmodes;
+};
+
+struct searchNode *qusers_parse(int type, int argc, char **argv) {
+  struct searchNode *thenode;
+  struct qusers_localdata *localdata;
+
+  if (type != SEARCHTYPE_CHANNEL) {
+    parseError = "qusers: this function is only valid for channel searches.";
+    return NULL;
+  }
+
+  if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
+    parseError = "malloc: could not allocate memory for this search.";
+    return NULL;
+  }
+
+  thenode->localdata=localdata=malloc(sizeof(struct qusers_localdata));
+  thenode->returntype = RETURNTYPE_INT;
+  thenode->exe = qusers_exe;
+  thenode->free = qusers_free;
+
+  if (argc==0) {
+    localdata->setmodes=0;
+    localdata->clearmodes=0;
+  } else {
+    localdata->setmodes=0;
+    localdata->clearmodes=~0;
+    
+    setflags(&(localdata->setmodes), QCUFLAG_ALL, argv[0], rcuflags, REJECT_NONE);
+    setflags(&(localdata->clearmodes), QCUFLAG_ALL, argv[0], rcuflags, REJECT_NONE);
+    
+    localdata->clearmodes = ~localdata->clearmodes;
+  }
+
+  return thenode;
+}
+
+void *qusers_exe(struct searchNode *thenode, void *theinput) {
+  chanindex *cip = (chanindex *)theinput;
+  regchan *rcp;
+  regchanuser *rcup;
+  struct qusers_localdata *localdata=thenode->localdata;
+  unsigned long i,count=0;
+  
+  if (!(rcp=cip->exts[chanservext]))
+    return (void *)0;
+  
+  for (i=0;i<REGCHANUSERHASHSIZE;i++) {
+    for (rcup=rcp->regusers[i];rcup;rcup=rcup->nextbychan) {
+      if ((rcup->flags & localdata->setmodes) != localdata->setmodes)
+        continue;
+      
+      if (rcup->flags & localdata->clearmodes)
+        continue;
+      
+      count++;
+    }
+  }
+  
+  return (void *)count;
+}
+
+void qusers_free(struct searchNode *thenode) {
+  free(thenode->localdata);
+  free(thenode);
+}
+
index 1511a852deefa6b0e8c5453a569390f9cbf116fb..f770ae743e7129a2d4ef95ac582067aa24b33a6d 100644 (file)
@@ -4,6 +4,35 @@
 #include "../../newsearch/newsearch.h"
 #include "../../control/control.h"
 
+void printchannel_qusers(nick *sender, chanindex *cip) {
+  regchanuser *rcup;
+  regchan *rcp;
+  int i;
+  int own=0,mas=0,op=0,voi=0,kno=0,ban=0,tot=0;
+  
+  if (!(rcp=cip->exts[chanservext])) {
+    controlreply(sender,"[              - not registered -                 ] %s",cip->name->content);
+    return;
+  }
+  
+  for (i=0;i<REGCHANUSERHASHSIZE;i++) {
+    for (rcup=rcp->regusers[i];rcup;rcup=rcup->nextbychan) {
+      tot++;
+      
+      if (CUIsOwner(rcup)) own++; else
+      if (CUIsMaster(rcup)) mas++; else
+      if (CUIsOp(rcup)) op++; else
+      if (CUIsVoice(rcup)) voi++; else
+      if (CUIsKnown(rcup)) kno++;
+      
+      if (CUIsBanned(rcup)) ban++;
+    }
+  }
+  
+  controlreply(sender,"[%4dn %4dm %4do %4dv %4dk %4db - %4d total ] %s",own,mas,op,voi,kno,ban,tot,cip->name->content);
+}
+  
+
 void printnick_auth(nick *sender, nick *np) {
   struct reguser *rup;