]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Pass the ModeHandler to User::HasModePermission()
authorAttila Molnar <attilamolnar@hush.com>
Tue, 30 Aug 2016 14:05:01 +0000 (16:05 +0200)
committerAttila Molnar <attilamolnar@hush.com>
Tue, 30 Aug 2016 14:05:01 +0000 (16:05 +0200)
Mark the method as const

include/users.h
src/mode.cpp
src/modules/m_check.cpp
src/users.cpp

index b97c62d4aa91a2fea09f8befd3426951a417818d..ae76d2eb3a3ffa18948bf460fd1e0175bd40596e 100644 (file)
@@ -455,11 +455,10 @@ class CoreExport User : public Extensible
        /** Returns true or false if a user can set a privileged user or channel mode.
         * This is done by looking up their oper type from User::oper, then referencing
         * this to their oper classes, and checking the modes they can set.
-        * @param mode The mode the check
-        * @param type ModeType (MODETYPE_CHANNEL or MODETYPE_USER).
+        * @param mh Mode to check
         * @return True if the user can set or unset this mode.
         */
-       virtual bool HasModePermission(unsigned char mode, ModeType type);
+       virtual bool HasModePermission(const ModeHandler* mh) const;
 
        /** Creates a usermask with real host.
         * Takes a buffer to use and fills the given buffer with the hostmask in the format user\@host
@@ -864,11 +863,10 @@ class CoreExport LocalUser : public User, public insp::intrusive_list_node<Local
        /** Returns true or false if a user can set a privileged user or channel mode.
         * This is done by looking up their oper type from User::oper, then referencing
         * this to their oper classes, and checking the modes they can set.
-        * @param mode The mode the check
-        * @param type ModeType (MODETYPE_CHANNEL or MODETYPE_USER).
+        * @param mh Mode to check
         * @return True if the user can set or unset this mode.
         */
-       bool HasModePermission(unsigned char mode, ModeType type);
+       bool HasModePermission(const ModeHandler* mh) const;
 };
 
 class RemoteUser : public User
index beea6d3a0287bd682acbac0f23a9675cd00ef772..b7a7b7d41b4b243633135bd7fa8755297c908e8b 100644 (file)
@@ -294,7 +294,7 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, Mode
                }
        }
 
-       if (adding && IS_LOCAL(user) && mh->NeedsOper() && !user->HasModePermission(modechar, type))
+       if ((adding) && (IS_LOCAL(user)) && (mh->NeedsOper()) && (!user->HasModePermission(mh)))
        {
                /* It's an oper only mode, and they don't have access to it. */
                if (user->IsOper())
index 17eb9d9c59d2194840645ceb75aab17dd354f46c..ddac033c1088ce65916aef450f3ce56238088509 100644 (file)
@@ -184,10 +184,10 @@ class CommandCheck : public Command
                                        for(char c='A'; c <= 'z'; c++)
                                        {
                                                ModeHandler* mh = ServerInstance->Modes->FindMode(c, MODETYPE_USER);
-                                               if (mh && mh->NeedsOper() && loctarg->HasModePermission(c, MODETYPE_USER))
+                                               if (mh && mh->NeedsOper() && loctarg->HasModePermission(mh))
                                                        umodes.push_back(c);
                                                mh = ServerInstance->Modes->FindMode(c, MODETYPE_CHANNEL);
-                                               if (mh && mh->NeedsOper() && loctarg->HasModePermission(c, MODETYPE_CHANNEL))
+                                               if (mh && mh->NeedsOper() && loctarg->HasModePermission(mh))
                                                        cmodes.push_back(c);
                                        }
                                        context.Write("modeperms", "user=" + umodes + " channel=" + cmodes);
index c57b6fc14d3e2f6580ab536ee1d92d01512fe3c4..5d1c12b136c1979863d90af3dc4e0b46ce64bee9 100644 (file)
@@ -153,19 +153,20 @@ const std::string& User::GetFullRealHost()
        return this->cached_fullrealhost;
 }
 
-bool User::HasModePermission(unsigned char, ModeType)
+bool User::HasModePermission(const ModeHandler* mh) const
 {
        return true;
 }
 
-bool LocalUser::HasModePermission(unsigned char mode, ModeType type)
+bool LocalUser::HasModePermission(const ModeHandler* mh) const
 {
        if (!this->IsOper())
                return false;
 
+       const unsigned char mode = mh->GetModeChar();
        if (mode < 'A' || mode > ('A' + 64)) return false;
 
-       return ((type == MODETYPE_USER ? oper->AllowedUserModes : oper->AllowedChanModes))[(mode - 'A')];
+       return ((mh->GetModeType() == MODETYPE_USER ? oper->AllowedUserModes : oper->AllowedChanModes))[(mode - 'A')];
 
 }
 /*