diff --git a/include/znc/Modules.h b/include/znc/Modules.h index df864864..048646a0 100644 --- a/include/znc/Modules.h +++ b/include/znc/Modules.h @@ -1207,6 +1207,7 @@ public: static bool GetModInfo(CModInfo& ModInfo, const CString& sModule, CString &sRetMsg); static bool GetModPathInfo(CModInfo& ModInfo, const CString& sModule, const CString& sModPath, CString &sRetMsg); static void GetAvailableMods(std::set& ssMods, CModInfo::EModuleType eType = CModInfo::UserModule); + static void GetDefaultMods(std::set& ssMods, CModInfo::EModuleType eType = CModInfo::UserModule); // This returns the path to the .so and to the data dir // which is where static data (webadmin skins) are saved diff --git a/include/znc/znc.h b/include/znc/znc.h index 7c4f64fc..b4f3e8de 100644 --- a/include/znc/znc.h +++ b/include/znc/znc.h @@ -107,7 +107,6 @@ public: CSockManager& GetManager() { return m_Manager; } const CSockManager& GetManager() const { return m_Manager; } CModules& GetModules() { return *m_pModules; } - size_t FilterUncommonModules(std::set& ssModules); CString GetSkinName() const { return m_sSkinName; } const CString& GetStatusPrefix() const { return m_sStatusPrefix; } const CString& GetCurPath() const; diff --git a/src/Modules.cpp b/src/Modules.cpp index b696831f..90e92473 100644 --- a/src/Modules.cpp +++ b/src/Modules.cpp @@ -1196,6 +1196,28 @@ void CModules::GetAvailableMods(set& ssMods, CModInfo::EModuleType eTy GLOBALMODULECALL(OnGetAvailableMods(ssMods, eType), NOTHING); } +void CModules::GetDefaultMods(set& ssMods, CModInfo::EModuleType eType) { + + GetAvailableMods(ssMods, eType); + + const map ns = { + { "chansaver", CModInfo::UserModule }, + { "controlpanel", CModInfo::UserModule }, + { "simple_away", CModInfo::NetworkModule }, + { "webadmin", CModInfo::GlobalModule } + }; + + auto it = ssMods.begin(); + while (it != ssMods.end()) { + auto it2 = ns.find(it->GetName()); + if (it2 != ns.end() && it2->second == eType) { + ++it; + } else { + it = ssMods.erase(it); + } + } +} + bool CModules::FindModPath(const CString& sModule, CString& sModPath, CString& sDataPath) { CString sMod = sModule; diff --git a/src/znc.cpp b/src/znc.cpp index 05cf38c3..14310475 100644 --- a/src/znc.cpp +++ b/src/znc.cpp @@ -645,50 +645,13 @@ bool CZNC::WriteNewConfig(const CString& sConfigFile) { // !Listen set ssGlobalMods; - GetModules().GetAvailableMods(ssGlobalMods, CModInfo::GlobalModule); - size_t uNrOtherGlobalMods = FilterUncommonModules(ssGlobalMods); - - if (!ssGlobalMods.empty()) { - CUtils::PrintMessage(""); - CUtils::PrintMessage("-- Global Modules --"); - CUtils::PrintMessage(""); - - CTable Table; - Table.AddColumn("Name"); - Table.AddColumn("Description"); - set::iterator it; - - for (it = ssGlobalMods.begin(); it != ssGlobalMods.end(); ++it) { - const CModInfo& Info = *it; - Table.AddRow(); - Table.SetCell("Name", Info.GetName()); - Table.SetCell("Description", Info.GetDescription().Ellipsize(128)); - } - - unsigned int uTableIdx = 0; CString sLine; - while (Table.GetLine(uTableIdx++, sLine)) { - CUtils::PrintMessage(sLine); - } - - if (uNrOtherGlobalMods > 0) { - CUtils::PrintMessage("And " + CString(uNrOtherGlobalMods) + " other (uncommon) modules. You can enable those later."); - } - - CUtils::PrintMessage(""); - - for (it = ssGlobalMods.begin(); it != ssGlobalMods.end(); ++it) { - const CModInfo& Info = *it; - CString sName = Info.GetName(); - - if (CDebug::StdoutIsTTY()) { - if (CUtils::GetBoolInput("Load global module <\033[1m" + sName + "\033[22m>?", false)) - vsLines.push_back("LoadModule = " + sName); - } else { - if (CUtils::GetBoolInput("Load global module <" + sName + ">?", false)) - vsLines.push_back("LoadModule = " + sName); - } - } + GetModules().GetDefaultMods(ssGlobalMods, CModInfo::GlobalModule); + vector vsGlobalModNames; + for (set::const_iterator it = ssGlobalMods.begin(); it != ssGlobalMods.end(); ++it) { + vsGlobalModNames.push_back(it->GetName()); + vsLines.push_back("LoadModule = " + it->GetName()); } + CUtils::PrintMessage("Enabled the default global modules [" + CString(", ").Join(vsGlobalModNames.begin(), vsGlobalModNames.end()) + "]"); // User CUtils::PrintMessage(""); @@ -754,51 +717,13 @@ bool CZNC::WriteNewConfig(const CString& sConfigFile) { } set ssUserMods; - GetModules().GetAvailableMods(ssUserMods); - size_t uNrOtherUserMods = FilterUncommonModules(ssUserMods); - - if (!ssUserMods.empty()) { - vsLines.push_back(""); - CUtils::PrintMessage(""); - CUtils::PrintMessage("-- User Modules --"); - CUtils::PrintMessage(""); - - CTable Table; - Table.AddColumn("Name"); - Table.AddColumn("Description"); - set::iterator it; - - for (it = ssUserMods.begin(); it != ssUserMods.end(); ++it) { - const CModInfo& Info = *it; - Table.AddRow(); - Table.SetCell("Name", Info.GetName()); - Table.SetCell("Description", Info.GetDescription().Ellipsize(128)); - } - - unsigned int uTableIdx = 0; CString sLine; - while (Table.GetLine(uTableIdx++, sLine)) { - CUtils::PrintMessage(sLine); - } - - if (uNrOtherUserMods > 0) { - CUtils::PrintMessage("And " + CString(uNrOtherUserMods) + " other (uncommon) modules. You can enable those later."); - } - - CUtils::PrintMessage(""); - - for (it = ssUserMods.begin(); it != ssUserMods.end(); ++it) { - const CModInfo& Info = *it; - CString sName = Info.GetName(); - - if (CDebug::StdoutIsTTY()) { - if (CUtils::GetBoolInput("Load module <\033[1m" + sName + "\033[22m>?", false)) - vsLines.push_back("\tLoadModule = " + sName); - } else { - if (CUtils::GetBoolInput("Load module <" + sName + ">?", false)) - vsLines.push_back("\tLoadModule = " + sName); - } - } + GetModules().GetDefaultMods(ssUserMods, CModInfo::UserModule); + vector vsUserModNames; + for (set::const_iterator it = ssUserMods.begin(); it != ssUserMods.end(); ++it) { + vsUserModNames.push_back(it->GetName()); + vsLines.push_back("LoadModule = " + it->GetName()); } + CUtils::PrintMessage("Enabled the default user modules [" + CString(", ").Join(vsUserModNames.begin(), vsUserModNames.end()) + "]"); CUtils::PrintMessage(""); CString sAAnother = "a"; @@ -813,50 +738,13 @@ bool CZNC::WriteNewConfig(const CString& sConfigFile) { vsLines.push_back("\t"); set ssNetworkMods; - GetModules().GetAvailableMods(ssNetworkMods, CModInfo::NetworkModule); - size_t uNrOtherNetworkMods = FilterUncommonModules(ssNetworkMods); - - if (!ssNetworkMods.empty()) { - CUtils::PrintMessage(""); - CUtils::PrintMessage("-- Network Modules --"); - CUtils::PrintMessage(""); - - CTable Table; - Table.AddColumn("Name"); - Table.AddColumn("Description"); - set::iterator it; - - for (it = ssNetworkMods.begin(); it != ssNetworkMods.end(); ++it) { - const CModInfo& Info = *it; - Table.AddRow(); - Table.SetCell("Name", Info.GetName()); - Table.SetCell("Description", Info.GetDescription().Ellipsize(128)); - } - - unsigned int uTableIdx = 0; CString sLine; - while (Table.GetLine(uTableIdx++, sLine)) { - CUtils::PrintMessage(sLine); - } - - if (uNrOtherNetworkMods > 0) { - CUtils::PrintMessage("And " + CString(uNrOtherNetworkMods) + " other (uncommon) modules. You can enable those later."); - } - - CUtils::PrintMessage(""); - - for (it = ssNetworkMods.begin(); it != ssNetworkMods.end(); ++it) { - const CModInfo& Info = *it; - CString sName = Info.GetName(); - - if (CDebug::StdoutIsTTY()) { - if (CUtils::GetBoolInput("Load module <\033[1m" + sName + "\033[22m>?", false)) - vsLines.push_back("\t\tLoadModule = " + sName); - } else { - if (CUtils::GetBoolInput("Load module <" + sName + ">?", false)) - vsLines.push_back("\t\tLoadModule = " + sName); - } - } + GetModules().GetDefaultMods(ssNetworkMods, CModInfo::NetworkModule); + vector vsNetworkModNames; + for (set::const_iterator it = ssNetworkMods.begin(); it != ssNetworkMods.end(); ++it) { + vsNetworkModNames.push_back(it->GetName()); + vsLines.push_back("LoadModule = " + it->GetName()); } + CUtils::PrintMessage("Enabled the default network modules [" + CString(", ").Join(vsNetworkModNames.begin(), vsNetworkModNames.end()) + "]"); vsLines.push_back(""); CUtils::PrintMessage(""); @@ -1001,26 +889,6 @@ bool CZNC::WriteNewConfig(const CString& sConfigFile) { return bFileOpen && CUtils::GetBoolInput("Launch ZNC now?", true); } -size_t CZNC::FilterUncommonModules(set& ssModules) { - const char* ns[] = { "webadmin", "controlpanel", - "chansaver", "keepnick", "simple_away", "partyline", - "kickrejoin", "nickserv", "perform" }; - const set ssNames(ns, ns + sizeof(ns) / sizeof(ns[0])); - - size_t uNrRemoved = 0; - for(set::iterator it = ssModules.begin(); it != ssModules.end(); ) { - if(ssNames.count(it->GetName()) > 0) { - ++it; - } else { - set::iterator it2 = it++; - ssModules.erase(it2); - uNrRemoved++; - } - } - - return uNrRemoved; -} - void CZNC::BackupConfigOnce(const CString& sSuffix) { static bool didBackup = false; if (didBackup)