diff --git a/Client.cpp b/Client.cpp index 0a022ae3..70124aa0 100644 --- a/Client.cpp +++ b/Client.cpp @@ -601,11 +601,6 @@ bool CClient::SendMotd() { return true; } -bool CClient::ConnectionFrom(const CString& sHost, unsigned short uPort) { - DEBUG_ONLY(cout << GetSockName() << " == ConnectionFrom(" << sHost << ", " << uPort << ")" << endl); - return CZNC::Get().IsHostAllowed(sHost); -} - void CClient::AuthUser() { /* #ifdef _MODULES @@ -729,12 +724,6 @@ void CClient::IRCDisconnected() { m_pIRCSock = NULL; } -Csock* CClient::GetSockObj(const CString& sHost, unsigned short uPort) { - CClient* pSock = new CClient(sHost, uPort); - pSock->StartLoginTimeout(); - return pSock; -} - void CClient::PutIRC(const CString& sLine) { if (m_pIRCSock) { m_pIRCSock->PutIRC(sLine); diff --git a/Client.h b/Client.h index 6849e46a..a6e8271f 100644 --- a/Client.h +++ b/Client.h @@ -65,17 +65,7 @@ protected: class CClient : public Csock { public: - CClient() : Csock() { - InitClient(); - } - CClient(const CString& sHostname, unsigned short uPort, int iTimeout = 60) : Csock(sHostname, uPort, iTimeout) { - InitClient(); - } - - virtual ~CClient(); - - void InitClient() { m_pUser = NULL; m_pTimeout = NULL; m_pIRCSock = NULL; @@ -85,8 +75,12 @@ public: m_bNamesx = false; m_bUHNames = false; EnableReadLine(); + + StartLoginTimeout(); } + virtual ~CClient(); + void AcceptLogin(CUser& User); void RefuseLogin(const CString& sReason); void StartLoginTimeout(); @@ -118,8 +112,6 @@ public: virtual void Connected(); virtual void Disconnected(); virtual void ConnectionRefused(); - virtual bool ConnectionFrom(const CString& sHost, unsigned short uPort); - virtual Csock* GetSockObj(const CString& sHost, unsigned short uPort); void SetNick(const CString& s); CUser* GetUser() const { return m_pUser; } diff --git a/znc.h b/znc.h index 3a82af7d..36d51ad6 100644 --- a/znc.h +++ b/znc.h @@ -223,6 +223,21 @@ protected: CConnectUserTimer *m_pConnectUserTimer; }; +class CRealListener : public Csock { +public: + CRealListener() : Csock() {} + ~CRealListener() {} + + virtual bool ConnectionFrom(const CString& sHost, unsigned short uPort) { + DEBUG_ONLY(cout << GetSockName() << " == ConnectionFrom(" << sHost << ", " << uPort << ")" << endl); + return CZNC::Get().IsHostAllowed(sHost); + } + + virtual Csock* GetSockObj(const CString& sHost, unsigned short uPort) { + return new CClient(sHost, uPort); + } +}; + class CListener { public: CListener(unsigned short uPort, const CString& sBindHost, bool bSSL, bool bIPV6) { @@ -230,12 +245,12 @@ public: m_sBindHost = sBindHost; m_bSSL = bSSL; m_bIPV6 = bIPV6; - m_pClient = NULL; + m_pListener = NULL; } virtual ~CListener() { - if (m_pClient) - CZNC::Get().GetManager().DelSockByAddr(m_pClient); + if (m_pListener) + CZNC::Get().GetManager().DelSockByAddr(m_pListener); } // Setters @@ -253,21 +268,22 @@ public: // !Getters bool Listen() { - if (!m_uPort || m_pClient) { + if (!m_uPort || m_pListener) { return false; } - m_pClient = new CClient; + m_pListener = new CRealListener; bool bSSL = false; #ifdef HAVE_LIBSSL if (IsSSL()) { bSSL = true; - m_pClient->SetPemLocation(CZNC::Get().GetPemLocation()); + m_pListener->SetPemLocation(CZNC::Get().GetPemLocation()); } #endif - return CZNC::Get().GetManager().ListenHost(m_uPort, "_LISTENER", m_sBindHost, bSSL, SOMAXCONN, m_pClient, 0, m_bIPV6); + return CZNC::Get().GetManager().ListenHost(m_uPort, "_LISTENER", m_sBindHost, bSSL, SOMAXCONN, + m_pListener, 0, m_bIPV6); } private: protected: @@ -275,7 +291,7 @@ protected: bool m_bIPV6; unsigned short m_uPort; CString m_sBindHost; - CClient* m_pClient; + CRealListener* m_pListener; }; #endif // !_ZNC_H