]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_channames.cpp
m_spanningtree Remove duplicate code for sending channel messages from RouteCommand()
[user/henk/code/inspircd.git] / src / modules / m_channames.cpp
index f1704a52891ab6a0d13daf0aefb2b5b745875011..fcb2ef6d74d7fda8d38bcfbe0bb34138cb7ca19e 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,19 +47,21 @@ 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);
        }
 
@@ -71,25 +71,33 @@ class ModuleChannelNames : public Module
                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))
+                       if (!ServerInstance->IsChannel(i->second->name))
                                chanvec.push_back(i->second);
                }
                std::vector<Channel*>::reverse_iterator c2 = chanvec.rbegin();
                while (c2 != chanvec.rend())
                {
                        Channel* c = *c2++;
-                       if (c->IsModeSet('P') && c->GetUserCounter())
+                       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)
+                       for(UserMembCIter 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
+                                       UserMembCIter it = j++;
+                                       c->KickUser(ServerInstance->FakeClient, it->first, "Channel name no longer valid");
+                               }
+                               else
+                                       ++j;
+                       }
                }
                badchan = false;
        }