]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_hidelist.cpp
Replace all abstract usages of his/he/her with they/their/it.
[user/henk/code/inspircd.git] / src / modules / m_hidelist.cpp
index f7a05ed0abdf471abf1bff3fd801d2d16bc75bf3..9c8811fb80203350c1d8d90f180c7a2738899264 100644 (file)
 
 class ListWatcher : public ModeWatcher
 {
+       // Minimum rank required to view the list
+       const unsigned int minrank;
+
  public:
-       ListWatcher(Module* mod, const std::string& modename)
+       ListWatcher(Module* mod, const std::string& modename, unsigned int rank)
                : ModeWatcher(mod, modename, MODETYPE_CHANNEL)
+               , minrank(rank)
        {
        }
 
-       bool BeforeMode(User* user, User* destuser, Channel* chan, std::string& param, bool adding)
+       bool BeforeMode(User* user, User* destuser, Channel* chan, std::string& param, bool adding) CXX11_OVERRIDE
        {
                // Only handle listmode list requests
                if (!param.empty())
@@ -36,13 +40,13 @@ class ListWatcher : public ModeWatcher
                // If the user requesting the list is a member of the channel see if they have the
                // rank required to view the list
                Membership* memb = chan->GetUser(user);
-               if ((memb) && (memb->getRank() >= HALFOP_VALUE))
+               if ((memb) && (memb->getRank() >= minrank))
                        return true;
 
                if (user->HasPrivPermission("channels/auspex"))
                        return true;
 
-               user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s :You do not have access to view the %s list", chan->name.c_str(), GetModeName().c_str());
+               user->WriteNumeric(ERR_CHANOPRIVSNEEDED, chan->name, InspIRCd::Format("You do not have access to view the %s list", GetModeName().c_str()));
                return false;
        }
 };
@@ -54,16 +58,26 @@ class ModuleHideList : public Module
  public:
        void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
-               stdalgo::delete_all(watchers);
-               watchers.clear();
-
                ConfigTagList tags = ServerInstance->Config->ConfTags("hidelist");
+               typedef std::vector<std::pair<std::string, unsigned int> > NewConfigs;
+               NewConfigs newconfigs;
                for (ConfigIter i = tags.first; i != tags.second; ++i)
                {
                        ConfigTag* tag = i->second;
                        std::string modename = tag->getString("mode");
-                       watchers.push_back(new ListWatcher(this, modename));
+                       if (modename.empty())
+                               throw ModuleException("Empty <hidelist:mode> at " + tag->getTagLocation());
+                       // If rank is set to 0 everyone inside the channel can view the list,
+                       // but non-members may not
+                       unsigned int rank = tag->getUInt("rank", HALFOP_VALUE);
+                       newconfigs.push_back(std::make_pair(modename, rank));
                }
+
+               stdalgo::delete_all(watchers);
+               watchers.clear();
+
+               for (NewConfigs::const_iterator i = newconfigs.begin(); i != newconfigs.end(); ++i)
+                       watchers.push_back(new ListWatcher(this, i->first, i->second));
        }
 
        ~ModuleHideList()