+ permchannelsconf = ServerInstance->Config->ConfValue("permchanneldb")->getString("filename");
+ }
+
+ void LoadDatabase()
+ {
+ /*
+ * Process config-defined list of permanent channels.
+ * -- w00t
+ */
+ ConfigTagList permchannels = ServerInstance->Config->ConfTags("permchannels");
+ for (ConfigIter i = permchannels.first; i != permchannels.second; ++i)
+ {
+ ConfigTag* tag = i->second;
+ std::string channel = tag->getString("channel");
+ std::string topic = tag->getString("topic");
+ std::string modes = tag->getString("modes");
+
+ if (channel.empty())
+ {
+ ServerInstance->Logs->Log("m_permchannels", DEBUG, "Malformed permchannels tag with empty channel name.");
+ continue;
+ }
+
+ Channel *c = ServerInstance->FindChan(channel);
+
+ if (!c)
+ {
+ c = new Channel(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("m_permchannels", DEBUG, "Added %s with topic %s", channel.c_str(), topic.c_str());
+
+ if (modes.empty())
+ continue;
+
+ irc::spacesepstream list(modes);
+ std::string modeseq;
+ std::string par;
+
+ list.GetToken(modeseq);
+
+ // XXX bleh, should we pass this to the mode parser instead? ugly. --w00t
+ for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
+ {
+ ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
+ if (mode)
+ {
+ if (mode->GetNumParams(true))
+ list.GetToken(par);
+ else
+ par.clear();
+
+ mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, c, par, true);
+ }
+ }
+ }
+ }
+ }
+
+ virtual ModResult OnRawMode(User* user, Channel* chan, const char mode, const std::string ¶m, bool adding, int pcnt)
+ {
+ if (chan && (chan->IsModeSet('P') || mode == 'P'))
+ dirty = true;
+
+ return MOD_RES_PASSTHRU;
+ }
+
+ virtual void OnPostTopicChange(User*, Channel *c, const std::string&)
+ {
+ if (c->IsModeSet('P'))
+ dirty = true;
+ }
+
+ void OnBackgroundTimer(time_t)
+ {
+ if (dirty)
+ WriteDatabase();
+ dirty = false;
+ }
+
+ void Prioritize()
+ {
+ // XXX: Load the DB here because the order in which modules are init()ed at boot is
+ // alphabetical, this means we must wait until all modules have done their init()
+ // to be able to set the modes they provide (e.g.: m_stripcolor is inited after us)
+ // Prioritize() is called after all module initialization is complete, consequently
+ // all modes are available now
+
+ static bool loaded = false;
+ if (loaded)
+ return;
+
+ loaded = true;
+
+ // Load only when there are no linked servers - we set the TS of the channels we
+ // create to the current time, this can lead to desync because spanningtree has
+ // no way of knowing what we do
+ ProtoServerList serverlist;
+ ServerInstance->PI->GetServerList(serverlist);
+ if (serverlist.size() < 2)
+ {
+ try
+ {
+ LoadDatabase();
+ }
+ catch (CoreException& e)
+ {
+ ServerInstance->Logs->Log("m_permchannels", DEFAULT, "Error loading permchannels database: " + std::string(e.GetReason()));
+ }
+ }