summaryrefslogtreecommitdiff
path: root/src/command_parse.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-11-04 20:35:30 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-11-04 20:35:30 +0000
commit8d57be001c39936b6851115e3f1df3df1fefda83 (patch)
tree2f130bc068939c73c94ba604a568b5780e9890ed /src/command_parse.cpp
parentf97f171c491a27de2c70f332ed747417d9d4e1c0 (diff)
Smart voodoo to weed out duplicates in a comma seperated list for LoopCall. voooodooo!
Thanks for the suggestion of using std::map, w00tie :) git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5647 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/command_parse.cpp')
-rw-r--r--src/command_parse.cpp44
1 files changed, 31 insertions, 13 deletions
diff --git a/src/command_parse.cpp b/src/command_parse.cpp
index 10f760e40..dcdff1b43 100644
--- a/src/command_parse.cpp
+++ b/src/command_parse.cpp
@@ -210,6 +210,12 @@ 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<std::string, bool> dupes;
+
/* Create two lists, one for channel names, one for keys
*/
irc::commasepstream items1(parameters[splithere]);
@@ -223,17 +229,22 @@ int CommandParser::LoopCall(userrec* user, command_t* CommandObj, const char** p
*/
while (((item = items1.GetToken()) != "") && (max++ < ServerInstance->Config->MaxTargets))
{
- const char* new_parameters[127];
+ if (dupes.find(item) == dupes.end())
+ {
+ const char* new_parameters[127];
- for (int t = 0; (t < pcnt) && (t < 127); t++)
- new_parameters[t] = parameters[t];
+ for (int t = 0; (t < pcnt) && (t < 127); t++)
+ new_parameters[t] = parameters[t];
- std::string extrastuff = items2.GetToken();
+ std::string extrastuff = items2.GetToken();
- new_parameters[splithere] = item.c_str();
- new_parameters[extra] = extrastuff.c_str();
+ new_parameters[splithere] = item.c_str();
+ new_parameters[extra] = extrastuff.c_str();
- CommandObj->Handle(new_parameters,pcnt,user);
+ CommandObj->Handle(new_parameters,pcnt,user);
+
+ dupes[item] = true;
+ }
}
return 1;
}
@@ -246,6 +257,8 @@ int CommandParser::LoopCall(userrec* user, command_t* CommandObj, const char** p
if (!strchr(parameters[splithere],','))
return 0;
+ std::map<std::string, bool> dupes;
+
/* Only one commasepstream here */
ServerInstance->Log(DEBUG,"Splitting '%s'",parameters[splithere]);
irc::commasepstream items1(parameters[splithere]);
@@ -258,15 +271,20 @@ int CommandParser::LoopCall(userrec* user, command_t* CommandObj, const char** p
*/
while (((item = items1.GetToken()) != "") && (max++ < ServerInstance->Config->MaxTargets))
{
- const char* new_parameters[127];
+ if (dupes.find(item) == dupes.end())
+ {
+ const char* new_parameters[127];
- for (int t = 0; (t < pcnt) && (t < 127); t++)
- new_parameters[t] = parameters[t];
+ for (int t = 0; (t < pcnt) && (t < 127); t++)
+ new_parameters[t] = parameters[t];
- new_parameters[splithere] = item.c_str();
+ new_parameters[splithere] = item.c_str();
- parameters[splithere] = item.c_str();
- CommandObj->Handle(new_parameters,pcnt,user);
+ parameters[splithere] = item.c_str();
+ CommandObj->Handle(new_parameters,pcnt,user);
+
+ dupes[item] = 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