added cmd_setbot for dynamic bot management
[NeonServV5.git] / src / modcmd.c
index 50f71c86c138c4fea960643a6c3e8ef2908eeb03..058612a2b353cd09887d543c67d5ddf000389947 100644 (file)
@@ -253,13 +253,23 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
                 int args_pos = 0;
                 char *uargs[MAXNUMPARAMS];
                 int uargc = 0;
-                char *b;
+                char *b, *c;
                 int i;
                 int allargs, argi;
                 for(i = 0; i < cbind->paramcount; i++) {
                     b = cbind->parameters[i];
                     if(b[0] == '%') {
                         b++;
+                        c = b;
+                        while(*c && *c != ' ') {
+                            if(*c == '|') break;
+                            c++;
+                        }
+                        if(!*c || *c == ' ') c = NULL;
+                        else {
+                            *c = '\0';
+                            c++;
+                        }
                         if(b[strlen(b)-1] == '-') {
                             allargs = strlen(b)-1;
                             b[allargs] = '\0';
@@ -297,6 +307,9 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
                             } else if((cbind->func->flags & CMDFLAG_EMPTY_ARGS)) {
                                 uargs[uargc++] = args_buffer + args_pos;
                                 args_buffer[args_pos++] = '\0';
+                            } else if(c) {
+                                uargs[uargc++] = args_buffer + args_pos;
+                                args_pos += sprintf(args_buffer + args_pos, "%s", c) + 1;
                             }
                         } else if(!strcmp(b, "c")) {
                             uargs[uargc++] = args_buffer + args_pos;
@@ -305,6 +318,7 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
                             uargs[uargc++] = args_buffer + args_pos;
                             args_pos += sprintf(args_buffer + args_pos, "%s", user->nick) + 1;
                         }
+                        if(c) c[-1] = '|'; //reset \0 to |
                     } else {
                         uargs[uargc++] = args_buffer + args_pos;
                         args_pos += sprintf(args_buffer + args_pos, "%s", b) + 1;
@@ -690,6 +704,8 @@ int unbind_botwise_cmd(int botid, int clientid, char *cmd) {
                 for(i = 0; i < cbind->paramcount; i++)
                     free(cbind->parameters[i]);
             }
+            if(cbind->channel_access)
+                free(cbind->channel_access);
             free(cbind);
             return 1;
         } else
@@ -698,6 +714,33 @@ int unbind_botwise_cmd(int botid, int clientid, char *cmd) {
     return 0;
 }
 
+int unbind_botwise_allcmd(int clientid) {
+    int i;
+    for(i = 0; i < 27; i++) {
+        struct cmd_binding *cbind, *next, *last = NULL;
+        for(cbind = cmd_binds[i]; cbind; cbind = next) {
+            next = cbind->next;
+            if(clientid == cbind->clientid) {
+                if(last)
+                    last->next = cbind->next;
+                else
+                    cmd_binds[i] = cbind->next;
+                free(cbind->cmd);
+                if(cbind->paramcount) {
+                    int j;
+                    for(j = 0; j < cbind->paramcount; j++)
+                        free(cbind->parameters[j]);
+                }
+                if(cbind->channel_access)
+                    free(cbind->channel_access);
+                free(cbind);
+            } else
+                last = cbind;
+        }
+    }
+    return 1;
+}
+
 struct cmd_function *find_cmd_function(int botid, char *name) {
     struct cmd_function *cmdfunc;
     char *c;