diff --git a/include/znc/IRCNetwork.h b/include/znc/IRCNetwork.h index 8b06069d..5d6f2dbc 100644 --- a/include/znc/IRCNetwork.h +++ b/include/znc/IRCNetwork.h @@ -182,6 +182,7 @@ public: CString& ExpandString(const CString& sStr, CString& sRet) const; private: bool JoinChan(CChan* pChan); + bool LoadModule(const CString& sModName, const CString& sArgs, const CString& sNotice, CString& sError); protected: CString m_sName; 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/modules/awaynick.cpp b/modules/awaynick.cpp index 20c25d0a..e7e4a451 100644 --- a/modules/awaynick.cpp +++ b/modules/awaynick.cpp @@ -14,191 +14,20 @@ * limitations under the License. */ -// @todo handle raw 433 (nick in use) -#include -#include - -class CAwayNickMod; - -class CAwayNickTimer : public CTimer { -public: - CAwayNickTimer(CAwayNickMod& Module); - -private: - virtual void RunJob(); - -private: - CAwayNickMod& m_Module; -}; - -class CBackNickTimer : public CTimer { -public: - CBackNickTimer(CModule& Module) - : CTimer(&Module, 3, 1, "BackNickTimer", "Set your nick back when you reattach"), - m_Module(Module) {} - -private: - virtual void RunJob() { - CIRCNetwork* pNetwork = m_Module.GetNetwork(); - - if (pNetwork->IsUserAttached() && pNetwork->IsIRCConnected()) { - CString sConfNick = pNetwork->GetNick(); - m_Module.PutIRC("NICK " + sConfNick); - } - } - -private: - CModule& m_Module; -}; +#include class CAwayNickMod : public CModule { public: MODCONSTRUCTOR(CAwayNickMod) {} - virtual bool OnLoad(const CString& sArgs, CString& sMessage) { - if (!sArgs.empty()) - m_sFormat = sArgs; - else - m_sFormat = GetNV("nick"); - - if (m_sFormat.empty()) { - m_sFormat = "zz_%nick%"; - } - - SetNV("nick", m_sFormat); - - return true; + virtual bool OnLoad(const CString&, CString& sMessage) { + sMessage = "retired module - see http://wiki.znc.in/awaynick"; + return false; } - - virtual ~CAwayNickMod() { - } - - void StartAwayNickTimer() { - RemTimer("AwayNickTimer"); - if (FindTimer("BackNickTimer")) { - // Client disconnected before we got set back, so do nothing. - RemTimer("BackNickTimer"); - return; - } - AddTimer(new CAwayNickTimer(*this)); - } - - void StartBackNickTimer() { - CIRCSock* pIRCSock = GetNetwork()->GetIRCSock(); - - if (pIRCSock) { - CString sConfNick = GetNetwork()->GetNick(); - - if (pIRCSock->GetNick().Equals(m_sAwayNick.Left(pIRCSock->GetNick().length()))) { - RemTimer("BackNickTimer"); - AddTimer(new CBackNickTimer(*this)); - } - } - } - - virtual EModRet OnIRCRegistration(CString& sPass, CString& sNick, - CString& sIdent, CString& sRealName) { - CIRCNetwork* pNetwork = GetNetwork(); - if (pNetwork && !pNetwork->IsUserAttached()) { - m_sAwayNick = m_sFormat; - - // ExpandString doesn't know our nick yet, so do it by hand. - m_sAwayNick.Replace("%nick%", sNick); - - // We don't limit this to NICKLEN, because we dont know - // NICKLEN yet. - sNick = m_sAwayNick = pNetwork->ExpandString(m_sAwayNick); - } - return CONTINUE; - } - - virtual void OnIRCDisconnected() { - RemTimer("AwayNickTimer"); - RemTimer("BackNickTimer"); - } - - virtual void OnClientLogin() { - StartBackNickTimer(); - } - - virtual void OnClientDisconnect() { - if (!GetNetwork()->IsUserAttached()) { - StartAwayNickTimer(); - } - } - - virtual void OnModCommand(const CString& sLine) { - CString sCommand = sLine.Token(0); - if (sCommand.Equals("TIMERS")) { - ListTimers(); - } - else if (sCommand.Equals("SET")) { - CString sFormat = sLine.Token(1); - - if (!sFormat.empty()) { - m_sFormat = sFormat; - SetNV("nick", m_sFormat); - } - - if (GetNetwork()) { - CString sExpanded = GetAwayNick(); - CString sMsg = "AwayNick is set to [" + m_sFormat + "]"; - - if (m_sFormat != sExpanded) { - sMsg += " (" + sExpanded + ")"; - } - - PutModule(sMsg); - } - } else if (sCommand.Equals("SHOW")) { - if (GetNetwork()) { - CString sExpanded = GetAwayNick(); - CString sMsg = "AwayNick is set to [" + m_sFormat + "]"; - - if (m_sFormat != sExpanded) { - sMsg += " (" + sExpanded + ")"; - } - - PutModule(sMsg); - } - } else if (sCommand.Equals("HELP")) { - PutModule("Commands are: show, timers, set [awaynick]"); - } - } - - CString GetAwayNick() { - unsigned int uLen = 9; - CIRCSock* pIRCSock = GetNetwork()->GetIRCSock(); - - if (pIRCSock) { - uLen = pIRCSock->GetMaxNickLen(); - } - - m_sAwayNick = GetNetwork()->ExpandString(m_sFormat).Left(uLen); - return m_sAwayNick; - } - -private: - CString m_sFormat; - CString m_sAwayNick; }; -CAwayNickTimer::CAwayNickTimer(CAwayNickMod& Module) - : CTimer(&Module, 30, 1, "AwayNickTimer", "Set your nick while you're detached"), - m_Module(Module) {} - -void CAwayNickTimer::RunJob() { - CIRCNetwork* pNetwork = m_Module.GetNetwork(); - - if (!pNetwork->IsUserAttached() && pNetwork->IsIRCConnected()) { - m_Module.PutIRC("NICK " + m_Module.GetAwayNick()); - } -} - template<> void TModInfo(CModInfo& Info) { Info.SetWikiPage("awaynick"); - Info.SetHasArgs(true); - Info.SetArgsHelpText("This will be your nickname while you are away. Examples: nick_off or zzz_nick."); } -NETWORKMODULEDEFS(CAwayNickMod, "Change your nick while you are away") +NETWORKMODULEDEFS(CAwayNickMod, "retired module - see http://wiki.znc.in/awaynick") diff --git a/src/IRCNetwork.cpp b/src/IRCNetwork.cpp index ae3f6809..1e17cfe3 100644 --- a/src/IRCNetwork.cpp +++ b/src/IRCNetwork.cpp @@ -22,6 +22,7 @@ #include #include #include +#include using std::vector; using std::set; @@ -377,38 +378,46 @@ bool CIRCNetwork::ParseConfig(CConfig *pConfig, CString& sError, bool bUpgrade) for (vit = vsList.begin(); vit != vsList.end(); ++vit) { CString sValue = *vit; CString sModName = sValue.Token(0); + CString sNotice = "Loading network module [" + sModName + "]"; // XXX Legacy crap, added in ZNC 0.203, modified in 0.207 // Note that 0.203 == 0.207 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 ZNC 0.207 if (sModName == "autoaway") { - CUtils::PrintMessage("NOTICE: [autoaway] was renamed, " - "loading [awaystore] instead"); + sNotice = "NOTICE: [autoaway] 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"; } - CUtils::PrintAction("Loading network module [" + sModName + "]"); CString sModRet; CString sArgs = sValue.Token(1, true); - bool bModRet = GetModules().LoadModule(sModName, sArgs, CModInfo::NetworkModule, GetUser(), this, sModRet); + bool bModRet = LoadModule(sModName, sArgs, sNotice, sModRet); - CUtils::PrintStatus(bModRet, sModRet); if (!bModRet) { - sError = sModRet; - return false; + // XXX The awaynick module was retired in 1.6 (still available as external module) + if (sModName == "awaynick") { + // load simple_away instead, unless it's already on the list + if (std::find(vsList.begin(), vsList.end(), "simple_away") == vsList.end()) { + sNotice = "Loading network module [simple_away] instead"; + sModName = "simple_away"; + // not a fatal error if simple_away is not available + LoadModule(sModName, sArgs, sNotice, sModRet); + } + } else { + sError = sModRet; + return false; + } } } } @@ -1351,3 +1360,17 @@ CString& CIRCNetwork::ExpandString(const CString& sStr, CString& sRet) const { return m_pUser->ExpandString(sRet, sRet); } + +bool CIRCNetwork::LoadModule(const CString& sModName, const CString& sArgs, const CString& sNotice, CString& sError) +{ + CUtils::PrintAction(sNotice); + CString sModRet; + + bool bModRet = GetModules().LoadModule(sModName, sArgs, CModInfo::NetworkModule, GetUser(), this, sModRet); + + CUtils::PrintStatus(bModRet, sModRet); + if (!bModRet) { + sError = sModRet; + } + return bModRet; +} diff --git a/src/Modules.cpp b/src/Modules.cpp index 20b0d6af..dd55f26a 100644 --- a/src/Modules.cpp +++ b/src/Modules.cpp @@ -1077,7 +1077,7 @@ bool CModules::LoadModule(const CString& sModule, const CString& sArgs, CModInfo } if (!sRetMsg.empty()) { - sRetMsg += "[" + sRetMsg + "] "; + sRetMsg += " "; } sRetMsg += "[" + sModPath + "]"; return true; diff --git a/src/User.cpp b/src/User.cpp index edb409b9..e89b4b71 100644 --- a/src/User.cpp +++ b/src/User.cpp @@ -21,6 +21,7 @@ #include #include #include +#include using std::vector; using std::set; @@ -357,35 +358,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,46 +412,26 @@ 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) { - sError = sModRet; - return false; + // XXX The awaynick module was retired in 1.6 (still available as external module) + if (sModName == "awaynick") { + // load simple_away instead, unless it's already on the list + if (std::find(vsList.begin(), vsList.end(), "simple_away") == vsList.end()) { + sNotice = "Loading [simple_away] module instead"; + sModName = "simple_away"; + // not a fatal error if simple_away is not available + LoadModule(sModName, sArgs, sNotice, sModRet); + } + } else { + sError = sModRet; + return false; + } } continue; } @@ -1098,6 +1079,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; }