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