]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-nickiter.c
2 * NICKITER functionality
10 void nickiter_free(searchCtx
*ctx
, struct searchNode
*thenode
);
11 void *nickiter_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
);
13 struct nickiter_localdata
{
15 struct searchVariable
*variable
;
16 chanindex
*lastchanindex
;
19 struct searchNode
*nickiter_parse(searchCtx
*ctx
, int argc
, char **argv
) {
21 struct nickiter_localdata
*localdata
;
24 parseError
= "nickiter: usage: nickiter variable";
28 if(!(localdata
=(struct nickiter_localdata
*)malloc(sizeof(struct nickiter_localdata
)))) {
29 parseError
= "malloc: could not allocate memory for this search.";
34 if(!(localdata
->variable
=var_register(ctx
, argv
[0], RETURNTYPE_STRING
))) {
39 if(!(thenode
=(struct searchNode
*)malloc(sizeof(struct searchNode
)))) {
40 parseError
= "malloc: could not allocate memory for this search.";
45 localdata
->currentnick
= 0;
46 localdata
->lastchanindex
= NULL
;
48 thenode
->returntype
= RETURNTYPE_BOOL
;
49 thenode
->localdata
= localdata
;
50 thenode
->exe
= nickiter_exe
;
51 thenode
->free
= nickiter_free
;
56 void nickiter_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
57 free(thenode
->localdata
);
61 void *nickiter_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
62 struct nickiter_localdata
*localdata
= thenode
->localdata
;
63 chanindex
*cip
= (chanindex
*)theinput
;
66 if(cip
!= localdata
->lastchanindex
) {
67 localdata
->lastchanindex
= cip
;
68 localdata
->currentnick
= 0;
71 if(!cip
->channel
|| !cip
->channel
->users
)
74 while(localdata
->currentnick
< cip
->channel
->users
->hashsize
) {
75 if(cip
->channel
->users
->content
[localdata
->currentnick
] != nouser
) {
76 np
= getnickbynumeric(cip
->channel
->users
->content
[localdata
->currentnick
]);
77 localdata
->currentnick
++;
82 var_setstr(localdata
->variable
, np
->nick
);
85 localdata
->currentnick
++;