From 0bbab8f47224de8f191771ecea727951aa796602 Mon Sep 17 00:00:00 2001 From: prozacx Date: Sun, 22 May 2005 02:03:31 +0000 Subject: [PATCH] Added some more global module support git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@349 726aef4b-f618-498e-8847-2d620e286838 --- Modules.cpp | 11 ++++++++--- Modules.h | 7 +++++-- znc.cpp | 38 ++++++++++++++++++++++++++++++++------ 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/Modules.cpp b/Modules.cpp index 13da3f4e..c41d1ab0 100644 --- a/Modules.cpp +++ b/Modules.cpp @@ -677,21 +677,26 @@ CString CModules::FindModPath(const CString& sModule, CUser* pUser) { return (m_pZNC) ? m_pZNC->FindModPath(sModule) : ""; } -void CModules::GetAvailableMods(set& ssMods, CZNC* pZNC) { +void CModules::GetAvailableMods(set& ssMods, CZNC* pZNC, bool bGlobal) { ssMods.clear(); unsigned int a = 0; CDir Dir; Dir.FillByWildcard(pZNC->GetModPath(), "*.so"); + for (a = 0; a < Dir.size(); a++) { CFile& File = *Dir[a]; - ssMods.insert(CModInfo(File.GetShortName(), File.GetLongName(), false)); + if ((File.GetShortName().Left(2).CaseCmp("g_") == 0) == bGlobal) { + ssMods.insert(CModInfo(File.GetShortName(), File.GetLongName(), false, bGlobal)); + } } Dir.FillByWildcard(_MODDIR_, "*.so"); for (a = 0; a < Dir.size(); a++) { CFile& File = *Dir[a]; - ssMods.insert(CModInfo(File.GetShortName(), File.GetLongName(), true)); + if ((File.GetShortName().Left(2).CaseCmp("g_") == 0) == bGlobal) { + ssMods.insert(CModInfo(File.GetShortName(), File.GetLongName(), true, bGlobal)); + } } } diff --git a/Modules.h b/Modules.h index b3354dc7..723b71e5 100644 --- a/Modules.h +++ b/Modules.h @@ -96,8 +96,9 @@ private: class CModInfo { public: - CModInfo(const CString& sName, const CString& sPath, bool bSystem) { + CModInfo(const CString& sName, const CString& sPath, bool bSystem, bool bGlobal) { m_bSystem = bSystem; + m_bGlobal = bGlobal; m_sName = sName; m_sPath = sPath; } @@ -111,10 +112,12 @@ public: const CString& GetName() const { return m_sName; } const CString& GetPath() const { return m_sPath; } bool IsSystem() const { return m_bSystem; } + bool IsGlobal() const { return m_bGlobal; } // !Getters private: protected: bool m_bSystem; + bool m_bGlobal; CString m_sName; CString m_sPath; }; @@ -282,7 +285,7 @@ public: bool ReloadModule(const CString& sModule, const CString& sArgs, CUser* pUser, CString& sRetMsg); CString FindModPath(const CString& sModule, CUser* pUser = NULL); - static void GetAvailableMods(set& ssMods, CZNC* pZNC); + static void GetAvailableMods(set& ssMods, CZNC* pZNC, bool bGlobal = false); private: CZNC* m_pZNC; diff --git a/znc.cpp b/znc.cpp index 747d9dc3..4fcf5cfc 100644 --- a/znc.cpp +++ b/znc.cpp @@ -283,6 +283,32 @@ bool CZNC::WriteNewConfig(const CString& sConfig) { vsLines.push_back("ListenPort = " + CString((bAnswer) ? "+" : "") + CString::ToString(uPort)); // !ListenPort +#ifdef _MODULES + set ssGlobalMods; + CModules::GetAvailableMods(ssGlobalMods, this, true); + + if (ssGlobalMods.size()) { + CUtils::PrintMessage(""); + CUtils::PrintMessage("-- Global Modules --"); + CUtils::PrintMessage(""); + + if (CUtils::GetBoolInput("Do you want to load any global modules?")) { + for (set::iterator it = ssGlobalMods.begin(); it != ssGlobalMods.end(); it++) { + const CModInfo& Info = *it; + CString sName = Info.GetName(); + + if (sName.Right(3).CaseCmp(".so") == 0) { + sName.RightChomp(3); + } + + if (CUtils::GetBoolInput("Load global module <\033[1m" + sName + "\033[22m>?", false)) { + vsLines.push_back("LoadModule = " + sName); + } + } + } + } +#endif + // User CUtils::PrintMessage(""); CUtils::PrintMessage("Now we need to setup a user..."); @@ -324,17 +350,17 @@ bool CZNC::WriteNewConfig(const CString& sConfig) { } #ifdef _MODULES - set ssMods; - CModules::GetAvailableMods(ssMods, this); + set ssUserMods; + CModules::GetAvailableMods(ssUserMods, this); - if (ssMods.size()) { + if (ssUserMods.size()) { vsLines.push_back(""); CUtils::PrintMessage(""); - CUtils::PrintMessage("-- Modules --"); + CUtils::PrintMessage("-- User Modules --"); CUtils::PrintMessage(""); - if (CUtils::GetBoolInput("Do you want to automatically load any modules at all?")) { - for (set::iterator it = ssMods.begin(); it != ssMods.end(); it++) { + if (CUtils::GetBoolInput("Do you want to automatically load any user modules for this user?")) { + for (set::iterator it = ssUserMods.begin(); it != ssUserMods.end(); it++) { const CModInfo& Info = *it; CString sName = Info.GetName();