#include <stdio.h>
#include <stdlib.h>
-void *kick_exe(struct searchNode *thenode, void *theinput);
-void kick_free(struct searchNode *thenode);
-
-struct searchNode *kick_parse(int type, int argc, char **argv) {
- struct searchNode *thenode;
- void *localdata;
-
- if (type!=SEARCHTYPE_CHANNEL) {
- parseError="kick: only channel searches are supported";
- return NULL;
- }
+void *kick_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void kick_free(searchCtx *ctx, struct searchNode *thenode);
+struct searchNode *kick_parse(searchCtx *ctx, int argc, char **argv) {
+ struct searchNode *thenode, *kicknick;
+ nick *np;
+ char *p;
+
if (argc!=1) {
parseError="kick: usage: (kick target)";
return NULL;
}
- if ((localdata=getnickbynick(argv[0]))==NULL) {
+ if (!(kicknick=argtoconststr("kick", ctx, argv[0], &p)))
+ return NULL;
+
+ np=getnickbynick(p);
+ kicknick->free(ctx, kicknick);
+
+ if (np==NULL) {
parseError="kick: unknown nickname";
return NULL;
}
+
+ if (IsOper(np) || IsService(np)) {
+ parseError="kick: can't kick opers or services";
+ return NULL;
+ }
if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) {
parseError = "malloc: could not allocate memory for this search.";
}
thenode->returntype = RETURNTYPE_BOOL;
- thenode->localdata = localdata;
+ thenode->localdata = np;
thenode->exe = kick_exe;
thenode->free = kick_free;
return thenode;
}
-void *kick_exe(struct searchNode *thenode, void *theinput) {
+void *kick_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
nick *np;
chanindex *cip;
if (cip->channel==NULL || getnumerichandlefromchanhash(cip->channel->users, np->numeric)==NULL)
return (void *)0;
- localkickuser(NULL, cip->channel, np, NULL);
+ localkickuser(NULL, cip->channel, np, "");
return (void *)1;
}
-void kick_free(struct searchNode *thenode) {
+void kick_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode);
}