]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_channames.cpp
Remove current time parameter of the Timer constructor
[user/henk/code/inspircd.git] / src / modules / m_channames.cpp
index f1704a52891ab6a0d13daf0aefb2b5b745875011..3a27cab73eb211c6cc801b31f968ccc20e3fc87c 100644 (file)
 
 #include "inspircd.h"
 
-/* $ModDesc: Implements config tags which allow changing characters allowed in channel names */
-
 static std::bitset<256> allowedmap;
 
-class NewIsChannelHandler : public HandlerBase2<bool, const std::string&, size_t>
+class NewIsChannelHandler : public HandlerBase1<bool, const std::string&>
 {
  public:
-       NewIsChannelHandler() { }
-       ~NewIsChannelHandler() { }
-       bool Call(const std::string&, size_t);
+       bool Call(const std::string&);
 };
 
-bool NewIsChannelHandler::Call(const std::string& channame, size_t max)
+bool NewIsChannelHandler::Call(const std::string& channame)
 {
-       if (channame.empty() || channame.length() > max || channame[0] != '#')
+       if (channame.empty() || channame.length() > ServerInstance->Config->Limits.ChanMax || channame[0] != '#')
                return false;
 
        for (std::string::const_iterator c = channame.begin(); c != channame.end(); ++c)
@@ -49,56 +45,70 @@ bool NewIsChannelHandler::Call(const std::string& channame, size_t max)
 class ModuleChannelNames : public Module
 {
        NewIsChannelHandler myhandler;
-       caller2<bool, const std::string&, size_t> rememberer;
+       caller1<bool, const std::string&> rememberer;
        bool badchan;
+       ChanModeReference permchannelmode;
 
  public:
-       ModuleChannelNames() : rememberer(ServerInstance->IsChannel), badchan(false)
+       ModuleChannelNames()
+               : rememberer(ServerInstance->IsChannel)
+               , badchan(false)
+               , permchannelmode(this, "permanent")
        {
        }
 
        void init() CXX11_OVERRIDE
        {
                ServerInstance->IsChannel = &myhandler;
-               Implementation eventlist[] = { I_OnRehash, I_OnUserKick };
-               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
-               OnRehash(NULL);
        }
 
        void ValidateChans()
        {
                badchan = true;
-               std::vector<Channel*> chanvec;
-               for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); ++i)
-               {
-                       if (!ServerInstance->IsChannel(i->second->name, MAXBUF))
-                               chanvec.push_back(i->second);
-               }
-               std::vector<Channel*>::reverse_iterator c2 = chanvec.rbegin();
-               while (c2 != chanvec.rend())
+               const chan_hash& chans = ServerInstance->GetChans();
+               for (chan_hash::const_iterator i = chans.begin(); i != chans.end(); )
                {
-                       Channel* c = *c2++;
-                       if (c->IsModeSet('P') && c->GetUserCounter())
+                       Channel* c = i->second;
+                       // Move iterator before we begin kicking
+                       ++i;
+                       if (ServerInstance->IsChannel(c->name))
+                               continue; // The name of this channel is still valid
+
+                       if (c->IsModeSet(permchannelmode) && c->GetUserCounter())
                        {
                                std::vector<std::string> modes;
                                modes.push_back(c->name);
-                               modes.push_back("-P");
+                               modes.push_back(std::string("-") + permchannelmode->GetModeChar());
 
-                               ServerInstance->SendGlobalMode(modes, ServerInstance->FakeClient);
+                               ServerInstance->Modes->Process(modes, ServerInstance->FakeClient);
                        }
-                       const UserMembList* users = c->GetUsers();
-                       for(UserMembCIter j = users->begin(); j != users->end(); ++j)
+                       UserMembList& users = c->userlist;
+                       for (UserMembIter j = users.begin(); j != users.end(); )
+                       {
                                if (IS_LOCAL(j->first))
-                                       c->KickUser(ServerInstance->FakeClient, j->first, "Channel name no longer valid");
+                               {
+                                       // KickUser invalidates the iterator
+                                       UserMembIter it = j++;
+                                       c->KickUser(ServerInstance->FakeClient, it, "Channel name no longer valid");
+                               }
+                               else
+                                       ++j;
+                       }
                }
                badchan = false;
        }
 
-       void OnRehash(User* user) CXX11_OVERRIDE
+       void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("channames");
                std::string denyToken = tag->getString("denyrange");
                std::string allowToken = tag->getString("allowrange");
+
+               if (!denyToken.compare(0, 2, "0-"))
+                       denyToken[0] = '1';
+               if (!allowToken.compare(0, 2, "0-"))
+                       allowToken[0] = '1';
+
                allowedmap.set();
 
                irc::portparser denyrange(denyToken, false);
@@ -129,10 +139,11 @@ class ModuleChannelNames : public Module
                }
        }
 
-       ~ModuleChannelNames()
+       CullResult cull() CXX11_OVERRIDE
        {
                ServerInstance->IsChannel = rememberer;
                ValidateChans();
+               return Module::cull();
        }
 
        Version GetVersion() CXX11_OVERRIDE