]>
Commit | Line | Data |
---|---|---|
f90de116 IB |
1 | /* |
2 | * oppct functionality | |
3 | */ | |
4 | ||
5 | #include "newsearch.h" | |
6 | ||
7 | #include <stdio.h> | |
8 | #include <stdlib.h> | |
9 | ||
c8be5183 CP |
10 | void *oppct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput); |
11 | void oppct_free(searchCtx *ctx, struct searchNode *thenode); | |
f90de116 | 12 | |
c8be5183 | 13 | struct searchNode *oppct_parse(searchCtx *ctx, int type, int argc, char **argv) { |
f90de116 IB |
14 | struct searchNode *thenode; |
15 | ||
16 | if (type != SEARCHTYPE_CHANNEL) { | |
17 | parseError = "oppct: this function is only valid for channel searches."; | |
18 | return NULL; | |
19 | } | |
20 | ||
f90de116 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."; | |
f90de116 IB |
24 | return NULL; |
25 | } | |
26 | ||
c7f7a584 | 27 | thenode->returntype = RETURNTYPE_INT; |
28 | thenode->localdata = NULL; | |
f90de116 IB |
29 | thenode->exe = oppct_exe; |
30 | thenode->free = oppct_free; | |
31 | ||
32 | return thenode; | |
33 | } | |
34 | ||
c8be5183 | 35 | void *oppct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { |
f90de116 | 36 | int i; |
c7f7a584 | 37 | int ops; |
f90de116 | 38 | chanindex *cip = (chanindex *)theinput; |
f90de116 | 39 | |
c7f7a584 | 40 | if (cip->channel==NULL || cip->channel->users->totalusers==0) |
41 | return (void *)0; | |
f90de116 | 42 | |
c7f7a584 | 43 | ops=0; |
f90de116 IB |
44 | |
45 | for (i=0;i<cip->channel->users->hashsize;i++) { | |
46 | if (cip->channel->users->content[i]!=nouser) { | |
47 | if (!(cip->channel->users->content[i] & CUMODE_OP)) { | |
c7f7a584 | 48 | ops++; |
f90de116 IB |
49 | } |
50 | } | |
51 | } | |
52 | ||
c54295ef | 53 | return (void *)(long)((ops * 100) / cip->channel->users->totalusers); |
f90de116 IB |
54 | } |
55 | ||
c8be5183 | 56 | void oppct_free(searchCtx *ctx, struct searchNode *thenode) { |
f90de116 IB |
57 | free(thenode); |
58 | } | |
59 |