]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/mode.cpp
Threadengine stuff
[user/henk/code/inspircd.git] / src / mode.cpp
index 085a5432646d063a2c9325c66dae75cc44aa4c9a..5a0cdbf1ee0a460c5766d1e5ef0005e55fc4a1e1 100644 (file)
@@ -119,7 +119,7 @@ char ModeHandler::GetModeChar()
        return mode;
 }
 
-ModeAction ModeHandler::OnModeChange(User*, User*, Channel*, std::string&, bool)
+ModeAction ModeHandler::OnModeChange(User*, User*, Channel*, std::string&, bool, bool)
 {
        return MODEACTION_DENY;
 }
@@ -167,12 +167,12 @@ ModeType ModeWatcher::GetModeType()
        return m_type;
 }
 
-bool ModeWatcher::BeforeMode(User*, User*, Channel*, std::string&, bool, ModeType)
+bool ModeWatcher::BeforeMode(User*, User*, Channel*, std::string&, bool, ModeType, bool)
 {
        return true;
 }
 
-void ModeWatcher::AfterMode(User*, User*, Channel*, const std::string&, bool, ModeType)
+void ModeWatcher::AfterMode(User*, User*, Channel*, const std::string&, bool, ModeType, bool)
 {
 }
 
@@ -289,7 +289,7 @@ void ModeParser::DisplayCurrentModes(User *user, User* targetuser, Channel* targ
        return;
 }
 
-void ModeParser::Process(const char** parameters, int pcnt, User *user, bool servermode)
+void ModeParser::Process(const char* const* parameters, int pcnt, User *user, bool servermode)
 {
        std::string target = parameters[0];
        ModeType type = MODETYPE_USER;
@@ -387,6 +387,8 @@ void ModeParser::Process(const char** parameters, int pcnt, User *user, bool ser
        }
        else if (pcnt > 1)
        {
+               bool SkipAccessChecks = false;
+
                if (targetchannel)
                {
                        type = MODETYPE_CHANNEL;
@@ -403,6 +405,7 @@ void ModeParser::Process(const char** parameters, int pcnt, User *user, bool ser
                                FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user, NULL, targetchannel, AC_GENERAL_MODE));
                                if (MOD_RESULT == ACR_DENY)
                                        return;
+                               SkipAccessChecks = (MOD_RESULT == ACR_ALLOW);
                        }
                }
                else if (targetuser)
@@ -506,44 +509,49 @@ void ModeParser::Process(const char** parameters, int pcnt, User *user, bool ser
                                                                        continue;
                                                                }
 
-                                                               FOREACH_RESULT(I_OnRawMode, OnRawMode(user, targetchannel, modechar, parameter, adding, 1));
+                                                               FOREACH_RESULT(I_OnRawMode, OnRawMode(user, targetchannel, modechar, parameter, adding, 1, servermode));
                                                        }
                                                        else
                                                        {
-                                                               FOREACH_RESULT(I_OnRawMode, OnRawMode(user, targetchannel, modechar, "", adding, 0));
+                                                               FOREACH_RESULT(I_OnRawMode, OnRawMode(user, targetchannel, modechar, "", adding, 0, servermode));
                                                        }
 
                                                        if (IS_LOCAL(user) && (MOD_RESULT == ACR_DENY))
                                                                continue;
 
-
-                                                       if (IS_LOCAL(user) && (MOD_RESULT != ACR_ALLOW))
+                                                       if (!SkipAccessChecks && IS_LOCAL(user) && (MOD_RESULT != ACR_ALLOW))
                                                        {
+                                                               ServerInstance->Log(DEBUG,"Enter minimum prefix check");
                                                                /* Check access to this mode character */
                                                                if ((type == MODETYPE_CHANNEL) && (modehandlers[handler_id]->GetNeededPrefix()))
                                                                {
                                                                        char needed = modehandlers[handler_id]->GetNeededPrefix();
                                                                        ModeHandler* prefixmode = FindPrefix(needed);
-                                                                       if (prefixmode)
+                                                                       ServerInstance->Log(DEBUG,"Needed prefix: %c", needed);
+
+                                                                       /* If the mode defined by the handler is not '\0', but the handler for it
+                                                                        * cannot be found, they probably dont have the right module loaded to implement
+                                                                        * the prefix they want to compare the mode against, e.g. '&' for m_chanprotect.
+                                                                        * Revert to checking against the minimum core prefix, '%'.
+                                                                        */
+                                                                       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
+                                                                        * in NAMES(X) are not in rank order, we know the most powerful mode is listed
+                                                                        * first, so we don't need to iterate, we just look up the first instead.
+                                                                        */
+                                                                       std::string modestring = targetchannel->GetAllPrefixChars(user);
+                                                                       char ml = (modestring.empty() ? '\0' : modestring[0]);
+                                                                       ModeHandler* ourmode = FindPrefix(ml);
+                                                                       if (!ourmode || ourmode->GetPrefixRank() < neededrank)
                                                                        {
-                                                                               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
-                                                                                * in NAMES(X) are not in rank order, we know the most powerful mode is listed
-                                                                                * first, so we don't need to iterate, we just look up the first instead.
-                                                                                */
-                                                                               std::string modestring = targetchannel->GetAllPrefixChars(user);
-                                                                               if (!modestring.empty())
-                                                                               {
-                                                                                       ModeHandler* ourmode = FindPrefix(modestring[0]);
-                                                                                       if (!ourmode || ourmode->GetPrefixRank() < neededrank)
-                                                                                       {
-                                                                                               /* Bog off */
-                                                                                               user->WriteServ("482 %s %s :You require channel privilege '%c' or above to execute channel mode '%c'",
-                                                                                                               user->nick, targetchannel->name, needed, modechar);
-                                                                                               continue;
-                                                                                       }
-                                                                               }
+                                                                               /* Bog off */
+                                                                               user->WriteServ("482 %s %s :You must have channel privilege %c or above to %sset channel mode %c",
+                                                                                               user->nick, targetchannel->name, needed, adding ? "" : "un", modechar);
+                                                                               continue;
                                                                        }
                                                                }
                                                        }
@@ -552,7 +560,7 @@ void ModeParser::Process(const char** parameters, int pcnt, User *user, bool ser
                                                                
                                                        for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++)
                                                        {
-                                                               if ((*watchers)->BeforeMode(user, targetuser, targetchannel, parameter, adding, type) == false)
+                                                               if ((*watchers)->BeforeMode(user, targetuser, targetchannel, parameter, adding, type, servermode) == false)
                                                                {
                                                                        abort = true;
                                                                        break;
@@ -580,7 +588,7 @@ void ModeParser::Process(const char** parameters, int pcnt, User *user, bool ser
                                                        }
 
                                                        /* Call the handler for the mode */
-                                                       ModeAction ma = modehandlers[handler_id]->OnModeChange(user, targetuser, targetchannel, parameter, adding);
+                                                       ModeAction ma = modehandlers[handler_id]->OnModeChange(user, targetuser, targetchannel, parameter, adding, servermode);
 
                                                        if ((modehandlers[handler_id]->GetNumParams(adding)) && (parameter.empty()))
                                                        {
@@ -623,7 +631,7 @@ void ModeParser::Process(const char** parameters, int pcnt, User *user, bool ser
 
                                                                /* Call all the AfterMode events in the mode watchers for this mode */
                                                                for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++)
-                                                                       (*watchers)->AfterMode(user, targetuser, targetchannel, parameter, adding, type);
+                                                                       (*watchers)->AfterMode(user, targetuser, targetchannel, parameter, adding, type, servermode);
 
                                                                /* Reset the state change flag */
                                                                state_change = false;