diff options
-rw-r--r-- | conf/inspircd.conf.example | 10 | ||||
-rw-r--r-- | docs/inspircd.conf.example | 10 | ||||
-rw-r--r-- | src/command_parse.cpp | 78 | ||||
-rw-r--r-- | src/modules/m_alias.cpp | 31 |
4 files changed, 68 insertions, 61 deletions
diff --git a/conf/inspircd.conf.example b/conf/inspircd.conf.example index ac48be1ee..7da7a1596 100644 --- a/conf/inspircd.conf.example +++ b/conf/inspircd.conf.example @@ -710,7 +710,7 @@ # must be at the start of the line to trigger the # # alias. May contain spaces, but case insensitive. # # replace - The text to replace 'text' with. Usually this # -# will be "PRIVMSG ServiceName :" or similar. # +# will be "PRIVMSG ServiceName" or similar. # # requires - If you provide a value for 'requires' this means # # the given nickname MUST be online for the alias # # to successfully trigger. If they are not, then # @@ -724,10 +724,10 @@ # of a user trying to impersonate a service. # # # -<alias text="NICKSERV" replace="PRIVMSG NickServ :" requires="NickServ" uline="yes"> -<alias text="CHANSERV" replace="PRIVMSG ChanServ :" requires="ChanServ" uline="yes"> -<alias text="NS" replace="PRIVMSG NickServ :" requires="NickServ" uline="yes"> -<alias text="CS" replace="PRIVMSG ChanServ :" requires="ChanServ" uline="yes"> +<alias text="NICKSERV" replace="PRIVMSG NickServ" requires="NickServ" uline="yes"> +<alias text="CHANSERV" replace="PRIVMSG ChanServ" requires="ChanServ" uline="yes"> +<alias text="NS" replace="PRIVMSG NickServ" requires="NickServ" uline="yes"> +<alias text="CS" replace="PRIVMSG ChanServ" requires="ChanServ" uline="yes"> #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#- YAWN -#-#-#-#-#-#-#-#-#-#-#-#-#-#-# # # diff --git a/docs/inspircd.conf.example b/docs/inspircd.conf.example index ac48be1ee..7da7a1596 100644 --- a/docs/inspircd.conf.example +++ b/docs/inspircd.conf.example @@ -710,7 +710,7 @@ # must be at the start of the line to trigger the # # alias. May contain spaces, but case insensitive. # # replace - The text to replace 'text' with. Usually this # -# will be "PRIVMSG ServiceName :" or similar. # +# will be "PRIVMSG ServiceName" or similar. # # requires - If you provide a value for 'requires' this means # # the given nickname MUST be online for the alias # # to successfully trigger. If they are not, then # @@ -724,10 +724,10 @@ # of a user trying to impersonate a service. # # # -<alias text="NICKSERV" replace="PRIVMSG NickServ :" requires="NickServ" uline="yes"> -<alias text="CHANSERV" replace="PRIVMSG ChanServ :" requires="ChanServ" uline="yes"> -<alias text="NS" replace="PRIVMSG NickServ :" requires="NickServ" uline="yes"> -<alias text="CS" replace="PRIVMSG ChanServ :" requires="ChanServ" uline="yes"> +<alias text="NICKSERV" replace="PRIVMSG NickServ" requires="NickServ" uline="yes"> +<alias text="CHANSERV" replace="PRIVMSG ChanServ" requires="ChanServ" uline="yes"> +<alias text="NS" replace="PRIVMSG NickServ" requires="NickServ" uline="yes"> +<alias text="CS" replace="PRIVMSG ChanServ" requires="ChanServ" uline="yes"> #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#- YAWN -#-#-#-#-#-#-#-#-#-#-#-#-#-#-# # # diff --git a/src/command_parse.cpp b/src/command_parse.cpp index 7c26ffe61..1f17e4735 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -377,9 +377,10 @@ void CommandParser::ProcessCommand(userrec *user, char* cmd) } int total_params = 0; - if (strlen(cmd)>2) + unsigned int xl = strlen(cmd); + if (xl > 2) { - for (unsigned int q = 0; q < strlen(cmd)-1; q++) + for (unsigned int q = 0; q < xl - 1; q++) { if ((cmd[q] == ' ') && (cmd[q+1] == ':')) { @@ -426,7 +427,8 @@ void CommandParser::ProcessCommand(userrec *user, char* cmd) items = 0; command_p[0] = NULL; parameters = NULL; - for (unsigned int i = 0; i <= strlen(cmd); i++) + unsigned int tl = strlen(cmd); + for (unsigned int i = 0; i <= tl; i++) { cmd[i] = toupper(cmd[i]); } @@ -434,10 +436,12 @@ void CommandParser::ProcessCommand(userrec *user, char* cmd) } else { - strcpy(cmd,""); + *cmd = 0; j = 0; + + unsigned int vl = strlen(temp); /* strip out extraneous linefeeds through mirc's crappy pasting (thanks Craig) */ - for (unsigned int i = 0; i < strlen(temp); i++) + for (unsigned int i = 0; i < vl; i++) { if ((temp[i] != 10) && (temp[i] != 13) && (temp[i] != 0) && (temp[i] != 7)) { @@ -447,11 +451,14 @@ void CommandParser::ProcessCommand(userrec *user, char* cmd) } /* split the full string into a command plus parameters */ parameters = p; - strcpy(p," "); + p[0] = ' '; + p[1] = 0; + command = cmd; if (strchr(cmd,' ')) { - for (unsigned int i = 0; i <= strlen(cmd); i++) + unsigned int cl = strlen(cmd); + for (unsigned int i = 0; i <= cl; i++) { /* capitalise the command ONLY, leave params intact */ cmd[i] = toupper(cmd[i]); @@ -482,13 +489,13 @@ void CommandParser::ProcessCommand(userrec *user, char* cmd) return; } - for (unsigned int x = 0; x < strlen(command); x++) + for (char* x = command; *x; x++) { - if (((command[x] < 'A') || (command[x] > 'Z')) && (command[x] != '.')) + if (((*x < 'A') || (*x > 'Z')) && (*x != '.')) { - if (((command[x] < '0') || (command[x]> '9')) && (command[x] != '-')) + if (((*x < '0') || (*x> '9')) && (*x != '-')) { - if (strchr("@!\"$%^&*(){}[]_=+;:'#~,<>/?\\|`",command[x])) + if (strchr("@!\"$%^&*(){}[]_=+;:'#~,<>/?\\|`",*x)) { ServerInstance->stats->statsUnknown++; WriteServ(user->fd,"421 %s %s :Unknown command",user->nick,command); @@ -499,37 +506,40 @@ void CommandParser::ProcessCommand(userrec *user, char* cmd) } std::string xcommand = command; + + /* Tweak by brain - why was this INSIDE the mainloop? */ + if (parameters) + { + if (parameters[0]) + { + items = this->ProcessParameters(command_p,parameters); + } + else + { + items = 0; + command_p[0] = NULL; + } + } + else + { + items = 0; + command_p[0] = NULL; + } + + int MOD_RESULT = 0; + FOREACH_RESULT(OnPreCommand(command,command_p,items,user,false)); + if (MOD_RESULT == 1) { + return; + } + for (unsigned int i = 0; i != cmdlist.size(); i++) { if ((xcommand.length() >= cmdlist[i]->command.length()) && (xcommand == cmdlist[i]->command)) { - if (parameters) - { - if (parameters[0]) - { - items = this->ProcessParameters(command_p,parameters); - } - else - { - items = 0; - command_p[0] = NULL; - } - } - else - { - items = 0; - command_p[0] = NULL; - } - if (user) { /* activity resets the ping pending timer */ user->nping = TIME + user->pingmax; - int MOD_RESULT = 0; - FOREACH_RESULT(OnPreCommand(command,command_p,items,user,false)); - if (MOD_RESULT == 1) { - return; - } if ((items) < cmdlist[i]->min_params) { log(DEBUG,"not enough parameters: %s %s",user->nick,command); diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index a0d361e78..59492c828 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -95,7 +95,6 @@ class ModuleAlias : public Module for (unsigned int i = 0; i < Aliases.size(); i++) { - log(DEBUG,"Check against alias %s: %s",Aliases[i].text.c_str(),c.c_str()); if (Aliases[i].text == c) { if (Aliases[i].requires != "") @@ -118,28 +117,26 @@ class ModuleAlias : public Module } } - std::stringstream stuff(Aliases[i].replace_with); - for (int j = 1; j < pcnt; j++) + std::string n = ""; + for (int j = 0; j < pcnt; j++) { if (j) - stuff << " "; - stuff << parameters[j]; - } - - std::vector<std::string> items; - while (!stuff.eof()) - { - std::string data; - stuff >> data; - items.push_back(data); + n = n + " "; + n = n + parameters[j]; } + /* Final param now in n as one string */ + std::stringstream stuff(Aliases[i].replace_with); - char* para[127]; + std::string cmd = ""; + std::string target = ""; + stuff >> cmd; + stuff >> target; - for (unsigned int j = 1; j < items.size(); j++) - para[j-1] = (char*)items[j].c_str(); + char* para[2]; + para[0] = (char*)target.c_str(); + para[1] = (char*)n.c_str(); - Srv->CallCommandHandler(items[0],para,items.size()-1,user); + Srv->CallCommandHandler(cmd,para,2,user); return 1; } } |