Permalink
Browse files

Merge branch 'master' of github.com:znc/znc

  • Loading branch information...
2 parents f483053 + c7d171b commit 3c0e209363bb75463deffbdff9dc6b490f70d453 Alexey Sokolov committed Oct 6, 2011
Showing with 122 additions and 143 deletions.
  1. +1 −0 include/znc/IRCNetwork.h
  2. +16 −9 include/znc/znc.h
  3. +51 −1 src/IRCNetwork.cpp
  4. +54 −133 src/znc.cpp
@@ -95,6 +95,7 @@ class CIRCNetwork {
bool IsIRCAway() const { return m_bIRCAway; }
void SetIRCAway(bool b) { m_bIRCAway = b; }
+ bool Connect();
/** This method will return whether the user is connected and authenticated to an IRC server.
*/
bool IsIRCConnected() const;
View
@@ -15,13 +15,15 @@
#include <znc/Socket.h>
#include <znc/Listener.h>
#include <map>
+#include <list>
using std::map;
+using std::list;
class CListener;
class CUser;
class CIRCNetwork;
-class CConnectUserTimer;
+class CConnectQueueTimer;
class CConfig;
class CFile;
@@ -139,14 +141,18 @@ class CZNC {
const VCString& GetMotd() const { return m_vsMotd; }
// !MOTD
- // Create a CIRCSocket. Return false if user cant connect
- bool ConnectNetwork(CIRCNetwork *pNetwork);
- // This creates a CConnectUserTimer if we haven't got one yet
- void EnableConnectUser();
- void DisableConnectUser();
+ void AddServerThrottle(CString sName) { m_sConnectThrottle.AddItem(sName); }
+ bool GetServerThrottle(CString sName) { return m_sConnectThrottle.GetItem(sName); }
- // Never call this unless you are CConnectUserTimer::~CConnectUserTimer()
- void LeakConnectUser(CConnectUserTimer *pTimer);
+ void AddNetworkToQueue(CIRCNetwork *pNetwork);
+ list<CIRCNetwork*>& GetConnectionQueue() { return m_lpConnectQueue; }
+
+ // This creates a CConnectQueueTimer if we haven't got one yet
+ void EnableConnectQueue();
+ void DisableConnectQueue();
+
+ // Never call this unless you are CConnectQueueTimer::~CConnectQueueTimer()
+ void LeakConnectQueueTimer(CConnectQueueTimer *pTimer);
static void DumpConfig(const CConfig* Config);
@@ -187,7 +193,8 @@ class CZNC {
CModules* m_pModules;
unsigned long long m_uBytesRead;
unsigned long long m_uBytesWritten;
- CConnectUserTimer *m_pConnectUserTimer;
+ list<CIRCNetwork*> m_lpConnectQueue;
+ CConnectQueueTimer *m_pConnectQueueTimer;
TCacheMap<CString> m_sConnectThrottle;
bool m_bProtectWebSessions;
};
View
@@ -159,6 +159,9 @@ CIRCNetwork::~CIRCNetwork() {
m_vChans.clear();
SetUser(NULL);
+
+ // Make sure we are not in the connection queue
+ CZNC::Get().GetConnectionQueue().remove(this);
}
void CIRCNetwork::DelServers() {
@@ -810,6 +813,53 @@ CString CIRCNetwork::GetCurNick() const {
return "";
}
+bool CIRCNetwork::Connect() {
+ if (!m_pUser->GetIRCConnectEnabled() || m_pIRCSock || !HasServers())
+ return false;
+
+ CServer *pServer = GetNextServer();
+ if (!pServer)
+ return false;
+
+ if (CZNC::Get().GetServerThrottle(pServer->GetName())) {
+ CZNC::Get().AddNetworkToQueue(this);
+ return false;
+ }
+
+ CZNC::Get().AddServerThrottle(pServer->GetName());
+
+ bool bSSL = pServer->IsSSL();
+#ifndef HAVE_LIBSSL
+ if (bSSL) {
+ PutStatus("Cannot connect to [" + pServer->GetString(false) + "], ZNC is not compiled with SSL.");
+ CZNC::Get().AddNetworkToQueue(this);
+ return false;
+ }
+#endif
+
+ CIRCSock *pIRCSock = new CIRCSock(this);
+ pIRCSock->SetPass(pServer->GetPass());
+
+ DEBUG("Connecting user/network [" << m_sName << "/" << m_sName << "]");
+
+ NETWORKMODULECALL(OnIRCConnecting(pIRCSock), m_pUser, this, NULL,
+ DEBUG("Some module aborted the connection attempt");
+ PutStatus("Some module aborted the connection attempt");
+ delete pIRCSock;
+ CZNC::Get().AddNetworkToQueue(this);
+ return false;
+ );
+
+ CString sSockName = "IRC::" + m_pUser->GetUserName() + "::" + m_sName;
+ if (!CZNC::Get().GetManager().Connect(pServer->GetName(), pServer->GetPort(), sSockName, 120, bSSL, m_pUser->GetBindHost(), pIRCSock)) {
+ PutStatus("Unable to connect. (Bad host?)");
+ CZNC::Get().AddNetworkToQueue(this);
+ return false;
+ }
+
+ return true;
+}
+
bool CIRCNetwork::IsIRCConnected() const {
const CIRCSock* pSock = GetIRCSock();
return (pSock && pSock->IsAuthed());
@@ -832,7 +882,7 @@ void CIRCNetwork::IRCDisconnected() {
void CIRCNetwork::CheckIRCConnect() {
// Do we want to connect?
if (m_pUser->GetIRCConnectEnabled() && GetIRCSock() == NULL)
- CZNC::Get().EnableConnectUser();
+ CZNC::Get().AddNetworkToQueue(this);
}
bool CIRCNetwork::PutIRC(const CString& sLine) {
Oops, something went wrong.

0 comments on commit 3c0e209

Please sign in to comment.