]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/command_parse.cpp
Whoops, make /stats s work
[user/henk/code/inspircd.git] / src / command_parse.cpp
index a158ff6a36be9ac17d8e2def2f2ec91465988758..b67b269d20bd42e3ec115a5a510eaeec4a6f8a9c 100644 (file)
@@ -24,7 +24,6 @@
 #include "wildcard.h"
 #include "xline.h"
 #include "socketengine.h"
-#include "userprocess.h"
 #include "socket.h"
 #include "command_parse.h"
 
@@ -211,11 +210,17 @@ int CommandParser::LoopCall(userrec* user, command_t* CommandObj, const char** p
        if (!strchr(parameters[splithere],','))
                return 0;
 
+       /** Some lame ircds will weed out dupes using some shitty O(n^2) algorithm.
+        * By using std::map (thanks for the idea w00t) we can cut this down a ton.
+        * ...VOOODOOOO!
+        */
+       std::map<irc::string, bool> dupes;
+
        /* Create two lists, one for channel names, one for keys
         */
        irc::commasepstream items1(parameters[splithere]);
        irc::commasepstream items2(parameters[extra]);
-       std::string item = "";
+       std::string item = "*";
        unsigned int max = 0;
 
        /* Attempt to iterate these lists and call the command objech
@@ -224,10 +229,22 @@ int CommandParser::LoopCall(userrec* user, command_t* CommandObj, const char** p
         */
        while (((item = items1.GetToken()) != "") && (max++ < ServerInstance->Config->MaxTargets))
        {
-               std::string extrastuff = items2.GetToken();
-               parameters[splithere] = item.c_str();
-               parameters[extra] = extrastuff.c_str();
-               CommandObj->Handle(parameters,pcnt,user);
+               if (dupes.find(item.c_str()) == dupes.end())
+               {
+                       const char* new_parameters[127];
+
+                       for (int t = 0; (t < pcnt) && (t < 127); t++)
+                               new_parameters[t] = parameters[t];
+
+                       std::string extrastuff = items2.GetToken();
+
+                       new_parameters[splithere] = item.c_str();
+                       new_parameters[extra] = extrastuff.c_str();
+
+                       CommandObj->Handle(new_parameters,pcnt,user);
+
+                       dupes[item.c_str()] = true;
+               }
        }
        return 1;
 }
@@ -240,9 +257,12 @@ int CommandParser::LoopCall(userrec* user, command_t* CommandObj, const char** p
        if (!strchr(parameters[splithere],','))
                return 0;
 
+       std::map<irc::string, bool> dupes;
+
        /* Only one commasepstream here */
+       ServerInstance->Log(DEBUG,"Splitting '%s'",parameters[splithere]);
        irc::commasepstream items1(parameters[splithere]);
-       std::string item = "";
+       std::string item = "*";
        unsigned int max = 0;
 
        /* Parse the commasepstream until there are no tokens remaining.
@@ -251,8 +271,20 @@ int CommandParser::LoopCall(userrec* user, command_t* CommandObj, const char** p
         */
        while (((item = items1.GetToken()) != "") && (max++ < ServerInstance->Config->MaxTargets))
        {
-               parameters[splithere] = item.c_str();
-               CommandObj->Handle(parameters,pcnt,user);
+               if (dupes.find(item.c_str()) == dupes.end())
+               {
+                       const char* new_parameters[127];
+
+                       for (int t = 0; (t < pcnt) && (t < 127); t++)
+                               new_parameters[t] = parameters[t];
+
+                       new_parameters[splithere] = item.c_str();
+
+                       parameters[splithere] = item.c_str();
+                       CommandObj->Handle(new_parameters,pcnt,user);
+
+                       dupes[item.c_str()] = true;
+               }
        }
        /* By returning 1 we tell our caller that nothing is to be done,
         * as all the previous calls handled the data. This makes the parent
@@ -282,6 +314,15 @@ bool CommandParser::IsValidCommand(const std::string &commandname, int pcnt, use
        return false;
 }
 
+command_t* CommandParser::GetHandler(const std::string &commandname)
+{
+       nspace::hash_map<std::string,command_t*>::iterator n = cmdlist.find(commandname);
+       if (n != cmdlist.end())
+               return n->second;
+
+       return NULL;
+}
+
 // calls a handler function for a command
 
 CmdResult CommandParser::CallHandler(const std::string &commandname,const char** parameters, int pcnt, userrec *user)
@@ -327,7 +368,7 @@ void CommandParser::ProcessCommand(userrec *user, std::string &cmd)
        std::transform(command.begin(), command.end(), command.begin(), ::toupper);
                
        int MOD_RESULT = 0;
-       FOREACH_RESULT(I_OnPreCommand,OnPreCommand(command,command_p,items,user,false));
+       FOREACH_RESULT(I_OnPreCommand,OnPreCommand(command,command_p,items,user,false,cmd));
        if (MOD_RESULT == 1) {
                return;
        }
@@ -374,7 +415,7 @@ void CommandParser::ProcessCommand(userrec *user, std::string &cmd)
                                cm->second->total_bytes += cmd.length();
 
                                int MOD_RESULT = 0;
-                               FOREACH_RESULT(I_OnPreCommand,OnPreCommand(command,command_p,items,user,true));
+                               FOREACH_RESULT(I_OnPreCommand,OnPreCommand(command,command_p,items,user,true,cmd));
                                if (MOD_RESULT == 1)
                                        return;
 
@@ -387,7 +428,7 @@ void CommandParser::ProcessCommand(userrec *user, std::string &cmd)
 
                                if (result != CMD_USER_DELETED)
                                {
-                                       FOREACH_MOD(I_OnPostCommand,OnPostCommand(command, command_p, items, user, result));
+                                       FOREACH_MOD(I_OnPostCommand,OnPostCommand(command, command_p, items, user, result,cmd));
                                }
                                return;
                        }
@@ -518,7 +559,7 @@ bool CommandParser::ReloadCommand(const char* cmd)
                dlclose(command->second);
                RFCCommands.erase(command);
 
-               sprintf(filename, "cmd_%s.so", commandname);
+               snprintf(filename, MAXBUF, "cmd_%s.so", commandname);
                this->LoadCommand(filename);
 
                return true;