From fa7ec788ddf00d8c49ca93d3f81a4fd6cd1359e7 Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Mon, 12 Sep 2011 16:16:49 +0000 Subject: [PATCH] Add CIRCNetwork::ExpandString --- Client.cpp | 6 +++++- IRCNetwork.cpp | 14 ++++++++++++++ IRCNetwork.h | 3 +++ IRCSock.cpp | 4 ++-- modules/autoreply.cpp | 4 ++++ modules/awaynick.cpp | 4 ++-- modules/identfile.cpp | 2 +- modules/perform.cpp | 10 ++++++++-- modules/watch.cpp | 6 +++--- 9 files changed, 42 insertions(+), 11 deletions(-) diff --git a/Client.cpp b/Client.cpp index df0f3e6e..297deb40 100644 --- a/Client.cpp +++ b/Client.cpp @@ -568,7 +568,11 @@ bool CClient::SendMotd() { } for (unsigned int a = 0; a < vsMotd.size(); a++) { - PutStatusNotice(m_pUser->ExpandString(vsMotd[a])); + if (m_pNetwork) { + PutStatusNotice(m_pNetwork->ExpandString(vsMotd[a])); + } else { + PutStatusNotice(m_pUser->ExpandString(vsMotd[a])); + } } return true; diff --git a/IRCNetwork.cpp b/IRCNetwork.cpp index 4576367d..55ab4333 100644 --- a/IRCNetwork.cpp +++ b/IRCNetwork.cpp @@ -896,3 +896,17 @@ void CIRCNetwork::SetRealName(const CString& s) { } } +CString CIRCNetwork::ExpandString(const CString& sStr) const { + CString sRet; + return ExpandString(sStr, sRet); +} + +CString& CIRCNetwork::ExpandString(const CString& sStr, CString& sRet) const { + sRet.Replace("%defnick%", GetNick()); + sRet.Replace("%nick%", GetCurNick()); + sRet.Replace("%altnick%", GetAltNick()); + sRet.Replace("%ident%", GetIdent()); + sRet.Replace("%realname%", GetRealName()); + + return m_pUser->ExpandString(sRet, sRet); +} diff --git a/IRCNetwork.h b/IRCNetwork.h index 1b6c5f22..2566e625 100644 --- a/IRCNetwork.h +++ b/IRCNetwork.h @@ -128,6 +128,9 @@ public: void SetAltNick(const CString& s); void SetIdent(const CString& s); void SetRealName(const CString& s); + + CString ExpandString(const CString& sStr) const; + CString& ExpandString(const CString& sStr, CString& sRet) const; private: bool JoinChan(CChan* pChan); void JoinChans(set& sChans); diff --git a/IRCSock.cpp b/IRCSock.cpp index 19897bb4..414c1d2e 100644 --- a/IRCSock.cpp +++ b/IRCSock.cpp @@ -80,7 +80,7 @@ void CIRCSock::Quit(const CString& sQuitMsg) { if (!sQuitMsg.empty()) { PutIRC("QUIT :" + sQuitMsg); } else { - PutIRC("QUIT :" + m_pNetwork->GetUser()->ExpandString(m_pNetwork->GetUser()->GetQuitMsg())); + PutIRC("QUIT :" + m_pNetwork->ExpandString(m_pNetwork->GetUser()->GetQuitMsg())); } Close(CLT_AFTERWRITE); } @@ -789,7 +789,7 @@ bool CIRCSock::OnGeneralCTCP(CNick& Nick, CString& sMessage) { CString sReply; if (it != mssCTCPReplies.end()) { - sReply = m_pNetwork->GetUser()->ExpandString(it->second); + sReply = m_pNetwork->ExpandString(it->second); bHaveReply = true; } diff --git a/modules/autoreply.cpp b/modules/autoreply.cpp index 2792efdc..75f56965 100644 --- a/modules/autoreply.cpp +++ b/modules/autoreply.cpp @@ -39,6 +39,10 @@ public: SetReply(sReply); } + if (m_pNetwork) { + return m_pNetwork->ExpandString(sReply); + } + return m_pUser->ExpandString(sReply); } diff --git a/modules/awaynick.cpp b/modules/awaynick.cpp index e6960c36..ce4e3a7c 100644 --- a/modules/awaynick.cpp +++ b/modules/awaynick.cpp @@ -99,7 +99,7 @@ public: // We don't limit this to NICKLEN, because we dont know // NICKLEN yet. - sNick = m_sAwayNick = m_pUser->ExpandString(m_sAwayNick); + sNick = m_sAwayNick = m_pNetwork->ExpandString(m_sAwayNick); } return CONTINUE; } @@ -166,7 +166,7 @@ public: uLen = pIRCSock->GetMaxNickLen(); } - m_sAwayNick = m_pUser->ExpandString(m_sFormat).Left(uLen); + m_sAwayNick = m_pNetwork->ExpandString(m_sFormat).Left(uLen); return m_sAwayNick; } diff --git a/modules/identfile.cpp b/modules/identfile.cpp index 04a7e6c0..96091d73 100644 --- a/modules/identfile.cpp +++ b/modules/identfile.cpp @@ -83,7 +83,7 @@ public: return false; } - CString sData = m_pUser->ExpandString(GetNV("Format")); + CString sData = m_pNetwork->ExpandString(GetNV("Format")); // If the format doesn't contain anything expandable, we'll // assume this is an "old"-style format string. diff --git a/modules/perform.cpp b/modules/perform.cpp index 9af1df93..b928f6a7 100644 --- a/modules/perform.cpp +++ b/modules/perform.cpp @@ -7,6 +7,7 @@ */ #include "User.h" +#include "IRCNetwork.h" #include class CPerform : public CModule { @@ -50,7 +51,12 @@ class CPerform : public CModule { Table.SetCell("Id", CString(index)); Table.SetCell("Perform", *it); - sExpanded = GetUser()->ExpandString(*it); + if (m_pNetwork) { + sExpanded = m_pNetwork->ExpandString(*it); + } else { + sExpanded = GetUser()->ExpandString(*it); + } + if (sExpanded != *it) { Table.SetCell("Expanded", sExpanded); } @@ -122,7 +128,7 @@ public: virtual void OnIRCConnected() { for (VCString::const_iterator it = m_vPerform.begin(); it != m_vPerform.end(); ++it) { - PutIRC(GetUser()->ExpandString(*it)); + PutIRC(m_pNetwork->ExpandString(*it)); } } diff --git a/modules/watch.cpp b/modules/watch.cpp index bb236bf0..3a169b4c 100644 --- a/modules/watch.cpp +++ b/modules/watch.cpp @@ -58,7 +58,7 @@ public: } virtual ~CWatchEntry() {} - bool IsMatch(const CNick& Nick, const CString& sText, const CString& sSource, const CUser* pUser) { + bool IsMatch(const CNick& Nick, const CString& sText, const CString& sSource, const CIRCNetwork* pNetwork) { if (IsDisabled()) { return false; } @@ -85,7 +85,7 @@ public: return false; if (!Nick.GetHostMask().AsLower().WildCmp(m_sHostMask.AsLower())) return false; - return (sText.AsLower().WildCmp(pUser->ExpandString(m_sPattern).AsLower())); + return (sText.AsLower().WildCmp(pNetwork->ExpandString(m_sPattern).AsLower())); } bool operator ==(const CWatchEntry& WatchEntry) { @@ -287,7 +287,7 @@ private: for (list::iterator it = m_lsWatchers.begin(); it != m_lsWatchers.end(); ++it) { CWatchEntry& WatchEntry = *it; - if (WatchEntry.IsMatch(Nick, sMessage, sSource, m_pUser)) { + if (WatchEntry.IsMatch(Nick, sMessage, sSource, m_pNetwork)) { if (m_pNetwork->IsUserAttached()) { m_pNetwork->PutUser(":" + WatchEntry.GetTarget() + "!watch@znc.in PRIVMSG " + m_pNetwork->GetCurNick() + " :" + sMessage);