]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_channames.cpp
Replace hardcoded mode letters, part 3
[user/henk/code/inspircd.git] / src / modules / m_channames.cpp
index 9b43649a815e5db24cc21722d98d6672adc1ecf5..aed3ec2269f8d3f29d25958c7e1cac02917fdd8a 100644 (file)
@@ -19,8 +19,6 @@
 
 #include "inspircd.h"
 
-/* $ModDesc: Implements config tags which allow changing characters allowed in channel names */
-
 static std::bitset<256> allowedmap;
 
 class NewIsChannelHandler : public HandlerBase1<bool, const std::string&>
@@ -51,9 +49,13 @@ class ModuleChannelNames : public Module
        NewIsChannelHandler myhandler;
        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")
        {
        }
 
@@ -78,18 +80,26 @@ class ModuleChannelNames : public Module
                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("-" + 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;
        }