diff --git a/Client.cpp b/Client.cpp index 648a1a8d..b882699f 100644 --- a/Client.cpp +++ b/Client.cpp @@ -55,9 +55,6 @@ CClient::~CClient() { m_pUser->AddBytesRead(GetBytesRead()); m_pUser->AddBytesWritten(GetBytesWritten()); } - if (m_pTimeout) { - CZNC::Get().GetManager().DelCronByAddr(m_pTimeout); - } } void CClient::ReadLine(const CString& sData) { @@ -658,11 +655,6 @@ void CAuthBase::RefuseLogin(const CString& sReason) { } void CClient::RefuseLogin(const CString& sReason) { - if (m_pTimeout) { - m_pTimeout->Stop(); - m_pTimeout = NULL; - } - PutStatus("Bad username and/or password."); PutClient(":irc.znc.in 464 " + GetNick() + " :" + sReason); Close(Csock::CLT_AFTERWRITE); @@ -678,10 +670,9 @@ void CClient::AcceptLogin(CUser& User) { m_sPass = ""; m_pUser = &User; - if (m_pTimeout) { - m_pTimeout->Stop(); - m_pTimeout = NULL; - } + // Set our proper timeout and set back our proper timeout mode + // (constructor set a different timeout and mode) + SetTimeout(240, TMO_READ); SetSockName("USR::" + m_pUser->GetUserName()); @@ -693,23 +684,12 @@ void CClient::AcceptLogin(CUser& User) { MODULECALL(OnClientLogin(), m_pUser, this, ); } -void CClient::StartLoginTimeout() { - m_pTimeout = new CClientTimeout(this); - CZNC::Get().GetManager().AddCron(m_pTimeout); -} - -void CClient::LoginTimeout() { +void CClient::Timeout() { PutClient("ERROR :Closing link [Timeout]"); - Close(Csock::CLT_AFTERWRITE); - if (m_pTimeout) { - m_pTimeout->Stop(); - m_pTimeout = NULL; - } } void CClient::Connected() { DEBUG(GetSockName() << " == Connected();"); - SetTimeout(240, TMO_READ); // Now that we are connected, let nature take its course } void CClient::ConnectionRefused() { diff --git a/Client.h b/Client.h index 0e0e880d..7e5c46f6 100644 --- a/Client.h +++ b/Client.h @@ -18,7 +18,6 @@ class CZNC; class CUser; class CIRCSock; class CClient; -class CClientTimeout; // !Forward Declarations class CAuthBase { @@ -70,9 +69,8 @@ protected: class CClient : public CZNCSock { public: - CClient(const CString& sHostname, unsigned short uPort, int iTimeout = 60) : CZNCSock(sHostname, uPort, iTimeout) { + CClient(const CString& sHostname, unsigned short uPort) : CZNCSock(sHostname, uPort) { m_pUser = NULL; - m_pTimeout = NULL; m_pIRCSock = NULL; m_bGotPass = false; m_bGotNick = false; @@ -84,7 +82,9 @@ public: // a little more gentle ;) SetMaxBufferThreshold(1024); - StartLoginTimeout(); + // Disable all timeout types. The socket will now time out in 60 + // seconds, no matter what. AcceptLogin() fixes this up. + SetTimeout(60, 0); SetNick("unknown-nick"); } @@ -93,8 +93,6 @@ public: void AcceptLogin(CUser& User); void RefuseLogin(const CString& sReason); - void StartLoginTimeout(); - void LoginTimeout(); CString GetNick(bool bAllowIRCNick = true) const; CString GetNickMask() const; @@ -121,6 +119,7 @@ public: void HelpUser(); void AuthUser(); virtual void Connected(); + virtual void Timeout(); virtual void Disconnected(); virtual void ConnectionRefused(); virtual void ReachedMaxBuffer(); @@ -141,7 +140,6 @@ protected: CString m_sUser; CIRCSock* m_pIRCSock; CSmartPtr m_spAuth; - CClientTimeout* m_pTimeout; }; #endif // !_CLIENT_H diff --git a/Timers.h b/Timers.h index db00c34a..429fa15e 100644 --- a/Timers.h +++ b/Timers.h @@ -64,24 +64,4 @@ protected: CUser* m_pUser; }; -class CClientTimeout : public CCron { -public: - CClientTimeout(CClient* pClient) : CCron() { - m_pClient = pClient; - SetName("CClientTimeout::UNKNOWN"); - StartMaxCycles(60, 1); - } - virtual ~CClientTimeout() {} - -protected: - virtual void RunJob() { - if (m_pClient) { - m_pClient->LoginTimeout(); - m_pClient = NULL; - } - } - - CClient* m_pClient; -}; - #endif // !_TIMERS_H