]>
Commit | Line | Data |
---|---|---|
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 |
11 | void *kick_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput); |
12 | void kick_free(searchCtx *ctx, struct searchNode *thenode); | |
4e65afe3 | 13 | |
f33f3f52 | 14 | struct searchNode *kick_parse(searchCtx *ctx, int argc, char **argv) { |
31686847 | 15 | struct searchNode *thenode, *kicknick; |
d5043cfe | 16 | nick *np; |
31686847 | 17 | char *p; |
d5043cfe | 18 | |
4e65afe3 | 19 | if (argc!=1) { |
20 | parseError="kick: usage: (kick target)"; | |
21 | return NULL; | |
22 | } | |
23 | ||
31686847 CP |
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) { | |
4e65afe3 | 31 | parseError="kick: unknown nickname"; |
32 | return NULL; | |
33 | } | |
d5043cfe | 34 | |
35 | if (IsOper(np) || IsService(np)) { | |
36 | parseError="kick: can't kick opers or services"; | |
37 | return NULL; | |
38 | } | |
4e65afe3 | 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; | |
d5043cfe | 46 | thenode->localdata = np; |
4e65afe3 | 47 | thenode->exe = kick_exe; |
48 | thenode->free = kick_free; | |
49 | ||
50 | return thenode; | |
51 | } | |
52 | ||
c8be5183 | 53 | void *kick_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { |
4e65afe3 | 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 | ||
d5043cfe | 63 | localkickuser(NULL, cip->channel, np, ""); |
4e65afe3 | 64 | return (void *)1; |
65 | } | |
66 | ||
c8be5183 | 67 | void kick_free(searchCtx *ctx, struct searchNode *thenode) { |
4e65afe3 | 68 | free(thenode); |
69 | } |