From c424bd7acad08677f6f6140010804ef0f66ade05 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Sun, 12 Oct 2014 22:13:07 +0200 Subject: [PATCH] CChan: keep track of the state Make CChan keep track of the channel key, and schedule saving of the config file when appropriate. This is more robust than trying to do it from within the chansaver module. --- include/znc/Chan.h | 4 ++-- src/Chan.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/znc/Chan.h b/include/znc/Chan.h index d9f28e15..5fcd3316 100644 --- a/include/znc/Chan.h +++ b/include/znc/Chan.h @@ -110,7 +110,7 @@ public: // Setters void SetModeKnown(bool b) { m_bModeKnown = b; } void SetIsOn(bool b) { m_bIsOn = b; if (!b) { Reset(); } } - void SetKey(const CString& s) { m_sKey = s; } + void SetKey(const CString& s); void SetTopic(const CString& s) { m_sTopic = s; } void SetTopicOwner(const CString& s) { m_sTopicOwner = s; } void SetTopicDate(unsigned long u) { m_ulTopicDate = u; } @@ -118,7 +118,7 @@ public: void SetAutoClearChanBuffer(bool b); void InheritAutoClearChanBuffer(bool b); void SetDetached(bool b = true) { m_bDetached = b; } - void SetInConfig(bool b) { m_bInConfig = b; } + void SetInConfig(bool b); void SetCreationDate(unsigned long u) { m_ulCreationDate = u; } void Disable() { m_bDisabled = true; } void Enable(); diff --git a/src/Chan.cpp b/src/Chan.cpp index 5dea036e..b0e86ac4 100644 --- a/src/Chan.cpp +++ b/src/Chan.cpp @@ -19,6 +19,7 @@ #include #include #include +#include using std::set; using std::vector; @@ -364,6 +365,13 @@ void CChan::ModeChange(const CString& sModes, const CNick* pOpNick) { if (!bList) { (bAdd) ? AddMode(uMode, sArg) : RemMode(uMode); } + + // This is called when we join (ZNC requests the channel modes + // on join) *and* when someone changes the channel keys. + // We ignore channel key "*" because of some broken nets. + if (uMode == 'k' && !bNoChange && bAdd && sArg != "*") { + SetKey(sArg); + } } } } @@ -623,3 +631,21 @@ void CChan::Enable() { ResetJoinTries(); m_bDisabled = false; } + +void CChan::SetKey(const CString& s) { + if (m_sKey != s) { + m_sKey = s; + if (m_bInConfig) { + CZNC::Get().SetConfigState(CZNC::ECONFIG_NEED_WRITE); + } + } +} + +void CChan::SetInConfig(bool b) { + if (m_bInConfig != b) { + m_bInConfig = b; + if (m_bInConfig) { + CZNC::Get().SetConfigState(CZNC::ECONFIG_NEED_WRITE); + } + } +}