X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_permchannels.cpp;h=6a8694a1c6a37fcd99410e649e72e2599dead0ae;hb=226a95aab09b9e1f43f61e78179bfa1135816c2d;hp=40774e1fa1ff49bc534a84034065be530f7827e5;hpb=df2ee078aa3c3830ae7365a920faa502d97c66d1;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_permchannels.cpp b/src/modules/m_permchannels.cpp index 40774e1fa..6a8694a1c 100644 --- a/src/modules/m_permchannels.cpp +++ b/src/modules/m_permchannels.cpp @@ -44,7 +44,7 @@ static bool WriteDatabase() f = fopen(tempname.c_str(), "w"); if (!f) { - ServerInstance->Logs->Log("m_permchannels",DEFAULT, "permchannels: Cannot create database! %s (%d)", strerror(errno), errno); + ServerInstance->Logs->Log("m_permchannels",LOG_DEFAULT, "permchannels: Cannot create database! %s (%d)", strerror(errno), errno); ServerInstance->SNO->WriteToSnoMask('a', "database: cannot create new db: %s (%d)", strerror(errno), errno); return false; } @@ -95,7 +95,7 @@ static bool WriteDatabase() write_error |= fclose(f); if (write_error) { - ServerInstance->Logs->Log("m_permchannels",DEFAULT, "permchannels: Cannot write to new database! %s (%d)", strerror(errno), errno); + ServerInstance->Logs->Log("m_permchannels",LOG_DEFAULT, "permchannels: Cannot write to new database! %s (%d)", strerror(errno), errno); ServerInstance->SNO->WriteToSnoMask('a', "database: cannot write to new db: %s (%d)", strerror(errno), errno); return false; } @@ -103,7 +103,7 @@ static bool WriteDatabase() #ifdef _WIN32 if (remove(permchannelsconf.c_str())) { - ServerInstance->Logs->Log("m_permchannels",DEFAULT, "permchannels: Cannot remove old database! %s (%d)", strerror(errno), errno); + ServerInstance->Logs->Log("m_permchannels",LOG_DEFAULT, "permchannels: Cannot remove old database! %s (%d)", strerror(errno), errno); ServerInstance->SNO->WriteToSnoMask('a', "database: cannot remove old database: %s (%d)", strerror(errno), errno); return false; } @@ -111,7 +111,7 @@ static bool WriteDatabase() // Use rename to move temporary to new db - this is guarenteed not to fuck up, even in case of a crash. 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->Logs->Log("m_permchannels",LOG_DEFAULT, "permchannels: Cannot move new to old database! %s (%d)", strerror(errno), errno); ServerInstance->SNO->WriteToSnoMask('a', "database: cannot replace old with new db: %s (%d)", strerror(errno), errno); return false; } @@ -169,7 +169,7 @@ public: { ServerInstance->Modules->AddService(p); Implementation eventlist[] = { I_OnChannelPreDelete, I_OnPostTopicChange, I_OnRawMode, I_OnRehash, I_OnBackgroundTimer }; - ServerInstance->Modules->Attach(eventlist, this, 5); + ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); OnRehash(NULL); } @@ -201,14 +201,16 @@ public: } virtual void OnRehash(User *user) + { + permchannelsconf = ServerInstance->Config->ConfValue("permchanneldb")->getString("filename"); + } + + void LoadDatabase() { /* * Process config-defined list of permanent channels. * -- w00t */ - - permchannelsconf = ServerInstance->Config->ConfValue("permchanneldb")->getString("filename"); - ConfigTagList permchannels = ServerInstance->Config->ConfTags("permchannels"); for (ConfigIter i = permchannels.first; i != permchannels.second; ++i) { @@ -219,7 +221,7 @@ public: if (channel.empty()) { - ServerInstance->Logs->Log("blah", DEBUG, "Malformed permchannels tag with empty channel name."); + ServerInstance->Logs->Log("m_permchannels", LOG_DEBUG, "Malformed permchannels tag with empty channel name."); continue; } @@ -240,7 +242,7 @@ public: */ c->topicset = 42; } - ServerInstance->Logs->Log("blah", DEBUG, "Added %s with topic %s", channel.c_str(), topic.c_str()); + ServerInstance->Logs->Log("m_permchannels", LOG_DEBUG, "Added %s with topic %s", channel.c_str(), topic.c_str()); if (modes.empty()) continue; @@ -290,6 +292,38 @@ public: 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", LOG_DEFAULT, "Error loading permchannels database: " + std::string(e.GetReason())); + } + } + } + virtual Version GetVersion() { return Version("Provides support for channel mode +P to provide permanent channels",VF_VENDOR);