]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_permchannels.cpp
Remove InspIRCd* parameters and fields
[user/henk/code/inspircd.git] / src / modules / m_permchannels.cpp
index 41a5daf333efb06cb1a6881ad342796ea354779d..3e2e18a8e73abf6f9b14d4bf2e0960cc1afead01 100644 (file)
@@ -17,7 +17,7 @@
 
 // Not in a class due to circular dependancy hell.
 static std::string permchannelsconf;
-static bool WriteDatabase(InspIRCd *ServerInstance)
+static bool WriteDatabase()
 {
        FILE *f;
 
@@ -43,16 +43,43 @@ static bool WriteDatabase(InspIRCd *ServerInstance)
        }
 
        // Now, let's write.
-       Channel *c = NULL;
-
        for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); i++)
        {
-               c = i->second;
+               Channel* chan = i->second;
+               if (!chan->IsModeSet('P'))
+                       continue;
 
-               if (c->IsModeSet('P'))
+               char line[1024];
+               const char* items[] =
                {
-                       fprintf(f, "<permchannels channel=\"%s\" topic=\"%s\" modes=\"%s\">\n", c->name.c_str(), c->topic.c_str(), c->ChanModes(true));
+                       "<permchannels channel=",
+                       chan->name.c_str(),
+                       " topic=",
+                       chan->topic.c_str(),
+                       " modes=",
+                       chan->ChanModes(true),
+                       ">\n"
+               };
+
+               int lpos = 0, item = 0, ipos = 0;
+               while (lpos < 1022 && item < 7)
+               {
+                       char c = items[item][ipos++];
+                       if (c == 0)
+                       {
+                               // end of this string; hop to next string, insert a quote
+                               item++;
+                               ipos = 0;
+                               c = '"';
+                       }
+                       else if (c == '\\' || c == '"')
+                       {
+                               line[lpos++] = '\\';
+                       }
+                       line[lpos++] = c;
                }
+               line[--lpos] = 0;
+               fputs(line, f);
        }
 
        int write_error = 0;
@@ -61,7 +88,7 @@ static bool WriteDatabase(InspIRCd *ServerInstance)
        if (write_error)
        {
                ServerInstance->Logs->Log("m_permchannels",DEFAULT, "permchannels: Cannot write to new database! %s (%d)", strerror(errno), errno);
-               ServerInstance->SNO->WriteToSnoMask('x', "database: cannot write to new db: %s (%d)", strerror(errno), errno);
+               ServerInstance->SNO->WriteToSnoMask('a', "database: cannot write to new db: %s (%d)", strerror(errno), errno);
                return false;
        }
 
@@ -69,7 +96,7 @@ static bool WriteDatabase(InspIRCd *ServerInstance)
        if (rename(tempname.c_str(), permchannelsconf.c_str()) < 0)
        {
                ServerInstance->Logs->Log("m_permchannels",DEFAULT, "permchannels: Cannot move new to old database! %s (%d)", strerror(errno), errno);
-               ServerInstance->SNO->WriteToSnoMask('x', "database: cannot replace old with new db: %s (%d)", strerror(errno), errno);
+               ServerInstance->SNO->WriteToSnoMask('a', "database: cannot replace old with new db: %s (%d)", strerror(errno), errno);
                return false;
        }
 
@@ -83,7 +110,7 @@ static bool WriteDatabase(InspIRCd *ServerInstance)
 class PermChannel : public ModeHandler
 {
  public:
-       PermChannel(InspIRCd* Instance, Module* Creator) : ModeHandler(Creator, 'P', PARAM_NONE, MODETYPE_CHANNEL) { }
+       PermChannel(Module* Creator) : ModeHandler(Creator, 'P', PARAM_NONE, MODETYPE_CHANNEL) { }
 
        ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
        {
@@ -100,7 +127,7 @@ class PermChannel : public ModeHandler
                                channel->SetMode('P',true);
 
                                // Save permchannels db if needed.
-                               WriteDatabase(ServerInstance);
+                               WriteDatabase();
                                return MODEACTION_ALLOW;
                        }
                }
@@ -134,7 +161,7 @@ class PermChannel : public ModeHandler
                                channel->SetMode('P',false);
 
                                // Save permchannels db if needed.
-                               WriteDatabase(ServerInstance);
+                               WriteDatabase();
                                return MODEACTION_ALLOW;
                        }
                }
@@ -148,7 +175,7 @@ class ModulePermanentChannels : public Module
        PermChannel p;
 public:
 
-       ModulePermanentChannels(InspIRCd* Me) : Module(Me), p(Me, this)
+       ModulePermanentChannels() : p(this)
        {
                if (!ServerInstance->Modes->AddMode(&p))
                        throw ModuleException("Could not add new modes!");
@@ -188,7 +215,7 @@ public:
                 * Process config-defined list of permanent channels.
                 * -- w00t
                 */
-               ConfigReader MyConf(ServerInstance);
+               ConfigReader MyConf;
 
                permchannelsconf = MyConf.ReadValue("permchanneldb", "filename", "", 0, false);
 
@@ -208,7 +235,7 @@ public:
 
                        if (!c)
                        {
-                               c = new Channel(ServerInstance, channel, ServerInstance->Time());
+                               c = new Channel(channel, ServerInstance->Time());
                                if (!topic.empty())
                                {
                                        c->SetTopic(NULL, topic, true);
@@ -253,7 +280,7 @@ public:
        virtual ModResult OnRawMode(User* user, Channel* chan, const char mode, const std::string &param, bool adding, int pcnt)
        {
                if (chan && chan->IsModeSet('P'))
-                       WriteDatabase(ServerInstance);
+                       WriteDatabase();
 
                return MOD_RES_PASSTHRU;
        }
@@ -261,12 +288,12 @@ public:
        virtual void OnPostTopicChange(User*, Channel *c, const std::string&)
        {
                if (c->IsModeSet('P'))
-                       WriteDatabase(ServerInstance);
+                       WriteDatabase();
        }
 
        virtual Version GetVersion()
        {
-               return Version("$Id$",VF_COMMON|VF_VENDOR,API_VERSION);
+               return Version("Provides support for channel mode +P to provide permanent channels",VF_COMMON|VF_VENDOR,API_VERSION);
        }
 
        virtual ModResult OnChannelPreDelete(Channel *c)