]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_channames.cpp
Sync helpop chmodes s and p with docs
[user/henk/code/inspircd.git] / src / modules / m_channames.cpp
index 69b501792c77830bf407ecb7549e048d4ccdaff5..c5315b3077d446e9848d2fe90260a0e162589fbc 100644 (file)
@@ -1,6 +1,11 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
+ *   Copyright (C) 2013, 2017 Sadie Powell <sadie@witchery.services>
+ *   Copyright (C) 2013 Daniel Vassdal <shutter@canternet.org>
+ *   Copyright (C) 2012-2014 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2012 Robby <robby@chatbelgie.be>
+ *   Copyright (C) 2010 Craig Edwards <brain@inspircd.org>
  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
  *
  * This file is part of InspIRCd.  InspIRCd is free software: you can
 
 static std::bitset<256> allowedmap;
 
-class NewIsChannelHandler : public HandlerBase1<bool, const std::string&>
+class NewIsChannelHandler
 {
  public:
-       bool Call(const std::string&);
+       static bool Call(const std::string&);
 };
 
 bool NewIsChannelHandler::Call(const std::string& channame)
@@ -44,8 +49,7 @@ bool NewIsChannelHandler::Call(const std::string& channame)
 
 class ModuleChannelNames : public Module
 {
-       NewIsChannelHandler myhandler;
-       caller1<bool, const std::string&> rememberer;
+       TR1NS::function<bool(const std::string&)> rememberer;
        bool badchan;
        ChanModeReference permchannelmode;
 
@@ -59,39 +63,38 @@ class ModuleChannelNames : public Module
 
        void init() CXX11_OVERRIDE
        {
-               ServerInstance->IsChannel = &myhandler;
+               ServerInstance->IsChannel = NewIsChannelHandler::Call;
        }
 
        void ValidateChans()
        {
+               Modes::ChangeList removepermchan;
+
                badchan = true;
-               std::vector<Channel*> chanvec;
                const chan_hash& chans = ServerInstance->GetChans();
-               for (chan_hash::const_iterator i = chans.begin(); i != chans.end(); ++i)
-               {
-                       if (!ServerInstance->IsChannel(i->second->name))
-                               chanvec.push_back(i->second);
-               }
-               std::vector<Channel*>::reverse_iterator c2 = chanvec.rbegin();
-               while (c2 != chanvec.rend())
+               for (chan_hash::const_iterator i = chans.begin(); i != chans.end(); )
                {
-                       Channel* c = *c2++;
+                       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(std::string("-") + permchannelmode->GetModeChar());
-
-                               ServerInstance->Modes->Process(modes, ServerInstance->FakeClient);
+                               removepermchan.clear();
+                               removepermchan.push_remove(*permchannelmode);
+                               ServerInstance->Modes->Process(ServerInstance->FakeClient, c, NULL, removepermchan);
                        }
-                       const UserMembList* users = c->GetUsers();
-                       for(UserMembCIter j = users->begin(); j != users->end(); )
+
+                       Channel::MemberMap& users = c->userlist;
+                       for (Channel::MemberMap::iterator j = users.begin(); j != users.end(); )
                        {
                                if (IS_LOCAL(j->first))
                                {
                                        // KickUser invalidates the iterator
-                                       UserMembCIter it = j++;
-                                       c->KickUser(ServerInstance->FakeClient, it->first, "Channel name no longer valid");
+                                       Channel::MemberMap::iterator it = j++;
+                                       c->KickUser(ServerInstance->FakeClient, it, "Channel name no longer valid");
                                }
                                else
                                        ++j;
@@ -134,22 +137,23 @@ class ModuleChannelNames : public Module
        {
                if (badchan)
                {
-                       const UserMembList* users = memb->chan->GetUsers();
-                       for(UserMembCIter i = users->begin(); i != users->end(); i++)
+                       const Channel::MemberMap& users = memb->chan->GetUsers();
+                       for (Channel::MemberMap::const_iterator i = users.begin(); i != users.end(); ++i)
                                if (i->first != memb->user)
                                        except_list.insert(i->first);
                }
        }
 
-       ~ModuleChannelNames()
+       CullResult cull() CXX11_OVERRIDE
        {
                ServerInstance->IsChannel = rememberer;
                ValidateChans();
+               return Module::cull();
        }
 
        Version GetVersion() CXX11_OVERRIDE
        {
-               return Version("Implements config tags which allow changing characters allowed in channel names", VF_VENDOR);
+               return Version("Allows the server administrator to define what characters are allowed in channel names.", VF_VENDOR);
        }
 };