From 5fa8d03d2beaec1bff4979818b73abe5b11adfd6 Mon Sep 17 00:00:00 2001 From: psychon Date: Sat, 30 Aug 2008 19:46:28 +0000 Subject: [PATCH] Handle clients in CModules the same way users are This should remove some additional complexity, but I doubt one can benchmark these savings... BTW: Here is what I found out on how this works: The user module manager (CModules) always has m_pUser set to NULL which means that it never touches its module's user pointer. That way, the modules always have the correct pointer. For global modules, m_pUser is set on some calls. This pointer is then passed on to the modules and reset afterwards. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1182 726aef4b-f618-498e-8847-2d620e286838 --- Modules.cpp | 11 +++++------ Modules.h | 3 ++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Modules.cpp b/Modules.cpp index 773d4830..beb5588c 100644 --- a/Modules.cpp +++ b/Modules.cpp @@ -22,6 +22,7 @@ for (unsigned int a = 0; a < size(); a++) { \ try { \ type* pMod = (type *) (*this)[a]; \ + pMod->SetClient(m_pClient); \ if (m_pUser) { \ pMod->SetUser(m_pUser); \ pMod->func; \ @@ -29,6 +30,7 @@ } else { \ pMod->func; \ } \ + pMod->SetClient(NULL); \ } catch (CModule::EModException e) { \ if (e == CModule::UNLOAD) { \ UnloadModule((*this)[a]->GetModName()); \ @@ -45,6 +47,7 @@ try { \ type* pMod = (type*) (*this)[a]; \ CModule::EModRet e = CModule::CONTINUE; \ + pMod->SetClient(m_pClient); \ if (m_pUser) { \ pMod->SetUser(m_pUser); \ e = pMod->func; \ @@ -52,6 +55,7 @@ } else { \ e = pMod->func; \ } \ + pMod->SetClient(NULL); \ if (e == CModule::HALTMODS) { \ break; \ } else if (e == CModule::HALTCORE) { \ @@ -541,6 +545,7 @@ void CGlobalModule::OnFailedLogin(const CString& sUsername, const CString& sRemo CModules::CModules() { m_pUser = NULL; + m_pClient = NULL; } CModules::~CModules() { @@ -555,12 +560,6 @@ void CModules::UnloadAll() { } } -void CModules::SetClient(CClient* pClient) { - for (unsigned int a = 0; a < size(); a++) { - (*this)[a]->SetClient(pClient); - } -} - bool CModules::OnBoot() { for (unsigned int a = 0; a < size(); a++) { if (!(*this)[a]->OnBoot()) { diff --git a/Modules.h b/Modules.h index 5bac94c7..06f590ed 100644 --- a/Modules.h +++ b/Modules.h @@ -359,7 +359,7 @@ public: virtual ~CModules(); void SetUser(CUser* pUser) { m_pUser = pUser; } - void SetClient(CClient* pClient); + void SetClient(CClient* pClient) { m_pClient = pClient; } void UnloadAll(); @@ -426,6 +426,7 @@ public: protected: CUser* m_pUser; + CClient* m_pClient; }; class CGlobalModule : public CModule {