diff --git a/Chan.cpp b/Chan.cpp index 94bdc267..50350734 100644 --- a/Chan.cpp +++ b/Chan.cpp @@ -63,6 +63,8 @@ bool CChan::WriteConfig(CFile& File) { if (!GetDefaultModes().empty()) m_pUser->PrintLine(File, "\tModes", GetDefaultModes()); + CZNC::Get().GetModules().OnWriteChanConfig(File, *this); + File.Write("\t\n"); return true; } diff --git a/Modules.cpp b/Modules.cpp index 97610c9a..eb3bdc50 100644 --- a/Modules.cpp +++ b/Modules.cpp @@ -495,6 +495,9 @@ bool CModule::PutModNotice(const CString& sLine, const CString& sIdent, const CS // CGlobalModule // /////////////////// CModule::EModRet CGlobalModule::OnConfigLine(const CString& sName, const CString& sValue, CUser* pUser, CChan* pChan) { return CONTINUE; } +CModule::EModRet CGlobalModule::OnWriteConfig(CFile& Config) { return CONTINUE; } +void CGlobalModule::OnWriteUserConfig(CFile& Config, CUser& User) {} +void CGlobalModule::OnWriteChanConfig(CFile& Config, CChan& Chan) {} CModule::EModRet CGlobalModule::OnDeleteUser(CUser& User) { return CONTINUE; } void CGlobalModule::OnClientConnect(CClient* pClient, const CString& sHost, unsigned short uPort) {} CModule::EModRet CGlobalModule::OnLoginAttempt(CSmartPtr Auth) { return CONTINUE; } @@ -597,6 +600,18 @@ bool CGlobalModules::OnConfigLine(const CString& sName, const CString& sValue, C GLOBALMODHALTCHK(OnConfigLine(sName, sValue, pUser, pChan)); } +bool CGlobalModules::OnWriteConfig(CFile& Config) { + GLOBALMODHALTCHK(OnWriteConfig(Config)); +} + +void CGlobalModules::OnWriteUserConfig(CFile& Config, CUser& User) { + GLOBALMODCALL(OnWriteUserConfig(Config, User)); +} + +void CGlobalModules::OnWriteChanConfig(CFile& Config, CChan& Chan) { + GLOBALMODCALL(OnWriteChanConfig(Config, Chan)); +} + bool CGlobalModules::OnDeleteUser(CUser& User) { GLOBALMODHALTCHK(OnDeleteUser(User)); } diff --git a/Modules.h b/Modules.h index ea4455fe..ddf3ad46 100644 --- a/Modules.h +++ b/Modules.h @@ -862,9 +862,32 @@ public: * @param pChan If this line was found in a chan section, then this is * the corresponding CChan instance. * @return See CModule::EModRet. - * @todo How are modules supposed to write these into the config? */ virtual EModRet OnConfigLine(const CString& sName, const CString& sValue, CUser* pUser, CChan* pChan); + /** Called when ZNC starts rewriting the config file. This can be used + * re-write the "GM:" lines for OnConfigLine() which would get lost + * otherwise. + * @param Config Reference to the CFile which will be used for writing + * the config file. + * @return See CModule::EModRet. + */ + virtual EModRet OnWriteConfig(CFile& Config); + /** Called just before ZNC finishes a user section in the config file. + * This can be used to re-write the "GM:" lines for OnConfigLine() + * which would get lost otherwise. + * @param Config Reference to the CFile which will be used for writing + * the config file. + * @param User The user which is being written. + */ + virtual void OnWriteUserConfig(CFile& Config, CUser& User); + /** Called just before ZNC finishes a chan section in the config file. + * This can be used to re-write the "GM:" lines for OnConfigLine() + * which would get lost otherwise. + * @param Config Reference to the CFile which will be used for writing + * the config file. + * @param Chan The channel which is being written. + */ + virtual void OnWriteChanConfig(CFile& Config, CChan& Chan); /** This module hook is called when a user is deleted. * @param User The user which will be deleted. * @return See CModule::EModRet. @@ -907,6 +930,9 @@ public: ~CGlobalModules() {} bool OnConfigLine(const CString& sName, const CString& sValue, CUser* pUser, CChan* pChan); + bool OnWriteConfig(CFile& Config); + void OnWriteUserConfig(CFile& Config, CUser& User); + void OnWriteChanConfig(CFile& Config, CChan& Chan); bool OnDeleteUser(CUser& User); void OnClientConnect(CClient* pClient, const CString& sHost, unsigned short uPort); bool OnLoginAttempt(CSmartPtr Auth); diff --git a/User.cpp b/User.cpp index 78025ede..202fac29 100644 --- a/User.cpp +++ b/User.cpp @@ -707,6 +707,8 @@ bool CUser::WriteConfig(CFile& File) { } } + CZNC::Get().GetModules().OnWriteUserConfig(File, *this); + File.Write("\n"); return true; diff --git a/znc.cpp b/znc.cpp index b03ea958..4e4e1094 100644 --- a/znc.cpp +++ b/znc.cpp @@ -535,6 +535,10 @@ bool CZNC::WriteConfig() { return false; } + if (GetModules().OnWriteConfig(m_LockFile)) { + return false; + } + m_LockFile.Write("AnonIPLimit = " + CString(m_uiAnonIPLimit) + "\n"); for (size_t l = 0; l < m_vpListeners.size(); l++) {