From c5f46740e0362d66c6ae976300d2e039474fa3e5 Mon Sep 17 00:00:00 2001 From: pk910 Date: Mon, 24 Sep 2012 00:23:46 +0200 Subject: [PATCH] added SUB_LINKER command flag to add a quiet sub command linker --- src/modcmd.c | 31 ++++++++++++++++++-- src/modcmd.h | 33 +++++++++++----------- src/modules/global.mod/cmd_global_modcmd.c | 1 + 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/modcmd.c b/src/modcmd.c index f53a3c2..e19d261 100644 --- a/src/modcmd.c +++ b/src/modcmd.c @@ -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++; diff --git a/src/modcmd.h b/src/modcmd.h index 9f39e1f..214a096 100644 --- a/src/modcmd.h +++ b/src/modcmd.h @@ -20,22 +20,23 @@ #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; diff --git a/src/modules/global.mod/cmd_global_modcmd.c b/src/modules/global.mod/cmd_global_modcmd.c index 1aaa040..c1066ec 100644 --- a/src/modules/global.mod/cmd_global_modcmd.c +++ b/src/modules/global.mod/cmd_global_modcmd.c @@ -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} }; -- 2.20.1