From 83b9a28e4c04ea73209df6d0bfaca2aa4c1d4cdf Mon Sep 17 00:00:00 2001 From: Toon Schoenmakers Date: Thu, 10 Oct 2013 17:22:16 +0200 Subject: [PATCH 1/3] Implemented a nick compare function As suggested by the todos in IRCSock, added IsNick(CString) method so the ugly Nick.GetNick().Equals(GetNick()) could be simplified. Signed-off-by: Toon Schoenmakers --- include/znc/Nick.h | 1 + src/IRCSock.cpp | 9 +++------ src/Nick.cpp | 4 ++++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/znc/Nick.h b/include/znc/Nick.h index 97eb8482..00480ad8 100644 --- a/include/znc/Nick.h +++ b/include/znc/Nick.h @@ -37,6 +37,7 @@ public: void Parse(const CString& sNickMask); CString GetHostMask() const; size_t GetCommonChans(std::vector& vChans, CIRCNetwork* pNetwork) const; + bool IsNick(const CString& nickname) const; // Setters void SetNetwork(CIRCNetwork* pNetwork); diff --git a/src/IRCSock.cpp b/src/IRCSock.cpp index f9a394a1..2959f781 100644 --- a/src/IRCSock.cpp +++ b/src/IRCSock.cpp @@ -512,8 +512,7 @@ void CIRCSock::ReadLine(const CString& sData) { } } - // Todo: use nick compare function here - if (Nick.GetNick().Equals(GetNick())) { + if (Nick.IsNick(GetNick())) { // We are changing our own nick, the clients always must see this! bIsVisible = false; SetNick(sNewNick); @@ -563,8 +562,7 @@ void CIRCSock::ReadLine(const CString& sData) { CString sChan = sRest.Token(0).TrimPrefix_n(); CChan* pChan; - // Todo: use nick compare function - if (Nick.GetNick().Equals(GetNick())) { + if (Nick.IsNick(GetNick())) { m_pNetwork->AddChan(sChan, false); pChan = m_pNetwork->FindChan(sChan); if (pChan) { @@ -598,8 +596,7 @@ void CIRCSock::ReadLine(const CString& sData) { bDetached = true; } - // Todo: use nick compare function - if (Nick.GetNick().Equals(GetNick())) { + if (Nick.IsNick(GetNick())) { m_pNetwork->DelChan(sChan); } diff --git a/src/Nick.cpp b/src/Nick.cpp index 55ba4759..79de72f4 100644 --- a/src/Nick.cpp +++ b/src/Nick.cpp @@ -78,6 +78,10 @@ size_t CNick::GetCommonChans(vector& vRetChans, CIRCNetwork* pNetwork) c return vRetChans.size(); } +bool CNick::IsNick(const CString& nickname) const { + return m_sNick.Equals(nickname); +} + void CNick::SetNetwork(CIRCNetwork* pNetwork) { m_pNetwork = pNetwork; } void CNick::SetNick(const CString& s) { m_sNick = s; } void CNick::SetIdent(const CString& s) { m_sIdent = s; } From 9166f5a25009ff0f642fac979d150058a5915635 Mon Sep 17 00:00:00 2001 From: Toon Schoenmakers Date: Thu, 10 Oct 2013 18:36:03 +0200 Subject: [PATCH 2/3] Renamed IsNick to NickEquals Also added a TODO to add proper IRC case comparing. Signed-off-by: Toon Schoenmakers --- include/znc/Nick.h | 2 +- src/IRCSock.cpp | 6 +++--- src/Nick.cpp | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/znc/Nick.h b/include/znc/Nick.h index 00480ad8..9f691f30 100644 --- a/include/znc/Nick.h +++ b/include/znc/Nick.h @@ -37,7 +37,7 @@ public: void Parse(const CString& sNickMask); CString GetHostMask() const; size_t GetCommonChans(std::vector& vChans, CIRCNetwork* pNetwork) const; - bool IsNick(const CString& nickname) const; + bool NickEquals(const CString& nickname) const; // Setters void SetNetwork(CIRCNetwork* pNetwork); diff --git a/src/IRCSock.cpp b/src/IRCSock.cpp index 2959f781..101bc970 100644 --- a/src/IRCSock.cpp +++ b/src/IRCSock.cpp @@ -512,7 +512,7 @@ void CIRCSock::ReadLine(const CString& sData) { } } - if (Nick.IsNick(GetNick())) { + if (Nick.NickEquals(GetNick())) { // We are changing our own nick, the clients always must see this! bIsVisible = false; SetNick(sNewNick); @@ -562,7 +562,7 @@ void CIRCSock::ReadLine(const CString& sData) { CString sChan = sRest.Token(0).TrimPrefix_n(); CChan* pChan; - if (Nick.IsNick(GetNick())) { + if (Nick.NickEquals(GetNick())) { m_pNetwork->AddChan(sChan, false); pChan = m_pNetwork->FindChan(sChan); if (pChan) { @@ -596,7 +596,7 @@ void CIRCSock::ReadLine(const CString& sData) { bDetached = true; } - if (Nick.IsNick(GetNick())) { + if (Nick.NickEquals(GetNick())) { m_pNetwork->DelChan(sChan); } diff --git a/src/Nick.cpp b/src/Nick.cpp index 79de72f4..858990da 100644 --- a/src/Nick.cpp +++ b/src/Nick.cpp @@ -78,7 +78,9 @@ size_t CNick::GetCommonChans(vector& vRetChans, CIRCNetwork* pNetwork) c return vRetChans.size(); } -bool CNick::IsNick(const CString& nickname) const { +bool CNick::NickEquals(const CString& nickname) const { + //TODO add proper IRC case mapping here + //https://tools.ietf.org/html/draft-brocklesby-irc-isupport-03#section-3.1 return m_sNick.Equals(nickname); } From 98ceafb1ba097e806526c34a4619ed924f5271a2 Mon Sep 17 00:00:00 2001 From: Toon Schoenmakers Date: Thu, 10 Oct 2013 22:35:49 +0200 Subject: [PATCH 3/3] Replaced the GetNick().Equals() with NickEquals() where possible Signed-off-by: Toon Schoenmakers --- modules/autocycle.cpp | 2 +- modules/keepnick.cpp | 6 +++--- modules/nickserv.cpp | 2 +- modules/q.cpp | 4 ++-- modules/savebuff.cpp | 6 +++--- src/Chan.cpp | 6 +++--- src/IRCSock.cpp | 4 ++-- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/modules/autocycle.cpp b/modules/autocycle.cpp index aadfd6cb..159537e6 100644 --- a/modules/autocycle.cpp +++ b/modules/autocycle.cpp @@ -142,7 +142,7 @@ protected: // Is that person us and we don't have op? const CNick& pNick = Channel.GetNicks().begin()->second; - if (!pNick.HasPerm(CChan::Op) && pNick.GetNick().Equals(m_pNetwork->GetCurNick())) { + if (!pNick.HasPerm(CChan::Op) && pNick.NickEquals(m_pNetwork->GetCurNick())) { Channel.Cycle(); m_recentlyCycled.AddItem(Channel.GetName()); } diff --git a/modules/keepnick.cpp b/modules/keepnick.cpp index 471a6ba7..511bc9b0 100644 --- a/modules/keepnick.cpp +++ b/modules/keepnick.cpp @@ -78,7 +78,7 @@ public: void OnNick(const CNick& Nick, const CString& sNewNick, const vector& vChans) { if (sNewNick == m_pNetwork->GetIRCSock()->GetNick()) { // We are changing our own nick - if (Nick.GetNick().Equals(GetNick())) { + if (Nick.NickEquals(GetNick())) { // We are changing our nick away from the conf setting. // Let's assume the user wants this and disable // this module (to avoid fighting nickserv). @@ -92,14 +92,14 @@ public: } // If the nick we want is free now, be fast and get the nick - if (Nick.GetNick().Equals(GetNick())) { + if (Nick.NickEquals(GetNick())) { KeepNick(); } } void OnQuit(const CNick& Nick, const CString& sMessage, const vector& vChans) { // If someone with the nick we want quits, be fast and get the nick - if (Nick.GetNick().Equals(GetNick())) { + if (Nick.NickEquals(GetNick())) { KeepNick(); } } diff --git a/modules/nickserv.cpp b/modules/nickserv.cpp index a03d5588..0590db47 100644 --- a/modules/nickserv.cpp +++ b/modules/nickserv.cpp @@ -157,7 +157,7 @@ public: void HandleMessage(CNick& Nick, const CString& sMessage) { CString sNickServName = (!GetNV("NickServName").empty()) ? GetNV("NickServName") : "NickServ"; if (!GetNV("Password").empty() - && Nick.GetNick().Equals(sNickServName) + && Nick.NickEquals(sNickServName) && (sMessage.find("msg") != CString::npos || sMessage.find("authenticate") != CString::npos || sMessage.find("choose a different nickname") != CString::npos diff --git a/modules/q.cpp b/modules/q.cpp index 750f8632..9e422a88 100644 --- a/modules/q.cpp +++ b/modules/q.cpp @@ -312,7 +312,7 @@ private: } EModRet HandleMessage(const CNick& Nick, CString sMessage) { - if (!Nick.GetNick().Equals("Q") || !Nick.GetHost().Equals("CServe.quakenet.org")) + if (!Nick.NickEquals("Q") || !Nick.GetHost().Equals("CServe.quakenet.org")) return CONTINUE; sMessage.Trim(); @@ -418,7 +418,7 @@ private: } bool IsSelf(const CNick& Nick) { - return Nick.GetNick().Equals(m_pNetwork->GetCurNick()); + return Nick.NickEquals(m_pNetwork->GetCurNick()); } bool PackHex(const CString& sHex, CString& sPackedHex) { diff --git a/modules/savebuff.cpp b/modules/savebuff.cpp index ea291a49..f3e4c742 100644 --- a/modules/savebuff.cpp +++ b/modules/savebuff.cpp @@ -297,7 +297,7 @@ public: { AddBuffer(*vChans[a], SpoofChanMsg(vChans[a]->GetName(), cNick.GetNickMask() + " QUIT " + sMessage)); } - if (cNick.GetNick().Equals(m_pUser->GetNick())) + if (cNick.NickEquals(m_pUser->GetNick())) SaveBufferToDisk(); // need to force a save here to see this! } @@ -314,7 +314,7 @@ public: } virtual void OnJoin(const CNick& cNick, CChan& cChannel) { - if (cNick.GetNick().Equals(m_pUser->GetNick()) && cChannel.GetBuffer().empty()) + if (cNick.NickEquals(m_pUser->GetNick()) && cChannel.GetBuffer().empty()) { BootStrap((CChan *)&cChannel); if (!cChannel.GetBuffer().empty()) @@ -325,7 +325,7 @@ public: virtual void OnPart(const CNick& cNick, CChan& cChannel) { AddBuffer(cChannel, SpoofChanMsg(cChannel.GetName(), cNick.GetNickMask() + " PART")); - if (cNick.GetNick().Equals(m_pUser->GetNick())) + if (cNick.NickEquals(m_pUser->GetNick())) SaveBufferToDisk(); // need to force a save here to see this! } #endif /* LEGACY_SAVEBUFF */ diff --git a/src/Chan.cpp b/src/Chan.cpp index b67002df..f46bebb8 100644 --- a/src/Chan.cpp +++ b/src/Chan.cpp @@ -286,13 +286,13 @@ void CChan::ModeChange(const CString& sModes, const CNick* pOpNick) { if (bAdd) { pNick->AddPerm(uPerm); - if (pNick->GetNick().Equals(m_pNetwork->GetCurNick())) { + if (pNick->NickEquals(m_pNetwork->GetCurNick())) { AddPerm(uPerm); } } else { pNick->RemPerm(uPerm); - if (pNick->GetNick().Equals(m_pNetwork->GetCurNick())) { + if (pNick->NickEquals(m_pNetwork->GetCurNick())) { RemPerm(uPerm); } } @@ -464,7 +464,7 @@ bool CChan::AddNick(const CString& sNick) { pNick->AddPerm(sPrefix[i]); } - if (pNick->GetNick().Equals(m_pNetwork->GetCurNick())) { + if (pNick->NickEquals(m_pNetwork->GetCurNick())) { for (CString::size_type i = 0; i < sPrefix.length(); i++) { AddPerm(sPrefix[i]); } diff --git a/src/IRCSock.cpp b/src/IRCSock.cpp index 101bc970..0962fc4a 100644 --- a/src/IRCSock.cpp +++ b/src/IRCSock.cpp @@ -530,7 +530,7 @@ void CIRCSock::ReadLine(const CString& sData) { // :nick!ident@host.com QUIT :message - if (Nick.GetNick().Equals(GetNick())) { + if (Nick.NickEquals(GetNick())) { m_pNetwork->PutStatus("You quit [" + sMessage + "]"); // We don't call module hooks and we don't // forward this quit to clients (Some clients @@ -700,7 +700,7 @@ void CIRCSock::ReadLine(const CString& sData) { } } - if (Nick.GetNick().Equals(m_pNetwork->GetIRCServer())) { + if (Nick.NickEquals(m_pNetwork->GetIRCServer())) { m_pNetwork->PutUser(":" + Nick.GetNick() + " NOTICE " + sTarget + " :" + sMsg); } else { m_pNetwork->PutUser(":" + Nick.GetNickMask() + " NOTICE " + sTarget + " :" + sMsg);