]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/mode.cpp
Include explicit parameter list in ProtocolInterface::SendMode
[user/henk/code/inspircd.git] / src / mode.cpp
index bdec78737d87aa9ae0958d5993d09c3050b86997..40bd7096371679ce3b95a884296f30ab757da0e5 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
  * See: http://www.inspircd.org/wiki/index.php/Credits
  *
  * This program is free but copyrighted software; see
@@ -52,8 +52,8 @@
 /* +s (server notice masks) */
 #include "modes/umode_s.h"
 
-ModeHandler::ModeHandler(InspIRCd* Instance, char modeletter, int parameters_on, int parameters_off, bool listmode, ModeType type, bool operonly, char mprefix, char prefixrequired)
-       : ServerInstance(Instance), mode(modeletter), n_params_on(parameters_on), n_params_off(parameters_off), list(listmode), m_type(type), oper(operonly), prefix(mprefix), count(0), prefixneeded(prefixrequired)
+ModeHandler::ModeHandler(InspIRCd* Instance, char modeletter, int parameters_on, int parameters_off, bool listmode, ModeType type, bool operonly, char mprefix, char prefixrequired, TranslateType translate)
+       : ServerInstance(Instance), mode(modeletter), n_params_on(parameters_on), n_params_off(parameters_off), list(listmode), m_type(type), m_paramtype(translate), oper(operonly), prefix(mprefix), count(0), prefixneeded(prefixrequired)
 {
 }
 
@@ -97,6 +97,11 @@ ModeType ModeHandler::GetModeType()
        return m_type;
 }
 
+TranslateType ModeHandler::GetTranslateType()
+{
+       return m_paramtype;
+}
+
 bool ModeHandler::NeedsOper()
 {
        return oper;
@@ -366,6 +371,8 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
        User* targetuser  = ServerInstance->FindNick(parameters[0]);
 
        LastParse.clear();
+       LastParseParams.clear();
+       LastParseTranslate.clear();
 
        /* Special case for displaying the list for listmodes,
         * e.g. MODE #chan b, or MODE #chan +b without a parameter
@@ -378,7 +385,7 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
                seq++;
 
                mask = MASK_CHANNEL;
-               
+
                while (mode && *mode)
                {
                        unsigned char mletter = *mode;
@@ -388,7 +395,7 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
                                mode++;
                                continue;
                        }
-                       
+
                        /* Ensure the user doesnt request the same mode twice,
                         * so they cant flood themselves off out of idiocy.
                         */
@@ -432,7 +439,7 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
                                for(ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++)
                                {
                                        std::string dummyparam;
-                                       
+
                                        if (!((*watchers)->BeforeMode(user, NULL, targetchannel, dummyparam, true, MODETYPE_CHANNEL)))
                                                display = false;
                                }
@@ -504,6 +511,7 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
                unsigned int parameter_counter = 2; /* Index of first parameter */
                unsigned int parameter_count = 0;
                bool last_successful_state_change = false;
+               LastParseTranslate.push_back(TR_TEXT);
 
                /* A mode sequence that doesnt start with + or -. Assume +. - Thanks for the suggestion spike (bug#132) */
                if ((*mode_sequence.begin() != '+') && (*mode_sequence.begin() != '-'))
@@ -605,7 +613,7 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
                                                                         */
                                                                        if (needed && !prefixmode)
                                                                                prefixmode = FindPrefix('%');
-                                               
+
                                                                        unsigned int neededrank = prefixmode->GetPrefixRank();
                                                                        /* Compare our rank on the channel against the rank of the required prefix,
                                                                         * allow if >= ours. Because mIRC and xchat throw a tizz if the modes shown
@@ -626,7 +634,7 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
                                                        }
 
                                                        bool had_parameter = !parameter.empty();
-                                                               
+
                                                        for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++)
                                                        {
                                                                if ((*watchers)->BeforeMode(user, targetuser, targetchannel, parameter, adding, type, servermode) == false)
@@ -700,7 +708,7 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
                                                                                output_sequence.append(adding ? "+" : "-");
                                                                        last_successful_state_change = adding;
                                                                }
-                                                               
+
                                                                /* Add the mode letter */
                                                                output_sequence.push_back(modechar);
 
@@ -710,6 +718,8 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
                                                                if ((modehandlers[handler_id]->GetNumParams(adding)) && (!parameter.empty()))
                                                                {
                                                                        parameter_list << " " << parameter;
+                                                                       LastParseParams.push_back(parameter);
+                                                                       LastParseTranslate.push_back(modehandlers[handler_id]->GetTranslateType());
                                                                        parameter_count++;
                                                                        /* Does this mode have a prefix? */
                                                                        if (modehandlers[handler_id]->GetPrefix() && targetchannel)
@@ -765,16 +775,17 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
                        }
                        else
                        {
+                               LastParseParams.push_front(output_sequence);
                                if (type == MODETYPE_CHANNEL)
                                {
                                        targetchannel->WriteChannel(user, "MODE %s %s%s", targetchannel->name.c_str(), output_sequence.c_str(), parameter_list.str().c_str());
-                                       FOREACH_MOD(I_OnMode,OnMode(user, targetchannel, TYPE_CHANNEL, output_sequence + parameter_list.str()));
+                                       FOREACH_MOD(I_OnMode,OnMode(user, targetchannel, TYPE_CHANNEL, LastParseParams, LastParseTranslate));
                                        this->LastParse = targetchannel->name;
                                }
                                else
                                {
                                        user->WriteTo(targetuser, "MODE %s %s%s", targetuser->nick.c_str(), output_sequence.c_str(), parameter_list.str().c_str());
-                                       FOREACH_MOD(I_OnMode,OnMode(user, targetuser, TYPE_USER, output_sequence + parameter_list.str()));
+                                       FOREACH_MOD(I_OnMode,OnMode(user, targetuser, TYPE_USER, LastParseParams, LastParseTranslate));
                                        this->LastParse = targetuser->nick;
                                }
                        }
@@ -931,9 +942,6 @@ std::string ModeParser::ChannelModeList()
 
        for (unsigned char mode = 'A'; mode <= 'z'; mode++)
        {
-               if ((!ServerInstance->Config->AllowHalfop) && (mode == 'h'))
-                       continue;
-
                unsigned char pos = (mode-65) | MASK_CHANNEL;
 
                if (modehandlers[pos])
@@ -950,9 +958,6 @@ std::string ModeParser::ParaModeList()
 
        for (unsigned char mode = 'A'; mode <= 'z'; mode++)
        {
-               if ((!ServerInstance->Config->AllowHalfop) && (mode == 'h'))
-                       continue;
-
                unsigned char pos = (mode-65) | MASK_CHANNEL;
 
                if ((modehandlers[pos]) && (modehandlers[pos]->GetNumParams(true)))
@@ -1010,7 +1015,7 @@ std::string ModeParser::ModeString(User* user, Channel* channel, bool nick_suffi
                return types;
 }
 
-std::string ModeParser::ChanModes()
+std::string ModeParser::GiveModeList(ModeMasks m)
 {
        std::string type1;      /* Listmodes EXCEPT those with a prefix */
        std::string type2;      /* Modes that take a param when adding or removing */
@@ -1019,13 +1024,10 @@ std::string ModeParser::ChanModes()
 
        for (unsigned char mode = 'A'; mode <= 'z'; mode++)
        {
-               if ((!ServerInstance->Config->AllowHalfop) && (mode == 'h'))
-                       continue;
-
-               unsigned char pos = (mode-65) | MASK_CHANNEL;
+               unsigned char pos = (mode-65) | m;
                 /* One parameter when adding */
                if (modehandlers[pos])
-               {       
+               {
                        if (modehandlers[pos]->GetNumParams(true))
                        {
                                if ((modehandlers[pos]->IsListMode()) && (!modehandlers[pos]->GetPrefix()))
@@ -1055,14 +1057,13 @@ std::string ModeParser::ChanModes()
                                type4 += modehandlers[pos]->GetModeChar();
                        }
                }
-                        
        }
 
        return type1 + "," + type2 + "," + type3 + "," + type4;
 }
 
 bool ModeParser::PrefixComparison(prefixtype one, prefixtype two)
-{       
+{
        return one.second > two.second;
 }
 
@@ -1075,9 +1076,6 @@ std::string ModeParser::BuildPrefixes()
 
        for (unsigned char mode = 'A'; mode <= 'z'; mode++)
        {
-               if ((!ServerInstance->Config->AllowHalfop) && (mode == 'h'))
-                       continue;
-
                unsigned char pos = (mode-65) | MASK_CHANNEL;
 
                if ((modehandlers[pos]) && (modehandlers[pos]->GetPrefix()))