diff --git a/Modules.cpp b/Modules.cpp index a507e1f4..87c2b763 100644 --- a/Modules.cpp +++ b/Modules.cpp @@ -160,6 +160,7 @@ const CString& CSocket::GetLabel() const { return m_sLabel; } /////////////////// !Socket /////////////////// CModule::CModule(void* pDLL, CUser* pUser, const CString& sModName) { + m_bFake = false; m_pDLL = pDLL; m_pManager = &(CZNC::Get().GetManager());; m_pUser = pUser; @@ -172,6 +173,7 @@ CModule::CModule(void* pDLL, CUser* pUser, const CString& sModName) { } CModule::CModule(void* pDLL, const CString& sModName) { + m_bFake = false; m_pDLL = pDLL; m_pManager = &(CZNC::Get().GetManager()); m_pUser = NULL; @@ -497,7 +499,9 @@ CModules::CModules() { m_pUser = NULL; } -CModules::~CModules() {} +CModules::~CModules() { + UnloadAll(); +} void CModules::UnloadAll() { while (size()) { @@ -666,7 +670,7 @@ CModule* CModules::FindModule(const CString& sModule) const { return NULL; } -bool CModules::LoadModule(const CString& sModule, const CString& sArgs, CUser* pUser, CString& sRetMsg) { +bool CModules::LoadModule(const CString& sModule, const CString& sArgs, CUser* pUser, CString& sRetMsg, bool bFake) { #ifndef _MODULES sRetMsg = "Unable to load module [" + sModule + "] module support was not enabled."; return false; @@ -692,6 +696,16 @@ bool CModules::LoadModule(const CString& sModule, const CString& sArgs, CUser* p return false; } + if (bFake) { + CModule* pModule = new CModule(NULL, sModule); + pModule->SetArgs(sArgs); + pModule->SetDescription("<>"); + pModule->SetFake(true); + push_back(pModule); + sRetMsg = "Loaded fake module [" + sModule + "] [" + sModPath + "]"; + return true; + } + unsigned int uDLFlags = RTLD_LAZY; if (!pUser) { @@ -808,6 +822,19 @@ bool CModules::UnloadModule(const CString& sModule, CString& sRetMsg) { return false; } + if (pModule->IsFake()) { + for (iterator it = begin(); it != end(); it++) { + if (*it == pModule) { + erase(it); + sRetMsg = "Fake module [" + sMod + "] unloaded"; + return true; + } + } + + sRetMsg = "Fake module [" + sMod + "] not loaded."; + return false; + } + void* p = pModule->GetDLL(); if (p) { diff --git a/Modules.h b/Modules.h index f1b20748..6560b3e9 100644 --- a/Modules.h +++ b/Modules.h @@ -279,11 +279,13 @@ public: const CString& GetSavePath() const { if (!CFile::Exists(m_sSavePath)) { CUtils::MakeDir(m_sSavePath); } return m_sSavePath; } // Setters + void SetFake(bool b) { m_bFake = b; } void SetDescription(const CString& s) { m_sDescription = s; } void SetArgs(const CString& s) { m_sArgs = s; } // !Setters // Getters + bool IsFake() const { return m_bFake; } const CString& GetDescription() const { return m_sDescription; } const CString& GetArgs() const { return m_sArgs; } CUser* GetUser() { return m_pUser; } @@ -291,6 +293,7 @@ public: // !Getters protected: + bool m_bFake; CString m_sDescription; vector m_vTimers; vector m_vSockets; @@ -355,7 +358,7 @@ public: virtual bool OnChanNotice(const CNick& Nick, CChan& Channel, CString& sMessage); CModule* FindModule(const CString& sModule) const; - bool LoadModule(const CString& sModule, const CString& sArgs, CUser* pUser, CString& sRetMsg); + bool LoadModule(const CString& sModule, const CString& sArgs, CUser* pUser, CString& sRetMsg, bool bFake = false); bool UnloadModule(const CString& sModule); bool UnloadModule(const CString& sModule, CString& sRetMsg); bool ReloadModule(const CString& sModule, const CString& sArgs, CUser* pUser, CString& sRetMsg);