diff --git a/Chan.cpp b/Chan.cpp index c83566c9..f14d85d6 100644 --- a/Chan.cpp +++ b/Chan.cpp @@ -39,6 +39,20 @@ void CChan::Reset() { ClearNicks(); } +bool CChan::WriteConfig(CFile& File) { + File.Write("\t\r\n"); + + File.Write("\t\tBuffer = " + CString::ToString(GetBufferCount()) + "\r\n"); + File.Write("\t\tKeepBuffer = " + CString((KeepBuffer()) ? "true" : "false") + "\r\n"); + File.Write("\t\tDetached = " + CString((IsDetached()) ? "true" : "false") + "\r\n"); + File.Write("\t\tAutoCycle = " + CString((AutoCycle()) ? "true" : "false") + "\r\n"); + if (!GetKey().empty()) { File.Write("\t\tKey = " + GetKey() + "\r\n"); } + if (!GetDefaultModes().empty()) { File.Write("\t\tModes = " + GetDefaultModes() + "\r\n"); } + + File.Write("\t\r\n"); + return true; +} + void CChan::Joined() { } diff --git a/Chan.h b/Chan.h index d48c15e0..2cff6177 100644 --- a/Chan.h +++ b/Chan.h @@ -4,6 +4,7 @@ #include "main.h" #include "Nick.h" #include "String.h" +#include "FileUtils.h" #include #include #include @@ -44,6 +45,7 @@ public: virtual ~CChan(); void Reset(); + bool WriteConfig(CFile& File); void Joined(); void Cycle() const; void JoinUser(bool bForce = false, const CString& sKey = ""); diff --git a/User.cpp b/User.cpp index 04a8d570..563ae244 100644 --- a/User.cpp +++ b/User.cpp @@ -321,6 +321,78 @@ bool CUser::DelChan(const CString& sName) { return false; } +bool CUser::PrintLine(CFile& File, const CString& sName, const CString& sValue) { + if (sName.empty() || sValue.empty()) { + return false; + } + + return File.Write("\t" + sName + " = " + sValue + "\r\n"); +} + +bool CUser::WriteConfig(CFile& File) { + File.Write("\r\n"); + + PrintLine(File, "Pass", GetPass() + ((IsPassHashed()) ? " -" : "")); + PrintLine(File, "Nick", GetNick()); + PrintLine(File, "AltNick", GetAltNick()); + PrintLine(File, "Ident", GetIdent()); + PrintLine(File, "RealName", GetRealName()); + PrintLine(File, "AwaySuffix", GetAwaySuffix()); + PrintLine(File, "StatusPrefix", GetStatusPrefix()); + PrintLine(File, "KeepNick", CString((GetKeepNick()) ? "true" : "false")); + PrintLine(File, "Buffer", CString::ToString(GetBufferCount())); + PrintLine(File, "KeepBuffer", CString((KeepBuffer()) ? "true" : "false")); + PrintLine(File, "ChanModes", GetDefaultChanModes()); + PrintLine(File, "BounceDCCs", CString((BounceDCCs()) ? "true" : "false")); + PrintLine(File, "AutoCycle", CString((AutoCycle()) ? "true" : "false")); + PrintLine(File, "DCCLookupMethod", CString((UseClientIP()) ? "client" : "default")); + File.Write("\r\n"); + + // Allow Hosts + for (set::iterator it = m_ssAllowedHosts.begin(); it != m_ssAllowedHosts.end(); it++) { + PrintLine(File, "Allow", *it); + } + + File.Write("\r\n"); + + // CTCP Replies + for (MCString::iterator itb = m_mssCTCPReplies.begin(); itb != m_mssCTCPReplies.end(); itb++) { + PrintLine(File, "CTCPReply", itb->first.AsUpper() + " " + itb->second); + } + File.Write("\r\n"); + + // Modules + CModules& Mods = GetModules(); + + for (unsigned int a = 0; a < Mods.size(); a++) { + CString sArgs = Mods[a]->GetArgs(); + + if (!sArgs.empty()) { + sArgs = " " + sArgs; + } + + PrintLine(File, "LoadModule", Mods[a]->GetModName() + sArgs); + } + File.Write("\r\n"); + + // Servers + for (unsigned int b = 0; b < m_vServers.size(); b++) { + PrintLine(File, "Server", m_vServers[b]->GetString()); + } + File.Write("\r\n"); + + // Chans + for (unsigned int c = 0; c < m_vChans.size(); c++) { + if (!m_vChans[c]->WriteConfig(File)) { + return false; + } + } + + File.Write("\r\n"); + + return true; +} + CChan* CUser::FindChan(const CString& sName) const { for (unsigned int a = 0; a < m_vChans.size(); a++) { CChan* pChan = m_vChans[a]; diff --git a/User.h b/User.h index a79d5cca..68c3f3f5 100644 --- a/User.h +++ b/User.h @@ -27,6 +27,8 @@ public: CUser(const CString& sUserName, CZNC* pZNC); virtual ~CUser(); + bool PrintLine(CFile& File, const CString& sName, const CString& sValue); + bool WriteConfig(CFile& File); CChan* FindChan(const CString& sName) const; bool AddChan(CChan* pChan); bool AddChan(const CString& sName, bool bInConfig);