]> jfr.im git - irc/quakenet/newserv.git/blame - newsearch/ns-hostpct.c
merge
[irc/quakenet/newserv.git] / newsearch / ns-hostpct.c
CommitLineData
9cbe50dd
IB
1/*
2 * hostpct functionality
3 */
4
5#include "newsearch.h"
6
7#include <stdio.h>
8#include <stdlib.h>
9
c8be5183
CP
10void *hostpct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
11void hostpct_free(searchCtx *ctx, struct searchNode *thenode);
9cbe50dd 12
f33f3f52 13struct searchNode *hostpct_parse(searchCtx *ctx, int argc, char **argv) {
9cbe50dd
IB
14 struct searchNode *thenode;
15
9cbe50dd
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.";
9cbe50dd
IB
19 return NULL;
20 }
21
c7f7a584 22 thenode->returntype = RETURNTYPE_INT;
23 thenode->localdata = NULL;
9cbe50dd
IB
24 thenode->exe = hostpct_exe;
25 thenode->free = hostpct_free;
26
27 return thenode;
28}
29
c8be5183 30void *hostpct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
9cbe50dd
IB
31 int i;
32 unsigned int marker;
c7f7a584 33 unsigned int hosts=0;
9cbe50dd
IB
34 nick *np;
35 chanindex *cip = (chanindex *)theinput;
9cbe50dd 36
9cbe50dd 37 if (cip->channel==NULL)
c7f7a584 38 return (void *)0;
9cbe50dd
IB
39
40 marker=nexthostmarker();
41
9cbe50dd
IB
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])))
47 continue;
48
49 if (np->host->marker!=marker) {
c7f7a584 50 hosts++;
9cbe50dd
IB
51 np->host->marker=marker;
52 }
53 }
54
c54295ef 55 return (void *)(long)((hosts * 100)/cip->channel->users->totalusers);
9cbe50dd
IB
56}
57
c8be5183 58void hostpct_free(searchCtx *ctx, struct searchNode *thenode) {
9cbe50dd
IB
59 free(thenode);
60}
61