mirror of
https://github.com/znc/znc.git
synced 2026-05-02 03:22:33 +02:00
Merge pull request #917 from jpnurmi/stripcontrols
Replace StripControls setting with a separate module
This commit is contained in:
@@ -120,8 +120,6 @@ public:
|
||||
void SetDefaultModes(const CString& s) { m_sDefaultModes = s; }
|
||||
void SetAutoClearChanBuffer(bool b);
|
||||
void InheritAutoClearChanBuffer(bool b);
|
||||
void SetStripControls(bool b);
|
||||
void InheritStripControls(bool b);
|
||||
void SetDetached(bool b = true) { m_bDetached = b; }
|
||||
void SetInConfig(bool b);
|
||||
void SetCreationDate(unsigned long u) { m_ulCreationDate = u; }
|
||||
@@ -149,14 +147,12 @@ public:
|
||||
size_t GetNickCount() const { return m_msNicks.size(); }
|
||||
bool AutoClearChanBuffer() const { return m_bAutoClearChanBuffer; }
|
||||
bool IsDetached() const { return m_bDetached; }
|
||||
bool StripControls() const { return m_bStripControls; }
|
||||
bool InConfig() const { return m_bInConfig; }
|
||||
unsigned long GetCreationDate() const { return m_ulCreationDate; }
|
||||
bool IsDisabled() const { return m_bDisabled; }
|
||||
unsigned int GetJoinTries() const { return m_uJoinTries; }
|
||||
bool HasBufferCountSet() const { return m_bHasBufferCountSet; }
|
||||
bool HasAutoClearChanBufferSet() const { return m_bHasAutoClearChanBufferSet; }
|
||||
bool HasStripControlsSet() const { return m_bHasStripControlsSet; }
|
||||
// !Getters
|
||||
private:
|
||||
protected:
|
||||
@@ -167,8 +163,6 @@ protected:
|
||||
bool m_bDisabled;
|
||||
bool m_bHasBufferCountSet;
|
||||
bool m_bHasAutoClearChanBufferSet;
|
||||
bool m_bStripControls;
|
||||
bool m_bHasStripControlsSet;
|
||||
CString m_sName;
|
||||
CString m_sKey;
|
||||
CString m_sTopic;
|
||||
|
||||
@@ -131,9 +131,6 @@ public:
|
||||
void SetIRCConnectEnabled(bool b);
|
||||
bool GetIRCConnectEnabled() const { return m_bIRCConnectEnabled; }
|
||||
|
||||
void SetStripControls(bool b);
|
||||
bool StripControls() const { return m_bStripControls; }
|
||||
|
||||
CIRCSock* GetIRCSock() { return m_pIRCSock; }
|
||||
const CIRCSock* GetIRCSock() const { return m_pIRCSock; }
|
||||
const CString& GetIRCServer() const;
|
||||
@@ -227,7 +224,6 @@ protected:
|
||||
CString m_sChanPrefixes;
|
||||
|
||||
bool m_bIRCConnectEnabled;
|
||||
bool m_bStripControls;
|
||||
CString m_sIRCServer;
|
||||
std::vector<CServer*> m_vServers;
|
||||
size_t m_uServerIdx; ///< Index in m_vServers of our current server + 1
|
||||
|
||||
@@ -121,7 +121,6 @@ class CAdminMod : public CModule {
|
||||
{"Encoding", str},
|
||||
#endif
|
||||
{"QuitMsg", str},
|
||||
{"StripControls", boolean},
|
||||
};
|
||||
PrintVarsHelp(sVarFilter, nvars, ARRAY_SIZE(nvars), "The following variables are available when using the SetNetwork/GetNetwork commands:");
|
||||
}
|
||||
@@ -133,8 +132,7 @@ class CAdminMod : public CModule {
|
||||
{"Buffer", integer},
|
||||
{"InConfig", boolean},
|
||||
{"AutoClearChanBuffer", boolean},
|
||||
{"Detached", boolean},
|
||||
{"StripControls", boolean},
|
||||
{"Detached", boolean}
|
||||
};
|
||||
PrintVarsHelp(sVarFilter, cvars, ARRAY_SIZE(cvars), "The following variables are available when using the SetChan/GetChan commands:");
|
||||
}
|
||||
@@ -498,8 +496,6 @@ class CAdminMod : public CModule {
|
||||
#endif
|
||||
} else if (sVar.Equals("quitmsg")) {
|
||||
PutModule("QuitMsg = " + pNetwork->GetQuitMsg());
|
||||
} else if (sVar.Equals("stripcontrols")) {
|
||||
PutModule("StripControls = " + CString(pNetwork->StripControls()));
|
||||
} else {
|
||||
PutModule("Error: Unknown variable");
|
||||
}
|
||||
@@ -593,10 +589,6 @@ class CAdminMod : public CModule {
|
||||
} else if (sVar.Equals("quitmsg")) {
|
||||
pNetwork->SetQuitMsg(sValue);
|
||||
PutModule("QuitMsg = " + pNetwork->GetQuitMsg());
|
||||
} else if (sVar == "stripcontrols") {
|
||||
bool b = sValue.ToBool();
|
||||
pNetwork->SetStripControls(b);
|
||||
PutModule("StripControls = " + CString(b));
|
||||
} else {
|
||||
PutModule("Error: Unknown variable");
|
||||
}
|
||||
@@ -716,12 +708,6 @@ class CAdminMod : public CModule {
|
||||
PutModule(pChan->GetName() + ": AutoClearChanBuffer = " + sValue);
|
||||
} else if (sVar == "detached") {
|
||||
PutModule(pChan->GetName() + ": Detached = " + CString(pChan->IsDetached()));
|
||||
} else if (sVar == "stripcontrols") {
|
||||
CString sValue(pChan->StripControls());
|
||||
if (!pChan->HasStripControlsSet()) {
|
||||
sValue += " (default)";
|
||||
}
|
||||
PutModule(pChan->GetName() + ": StripControls = " + sValue);
|
||||
} else if (sVar == "key") {
|
||||
PutModule(pChan->GetName() + ": Key = " + pChan->GetKey());
|
||||
} else {
|
||||
@@ -793,10 +779,6 @@ class CAdminMod : public CModule {
|
||||
pChan->AttachUser();
|
||||
}
|
||||
PutModule(pChan->GetName() + ": Detached = " + CString(b));
|
||||
} else if (sVar == "stripcontrols") {
|
||||
bool b = sValue.ToBool();
|
||||
pChan->SetStripControls(b);
|
||||
PutModule(pChan->GetName() + ": StripControls = " + CString(b));
|
||||
} else if (sVar == "key") {
|
||||
pChan->SetKey(sValue);
|
||||
PutModule(pChan->GetName() + ": Key = " + sValue);
|
||||
|
||||
@@ -129,16 +129,6 @@
|
||||
<? INC encoding_settings.tmpl ?>
|
||||
</div>
|
||||
|
||||
<div class="subsection">
|
||||
<div class="inputlabel">Strip Controls:</div>
|
||||
<div class="checkbox">
|
||||
<input type="checkbox" name="stripcontrols" id="stripcontrols_checkbox"
|
||||
title="Strips control codes (Colors, Bold, ..) from channel and private messages."
|
||||
<? IF StripControls ?>checked="checked"<? ENDIF ?> />
|
||||
<label for="stripcontrols_checkbox">Enabled</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="clear: both;"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
59
modules/stripcontrols.cpp
Normal file
59
modules/stripcontrols.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 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/Modules.h>
|
||||
|
||||
class CStripControlsMod : public CModule {
|
||||
public:
|
||||
MODCONSTRUCTOR(CStripControlsMod) {}
|
||||
|
||||
EModRet OnPrivCTCP(CNick& Nick, CString& sMessage) override {
|
||||
sMessage.StripControls();
|
||||
return CONTINUE;
|
||||
}
|
||||
|
||||
EModRet OnChanCTCP(CNick& Nick, CChan& Channel, CString& sMessage) override {
|
||||
sMessage.StripControls();
|
||||
return CONTINUE;
|
||||
}
|
||||
|
||||
EModRet OnPrivNotice(CNick& Nick, CString& sMessage) override {
|
||||
sMessage.StripControls();
|
||||
return CONTINUE;
|
||||
}
|
||||
|
||||
EModRet OnChanNotice(CNick& Nick, CChan& Channel, CString& sMessage) override {
|
||||
sMessage.StripControls();
|
||||
return CONTINUE;
|
||||
}
|
||||
|
||||
EModRet OnPrivMsg(CNick& Nick, CString& sMessage) override {
|
||||
sMessage.StripControls();
|
||||
return CONTINUE;
|
||||
}
|
||||
|
||||
EModRet OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage) override {
|
||||
sMessage.StripControls();
|
||||
return CONTINUE;
|
||||
}
|
||||
};
|
||||
|
||||
template<> void TModInfo<CStripControlsMod>(CModInfo& Info) {
|
||||
Info.SetWikiPage("stripcontrols");
|
||||
Info.AddType(CModInfo::UserModule);
|
||||
}
|
||||
|
||||
NETWORKMODULEDEFS(CStripControlsMod, "Strips control codes (Colors, Bold, ..) from channel and private messages.")
|
||||
@@ -666,11 +666,6 @@ public:
|
||||
o4["DisplayName"] = "Disabled";
|
||||
if (pChan && pChan->IsDisabled()) { o4["Checked"] = "true"; }
|
||||
|
||||
CTemplate& o5 = Tmpl.AddRow("OptionLoop");
|
||||
o5["Name"] = "stripcontrols";
|
||||
o5["DisplayName"] = "Strip Controls";
|
||||
if (pChan && pChan->StripControls()) { o5["Checked"] = "true"; }
|
||||
|
||||
FOR_EACH_MODULE(i, pNetwork) {
|
||||
CTemplate& mod = Tmpl.AddRow("EmbeddedModuleLoop");
|
||||
mod.insert(Tmpl.begin(), Tmpl.end());
|
||||
@@ -734,11 +729,6 @@ public:
|
||||
else
|
||||
pChan->Enable();
|
||||
|
||||
bool bStripControls = WebSock.GetParam("stripcontrols").ToBool();
|
||||
if (pChan->StripControls() != bStripControls) {
|
||||
pChan->SetStripControls(bStripControls);
|
||||
}
|
||||
|
||||
CTemplate TmplMod;
|
||||
TmplMod["User"] = pUser->GetUserName();
|
||||
TmplMod["ChanName"] = pChan->GetName();
|
||||
@@ -845,7 +835,6 @@ public:
|
||||
|
||||
Tmpl["QuitMsg"] = pNetwork->GetQuitMsg();
|
||||
|
||||
Tmpl["StripControls"] = CString(pNetwork->StripControls());
|
||||
Tmpl["FloodProtection"] = CString(CIRCSock::IsFloodProtected(pNetwork->GetFloodRate()));
|
||||
Tmpl["FloodRate"] = CString(pNetwork->GetFloodRate());
|
||||
Tmpl["FloodBurst"] = CString(pNetwork->GetFloodBurst());
|
||||
@@ -1007,11 +996,6 @@ public:
|
||||
|
||||
pNetwork->SetJoinDelay(WebSock.GetParam("joindelay").ToUShort());
|
||||
|
||||
bool bStripControls = WebSock.GetParam("stripcontrols").ToBool();
|
||||
if (pNetwork->StripControls() != bStripControls) {
|
||||
pNetwork->SetStripControls(bStripControls);
|
||||
}
|
||||
|
||||
#ifdef HAVE_ICU
|
||||
CString sEncodingUtf = WebSock.GetParam("encoding_utf");
|
||||
if (sEncodingUtf == "legacy") {
|
||||
|
||||
26
src/Chan.cpp
26
src/Chan.cpp
@@ -33,8 +33,6 @@ CChan::CChan(const CString& sName, CIRCNetwork* pNetwork, bool bInConfig, CConfi
|
||||
m_bDisabled(false),
|
||||
m_bHasBufferCountSet(false),
|
||||
m_bHasAutoClearChanBufferSet(false),
|
||||
m_bStripControls(false),
|
||||
m_bHasStripControlsSet(false),
|
||||
m_sName(sName.Token(0)),
|
||||
m_sKey(sName.Token(1)),
|
||||
m_sTopic(""),
|
||||
@@ -70,8 +68,6 @@ CChan::CChan(const CString& sName, CIRCNetwork* pNetwork, bool bInConfig, CConfi
|
||||
if (pConfig->FindStringEntry("disabled", sValue))
|
||||
if (sValue.ToBool())
|
||||
Disable();
|
||||
if (pConfig->FindStringEntry("stripcontrols", sValue))
|
||||
SetStripControls(sValue.ToBool());
|
||||
if (pConfig->FindStringEntry("autocycle", sValue))
|
||||
if (sValue.Equals("true"))
|
||||
CUtils::PrintError("WARNING: AutoCycle has been removed, instead try -> LoadModule = autocycle " + sName);
|
||||
@@ -110,8 +106,6 @@ CConfig CChan::ToConfig() const {
|
||||
config.AddKeyValuePair("Detached", "true");
|
||||
if (IsDisabled())
|
||||
config.AddKeyValuePair("Disabled", "true");
|
||||
if (m_bHasStripControlsSet)
|
||||
config.AddKeyValuePair("StripControls", CString(StripControls()));
|
||||
if (!GetKey().empty())
|
||||
config.AddKeyValuePair("Key", GetKey());
|
||||
if (!GetDefaultModes().empty())
|
||||
@@ -124,7 +118,6 @@ void CChan::Clone(CChan& chan) {
|
||||
// We assume that m_sName and m_pNetwork are equal
|
||||
SetBufferCount(chan.GetBufferCount(), true);
|
||||
SetAutoClearChanBuffer(chan.AutoClearChanBuffer());
|
||||
SetStripControls(chan.StripControls());
|
||||
SetKey(chan.GetKey());
|
||||
SetDefaultModes(chan.GetDefaultModes());
|
||||
|
||||
@@ -269,17 +262,6 @@ void CChan::InheritAutoClearChanBuffer(bool b) {
|
||||
}
|
||||
}
|
||||
|
||||
void CChan::SetStripControls(bool b) {
|
||||
m_bHasStripControlsSet = true;
|
||||
m_bStripControls = b;
|
||||
}
|
||||
|
||||
void CChan::InheritStripControls(bool b) {
|
||||
if (!m_bHasStripControlsSet) {
|
||||
m_bStripControls = b;
|
||||
}
|
||||
}
|
||||
|
||||
void CChan::OnWho(const CString& sNick, const CString& sIdent, const CString& sHost) {
|
||||
CNick* pNick = FindNick(sNick);
|
||||
|
||||
@@ -414,14 +396,6 @@ CString CChan::GetOptions() const {
|
||||
}
|
||||
}
|
||||
|
||||
if (StripControls()) {
|
||||
if (HasStripControlsSet()) {
|
||||
vsRet.push_back("StripControls");
|
||||
} else {
|
||||
vsRet.push_back("StripControls (default)");
|
||||
}
|
||||
}
|
||||
|
||||
return CString(", ").Join(vsRet.begin(), vsRet.end());
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,6 @@ CIRCNetwork::CIRCNetwork(CUser *pUser, const CString& sName)
|
||||
m_vQueries(),
|
||||
m_sChanPrefixes(""),
|
||||
m_bIRCConnectEnabled(true),
|
||||
m_bStripControls(false),
|
||||
m_sIRCServer(""),
|
||||
m_vServers(),
|
||||
m_uServerIdx(0),
|
||||
@@ -174,7 +173,6 @@ void CIRCNetwork::Clone(const CIRCNetwork& Network, bool bCloneName) {
|
||||
SetBindHost(Network.GetBindHost());
|
||||
SetEncoding(Network.GetEncoding());
|
||||
SetQuitMsg(Network.GetQuitMsg());
|
||||
SetStripControls(Network.StripControls());
|
||||
m_ssTrustedFingerprints = Network.m_ssTrustedFingerprints;
|
||||
|
||||
// Servers
|
||||
@@ -343,7 +341,6 @@ bool CIRCNetwork::ParseConfig(CConfig *pConfig, CString& sError, bool bUpgrade)
|
||||
};
|
||||
TOption<bool> BoolOptions[] = {
|
||||
{ "ircconnectenabled", &CIRCNetwork::SetIRCConnectEnabled },
|
||||
{ "stripcontrols", &CIRCNetwork::SetStripControls },
|
||||
};
|
||||
TOption<double> DoubleOptions[] = {
|
||||
{ "floodrate", &CIRCNetwork::SetFloodRate },
|
||||
@@ -498,7 +495,6 @@ CConfig CIRCNetwork::ToConfig() const {
|
||||
config.AddKeyValuePair("FloodBurst", CString(GetFloodBurst()));
|
||||
config.AddKeyValuePair("JoinDelay", CString(GetJoinDelay()));
|
||||
config.AddKeyValuePair("Encoding", m_sEncoding);
|
||||
config.AddKeyValuePair("StripControls", CString(StripControls()));
|
||||
|
||||
if (!m_sQuitMsg.empty()) {
|
||||
config.AddKeyValuePair("QuitMsg", m_sQuitMsg);
|
||||
@@ -1258,14 +1254,6 @@ void CIRCNetwork::CheckIRCConnect() {
|
||||
CZNC::Get().AddNetworkToQueue(this);
|
||||
}
|
||||
|
||||
void CIRCNetwork::SetStripControls(bool b) {
|
||||
for (CChan* pChan : GetChans()) {
|
||||
pChan->InheritStripControls(b);
|
||||
}
|
||||
|
||||
m_bStripControls = b;
|
||||
}
|
||||
|
||||
bool CIRCNetwork::PutIRC(const CString& sLine) {
|
||||
CIRCSock* pIRCSock = GetIRCSock();
|
||||
|
||||
|
||||
@@ -687,10 +687,6 @@ void CIRCSock::ReadLine(const CString& sData) {
|
||||
sMsg.RightChomp();
|
||||
|
||||
if (sTarget.Equals(GetNick())) {
|
||||
if (m_pNetwork->StripControls()) {
|
||||
sMsg.StripControls();
|
||||
}
|
||||
|
||||
if (OnCTCPReply(Nick, sMsg)) {
|
||||
return;
|
||||
}
|
||||
@@ -700,19 +696,10 @@ void CIRCSock::ReadLine(const CString& sData) {
|
||||
return;
|
||||
} else {
|
||||
if (sTarget.Equals(GetNick())) {
|
||||
if (m_pNetwork->StripControls()) {
|
||||
sMsg.StripControls();
|
||||
}
|
||||
|
||||
if (OnPrivNotice(Nick, sMsg)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
CChan* pChan = m_pNetwork->FindChan(sTarget);
|
||||
if (pChan && pChan->StripControls()) {
|
||||
sMsg.StripControls();
|
||||
}
|
||||
|
||||
if (OnChanNotice(Nick, sTarget, sMsg)) {
|
||||
return;
|
||||
}
|
||||
@@ -757,19 +744,10 @@ void CIRCSock::ReadLine(const CString& sData) {
|
||||
sMsg.RightChomp();
|
||||
|
||||
if (sTarget.Equals(GetNick())) {
|
||||
if (m_pNetwork->StripControls()) {
|
||||
sMsg.StripControls();
|
||||
}
|
||||
|
||||
if (OnPrivCTCP(Nick, sMsg)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
CChan* pChan = m_pNetwork->FindChan(sTarget);
|
||||
if (pChan && pChan->StripControls()) {
|
||||
sMsg.StripControls();
|
||||
}
|
||||
|
||||
if (OnChanCTCP(Nick, sTarget, sMsg)) {
|
||||
return;
|
||||
}
|
||||
@@ -779,19 +757,10 @@ void CIRCSock::ReadLine(const CString& sData) {
|
||||
return;
|
||||
} else {
|
||||
if (sTarget.Equals(GetNick())) {
|
||||
if (m_pNetwork->StripControls()) {
|
||||
sMsg.StripControls();
|
||||
}
|
||||
|
||||
if (OnPrivMsg(Nick, sMsg)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
CChan* pChan = m_pNetwork->FindChan(sTarget);
|
||||
if (pChan && pChan->StripControls()) {
|
||||
sMsg.StripControls();
|
||||
}
|
||||
|
||||
if (OnChanMsg(Nick, sTarget, sMsg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user