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 34cf568d..1e17cfe3 100644 --- a/src/IRCNetwork.cpp +++ b/src/IRCNetwork.cpp @@ -22,6 +22,7 @@ #include #include #include +#include using std::vector; using std::set; @@ -404,8 +405,19 @@ bool CIRCNetwork::ParseConfig(CConfig *pConfig, CString& sError, bool bUpgrade) bool bModRet = LoadModule(sModName, sArgs, sNotice, 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; + } } } } diff --git a/src/User.cpp b/src/User.cpp index 7b74ce80..e89b4b71 100644 --- a/src/User.cpp +++ b/src/User.cpp @@ -21,6 +21,7 @@ #include #include #include +#include using std::vector; using std::set; @@ -418,8 +419,19 @@ bool CUser::ParseConfig(CConfig* pConfig, CString& sError) { 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; }