]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/command_parse.cpp
Forward-port: Fix an uninitialised variable in ConfigReader::GetError()
[user/henk/code/inspircd.git] / src / command_parse.cpp
index fd103908829c1e481abe73d24605bea743c7878e..3373f714f6330e566f52081f439388a89c44caa6 100644 (file)
@@ -287,10 +287,21 @@ bool CommandParser::ProcessCommand(User *user, std::string &cmd)
                if (MOD_RESULT == 1)
                        return true;
 
-               if (user->registered == REG_ALL)
-                       user->WriteNumeric(ERR_UNKNOWNCOMMAND, "%s %s :Unknown command",user->nick.c_str(),command.c_str());
-               ServerInstance->stats->statsUnknown++;
-               return true;
+               /*
+                * This double lookup is in case a module (abbreviation) wishes to change a command.
+                * Sure, the double lookup is a bit painful, but bear in mind this only happens for unknowns anyway.
+                *
+                * Thanks dz for making me actually understand why this is necessary!
+                * -- w00t
+                */
+               cm = cmdlist.find(command);
+               if (cm == cmdlist.end())
+               {
+                       if (user->registered == REG_ALL)
+                               user->WriteNumeric(ERR_UNKNOWNCOMMAND, "%s %s :Unknown command",user->nick.c_str(),command.c_str());
+                       ServerInstance->stats->statsUnknown++;
+                       return true;
+               }
        }
 
        if (cm->second->max_params && command_p.size() > cm->second->max_params)
@@ -330,6 +341,10 @@ bool CommandParser::ProcessCommand(User *user, std::string &cmd)
                command_p.push_back(lparam);
        }
 
+       /*
+        * We call OnPreCommand here seperately if the command exists, so the magic above can
+        * truncate to max_params if necessary. -- w00t
+        */
        int MOD_RESULT = 0;
        FOREACH_RESULT(I_OnPreCommand,OnPreCommand(command, command_p, user, false, cmd));
        if (MOD_RESULT == 1)
@@ -578,7 +593,13 @@ const char* CommandParser::LoadCommand(const char* name)
 
 void CommandParser::SetupCommandTable(User* user)
 {
-       RFCCommands.clear();
+       for (SharedObjectList::iterator command = RFCCommands.begin(); command != RFCCommands.end(); command++)
+       {
+               Command *cmdptr = cmdlist.find(command->first)->second;
+               cmdlist.erase(cmdlist.find(command->first));
+               RFCCommands.erase(command);
+               delete cmdptr;
+       }
 
        if (!user)
        {