]> jfr.im git - irc/quakenet/newserv.git/blame - newsearch/ns-authedpct.c
merge
[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
f33f3f52 13struct searchNode *authedpct_parse(searchCtx *ctx, int argc, char **argv) {
9d867b50
IB
14 struct searchNode *thenode;
15
9d867b50
IB
16 if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) {
17 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
18 parseError = "malloc: could not allocate memory for this search.";
9d867b50
IB
19 return NULL;
20 }
21
c7f7a584 22 thenode->returntype = RETURNTYPE_INT;
23 thenode->localdata = NULL;
9d867b50
IB
24 thenode->exe = authedpct_exe;
25 thenode->free = authedpct_free;
26
27 return thenode;
28}
29
c8be5183 30void *authedpct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
9d867b50
IB
31 int i;
32 int j=0;
33 nick *np;
34 chanindex *cip = (chanindex *)theinput;
35 struct authedpct_localdata *localdata;
36
37 localdata = thenode->localdata;
38
39 if (!cip->channel)
c7f7a584 40 return (void *)0;
9d867b50
IB
41
42 for (i=0;i<cip->channel->users->hashsize;i++) {
43 if (cip->channel->users->content[i]==nouser)
44 continue;
45
46 if ((np=getnickbynumeric(cip->channel->users->content[i])) && IsAccount(np))
47 j++;
48 }
c7f7a584 49
c54295ef 50 return (void *)(long)((j * 100) / cip->channel->users->totalusers);
c7f7a584 51}
9d867b50 52
c8be5183 53void authedpct_free(searchCtx *ctx, struct searchNode *thenode) {
9d867b50
IB
54 free(thenode);
55}
56