From 6686c0de79411811ac3e98f6a9191d083d6800fd Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Mon, 12 Sep 2011 15:56:28 +0000 Subject: [PATCH] Support having a nickname per network --- IRCNetwork.cpp | 101 ++++++++++++++++++ IRCNetwork.h | 15 +++ IRCSock.cpp | 12 +-- .../data/webadmin/tmpl/add_edit_network.tmpl | 19 ++++ modules/webadmin.cpp | 27 +++++ 5 files changed, 168 insertions(+), 6 deletions(-) diff --git a/IRCNetwork.cpp b/IRCNetwork.cpp index a7864c07..4576367d 100644 --- a/IRCNetwork.cpp +++ b/IRCNetwork.cpp @@ -178,11 +178,31 @@ CString CIRCNetwork::GetNetworkPath() { return sNetworkPath; } +template +struct TOption { + const char *name; + void (CIRCNetwork::*pSetter)(T); +}; + bool CIRCNetwork::ParseConfig(CConfig *pConfig, CString& sError, bool bUpgrade) { VCString vsList; VCString::const_iterator vit; if (!bUpgrade) { + TOption StringOptions[] = { + { "nick", &CIRCNetwork::SetNick }, + { "altnick", &CIRCNetwork::SetAltNick }, + { "ident", &CIRCNetwork::SetIdent }, + { "realname", &CIRCNetwork::SetRealName } + }; + size_t numStringOptions = sizeof(StringOptions) / sizeof(StringOptions[0]); + + for (size_t i = 0; i < numStringOptions; i++) { + CString sValue; + if (pConfig->FindStringEntry(StringOptions[i].name, sValue)) + (this->*StringOptions[i].pSetter)(sValue); + } + pConfig->FindStringVector("loadmodule", vsList); for (vit = vsList.begin(); vit != vsList.end(); ++vit) { CString sValue = *vit; @@ -247,6 +267,22 @@ bool CIRCNetwork::ParseConfig(CConfig *pConfig, CString& sError, bool bUpgrade) CConfig CIRCNetwork::ToConfig() { CConfig config; + if (!m_sNick.empty()) { + config.AddKeyValuePair("Nick", m_sNick); + } + + if (!m_sAltNick.empty()) { + config.AddKeyValuePair("AltNick", m_sAltNick); + } + + if (!m_sIdent.empty()) { + config.AddKeyValuePair("Ident", m_sIdent); + } + + if (!m_sRealName.empty()) { + config.AddKeyValuePair("RealName", m_sRealName); + } + // Modules CModules& Mods = GetModules(); @@ -795,3 +831,68 @@ bool CIRCNetwork::PutIRC(const CString& sLine) { pIRCSock->PutIRC(sLine); return true; } + +const CString& CIRCNetwork::GetNick(const bool bAllowDefault) const { + if (m_sNick.empty()) { + return m_pUser->GetNick(bAllowDefault); + } + + return m_sNick; +} + +const CString& CIRCNetwork::GetAltNick(const bool bAllowDefault) const { + if (m_sAltNick.empty()) { + return m_pUser->GetAltNick(bAllowDefault); + } + + return m_sAltNick; +} + +const CString& CIRCNetwork::GetIdent(const bool bAllowDefault) const { + if (m_sIdent.empty()) { + return m_pUser->GetIdent(bAllowDefault); + } + + return m_sIdent; +} + +const CString& CIRCNetwork::GetRealName() const { + if (m_sRealName.empty()) { + return m_pUser->GetRealName(); + } + + return m_sRealName; +} + +void CIRCNetwork::SetNick(const CString& s) { + if (m_pUser->GetNick().Equals(s)) { + m_sNick = ""; + } else { + m_sNick = s; + } +} + +void CIRCNetwork::SetAltNick(const CString& s) { + if (m_pUser->GetAltNick().Equals(s)) { + m_sAltNick = ""; + } else { + m_sAltNick = s; + } +} + +void CIRCNetwork::SetIdent(const CString& s) { + if (m_pUser->GetIdent().Equals(s)) { + m_sIdent = ""; + } else { + m_sIdent = s; + } +} + +void CIRCNetwork::SetRealName(const CString& s) { + if (m_pUser->GetRealName().Equals(s)) { + m_sRealName = ""; + } else { + m_sRealName = s; + } +} + diff --git a/IRCNetwork.h b/IRCNetwork.h index fab1f012..1b6c5f22 100644 --- a/IRCNetwork.h +++ b/IRCNetwork.h @@ -118,6 +118,16 @@ public: void ClearQueryBuffer() { m_QueryBuffer.Clear(); } // !Buffers + // la + const CString& GetNick(const bool bAllowDefault = true) const; + const CString& GetAltNick(const bool bAllowDefault = true) const; + const CString& GetIdent(const bool bAllowDefault = true) const; + const CString& GetRealName() const; + + void SetNick(const CString& s); + void SetAltNick(const CString& s); + void SetIdent(const CString& s); + void SetRealName(const CString& s); private: bool JoinChan(CChan* pChan); void JoinChans(set& sChans); @@ -126,6 +136,11 @@ protected: CString m_sName; CUser* m_pUser; + CString m_sNick; + CString m_sAltNick; + CString m_sIdent; + CString m_sRealName; + CModules* m_pModules; vector m_vClients; diff --git a/IRCSock.cpp b/IRCSock.cpp index 0ba5ed7c..19897bb4 100644 --- a/IRCSock.cpp +++ b/IRCSock.cpp @@ -24,7 +24,7 @@ CIRCSock::CIRCSock(CIRCNetwork* pNetwork) : CZNCSock() { m_bNamesx = false; m_bUHNames = false; EnableReadLine(); - m_Nick.SetIdent(m_pNetwork->GetUser()->GetIdent()); + m_Nick.SetIdent(m_pNetwork->GetIdent()); m_Nick.SetHost(m_pNetwork->GetUser()->GetBindHost()); m_uMaxNickLen = 9; @@ -904,9 +904,9 @@ void CIRCSock::Connected() { DEBUG(GetSockName() << " == Connected()"); CString sPass = m_sPass; - CString sNick = m_pNetwork->GetUser()->GetNick(); - CString sIdent = m_pNetwork->GetUser()->GetIdent(); - CString sRealName = m_pNetwork->GetUser()->GetRealName(); + CString sNick = m_pNetwork->GetNick(); + CString sIdent = m_pNetwork->GetIdent(); + CString sRealName = m_pNetwork->GetRealName(); NETWORKMODULECALL(OnIRCRegistration(sPass, sNick, sIdent, sRealName), m_pNetwork->GetUser(), m_pNetwork, NULL, return); @@ -1128,8 +1128,8 @@ void CIRCSock::SendAltNick(const CString& sBadNick) { unsigned int uMax = m_uMaxNickLen; - const CString& sConfNick = m_pNetwork->GetUser()->GetNick(); - const CString& sAltNick = m_pNetwork->GetUser()->GetAltNick(); + const CString& sConfNick = m_pNetwork->GetNick(); + const CString& sAltNick = m_pNetwork->GetAltNick(); CString sNewNick; if (sLastNick.Equals(sConfNick)) { diff --git a/modules/data/webadmin/tmpl/add_edit_network.tmpl b/modules/data/webadmin/tmpl/add_edit_network.tmpl index 8e548711..3131add1 100644 --- a/modules/data/webadmin/tmpl/add_edit_network.tmpl +++ b/modules/data/webadmin/tmpl/add_edit_network.tmpl @@ -8,6 +8,7 @@

Network Info

+ Nick, AltNick, Ident, RealName can be left empty to use the value from the user.
@@ -19,6 +20,24 @@
+
+
Nickname:
+
+
+
+
Alt. Nickname:
+
+
+
+
+
Ident:
+
+
+
+
Realname:
+
+
+
Servers: