added cmd_modcmd
[NeonServV5.git] / src / modcmd.c
index aca47f66a14682780e54fe289904bf28fabd771a..9af13218fc32a47f7a12efe713d5b83fadce5763 100644 (file)
@@ -1,4 +1,4 @@
-/* modcmd.c - NeonServ v5.2
+/* modcmd.c - NeonServ v5.3
  * Copyright (C) 2011  Philipp Kreil (pk910)
  * 
  * This program is free software: you can redistribute it and/or modify
@@ -69,7 +69,8 @@ static const struct default_language_entry msgtab[] = {
     {"MODCMD_PUBCMD",           "Public commands in $b%s$b are restricted."}, /* {ARGS: "#TestChan"} */
     {"MODCMD_ACCESS_DENIED",    "Access denied."},
     {"MODCMD_SUBCOMMANDS",      "Subcommands of %s: %s"}, /* {ARGS: "bot", "ADD, DEL, EDIT"} */
-    {"MODCMD_CROSSCHAN",        "You must be in %s (or on its userlist) to use this command."},
+    {"MODCMD_CROSSCHAN",        "You must be in %s (or on its userlist) to use this command."}, /* {ARGS: "#TestChan"} */
+    {"MODCMD_UNKNOWN",          "$b%s$b is an unknown command."}, /* {ARGS: "bla"} */
     {NULL, NULL}
 };
 
@@ -161,8 +162,12 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
         args++;
     }
     struct cmd_binding *cbind;
+    int found_cmd = 0;
     for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
         if(cbind->botid == client->botid && (cbind->botid || cbind->clientid == client->clientid) && stricmp(cbind->cmd, message) == 0) {
+            found_cmd = 1;
+            //get a text bot
+            tmp_text_client = get_botwise_prefered_bot(client->botid, (client->botid == 0 ? client->clientid : 0));
             if(cbind->func->func == modcmd_linker) {
                 //links subcommands
                 char command[MAXLEN];
@@ -191,7 +196,7 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
                             subcompos += sprintf(subcommands + subcompos, (subcompos ? ", %s" : "%s"), cbind->cmd + commandlen);
                         }
                     }
-                    reply(tmp_text_client, user, "MODCMD_SUBCOMMANDS", parent_bind->cmd, subcommands);
+                    reply(tmp_text_client, user, "MODCMD_SUBCOMMANDS", parent_bind->cmd, (subcompos ? subcommands : "\1dnone\1d"));
                     break;
                 }
             }
@@ -204,8 +209,6 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
                     break;
                 chan = sent_chan;
             }
-            //get a text bot
-            tmp_text_client = get_botwise_prefered_bot(client->botid, (client->botid == 0 ? client->clientid : 0));
             //parse the arguments...
             char *arga[MAXNUMPARAMS];
             char **argv;
@@ -361,6 +364,8 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
             break;
         }
     }
+    if(!found_cmd && !sent_chan)
+        reply(get_botwise_prefered_bot(client->botid, (client->botid == 0 ? client->clientid : 0)), user, "MODCMD_UNKNOWN", message);
     free(message);
     if(args_buffer)
         free(args_buffer);
@@ -609,6 +614,27 @@ int set_trigger_callback(int botid, trigger_callback_t *func) {
     return 1;
 }
 
+int flush_trigger_cache(int botid, int clientid) {
+    struct ChanNode *chan;
+    struct trigger_cache *trigger, *last;
+    for(chan = getAllChans(NULL); chan; chan = getAllChans(chan)) {
+        last = NULL;
+        for(trigger = chan->trigger; trigger; trigger = trigger->next) {
+            if(trigger->botid == botid && (botid || trigger->clientid == clientid)) {
+                if(last)
+                    last->next = trigger->next;
+                else
+                    chan->trigger = trigger->next;
+                free(trigger->trigger);
+                free(trigger);
+                break;
+            } else
+                last = trigger;
+        }
+    }
+    return 1;
+}
+
 int changeBotwiseChannelTrigger(int botid, int clientid, struct ChanNode *chan, char *new_trigger) {
     struct trigger_cache *trigger;
     for(trigger = chan->trigger; trigger; trigger = trigger->next) {
@@ -830,13 +856,15 @@ void bind_botwise_set_parameters(int botid, int clientid, char *cmd, char *param
                     free(cbind->parameters[i]);
                 cbind->paramcount = 0;
             }
-            char *a, *b = parameters;
-            do {
-                a = strstr(b, " ");
-                if(a) *a = '\0';
-                cbind->parameters[cbind->paramcount++] = strdup(b);
-                if(a) b = a+1;
-            } while(a);
+            if(parameters) {
+                char *a, *b = parameters;
+                do {
+                    a = strstr(b, " ");
+                    if(a) *a = '\0';
+                    cbind->parameters[cbind->paramcount++] = strdup(b);
+                    if(a) b = a+1;
+                } while(a);
+            }
             return;
         }
     }