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).
.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
/* 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);
}
--- /dev/null
+/*
+ * 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);
+}
+
#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;