]> 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 8722a2145599c9419f0d1ae16b86f0bf9443f218..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)