don't show sub-sub-commands in linker overview
[NeonServV5.git] / src / modcmd.c
index 03b24d8351b984f6a9b53df311e9c79ce1ee0292..18483ed63887f77cc09cebe55dfc735940c2b1ab 100644 (file)
@@ -1,5 +1,5 @@
 /* modcmd.c - NeonServ v5.3
- * Copyright (C) 2011  Philipp Kreil (pk910)
+ * Copyright (C) 2011-2012  Philipp Kreil (pk910)
  * 
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -141,6 +141,44 @@ static CMD_BIND(modcmd_linker) {
     //just empty
 }
 
+static struct cmd_binding *modcmd_linker_command(struct ClientSocket *client, 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 = strstr(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->func->func == modcmd_linker) {
+            return modcmd_linker_command(client, user, cbind, bind_index, args_ptr);
+        }
+        return cbind;
+    } else {
+        //list all sub commands
+        int commandlen = sprintf(command, "%s ", parent_bind->cmd);
+        char subcommands[MAXLEN];
+        int subcompos = 0;
+        for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
+            if(cbind->botid == client->botid && (cbind->botid || cbind->clientid == client->clientid) && stricmplen(cbind->cmd, command, commandlen) == 0) {
+                if(strstr(cbind->cmd + commandlen, " ")) continue; //ignore if there is another space in the command (sub-sub-command :D)
+                subcompos += sprintf(subcommands + subcompos, (subcompos ? ", %s" : "%s"), cbind->cmd + commandlen);
+            }
+        }
+        reply(tmp_text_client, user, "MODCMD_SUBCOMMANDS", parent_bind->cmd, (subcompos ? subcommands : "\1dnone\1d"));
+        return NULL;
+    }
+}
+
 static void handle_command(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, char *message) {
     struct ChanNode *sent_chan = chan;
     if(message[0] == '#') {
@@ -169,36 +207,8 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
             //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];
-                struct cmd_binding *parent_bind = cbind;
-                if(args) {
-                    char *subcmd = args;
-                    args = strstr(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;
-                    }
-                    if(!cbind)
-                        break;
-                } else {
-                    //list all sub commands
-                    int commandlen = sprintf(command, "%s ", parent_bind->cmd);
-                    char subcommands[MAXLEN];
-                    int subcompos = 0;
-                    for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
-                        if(cbind->botid == client->botid && (cbind->botid || cbind->clientid == client->clientid) && stricmplen(cbind->cmd, command, commandlen) == 0) {
-                            subcompos += sprintf(subcommands + subcompos, (subcompos ? ", %s" : "%s"), cbind->cmd + commandlen);
-                        }
-                    }
-                    reply(tmp_text_client, user, "MODCMD_SUBCOMMANDS", parent_bind->cmd, (subcompos ? subcommands : "\1dnone\1d"));
-                    break;
-                }
+                cbind = modcmd_linker_command(client, user, cbind, bind_index, &args);
+                if(cbind == NULL) break;
             }
             if(statistics_enabled)
                 statistics_commands++;
@@ -242,14 +252,6 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
                 }
             }
             argv = arga;
-            if(argc != 0 && argv[0][0] == '#' && !(BIND_FLAGS(cbind) & CMDFLAG_CHAN_PARAM)) {
-                struct ChanNode *chan2 = getChanByName(argv[0]);
-                if(chan2) {
-                    argv += 1;
-                    argc -= 1;
-                    chan = chan2;
-                }
-            }
             if(cbind->paramcount) {
                 //userdefined parameters...
                 args_buffer = malloc(MAXLEN * 2 * sizeof(*args_buffer));
@@ -330,6 +332,14 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
                 argv = uargs;
                 argc = uargc;
             }
+            if(argc != 0 && argv[0][0] == '#' && !(BIND_FLAGS(cbind) & CMDFLAG_CHAN_PARAM)) {
+                struct ChanNode *chan2 = getChanByName(argv[0]);
+                if(chan2) {
+                    argv += 1;
+                    argc -= 1;
+                    chan = chan2;
+                }
+            }
             if(argc < cbind->func->paramcount) {
                 reply(tmp_text_client, user, "MODCMD_LESS_PARAM_COUNT");
                 break;
@@ -364,7 +374,7 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
             break;
         }
     }
-    if(!found_cmd && !sent_chan)
+    if(!found_cmd && !sent_chan && !(client->flags & SOCKET_FLAG_SILENT))
         reply(get_botwise_prefered_bot(client->botid, (client->botid == 0 ? client->clientid : 0)), user, "MODCMD_UNKNOWN", message);
     free(message);
     if(args_buffer)
@@ -398,8 +408,12 @@ static void handle_command_async(struct ClientSocket *client, struct UserNode *u
             requested_uaccess = 1;
             uaccess = getChannelAccess(user, chan);
             if(!uaccess) {
-                reply(tmp_text_client, user, "MODCMD_CROSSCHAN", chan->name);
-                return;
+                if(isGodMode(user)) {
+                    eventflags |= CMDFLAG_OPLOG;
+                } else {
+                    reply(tmp_text_client, user, "MODCMD_CROSSCHAN", chan->name);
+                    return;
+                }
             }
         }
     }