]> 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 ae69ecc4ff3f0e75a1daedef8bc39ac82c21503f..647c840b57f4328f14b7bae5b4f29bd09e65c251 100644 (file)
@@ -3,7 +3,7 @@
  *       +------------------------------------+
  *
  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
+ * See: http://wiki.inspircd.org/Credits
  *
  * This program is free but copyrighted software; see
  *            the file COPYING for details.
@@ -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,30 +77,44 @@ 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);
 
-               OnRehash(NULL, "");
+               OnRehash(NULL);
        }
 
        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, const std::string &parameter)
+       virtual void OnRehash(User *user)
        {
                /*
                 * Process config-defined list of permanent channels.
@@ -125,7 +139,17 @@ public:
                        {
                                c = new Channel(ServerInstance, channel, ServerInstance->Time());
                                if (!topic.empty())
+                               {
                                        c->SetTopic(NULL, topic, true);
+
+                                       /*
+                                        * Due to the way protocol works in 1.2, we need to hack the topic TS in such a way that this
+                                        * topic will always win over others.
+                                        *
+                                        * This is scheduled for (proper) fixing in a later release, and can be removed at a later date.
+                                        */
+                                       c->topicset = 42;
+                               }
                                ServerInstance->Logs->Log("blah", DEBUG, "Added %s with topic %s", channel.c_str(), topic.c_str());
 
                                if (modes.empty())
@@ -160,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;
        }
 };