]> jfr.im git - irc/quakenet/newserv.git/blobdiff - newsearch/ns-kick.c
LUA: add function for channel chanop notice
[irc/quakenet/newserv.git] / newsearch / ns-kick.c
index 60d42959d63c7af30c138f49dad674dc60a6b37a..0b168a83b147337be2954b7c66f08721912bb281 100644 (file)
@@ -8,27 +8,34 @@
 #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.";
@@ -36,14 +43,14 @@ struct searchNode *kick_parse(int type, int argc, char **argv) {
   }
 
   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;
 
@@ -53,10 +60,10 @@ void *kick_exe(struct searchNode *thenode, void *theinput) {
   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);
 }