]>
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 | |
f33f3f52 | 13 | struct searchNode *oppct_parse(searchCtx *ctx, int argc, char **argv) { |
f90de116 IB |
14 | struct searchNode *thenode; |
15 | ||
f90de116 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."; | |
f90de116 IB |
19 | return NULL; |
20 | } | |
21 | ||
c7f7a584 | 22 | thenode->returntype = RETURNTYPE_INT; |
23 | thenode->localdata = NULL; | |
f90de116 IB |
24 | thenode->exe = oppct_exe; |
25 | thenode->free = oppct_free; | |
26 | ||
27 | return thenode; | |
28 | } | |
29 | ||
c8be5183 | 30 | void *oppct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { |
f90de116 | 31 | int i; |
c7f7a584 | 32 | int ops; |
f90de116 | 33 | chanindex *cip = (chanindex *)theinput; |
f90de116 | 34 | |
c7f7a584 | 35 | if (cip->channel==NULL || cip->channel->users->totalusers==0) |
36 | return (void *)0; | |
f90de116 | 37 | |
c7f7a584 | 38 | ops=0; |
f90de116 IB |
39 | |
40 | for (i=0;i<cip->channel->users->hashsize;i++) { | |
41 | if (cip->channel->users->content[i]!=nouser) { | |
d454928e | 42 | if (cip->channel->users->content[i] & CUMODE_OP) { |
c7f7a584 | 43 | ops++; |
f90de116 IB |
44 | } |
45 | } | |
46 | } | |
47 | ||
c54295ef | 48 | return (void *)(long)((ops * 100) / cip->channel->users->totalusers); |
f90de116 IB |
49 | } |
50 | ||
c8be5183 | 51 | void oppct_free(searchCtx *ctx, struct searchNode *thenode) { |
de8c57b4 | 52 | ctx->reply(senderNSExtern, "Notice: oppct is deprecated by cumodepct"); |
f90de116 IB |
53 | free(thenode); |
54 | } | |
55 |