mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Modulefy core server-dependent caps
This commit is contained in:
@@ -335,6 +335,7 @@ class CClient : public CIRCSocket {
|
||||
SCString m_ssServerDependentCaps;
|
||||
|
||||
friend class ClientTest;
|
||||
friend class CCoreCaps;
|
||||
};
|
||||
|
||||
#endif // !ZNC_CLIENT_H
|
||||
|
||||
@@ -240,6 +240,7 @@ class CIRCSock : public CIRCSocket {
|
||||
VCString m_vsSSLError;
|
||||
|
||||
friend class CIRCFloodTimer;
|
||||
friend class CCoreCaps;
|
||||
};
|
||||
|
||||
#endif // !ZNC_IRCSOCK_H
|
||||
|
||||
77
modules/corecaps.cpp
Normal file
77
modules/corecaps.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2024 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <znc/Client.h>
|
||||
#include <znc/IRCNetwork.h>
|
||||
#include <znc/IRCSock.h>
|
||||
#include <znc/Modules.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
class CCoreCaps : public CModule {
|
||||
class AwayNotify : public CCapability {
|
||||
void OnServerChangedSupport(CIRCNetwork* pNetwork,
|
||||
bool bState) override {
|
||||
pNetwork->GetIRCSock()->m_bAwayNotify = bState;
|
||||
}
|
||||
void OnClientChangedSupport(CClient* pClient, bool bState) override {
|
||||
pClient->m_bAwayNotify = bState;
|
||||
}
|
||||
};
|
||||
|
||||
class AccountNotify : public CCapability {
|
||||
void OnServerChangedSupport(CIRCNetwork* pNetwork,
|
||||
bool bState) override {
|
||||
pNetwork->GetIRCSock()->m_bAccountNotify = bState;
|
||||
}
|
||||
void OnClientChangedSupport(CClient* pClient, bool bState) override {
|
||||
pClient->m_bAccountNotify = bState;
|
||||
}
|
||||
};
|
||||
|
||||
class AccountTag : public CCapability {
|
||||
void OnServerChangedSupport(CIRCNetwork* pNetwork,
|
||||
bool bState) override {
|
||||
pNetwork->GetIRCSock()->m_bAccountTag = bState;
|
||||
}
|
||||
void OnClientChangedSupport(CClient* pClient, bool bState) override {
|
||||
pClient->m_bAccountTag = bState;
|
||||
pClient->SetTagSupport("account", bState);
|
||||
}
|
||||
};
|
||||
|
||||
class ExtendedJoin : public CCapability {
|
||||
void OnServerChangedSupport(CIRCNetwork* pNetwork,
|
||||
bool bState) override {
|
||||
pNetwork->GetIRCSock()->m_bExtendedJoin = bState;
|
||||
}
|
||||
void OnClientChangedSupport(CClient* pClient, bool bState) override {
|
||||
pClient->m_bExtendedJoin = bState;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
MODCONSTRUCTOR(CCoreCaps) {
|
||||
AddCapability("away-notify", std::make_unique<AwayNotify>());
|
||||
AddCapability("account-notify", std::make_unique<AccountNotify>());
|
||||
AddCapability("account-tag", std::make_unique<AccountTag>());
|
||||
AddCapability("extended-join", std::make_unique<ExtendedJoin>());
|
||||
}
|
||||
};
|
||||
|
||||
GLOBALMODULEDEFS(
|
||||
CCoreCaps,
|
||||
t_s("Adds support for several IRC capabilities, extracted from ZNC core."))
|
||||
@@ -764,17 +764,6 @@ CClient::CoreCaps() {
|
||||
}}},
|
||||
{"cap-notify",
|
||||
{false, [](CClient* pClient, bool bVal) { pClient->m_bCapNotify = bVal; }}},
|
||||
{"away-notify",
|
||||
{true, [](CClient* pClient, bool bVal) { pClient->m_bAwayNotify = bVal; }}},
|
||||
{"account-notify",
|
||||
{true, [](CClient* pClient, bool bVal) { pClient->m_bAccountNotify = bVal; }}},
|
||||
{"account-tag",
|
||||
{true, [](CClient* pClient, bool bVal) {
|
||||
pClient->m_bAccountTag = bVal;
|
||||
pClient->SetTagSupport("account", bVal);
|
||||
}}},
|
||||
{"extended-join",
|
||||
{true, [](CClient* pClient, bool bVal) { pClient->m_bExtendedJoin = bVal; }}},
|
||||
};
|
||||
|
||||
// For compatibility with older clients
|
||||
|
||||
@@ -379,11 +379,7 @@ bool CIRCSock::OnCapabilityMessage(CMessage& Message) {
|
||||
std::map<CString, std::function<void(bool bVal)>> mSupportedCaps = {
|
||||
{"multi-prefix", [this](bool bVal) { m_bNamesx = bVal; }},
|
||||
{"userhost-in-names", [this](bool bVal) { m_bUHNames = bVal; }},
|
||||
{"away-notify", [this](bool bVal) { m_bAwayNotify = bVal; }},
|
||||
{"account-notify", [this](bool bVal) { m_bAccountNotify = bVal; }},
|
||||
{"account-tag", [this](bool bVal) { m_bAccountTag = bVal; }},
|
||||
{"cap-notify", [](bool bVal) {}},
|
||||
{"extended-join", [this](bool bVal) { m_bExtendedJoin = bVal; }},
|
||||
{"server-time", [this](bool bVal) { m_bServerTime = bVal; }},
|
||||
{"znc.in/server-time-iso",
|
||||
[this](bool bVal) { m_bServerTime = bVal; }},
|
||||
|
||||
@@ -1621,9 +1621,12 @@ bool CModules::OnServerCapAvailable(const CString& sCap, const CString& sValue)
|
||||
pMod->SetClient(m_pClient);
|
||||
if (m_pUser) {
|
||||
CUser* pOldUser = pMod->GetUser();
|
||||
CIRCNetwork* pOldNetwork = pMod->GetNetwork();
|
||||
pMod->SetUser(m_pUser);
|
||||
pMod->SetNetwork(m_pNetwork);
|
||||
bResult |= pMod->OnServerCap302Available(sCap, sValue);
|
||||
pMod->SetUser(pOldUser);
|
||||
pMod->SetNetwork(pOldNetwork);
|
||||
} else {
|
||||
// WTF? Is that possible?
|
||||
bResult |= pMod->OnServerCap302Available(sCap, sValue);
|
||||
@@ -1691,9 +1694,12 @@ bool CModules::IsClientCapSupported(CClient* pClient, const CString& sCap,
|
||||
pMod->SetClient(m_pClient);
|
||||
if (m_pUser) {
|
||||
CUser* pOldUser = pMod->GetUser();
|
||||
CIRCNetwork* pOldNetwork = pMod->GetNetwork();
|
||||
pMod->SetUser(m_pUser);
|
||||
pMod->SetNetwork(m_pNetwork);
|
||||
bResult |= pMod->IsClientCapSupported(pClient, sCap, bState);
|
||||
pMod->SetUser(pOldUser);
|
||||
pMod->SetNetwork(pOldNetwork);
|
||||
} else {
|
||||
// WTF? Is that possible?
|
||||
bResult |= pMod->IsClientCapSupported(pClient, sCap, bState);
|
||||
@@ -1998,6 +2004,7 @@ void CModules::GetDefaultMods(set<CModInfo>& ssMods,
|
||||
const map<CString, CModInfo::EModuleType> ns = {
|
||||
{"chansaver", CModInfo::UserModule},
|
||||
{"controlpanel", CModInfo::UserModule},
|
||||
{"corecaps", CModInfo::GlobalModule},
|
||||
{"simple_away", CModInfo::NetworkModule},
|
||||
{"webadmin", CModInfo::GlobalModule}};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user