diff --git a/include/znc/Client.h b/include/znc/Client.h index af09e4aa..631c6528 100644 --- a/include/znc/Client.h +++ b/include/znc/Client.h @@ -103,7 +103,7 @@ class CClient : public CIRCSocket { m_bGotPass(false), m_bGotNick(false), m_bGotUser(false), - m_bCap302(false), + m_uCapVersion(0), m_bInCap(false), m_bCapNotify(false), m_bAwayNotify(false), @@ -182,6 +182,8 @@ class CClient : public CIRCSocket { CString GetNick(bool bAllowIRCNick = true) const; CString GetNickMask() const; CString GetIdentifier() const { return m_sIdentifier; } + unsigned short int CapVersion() const { return m_uCapVersion; } + bool HasCap302() const { return CapVersion() >= 302; } bool HasCapNotify() const { return m_bCapNotify; } bool HasAwayNotify() const { return m_bAwayNotify; } bool HasAccountNotify() const { return m_bAccountNotify; } @@ -350,7 +352,7 @@ class CClient : public CIRCSocket { bool m_bGotPass; bool m_bGotNick; bool m_bGotUser; - bool m_bCap302; + unsigned short int m_uCapVersion; bool m_bInCap; bool m_bCapNotify; bool m_bAwayNotify; diff --git a/src/Client.cpp b/src/Client.cpp index 44ec66be..7cc81f32 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -706,6 +706,7 @@ void CClient::HandleCap(const CMessage& Message) { CString sSubCmd = Message.GetParam(0); if (sSubCmd.Equals("LS")) { + m_uCapVersion = Message.GetParam(1).ToInt(); SCString ssOfferCaps; for (const auto& it : m_mCoreCaps) { bool bServerDependent = std::get<0>(it.second); @@ -716,8 +717,7 @@ void CClient::HandleCap(const CMessage& Message) { GLOBALMODULECALL(OnClientCapLs(this, ssOfferCaps), NOTHING); VCString vsCaps = MultiLine(ssOfferCaps); m_bInCap = true; - if (Message.GetParam(1).ToInt() >= 302) { - m_bCap302 = true; + if (HasCap302()) { m_bCapNotify = true; for (int i = 0; i < vsCaps.size() - 1; ++i) { RespondCap("LS * :" + vsCaps[i]); @@ -785,7 +785,7 @@ void CClient::HandleCap(const CMessage& Message) { RespondCap("ACK :" + Message.GetParam(1)); } else if (sSubCmd.Equals("LIST")) { VCString vsCaps = MultiLine(m_ssAcceptedCaps); - if (m_bCap302) { + if (HasCap302()) { for (int i = 0; i < vsCaps.size() - 1; ++i) { RespondCap("LIST * :" + vsCaps[i]); } diff --git a/test/integration/tests/core.cpp b/test/integration/tests/core.cpp index 8f9618f8..fab871cb 100644 --- a/test/integration/tests/core.cpp +++ b/test/integration/tests/core.cpp @@ -472,5 +472,37 @@ TEST_F(ZNCTest, CAP302MultiLS) { ASSERT_GT(rem.indexOf("LS :", w), 1); } +TEST_F(ZNCTest, CAP302LSValue) { + auto znc = Run(); + auto ircd = ConnectIRCd(); + auto client = LoginClient(); + InstallModule("testmod.cpp", R"( + #include + #include + class TestModule : public CModule { + public: + MODCONSTRUCTOR(TestModule) {} + void OnClientCapLs(CClient* pClient, SCString& ssCaps) override { + if (pClient->HasCap302()) { + ssCaps.insert("testcap=blah"); + } else { + ssCaps.insert("testcap"); + } + } + }; + GLOBALMODULEDEFS(TestModule, "Test") + )"); + client.Write("znc loadmod testmod"); + client.ReadUntil("Loaded module testmod"); + + auto client2 = ConnectClient(); + client2.Write("CAP LS"); + client2.ReadUntil("testcap "); + + client2 = ConnectClient(); + client2.Write("CAP LS 302"); + client2.ReadUntil("testcap="); +} + } // namespace } // namespace znc_inttest