added SUB_LINKER command flag to add a quiet sub command linker
authorpk910 <philipp@zoelle1.de>
Sun, 23 Sep 2012 22:23:46 +0000 (00:23 +0200)
committerpk910 <philipp@zoelle1.de>
Sun, 23 Sep 2012 22:23:46 +0000 (00:23 +0200)
src/modcmd.c
src/modcmd.h
src/modules/global.mod/cmd_global_modcmd.c

index f53a3c22a93bfa88dafc2820c288c7f80599f053..e19d261318cd71f169f894bee1efc2a1ea5259c8 100644 (file)
@@ -179,6 +179,32 @@ static struct cmd_binding *modcmd_linker_command(struct ClientSocket *client, st
     }
 }
 
+static struct cmd_binding *modcmd_sub_linker_command(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct cmd_binding *cbind, int bind_index, char **args_ptr) {
+    //links subcommands
+    char command[MAXLEN];
+    struct cmd_binding *parent_bind = cbind;
+    char *args = *args_ptr;
+    if(args) {
+        char *subcmd = args;
+        args = strchr(args, ' ');
+        if(args) {
+            *args = '\0';
+            args++;
+        }
+        sprintf(command, "%s %s", parent_bind->cmd, subcmd);
+        for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
+            if(cbind->botid == client->botid && (cbind->botid || cbind->clientid == client->clientid) && stricmp(cbind->cmd, command) == 0)
+                break;
+        }
+        *args_ptr = args;
+        if(cbind && cbind->func->func == modcmd_linker) {
+            return modcmd_linker_command(client, textclient, user, cbind, bind_index, args_ptr);
+        }
+        return (cbind ? cbind : parent_bind);
+    } else
+        return parent_bind;
+}
+
 static void handle_command(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, char *message) {
     struct ChanNode *sent_chan = chan;
     if(message[0] == '#') {
@@ -193,7 +219,7 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
     }
     message = strdup(message);
     int bind_index = get_binds_index(message[0]);
-    char *args = strstr(message, " ");
+    char *args = strchr(message, ' ');
     char *args_buffer = NULL; //we need this to save a possible pointer to a allocation we need to free
     if(args) {
         *args = '\0';
@@ -209,7 +235,8 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
             if(cbind->func->func == modcmd_linker) {
                 cbind = modcmd_linker_command(client, textclient, user, cbind, bind_index, &args);
                 if(cbind == NULL) break;
-            }
+            } else if(cbind->flags & CMDFLAG_SUB_LINKER)
+                cbind = modcmd_sub_linker_command(client, textclient, user, cbind, bind_index, &args);
             if(statistics_enabled)
                 statistics_commands++;
             total_triggered++;
index 9f39e1fc48046c5014498a5b2b4788e1f0668d48..214a096f2b030a3ae746bb57e5f848ca11d2a053 100644 (file)
 
 #define MAXPARAMETERS 50
 
-#define CMDFLAG_REQUIRE_CHAN            0x0001
-#define CMDFLAG_REQUIRE_AUTH            0x0002
-#define CMDFLAG_REQUIRE_GOD             0x0004
-#define CMDFLAG_CHECK_AUTH              0x0008
-#define CMDFLAG_REGISTERED_CHAN         0x0010
-#define CMDFLAG_OVERRIDE_GLOBAL_ACCESS  0x0020
-#define CMDFLAG_OVERRIDE_CHANNEL_ACCESS 0x0040
-#define CMDFLAG_CHAN_PARAM              0x0080
-#define CMDFLAG_LOG                     0x0100
-#define CMDFLAG_OPLOG                   0x0200
-#define CMDFLAG_EMPTY_ARGS              0x0400
-#define CMDFLAG_REQUIRED                0x0800
-#define CMDFLAG_TEMPONARY_BIND          0x1000
-#define CMDFLAG_FUNCMD                  0x2000
-#define CMDFLAG_ESCAPE_ARGS             0x4000
-#define CMDFLAG_NO_CROSSCHAN            0x8000
+#define CMDFLAG_REQUIRE_CHAN            0x00001
+#define CMDFLAG_REQUIRE_AUTH            0x00002
+#define CMDFLAG_REQUIRE_GOD             0x00004
+#define CMDFLAG_CHECK_AUTH              0x00008
+#define CMDFLAG_REGISTERED_CHAN         0x00010
+#define CMDFLAG_OVERRIDE_GLOBAL_ACCESS  0x00020
+#define CMDFLAG_OVERRIDE_CHANNEL_ACCESS 0x00040
+#define CMDFLAG_CHAN_PARAM              0x00080
+#define CMDFLAG_LOG                     0x00100
+#define CMDFLAG_OPLOG                   0x00200
+#define CMDFLAG_EMPTY_ARGS              0x00400
+#define CMDFLAG_REQUIRED                0x00800
+#define CMDFLAG_TEMPONARY_BIND          0x01000
+#define CMDFLAG_FUNCMD                  0x02000
+#define CMDFLAG_ESCAPE_ARGS             0x04000
+#define CMDFLAG_NO_CROSSCHAN            0x08000
+#define CMDFLAG_SUB_LINKER              0x10000
 
 struct ClientSocket;
 struct UserNode;
index 1aaa040b2a0dbd85a4c14e5376cf9c2f306e8146..c1066ec1c30c74282ec6f81df075699f52e1e4da 100644 (file)
@@ -113,6 +113,7 @@ static const struct {
     {"FUNCMD",              CMDFLAG_FUNCMD},
     {"ESCAPED_ARGS",        CMDFLAG_ESCAPE_ARGS},       //allows arguments to be escaped ("a\ b" = "a b" as one argument)
     {"NO_CROSSCHAN",        CMDFLAG_NO_CROSSCHAN},
+    {"SUB_LINKER",          CMDFLAG_SUB_LINKER},        //adds a "quiet" subcommand linker with the binding function as default
     {NULL, 0}
 };