]> jfr.im git - irc/quakenet/newserv.git/blame - newsearch/ns-kick.c
Whoops, bit too much copy paste there...
[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
c8be5183 14struct searchNode *kick_parse(searchCtx *ctx, int type, int argc, char **argv) {
4e65afe3 15 struct searchNode *thenode;
d5043cfe 16 nick *np;
17
4e65afe3 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
d5043cfe 28 if ((np=getnickbynick(argv[0]))==NULL) {
4e65afe3 29 parseError="kick: unknown nickname";
30 return NULL;
31 }
d5043cfe 32
33 if (IsOper(np) || IsService(np)) {
34 parseError="kick: can't kick opers or services";
35 return NULL;
36 }
4e65afe3 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;
d5043cfe 44 thenode->localdata = np;
4e65afe3 45 thenode->exe = kick_exe;
46 thenode->free = kick_free;
47
48 return thenode;
49}
50
c8be5183 51void *kick_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
4e65afe3 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
d5043cfe 61 localkickuser(NULL, cip->channel, np, "");
4e65afe3 62 return (void *)1;
63}
64
c8be5183 65void kick_free(searchCtx *ctx, struct searchNode *thenode) {
4e65afe3 66 free(thenode);
67}