From: pk910 Date: Mon, 3 Oct 2011 17:34:04 +0000 (+0200) Subject: fixed modcmd parameter handling X-Git-Tag: v5.3~330 X-Git-Url: http://git.pk910.de/?p=NeonServV5.git;a=commitdiff_plain;h=ea3d053ce9a94ec944710faa11de948dc48b5d76 fixed modcmd parameter handling --- diff --git a/src/cmd_neonserv_command.c b/src/cmd_neonserv_command.c index e3e47a2..3f1d214 100644 --- a/src/cmd_neonserv_command.c +++ b/src/cmd_neonserv_command.c @@ -33,7 +33,15 @@ CMD_BIND(neonserv_cmd_command) { return; } ident = argv[0]; - reply(getTextBot(), user, "NS_COMMAND_BINDING", cbind->cmd, cbind->func->name, (cbind->parameters ? cbind->parameters : "")); + char parameters[MAXLEN]; + if(cbind->paramcount) { + int i, parampos = 0; + for(i = 0; i < cbind->paramcount; i++) { + parampos += sprintf(parameters + parampos, (i ? " %s" : "%s"), cbind->parameters[i]); + } + } else + parameters[0] = '\0'; + reply(getTextBot(), user, "NS_COMMAND_BINDING", cbind->cmd, cbind->func->name, parameters); if(chan) reply(getTextBot(), user, "NS_COMMAND_ACCESS", neonserv_cmd_command_chanaccess(cbind, chan), neonserv_cmd_command_operaccess(cbind)); printf_mysql_query("SELECT `user_lang` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth)); diff --git a/src/modcmd.c b/src/modcmd.c index a80ccca..ac3e400 100644 --- a/src/modcmd.c +++ b/src/modcmd.c @@ -168,15 +168,15 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s chan = chan2; } } - if(cbind->parameters) { + if(cbind->paramcount) { //userdefined parameters... char *uargs[MAXNUMPARAMS]; int uargc = 0; - char *a,*b = cbind->parameters; + char *b; + int i; int allargs, argi; - do { - a = strstr(b, " "); - if(a) *a = '\0'; + for(i = 0; i < cbind->paramcount; i++) { + b = cbind->parameters[i]; if(b[0] == '%') { b++; if(b[strlen(b)-1] == '-') { @@ -204,11 +204,7 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s } else { uargs[uargc++] = b; } - if(a) { - *a = ' '; - b = a+1; - } - } while(a); + } argv = uargs; argc = uargc; } @@ -488,7 +484,7 @@ int bind_cmd_to_function(int botid, char *cmd, struct cmd_function *func) { cbind->botid = botid; cbind->cmd = strdup(cmd); cbind->func = func; - cbind->parameters = NULL; + cbind->paramcount = 0; cbind->global_access = 0; cbind->channel_access = NULL; cbind->flags = 0; @@ -519,7 +515,7 @@ int bind_cmd_to_command(int botid, char *cmd, char *func) { cbind->cmd = strdup(cmd); cbind->func = cmdfunc; cbind->next = cmd_binds[bind_index]; - cbind->parameters = NULL; + cbind->paramcount = 0; cbind->global_access = 0; cbind->channel_access = NULL; cbind->flags = 0; @@ -537,8 +533,11 @@ int unbind_cmd(int botid, char *cmd) { else cmd_binds[bind_index] = cbind->next; free(cbind->cmd); - if(cbind->parameters) - free(cbind->parameters); + if(cbind->paramcount) { + int i; + for(i = 0; i < cbind->paramcount; i++) + free(cbind->parameters[i]); + } free(cbind); return 1; } else @@ -574,8 +573,11 @@ void free_modcmd() { for(cbind = cmd_binds[i]; cbind; cbind = next) { next = cbind->next; free(cbind->cmd); - if(cbind->parameters) - free(cbind->parameters); + 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); @@ -602,9 +604,19 @@ void bind_set_parameters(int botid, char *cmd, char *parameters) { struct cmd_binding *cbind; for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) { if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0) { - if(cbind->parameters) - free(cbind->parameters); - cbind->parameters = strdup(parameters); + if(cbind->paramcount) { + int i; + for(i = 0; i < cbind->paramcount; i++) + 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); return; } } diff --git a/src/modcmd.h b/src/modcmd.h index e33a54a..7df181c 100644 --- a/src/modcmd.h +++ b/src/modcmd.h @@ -18,6 +18,8 @@ #define _modcmd_h #include "main.h" +#define MAXPARAMETERS 50 + #define CMDFLAG_REQUIRE_CHAN 0x0001 #define CMDFLAG_REQUIRE_AUTH 0x0002 #define CMDFLAG_REQUIRE_GOD 0x0004 @@ -55,7 +57,8 @@ struct cmd_binding { int botid; struct cmd_function *func; unsigned int flags; - char *parameters; + char *parameters[MAXPARAMETERS]; + int paramcount; int global_access; char *channel_access;