X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2Fmodcmd.c;h=3f51761a0f30bbf5e3e47abdc3b82027fcffe0ba;hb=c575e458c6257e75b97884847143b20965a5dfda;hp=ac3e400fc13e50758c2b04841fa9f50168e24abd;hpb=ea3d053ce9a94ec944710faa11de948dc48b5d76;p=NeonServV5.git diff --git a/src/modcmd.c b/src/modcmd.c index ac3e400..3f51761 100644 --- a/src/modcmd.c +++ b/src/modcmd.c @@ -1,4 +1,4 @@ -/* modcmd.c - NeonServ v5.0 +/* modcmd.c - NeonServ v5.2 * Copyright (C) 2011 Philipp Kreil (pk910) * * This program is free software: you can redistribute it and/or modify @@ -41,7 +41,7 @@ struct command_check_user_cache { struct ChanNode *chan, *sent_chan; char **argv; int argc; - char *message; + char *message, *args_buffer; struct cmd_binding *cbind; }; @@ -116,6 +116,9 @@ static USERAUTH_CALLBACK(command_checked_auth) { tmp_text_client = cache->textclient; handle_command_async(cache->client, user, cache->chan, cache->sent_chan, cache->cbind, cache->argv, cache->argc); free(cache->message); + if(cache->args_buffer) + free(cache->args_buffer); + free(cache->argv); free(cache); } @@ -134,6 +137,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_buffer = NULL; //we need this to save a possible pointer to a allocation we need to free if(args) { *args = '\0'; args++; @@ -170,6 +174,8 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s } if(cbind->paramcount) { //userdefined parameters... + args_buffer = malloc(MAXLEN * 2 * sizeof(*args_buffer)); + int args_pos = 0; char *uargs[MAXNUMPARAMS]; int uargc = 0; char *b; @@ -180,29 +186,53 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s if(b[0] == '%') { b++; if(b[strlen(b)-1] == '-') { + allargs = strlen(b)-1; + b[allargs] = '\0'; + argi = atoi(b); + b[allargs] = '-'; allargs = 1; - b[strlen(b)-1] = '\0'; + } else if(b[strlen(b)-1] == '+') { + allargs = strlen(b)-1; + b[allargs] = '\0'; argi = atoi(b); - b[strlen(b)-1] = '-'; + b[allargs] = '+'; + allargs = 2; } else { allargs = 0; argi = atoi(b); } if(argi > 0) { if(argi <= argc) { - uargs[uargc++] = argv[argi-1]; - if(allargs) { - for(argi++; argi <= argc; argi++) - uargs[uargc++] = argv[argi-1]; + uargs[uargc++] = args_buffer + args_pos; + if(allargs == 0) { + args_pos += sprintf(args_buffer + args_pos, "%s", argv[argi-1]) + 1; + } else if(allargs == 1) { + args_pos += sprintf(args_buffer + args_pos, "%s", argv[argi-1]) + 1; + for(argi++; argi <= argc; argi++) { + uargs[uargc++] = args_buffer + args_pos; + args_pos += sprintf(args_buffer + args_pos, "%s", argv[argi-1]) + 1; + } + } else if(allargs == 2) { + for(;argi <= argc; argi++) { + args_pos += sprintf(args_buffer + args_pos, (allargs ? "%s" : " %s"), argv[argi-1]); + allargs = 0; + } + args_pos++; } + } else if((cbind->func->flags & CMDFLAG_EMPTY_ARGS)) { + uargs[uargc++] = args_buffer + args_pos; + args_buffer[args_pos++] = '\0'; } } else if(!strcmp(b, "c")) { - uargs[uargc++] = (chan ? chan->name : NULL); + uargs[uargc++] = args_buffer + args_pos; + args_pos += sprintf(args_buffer + args_pos, "%s", (chan ? chan->name : "")) + 1; } else if(!strcmp(b, "n")) { - uargs[uargc++] = user->nick; + uargs[uargc++] = args_buffer + args_pos; + args_pos += sprintf(args_buffer + args_pos, "%s", user->nick) + 1; } } else { - uargs[uargc++] = b; + uargs[uargc++] = args_buffer + args_pos; + args_pos += sprintf(args_buffer + args_pos, "%s", b) + 1; } } argv = uargs; @@ -232,6 +262,7 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s data->chan = chan; data->sent_chan = sent_chan; data->message = message; + data->args_buffer = args_buffer; data->cbind = cbind; data->textclient = tmp_text_client; get_userauth(user, command_checked_auth, data); @@ -242,6 +273,8 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s } } free(message); + if(args_buffer) + free(args_buffer); } static void handle_command_async(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct ChanNode *sent_chan, struct cmd_binding *cbind, char **argv, int argc) {