]> jfr.im git - irc/quakenet/newserv.git/blame - newsearch/ns-kick.c
newsearch changes to support addition of trust_search/patriciasearch
[irc/quakenet/newserv.git] / newsearch / ns-kick.c
CommitLineData
4e65afe3 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
c8be5183
CP
11void *kick_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
12void kick_free(searchCtx *ctx, struct searchNode *thenode);
4e65afe3 13
f33f3f52 14struct searchNode *kick_parse(searchCtx *ctx, int argc, char **argv) {
4e65afe3 15 struct searchNode *thenode;
d5043cfe 16 nick *np;
17
4e65afe3 18 if (argc!=1) {
19 parseError="kick: usage: (kick target)";
20 return NULL;
21 }
22
d5043cfe 23 if ((np=getnickbynick(argv[0]))==NULL) {
4e65afe3 24 parseError="kick: unknown nickname";
25 return NULL;
26 }
d5043cfe 27
28 if (IsOper(np) || IsService(np)) {
29 parseError="kick: can't kick opers or services";
30 return NULL;
31 }
4e65afe3 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;
d5043cfe 39 thenode->localdata = np;
4e65afe3 40 thenode->exe = kick_exe;
41 thenode->free = kick_free;
42
43 return thenode;
44}
45
c8be5183 46void *kick_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
4e65afe3 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
d5043cfe 56 localkickuser(NULL, cip->channel, np, "");
4e65afe3 57 return (void *)1;
58}
59
c8be5183 60void kick_free(searchCtx *ctx, struct searchNode *thenode) {
4e65afe3 61 free(thenode);
62}