]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Replace loop over alphabet with loop over mode list in several places
authorAttila Molnar <attilamolnar@hush.com>
Tue, 30 Aug 2016 14:12:39 +0000 (16:12 +0200)
committerAttila Molnar <attilamolnar@hush.com>
Tue, 30 Aug 2016 14:12:39 +0000 (16:12 +0200)
src/mode.cpp
src/modules/m_check.cpp
src/modules/m_spanningtree/capab.cpp

index b7a7b7d41b4b243633135bd7fa8755297c908e8b..d58944f1f7278e779cfd9158b3afd26d4487ee45 100644 (file)
@@ -246,11 +246,12 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, Mode
                        unsigned int ourrank = chan->GetPrefixValue(user);
                        if (ourrank < neededrank)
                        {
-                               PrefixMode* neededmh = NULL;
-                               for(char c='A'; c <= 'z'; c++)
+                               const PrefixMode* neededmh = NULL;
+                               const PrefixModeList& prefixmodes = GetPrefixModes();
+                               for (PrefixModeList::const_iterator i = prefixmodes.begin(); i != prefixmodes.end(); ++i)
                                {
-                                       PrefixMode* privmh = FindPrefixMode(c);
-                                       if (privmh && privmh->GetPrefixRank() >= neededrank)
+                                       const PrefixMode* const privmh = *i;
+                                       if (privmh->GetPrefixRank() >= neededrank)
                                        {
                                                // this mode is sufficient to allow this action
                                                if (!neededmh || privmh->GetPrefixRank() < neededmh->GetPrefixRank())
index ddac033c1088ce65916aef450f3ce56238088509..4330f410dd667eb3a8a430347d6e8575e8ed2981 100644 (file)
@@ -109,6 +109,19 @@ class CommandCheck : public Command
                return ret;
        }
 
+       static std::string GetAllowedOperOnlyModes(LocalUser* user, ModeType modetype)
+       {
+               std::string ret;
+               const ModeParser::ModeHandlerMap& modes = ServerInstance->Modes.GetModes(modetype);
+               for (ModeParser::ModeHandlerMap::const_iterator i = modes.begin(); i != modes.end(); ++i)
+               {
+                       const ModeHandler* const mh = i->second;
+                       if ((mh->NeedsOper()) && (user->HasModePermission(mh)))
+                               ret.push_back(mh->GetModeChar());
+               }
+               return ret;
+       }
+
  public:
        CommandCheck(Module* parent)
                : Command(parent,"CHECK", 1)
@@ -179,17 +192,8 @@ class CommandCheck : public Command
                                context.Write("opertype", oper->name);
                                if (loctarg)
                                {
-                                       std::string umodes;
-                                       std::string cmodes;
-                                       for(char c='A'; c <= 'z'; c++)
-                                       {
-                                               ModeHandler* mh = ServerInstance->Modes->FindMode(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(mh))
-                                                       cmodes.push_back(c);
-                                       }
+                                       std::string umodes = GetAllowedOperOnlyModes(loctarg, MODETYPE_USER);
+                                       std::string cmodes = GetAllowedOperOnlyModes(loctarg, MODETYPE_CHANNEL);
                                        context.Write("modeperms", "user=" + umodes + " channel=" + cmodes);
 
                                        CheckContext::List opcmdlist(context, "commandperms");
index b75fbc3cc52ac7d915b5bedd36dacacaba60ca25..a2e68aa6116135e3829ffc16df9c25da03d04d19 100644 (file)
@@ -82,22 +82,20 @@ std::string TreeSocket::MyModules(int filter)
 static std::string BuildModeList(ModeType type)
 {
        std::vector<std::string> modes;
-       for(char c='A'; c <= 'z'; c++)
+       const ModeParser::ModeHandlerMap& mhs = ServerInstance->Modes.GetModes(type);
+       for (ModeParser::ModeHandlerMap::const_iterator i = mhs.begin(); i != mhs.end(); ++i)
        {
-               ModeHandler* mh = ServerInstance->Modes->FindMode(c, type);
-               if (mh)
+               const ModeHandler* const mh = i->second;
+               std::string mdesc = mh->name;
+               mdesc.push_back('=');
+               const PrefixMode* const pm = mh->IsPrefixMode();
+               if (pm)
                {
-                       std::string mdesc = mh->name;
-                       mdesc.push_back('=');
-                       PrefixMode* pm = mh->IsPrefixMode();
-                       if (pm)
-                       {
-                               if (pm->GetPrefix())
-                                       mdesc.push_back(pm->GetPrefix());
-                       }
-                       mdesc.push_back(mh->GetModeChar());
-                       modes.push_back(mdesc);
+                       if (pm->GetPrefix())
+                               mdesc.push_back(pm->GetPrefix());
                }
+               mdesc.push_back(mh->GetModeChar());
+               modes.push_back(mdesc);
        }
        std::sort(modes.begin(), modes.end());
        return irc::stringjoiner(modes);