diff --git a/Chan.cpp b/Chan.cpp index 0610ff01..428e6b90 100644 --- a/Chan.cpp +++ b/Chan.cpp @@ -42,6 +42,7 @@ void CChan::Reset() { m_ulTopicDate = 0; m_ulCreationDate = 0; ClearNicks(); + ResetJoinTries(); } bool CChan::WriteConfig(CFile& File) { diff --git a/Chan.h b/Chan.h index ccc1ee36..03af07a0 100644 --- a/Chan.h +++ b/Chan.h @@ -113,6 +113,8 @@ public: void SetCreationDate(unsigned long u) { m_ulCreationDate = u; } void Disable() { m_bDisabled = true; } void Enable() { m_bDisabled = false; } + void IncJoinTries() { m_uJoinTries++; } + void ResetJoinTries() { m_uJoinTries = 0; } // !Setters // Getters @@ -140,6 +142,7 @@ public: bool InConfig() const { return m_bInConfig; } unsigned long GetCreationDate() const { return m_ulCreationDate; } bool IsDisabled() const { return m_bDisabled; } + unsigned int GetJoinTries() { return m_uJoinTries; } // !Getters private: protected: @@ -160,6 +163,7 @@ protected: CUser* m_pUser; CNick m_Nick; unsigned int m_uLimit; + unsigned int m_uJoinTries; CString m_sDefaultModes; vector m_vsBans; map m_msNicks; // Todo: make this caseless (irc style) diff --git a/IRCSock.cpp b/IRCSock.cpp index 26a70a03..c67ab3cc 100644 --- a/IRCSock.cpp +++ b/IRCSock.cpp @@ -476,12 +476,20 @@ void CIRCSock::ReadLine(const CString& sData) { sChan.LeftChomp(); } + CChan* pChan; + // Todo: use nick compare function if (Nick.GetNick().CaseCmp(GetNick()) == 0) { m_pUser->AddChan(sChan, false); + pChan = m_pUser->FindChan(sChan); + if (pChan) { + pChan->ResetJoinTries(); + pChan->Enable(); + } + } else { + pChan = m_pUser->FindChan(sChan); } - CChan* pChan = m_pUser->FindChan(sChan); if (pChan) { pChan->AddNick(Nick.GetNickMask()); MODULECALL(OnJoin(Nick.GetNickMask(), *pChan), m_pUser, NULL, ); diff --git a/User.cpp b/User.cpp index 762e9ff8..e701bb96 100644 --- a/User.cpp +++ b/User.cpp @@ -37,6 +37,7 @@ CUser::CUser(const CString& sUserName) { m_sStatusPrefix = "*"; m_sChanPrefixes = "#&"; m_uBufferCount = 50; + m_uMaxJoinTries = 0; m_bKeepBuffer = false; m_bAutoCycle = true; m_bBeingDeleted = false; @@ -543,6 +544,7 @@ bool CUser::WriteConfig(CFile& File) { PrintLine(File, "AppendTimestamp", CString((GetTimestampAppend()) ? "true" : "false")); PrintLine(File, "PrependTimestamp", CString((GetTimestampPrepend()) ? "true" : "false")); PrintLine(File, "TimezoneOffset", CString(m_fTimezoneOffset)); + PrintLine(File, "JoinTries", CString(m_uMaxJoinTries)); File.Write("\r\n"); // Allow Hosts @@ -618,7 +620,13 @@ void CUser::JoinChans() { for (unsigned int a = 0; a < m_vChans.size(); a++) { CChan* pChan = m_vChans[a]; if (!pChan->IsOn() && !pChan->IsDisabled()) { - PutIRC("JOIN " + pChan->GetName() + " " + pChan->GetKey()); + if (JoinTries() != 0 && pChan->GetJoinTries() >= JoinTries()) { + PutStatus("The channel " + pChan->GetName() + " could not be joined, disabling it."); + pChan->Disable(); + } else { + pChan->IncJoinTries(); + PutIRC("JOIN " + pChan->GetName() + " " + pChan->GetKey()); + } } } } @@ -657,7 +665,7 @@ bool CUser::DelServer(const CString& sName) { if (pIRCSock) { pIRCSock->Close(); - PutUser("Your current server was removed, jumping..."); + PutStatus("Your current server was removed, jumping..."); } } else if (m_uServerIdx >= m_vServers.size()) { m_uServerIdx = 0; diff --git a/User.h b/User.h index 4b19e91c..6a7213b9 100644 --- a/User.h +++ b/User.h @@ -138,6 +138,7 @@ public: void SetTimestampAppend(bool b) { m_bAppendTimestamp = b; } void SetTimestampPrepend(bool b) { m_bPrependTimestamp = b; } void SetTimezoneOffset(float b) { m_fTimezoneOffset = b; } + void SetJoinTries(unsigned int i) { m_uMaxJoinTries = i; } // !Setters // Getters @@ -186,6 +187,7 @@ public: float GetTimezoneOffset() const { return m_fTimezoneOffset; } unsigned long long BytesRead() const { return m_uBytesRead; } unsigned long long BytesWritten() const { return m_uBytesWritten; } + unsigned int JoinTries() const { return m_uMaxJoinTries; } // !Getters private: protected: @@ -242,6 +244,7 @@ protected: unsigned int m_uBufferCount; unsigned long long m_uBytesRead; unsigned long long m_uBytesWritten; + unsigned int m_uMaxJoinTries; #ifdef _MODULES CModules* m_pModules; diff --git a/znc.cpp b/znc.cpp index f6cf5ab0..ec94ea08 100644 --- a/znc.cpp +++ b/znc.cpp @@ -1028,6 +1028,9 @@ bool CZNC::ParseConfig(const CString& sConfig) { } else if (sName.CaseCmp("TimezoneOffset") == 0) { pUser->SetTimezoneOffset(sValue.ToDouble()); // there is no ToFloat() continue; + } else if (sName.CaseCmp("JoinTries") == 0) { + pUser->SetJoinTries(sValue.ToUInt()); + continue; } else if (sName.CaseCmp("LoadModule") == 0) { CString sModName = sValue.Token(0); CUtils::PrintAction("Loading Module [" + sModName + "]");