]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-oppct.c
10 struct oppct_localdata
{
14 void *oppct_exe(struct searchNode
*thenode
, int type
, void *theinput
);
15 void oppct_free(struct searchNode
*thenode
);
17 struct searchNode
*oppct_parse(int type
, int argc
, char **argv
) {
18 struct oppct_localdata
*localdata
;
19 struct searchNode
*thenode
;
21 if (type
!= SEARCHTYPE_CHANNEL
) {
22 parseError
= "oppct: this function is only valid for channel searches.";
27 parseError
="oppct: usage: (oppct number)";
31 if (!(localdata
=(struct oppct_localdata
*)malloc(sizeof(struct oppct_localdata
)))) {
32 parseError
= "malloc: could not allocate memory for this search.";
36 localdata
->pct
= strtoul(argv
[0],NULL
,10);
38 if (!(thenode
=(struct searchNode
*)malloc(sizeof(struct searchNode
)))) {
39 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
40 parseError
= "malloc: could not allocate memory for this search.";
45 thenode
->returntype
= RETURNTYPE_BOOL
;
46 thenode
->localdata
= localdata
;
47 thenode
->exe
= oppct_exe
;
48 thenode
->free
= oppct_free
;
53 void *oppct_exe(struct searchNode
*thenode
, int type
, void *theinput
) {
56 chanindex
*cip
= (chanindex
*)theinput
;
57 struct oppct_localdata
*localdata
;
59 localdata
= thenode
->localdata
;
61 if (cip
->channel
==NULL
)
62 return falseval(type
);
64 nonop
=(cip
->channel
->users
->totalusers
)-((cip
->channel
->users
->totalusers
*localdata
->pct
)/100);
66 for (i
=0;i
<cip
->channel
->users
->hashsize
;i
++) {
67 if (cip
->channel
->users
->content
[i
]!=nouser
) {
68 if (!(cip
->channel
->users
->content
[i
] & CUMODE_OP
)) {
70 return falseval(type
);
79 void oppct_free(struct searchNode
*thenode
) {
80 free(thenode
->localdata
);