From 2286291d6ba8b0e33408bc975c49d048c5fce555 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Sat, 18 Oct 2014 12:03:57 +0200 Subject: [PATCH] Add CUser::LoadModule() helper Makes it easier to retry loading replacement modules when loading retired modules fail. --- include/znc/User.h | 1 + src/User.cpp | 89 ++++++++++++++++++++++++++-------------------- 2 files changed, 52 insertions(+), 38 deletions(-) diff --git a/include/znc/User.h b/include/znc/User.h index f8e9108a..1f6428d3 100644 --- a/include/znc/User.h +++ b/include/znc/User.h @@ -238,6 +238,7 @@ protected: private: void SetKeepBuffer(bool b) { SetAutoClearChanBuffer(!b); } // XXX compatibility crap, added in 0.207 + bool LoadModule(const CString& sModName, const CString& sArgs, const CString& sNotice, CString& sError); }; #endif // !_USER_H diff --git a/src/User.cpp b/src/User.cpp index edb409b9..7b74ce80 100644 --- a/src/User.cpp +++ b/src/User.cpp @@ -357,35 +357,35 @@ bool CUser::ParseConfig(CConfig* pConfig, CString& sError) { for (vit = vsList.begin(); vit != vsList.end(); ++vit) { sValue = *vit; CString sModName = sValue.Token(0); + CString sNotice = "Loading user module [" + sModName + "]"; // XXX Legacy crap, added in ZNC 0.089 if (sModName == "discon_kick") { - CUtils::PrintMessage("NOTICE: [discon_kick] was renamed, loading [disconkick] instead"); + sNotice = "NOTICE: [discon_kick] was renamed, loading [disconkick] instead"; sModName = "disconkick"; } // XXX Legacy crap, added in ZNC 0.099 if (sModName == "fixfreenode") { - CUtils::PrintMessage("NOTICE: [fixfreenode] doesn't do anything useful anymore, ignoring it"); + sNotice = "NOTICE: [fixfreenode] doesn't do anything useful anymore, ignoring it"; continue; } // XXX Legacy crap, added in ZNC 0.207 if (sModName == "admin") { - CUtils::PrintMessage("NOTICE: [admin] module was renamed, loading [controlpanel] instead"); + sNotice = "NOTICE: [admin] module was renamed, loading [controlpanel] instead"; sModName = "controlpanel"; } // XXX Legacy crap, should have been added ZNC 0.207, but added only in 1.1 :( if (sModName == "away") { - CUtils::PrintMessage("NOTICE: [away] was renamed, " - "loading [awaystore] instead"); + sNotice = "NOTICE: [away] was renamed, loading [awaystore] instead"; sModName = "awaystore"; } // XXX Legacy crap, added in 1.1; fakeonline module was dropped in 1.0 and returned in 1.1 if (sModName == "fakeonline") { - CUtils::PrintMessage("NOTICE: [fakeonline] was renamed, loading [modules_online] instead"); + sNotice = "NOTICE: [fakeonline] was renamed, loading [modules_online] instead"; sModName = "modules_online"; } @@ -411,41 +411,10 @@ bool CUser::ParseConfig(CConfig* pConfig, CString& sError) { continue; } - CUtils::PrintAction("Loading user module [" + sModName + "]"); CString sModRet; CString sArgs = sValue.Token(1, true); - bool bModRet = true; - CModInfo ModInfo; - if (!CZNC::Get().GetModules().GetModInfo(ModInfo, sModName, sModRet)) { - sError = "Unable to find modinfo [" + sModName + "] [" + sModRet + "]"; - return false; - } - - if (!ModInfo.SupportsType(CModInfo::UserModule) && ModInfo.SupportsType(CModInfo::NetworkModule)) { - CUtils::PrintMessage("NOTICE: Module [" + sModName + "] is a network module, loading module for all networks in user."); - - // Do they have old NV? - CFile fNVFile = CFile(GetUserPath() + "/moddata/" + sModName + "/.registry"); - - for (vector::iterator it = m_vIRCNetworks.begin(); it != m_vIRCNetworks.end(); ++it) { - if (fNVFile.Exists()) { - CString sNetworkModPath = (*it)->GetNetworkPath() + "/moddata/" + sModName; - if (!CFile::Exists(sNetworkModPath)) { - CDir::MakeDir(sNetworkModPath); - } - - fNVFile.Copy(sNetworkModPath + "/.registry"); - } - - bModRet = (*it)->GetModules().LoadModule(sModName, sArgs, CModInfo::NetworkModule, this, *it, sModRet); - if (!bModRet) { - break; - } - } - } else { - bModRet = GetModules().LoadModule(sModName, sArgs, CModInfo::UserModule, this, NULL, sModRet); - } + bool bModRet = LoadModule(sModName, sArgs, sNotice, sModRet); CUtils::PrintStatus(bModRet, sModRet); if (!bModRet) { @@ -1098,6 +1067,50 @@ bool CUser::IsUserAttached() const { return false; } +bool CUser::LoadModule(const CString& sModName, const CString& sArgs, const CString& sNotice, CString& sError) +{ + bool bModRet = true; + CString sModRet; + + CModInfo ModInfo; + if (!CZNC::Get().GetModules().GetModInfo(ModInfo, sModName, sModRet)) { + sError = "Unable to find modinfo [" + sModName + "] [" + sModRet + "]"; + return false; + } + + CUtils::PrintAction(sNotice); + + if (!ModInfo.SupportsType(CModInfo::UserModule) && ModInfo.SupportsType(CModInfo::NetworkModule)) { + CUtils::PrintMessage("NOTICE: Module [" + sModName + "] is a network module, loading module for all networks in user."); + + // Do they have old NV? + CFile fNVFile = CFile(GetUserPath() + "/moddata/" + sModName + "/.registry"); + + for (vector::iterator it = m_vIRCNetworks.begin(); it != m_vIRCNetworks.end(); ++it) { + if (fNVFile.Exists()) { + CString sNetworkModPath = (*it)->GetNetworkPath() + "/moddata/" + sModName; + if (!CFile::Exists(sNetworkModPath)) { + CDir::MakeDir(sNetworkModPath); + } + + fNVFile.Copy(sNetworkModPath + "/.registry"); + } + + bModRet = (*it)->GetModules().LoadModule(sModName, sArgs, CModInfo::NetworkModule, this, *it, sModRet); + if (!bModRet) { + break; + } + } + } else { + bModRet = GetModules().LoadModule(sModName, sArgs, CModInfo::UserModule, this, NULL, sModRet); + } + + if (!bModRet) { + sError = sModRet; + } + return bModRet; +} + // Setters void CUser::SetNick(const CString& s) { m_sNick = s; } void CUser::SetAltNick(const CString& s) { m_sAltNick = s; }