]> jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-kick.c
newsearch changes to support addition of trust_search/patriciasearch
[irc/quakenet/newserv.git] / newsearch / ns-kick.c
1 /*
2 * KICK functionality
3 */
4
5 #include "newsearch.h"
6 #include "../localuser/localuserchannel.h"
7
8 #include <stdio.h>
9 #include <stdlib.h>
10
11 void *kick_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
12 void kick_free(searchCtx *ctx, struct searchNode *thenode);
13
14 struct searchNode *kick_parse(searchCtx *ctx, int argc, char **argv) {
15 struct searchNode *thenode;
16 nick *np;
17
18 if (argc!=1) {
19 parseError="kick: usage: (kick target)";
20 return NULL;
21 }
22
23 if ((np=getnickbynick(argv[0]))==NULL) {
24 parseError="kick: unknown nickname";
25 return NULL;
26 }
27
28 if (IsOper(np) || IsService(np)) {
29 parseError="kick: can't kick opers or services";
30 return NULL;
31 }
32
33 if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) {
34 parseError = "malloc: could not allocate memory for this search.";
35 return NULL;
36 }
37
38 thenode->returntype = RETURNTYPE_BOOL;
39 thenode->localdata = np;
40 thenode->exe = kick_exe;
41 thenode->free = kick_free;
42
43 return thenode;
44 }
45
46 void *kick_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
47 nick *np;
48 chanindex *cip;
49
50 np=thenode->localdata;
51 cip=(chanindex *)theinput;
52
53 if (cip->channel==NULL || getnumerichandlefromchanhash(cip->channel->users, np->numeric)==NULL)
54 return (void *)0;
55
56 localkickuser(NULL, cip->channel, np, "");
57 return (void *)1;
58 }
59
60 void kick_free(searchCtx *ctx, struct searchNode *thenode) {
61 free(thenode);
62 }