]> jfr.im git - irc/quakenet/newserv.git/blame - newsearch/ns-authedpct.c
review - ops first
[irc/quakenet/newserv.git] / newsearch / ns-authedpct.c
CommitLineData
9d867b50
IB
1/*
2 * authedpct functionality
3 */
4
5#include "newsearch.h"
6
7#include <stdio.h>
8#include <stdlib.h>
9
c8be5183
CP
10void *authedpct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
11void authedpct_free(searchCtx *ctx, struct searchNode *thenode);
9d867b50 12
c8be5183 13struct searchNode *authedpct_parse(searchCtx *ctx, int type, int argc, char **argv) {
9d867b50
IB
14 struct searchNode *thenode;
15
16 if (type != SEARCHTYPE_CHANNEL) {
17 parseError = "authedpct: this function is only valid for channel searches.";
18 return NULL;
19 }
20
9d867b50
IB
21 if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) {
22 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
23 parseError = "malloc: could not allocate memory for this search.";
9d867b50
IB
24 return NULL;
25 }
26
c7f7a584 27 thenode->returntype = RETURNTYPE_INT;
28 thenode->localdata = NULL;
9d867b50
IB
29 thenode->exe = authedpct_exe;
30 thenode->free = authedpct_free;
31
32 return thenode;
33}
34
c8be5183 35void *authedpct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
9d867b50
IB
36 int i;
37 int j=0;
38 nick *np;
39 chanindex *cip = (chanindex *)theinput;
40 struct authedpct_localdata *localdata;
41
42 localdata = thenode->localdata;
43
44 if (!cip->channel)
c7f7a584 45 return (void *)0;
9d867b50
IB
46
47 for (i=0;i<cip->channel->users->hashsize;i++) {
48 if (cip->channel->users->content[i]==nouser)
49 continue;
50
51 if ((np=getnickbynumeric(cip->channel->users->content[i])) && IsAccount(np))
52 j++;
53 }
c7f7a584 54
c54295ef 55 return (void *)(long)((j * 100) / cip->channel->users->totalusers);
c7f7a584 56}
9d867b50 57
c8be5183 58void authedpct_free(searchCtx *ctx, struct searchNode *thenode) {
9d867b50
IB
59 free(thenode);
60}
61