X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_permchannels.cpp;h=a9c4c8a72779e84602285f854efb31baa9e2bb10;hb=de69e28a4a1aea89e410b693bbbb67890ecb0bd3;hp=674a6dca54ffc826ce7fd4cbf66443024afdbe61;hpb=d9e3bb8d4343643504ab7ee6ab943a000065cc8a;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_permchannels.cpp b/src/modules/m_permchannels.cpp index 674a6dca5..a9c4c8a72 100644 --- a/src/modules/m_permchannels.cpp +++ b/src/modules/m_permchannels.cpp @@ -43,16 +43,43 @@ static bool WriteDatabase() } // 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[] = + { + "\n" + }; + + int lpos = 0, item = 0, ipos = 0; + while (lpos < 1022 && item < 7) { - fprintf(f, "\n", c->name.c_str(), c->topic.c_str(), c->ChanModes(true)); + 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() 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() 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() class PermChannel : public ModeHandler { public: - PermChannel(InspIRCd* Instance, Module* Creator) : ModeHandler(Creator, 'P', PARAM_NONE, MODETYPE_CHANNEL) { } + PermChannel(Module* Creator) : ModeHandler(Creator, "permanent", 'P', PARAM_NONE, MODETYPE_CHANNEL) { } ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding) { @@ -108,7 +135,7 @@ class PermChannel : public ModeHandler { if (channel->IsModeSet('P')) { - if (channel->GetUserCounter() == 0 && !IS_FAKE(source)) + if (channel->GetUserCounter() == 0 && !IS_SERVER(source)) { /* * ugh, ugh, UGH! @@ -148,19 +175,18 @@ 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!"); - Implementation eventlist[] = { I_OnChannelPreDelete, I_OnPostTopicChange, I_OnRawMode }; - ServerInstance->Modules->Attach(eventlist, this, 3); + Implementation eventlist[] = { I_OnChannelPreDelete, I_OnPostTopicChange, I_OnRawMode, I_OnRehash }; + ServerInstance->Modules->Attach(eventlist, this, 4); OnRehash(NULL); } - virtual ~ModulePermanentChannels() + CullResult cull() { - 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 @@ -174,12 +200,15 @@ public: { chan_hash::iterator at = iter; iter++; + FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(c)); ServerInstance->chanlist->erase(at); - delete c; + ServerInstance->GlobalCulls.AddItem(c); } else iter++; } + ServerInstance->Modes->DelMode(&p); + return Module::cull(); } virtual void OnRehash(User *user) @@ -188,7 +217,7 @@ public: * Process config-defined list of permanent channels. * -- w00t */ - ConfigReader MyConf(ServerInstance); + ConfigReader MyConf; permchannelsconf = MyConf.ReadValue("permchanneldb", "filename", "", 0, false); @@ -208,7 +237,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); @@ -266,7 +295,7 @@ public: 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); } virtual ModResult OnChannelPreDelete(Channel *c)