]> jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-kick.c
merge
[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 type, int argc, char **argv) {
15 struct searchNode *thenode;
16 nick *np;
17
18 if (type!=SEARCHTYPE_CHANNEL) {
19 parseError="kick: only channel searches are supported";
20 return NULL;
21 }
22
23 if (argc!=1) {
24 parseError="kick: usage: (kick target)";
25 return NULL;
26 }
27
28 if ((np=getnickbynick(argv[0]))==NULL) {
29 parseError="kick: unknown nickname";
30 return NULL;
31 }
32
33 if (IsOper(np) || IsService(np)) {
34 parseError="kick: can't kick opers or services";
35 return NULL;
36 }
37
38 if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) {
39 parseError = "malloc: could not allocate memory for this search.";
40 return NULL;
41 }
42
43 thenode->returntype = RETURNTYPE_BOOL;
44 thenode->localdata = np;
45 thenode->exe = kick_exe;
46 thenode->free = kick_free;
47
48 return thenode;
49 }
50
51 void *kick_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
52 nick *np;
53 chanindex *cip;
54
55 np=thenode->localdata;
56 cip=(chanindex *)theinput;
57
58 if (cip->channel==NULL || getnumerichandlefromchanhash(cip->channel->users, np->numeric)==NULL)
59 return (void *)0;
60
61 localkickuser(NULL, cip->channel, np, "");
62 return (void *)1;
63 }
64
65 void kick_free(searchCtx *ctx, struct searchNode *thenode) {
66 free(thenode);
67 }