This commit is contained in:
Alexey Sokolov
2024-01-05 00:45:41 +00:00
parent 4cbccac707
commit 66137bd89a
7 changed files with 186 additions and 12 deletions
+36 -6
View File
@@ -790,7 +790,7 @@ void CClient::HandleCap(const CMessage& Message) {
CString sSubCmd = Message.GetParam(0);
if (sSubCmd.Equals("LS")) {
m_uCapVersion = Message.GetParam(1).ToInt();
m_uCapVersion = std::max(m_uCapVersion, Message.GetParam(1).ToUShort());
SCString ssOfferCaps;
for (const auto& it : CoreCaps()) {
bool bServerDependent = std::get<0>(it.second);
@@ -798,7 +798,7 @@ void CClient::HandleCap(const CMessage& Message) {
m_ssServerDependentCaps.count(it.first) > 0)
ssOfferCaps.insert(it.first);
}
GLOBALMODULECALL(OnClientCapLs(this, ssOfferCaps), NOTHING);
NETWORKMODULECALL(OnClientCapLs(this, ssOfferCaps), GetUser(), GetNetwork(), this, NOTHING);
VCString vsCaps = MultiLine(ssOfferCaps);
m_bInCap = true;
if (HasCap302()) {
@@ -830,13 +830,13 @@ void CClient::HandleCap(const CMessage& Message) {
if (sCap.TrimPrefix("-")) bVal = false;
bool bAccepted = false;
const auto& it = CoreCaps().find(sCap);
auto it = CoreCaps().find(sCap);
if (CoreCaps().end() != it) {
bool bServerDependent = std::get<0>(it->second);
bAccepted = !bServerDependent ||
m_ssServerDependentCaps.count(sCap) > 0;
}
GLOBALMODULECALL(IsClientCapSupported(this, sCap, bVal),
NETWORKMODULECALL(IsClientCapSupported(this, sCap, bVal), GetUser(), GetNetwork(), this,
&bAccepted);
if (!bAccepted) {
@@ -857,7 +857,7 @@ void CClient::HandleCap(const CMessage& Message) {
const auto& handler = std::get<1>(handler_it->second);
handler(this, bVal);
}
GLOBALMODULECALL(OnClientCapRequest(this, sCap, bVal), NOTHING);
NETWORKMODULECALL(OnClientCapRequest(this, sCap, bVal), GetUser(), GetNetwork(), this, NOTHING);
if (bVal) {
m_ssAcceptedCaps.insert(sCap);
@@ -936,8 +936,38 @@ void CClient::SetTagSupport(const CString& sTag, bool bState) {
}
}
void CClient::NotifyServerDependentCap(const CString& sCap, bool bValue) {
void CClient::NotifyServerDependentCap(const CString& sCap, bool bValue, const CString& sValue,
const std::function<void(CClient*, bool)>& handler) {
if (bValue) {
if (HasCapNotify()) {
if (HasCap302() && !sValue.empty()) {
PutClient(":irc.znc.in CAP " + GetNick() + " NEW :" + sCap + "=" + sValue);
} else {
PutClient(":irc.znc.in CAP " + GetNick() + " NEW :" + sCap);
}
}
} else {
if (HasCapNotify()) {
PutClient(":irc.znc.in CAP " + GetNick() + " DEL :" + sCap);
}
handler(this, false);
m_ssAcceptedCaps.erase(sCap);
}
}
void CClient::PotentiallyNotifyServerDependentCap(const CString& sCap, bool bValue, const CString& sValue) {
auto it = CoreCaps().find(sCap);
if (CoreCaps().end() != it) {
const auto& [bServerDependent, handler] = it->second;
if (bServerDependent) {
NotifyServerDependentCap(sCap, bValue, sValue, handler);
}
}
if (!bValue) {
m_ssServerDependentCaps.erase(sCap);
}
return;
if (bValue) {
if (CoreCaps().end() != it) {
bool bServerDependent = std::get<0>(it->second);
+14 -2
View File
@@ -1417,12 +1417,24 @@ void CIRCNetwork::IRCDisconnected() {
CheckIRCConnect();
}
void CIRCNetwork::NotifyServerDependentCap(const CString& sCap, bool bValue) {
void CIRCNetwork::PotentiallyNotifyServerDependentCap(const CString& sCap, bool bValue) {
CString sValue = GetIRCSock() ? GetIRCSock()->GetCapLsValue(sCap) : "";
for (CClient* pClient : m_vClients) {
pClient->NotifyServerDependentCap(sCap, bValue);
pClient->PotentiallyNotifyServerDependentCap(sCap, bValue, sValue);
}
}
void CIRCNetwork::NotifyClientsAboutServerDependentCap(const CString& sCap, bool bValue, const std::function<void(CClient*, bool)>& handler) {
CString sValue = GetIRCSock() ? GetIRCSock()->GetCapLsValue(sCap) : "";
for (CClient* pClient : m_vClients) {
pClient->NotifyServerDependentCap(sCap, bValue, sValue, handler);
}
}
bool CIRCNetwork::IsServerCapAccepted(const CString& sCap) const {
return m_pIRCSock && m_pIRCSock->IsCapAccepted(sCap);
}
void CIRCNetwork::SetIRCConnectEnabled(bool b) {
m_bIRCConnectEnabled = b;
+14 -2
View File
@@ -398,7 +398,7 @@ bool CIRCSock::OnCapabilityMessage(CMessage& Message) {
m_ssAcceptedCaps.erase(sCap);
m_ssPendingCaps.erase(sCap);
if (m_bAuthed) {
m_pNetwork->NotifyServerDependentCap(sCap, false);
m_pNetwork->PotentiallyNotifyServerDependentCap(sCap, false);
}
};
@@ -415,6 +415,7 @@ bool CIRCSock::OnCapabilityMessage(CMessage& Message) {
sCap = sToken.substr(0, eq);
sValue = sToken.substr(eq + 1);
}
m_msCapLsValues[sCap] = sValue;
if (OnServerCapAvailable(sCap, sValue) || mSupportedCaps.count(sCap)) {
m_ssPendingCaps.insert(sCap);
}
@@ -428,7 +429,7 @@ bool CIRCSock::OnCapabilityMessage(CMessage& Message) {
}
m_ssAcceptedCaps.insert(sArgs);
if (m_bAuthed) {
m_pNetwork->NotifyServerDependentCap(sArgs, true);
m_pNetwork->PotentiallyNotifyServerDependentCap(sArgs, true);
}
} else if (sSubCmd == "NAK") {
// This should work because there's no [known]
@@ -441,6 +442,7 @@ bool CIRCSock::OnCapabilityMessage(CMessage& Message) {
for (const CString& sCap : vsTokens) {
RemoveCap(sCap);
m_msCapLsValues.erase(sCap);
}
}
@@ -1448,6 +1450,16 @@ CString CIRCSock::GetISupport(const CString& sKey,
}
}
CString CIRCSock::GetCapLsValue(const CString& sKey,
const CString& sDefault) const {
MCString::const_iterator i = m_msCapLsValues.find(sKey);
if (i == m_msCapLsValues.end()) {
return sDefault;
} else {
return i->second;
}
}
void CIRCSock::SendAltNick(const CString& sBadNick) {
const CString& sLastNick = m_Nick.GetNick();