]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_permchannels.cpp
Add initial query support to m_mysql [patch by Athenon]
[user/henk/code/inspircd.git] / src / modules / m_permchannels.cpp
index ff269934e6fd111b434ca8d7caaa9fc14d006531..647c840b57f4328f14b7bae5b4f29bd09e65c251 100644 (file)
@@ -21,9 +21,9 @@
 class PermChannel : public ModeHandler
 {
  public:
-       PermChannel(InspIRCd* Instance) : ModeHandler(Instance, 'P', 0, 0, false, MODETYPE_CHANNEL, false) { }
+       PermChannel(InspIRCd* Instance, Module* Creator) : ModeHandler(Instance, Creator, 'P', 0, 0, false, MODETYPE_CHANNEL, false) { }
 
-       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding, bool sm)
+       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
        {
                if (!source->HasPrivPermission("channels/set-permanent"))
                {
@@ -43,7 +43,7 @@ class PermChannel : public ModeHandler
                {
                        if (channel->IsModeSet('P'))
                        {
-                               if (channel->GetUserCounter() == 0 && !sm)
+                               if (channel->GetUserCounter() == 0 && !IS_FAKE(source))
                                {
                                        /*
                                         * ugh, ugh, UGH!
@@ -77,17 +77,13 @@ class PermChannel : public ModeHandler
 
 class ModulePermanentChannels : public Module
 {
-       PermChannel *p;
+       PermChannel p;
 public:
 
-       ModulePermanentChannels(InspIRCd* Me) : Module(Me)
+       ModulePermanentChannels(InspIRCd* Me) : Module(Me), p(Me, this)
        {
-               p = new PermChannel(ServerInstance);
-               if (!ServerInstance->Modes->AddMode(p))
-               {
-                       delete p;
+               if (!ServerInstance->Modes->AddMode(&p))
                        throw ModuleException("Could not add new modes!");
-               }
                Implementation eventlist[] = { I_OnChannelPreDelete };
                ServerInstance->Modules->Attach(eventlist, this, 1);
 
@@ -96,8 +92,26 @@ public:
 
        virtual ~ModulePermanentChannels()
        {
-               ServerInstance->Modes->DelMode(p);
-               delete p;
+               ServerInstance->Modes->DelMode(&p);
+               /*
+                * DelMode can't remove the +P mode on empty channels, or it will break
+                * merging modes with remote servers. Remove the empty channels now as
+                * we know this is not the case.
+                */
+               chan_hash::iterator iter = ServerInstance->chanlist->begin();
+               while (iter != ServerInstance->chanlist->end())
+               {
+                       Channel* c = iter->second;
+                       if (c->GetUserCounter() == 0)
+                       {
+                               chan_hash::iterator at = iter;
+                               iter++;
+                               ServerInstance->chanlist->erase(at);
+                               delete c;
+                       }
+                       else
+                               iter++;
+               }
        }
 
        virtual void OnRehash(User *user)
@@ -170,12 +184,12 @@ public:
                return Version("$Id$",VF_COMMON|VF_VENDOR,API_VERSION);
        }
 
-       virtual int OnChannelPreDelete(Channel *c)
+       virtual ModResult OnChannelPreDelete(Channel *c)
        {
                if (c->IsModeSet('P'))
-                       return 1;
+                       return MOD_RES_DENY;
 
-               return 0;
+               return MOD_RES_PASSTHRU;
        }
 };