From aed1d61a98809eb5a10bb0b80bec7187bfc2e145 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 10 Nov 2014 21:39:54 +0100 Subject: [PATCH] Revise CChan::JoinUser() & AttachUser() The old AttachUser() that sent JOIN without topic or names replies would leave clients in incomplete/broken state. JoinUser() was doing two things; depending on passed arguments it was either joining user on the channel on IRC, or attaching clients (properly). Now JoinUser() joins the user on IRC, and AttachUser() attaches as expected from the method names. --- include/znc/Chan.h | 4 ++-- modules/stickychan.cpp | 2 +- src/Chan.cpp | 20 +++++++++----------- src/Client.cpp | 2 +- src/IRCNetwork.cpp | 2 +- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/include/znc/Chan.h b/include/znc/Chan.h index 5fcd3316..4f33831d 100644 --- a/include/znc/Chan.h +++ b/include/znc/Chan.h @@ -63,9 +63,9 @@ public: CConfig ToConfig() const; void Clone(CChan& chan); void Cycle() const; - void JoinUser(bool bForce = false, const CString& sKey = "", CClient* pClient = NULL); + void JoinUser(const CString& sKey = ""); + void AttachUser(CClient* pClient = NULL); void DetachUser(); - void AttachUser(); void OnWho(const CString& sNick, const CString& sIdent, const CString& sHost); diff --git a/modules/stickychan.cpp b/modules/stickychan.cpp index 36755448..9a4737f4 100644 --- a/modules/stickychan.cpp +++ b/modules/stickychan.cpp @@ -44,7 +44,7 @@ public: if (pChan) { - pChan->JoinUser(true, "", GetClient()); + pChan->JoinUser(); return HALT; } } diff --git a/src/Chan.cpp b/src/Chan.cpp index b0e86ac4..21bf6c8d 100644 --- a/src/Chan.cpp +++ b/src/Chan.cpp @@ -116,7 +116,7 @@ void CChan::Clone(CChan& chan) { // and only attach if we are on the channel) if (IsOn()) { if (IsDetached()) { - JoinUser(false, ""); + AttachUser(); } else { DetachUser(); } @@ -129,13 +129,18 @@ void CChan::Cycle() const { m_pNetwork->PutIRC("PART " + GetName() + "\r\nJOIN " + GetName() + " " + GetKey()); } -void CChan::JoinUser(bool bForce, const CString& sKey, CClient* pClient) { - if (!bForce && (!IsOn() || !IsDetached())) { - m_pNetwork->PutIRC("JOIN " + GetName() + " " + ((sKey.empty()) ? GetKey() : sKey)); +void CChan::JoinUser(const CString& sKey) { + if (!sKey.empty()) { + SetKey(sKey); + } + if (!IsOn() || !IsDetached()) { + m_pNetwork->PutIRC("JOIN " + GetName() + " " + GetKey()); SetDetached(false); return; } +} +void CChan::AttachUser(CClient* pClient) { m_pNetwork->PutUser(":" + m_pNetwork->GetIRCNick().GetNickMask() + " JOIN :" + GetName(), pClient); if (!GetTopic().empty()) { @@ -199,13 +204,6 @@ void CChan::DetachUser() { } } -void CChan::AttachUser() { - if (m_bDetached) { - m_pNetwork->PutUser(":" + m_pNetwork->GetIRCNick().GetNickMask() + " JOIN " + GetName()); - m_bDetached = false; - } -} - CString CChan::GetModeString() const { CString sModes, sArgs; diff --git a/src/Client.cpp b/src/Client.cpp index b79e3576..b7809f76 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -435,7 +435,7 @@ void CClient::ReadLine(const CString& sData) { CChan* pChan = m_pNetwork->FindChan(sChannel); if (pChan) { - pChan->JoinUser(false, sKey); + pChan->JoinUser(sKey); continue; } diff --git a/src/IRCNetwork.cpp b/src/IRCNetwork.cpp index e809d243..fa97ba5a 100644 --- a/src/IRCNetwork.cpp +++ b/src/IRCNetwork.cpp @@ -621,7 +621,7 @@ void CIRCNetwork::ClientConnected(CClient *pClient) { const vector& vChans = GetChans(); for (size_t a = 0; a < vChans.size(); a++) { if ((vChans[a]->IsOn()) && (!vChans[a]->IsDetached())) { - vChans[a]->JoinUser(true, "", pClient); + vChans[a]->AttachUser(pClient); } }