From 19ecd6e508754876379f815b2431e27850ed98d4 Mon Sep 17 00:00:00 2001 From: psychon Date: Sun, 7 Mar 2010 13:44:56 +0000 Subject: [PATCH] Add basic support for CAP This adds support for the general CAP protocol and the multi-prefix and userhost-in-names (NAMESX and UHNAMES) to znc. There is no module call for CAP tokens yet, but if modules really want to "catch" capabilities, we should most likely add one. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1812 726aef4b-f618-498e-8847-2d620e286838 --- IRCSock.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/IRCSock.cpp b/IRCSock.cpp index 8d19d1bf..3cdd1de9 100644 --- a/IRCSock.cpp +++ b/IRCSock.cpp @@ -634,6 +634,39 @@ void CIRCSock::ReadLine(const CString& sData) { if (!m_pUser->IsUserAttached()) { m_pUser->AddQueryBuffer(":" + Nick.GetNickMask() + " WALLOPS ", ":" + m_pUser->AddTimestamp(sMsg), false); } + } else if (sCmd.Equals("CAP")) { + // sRest.Token(0) is most likely "*". No idea why, the + // CAP spec don't mention this, but all implementations + // I've seen add this extra asterisk + CString sSubCmd = sRest.Token(1); + CString sArgs = sRest.Token(2, true).TrimPrefix_n(":"); + + if (sSubCmd == "LS" && !m_bAuthed) { + VCString vsTokens; + VCString::iterator it; + sArgs.Split(" ", vsTokens, false); + + for (it = vsTokens.begin(); it != vsTokens.end(); ++it) { + if (*it == "multi-prefix" || *it == "userhost-in-names") { + PutIRC("CAP REQ " + *it); + } + } + + // Tell the IRC server we are done with CAP + PutIRC("CAP END"); + } else if (sSubCmd == "ACK" && !m_bAuthed) { + VCString vsTokens; + VCString::iterator it; + sArgs.Split(" ", vsTokens, false); + + for (it = vsTokens.begin(); it != vsTokens.end(); ++it) { + if (*it == "multi-prefix") { + m_bNamesx = true; + } else if (*it == "userhost-in-names") { + m_bUHNames = true; + } + } + } } } @@ -833,6 +866,8 @@ void CIRCSock::Connected() { MODULECALL(OnIRCRegistration(sPass, sNick, sIdent, sRealName), m_pUser, NULL, return); + PutIRC("CAP LS"); + if (!sPass.empty()) { PutIRC("PASS " + sPass); }