From 88f826ddc4f73d481b0cec089c4af9956f395d5b Mon Sep 17 00:00:00 2001 From: Lunatrius Date: Fri, 26 Jul 2013 02:38:24 +0200 Subject: [PATCH] Add detached only support to the watch module. --- modules/watch.cpp | 122 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 120 insertions(+), 2 deletions(-) diff --git a/modules/watch.cpp b/modules/watch.cpp index 1237adae..f04c0a21 100644 --- a/modules/watch.cpp +++ b/modules/watch.cpp @@ -46,6 +46,8 @@ class CWatchEntry { public: CWatchEntry(const CString& sHostMask, const CString& sTarget, const CString& sPattern) { m_bDisabled = false; + m_bDetachedClientOnly = false; + m_bDetachedChannelOnly = false; m_sPattern = (sPattern.size()) ? sPattern : "*"; CNick Nick; @@ -108,6 +110,8 @@ public: const CString& GetTarget() const { return m_sTarget; } const CString& GetPattern() const { return m_sPattern; } bool IsDisabled() const { return m_bDisabled; } + bool IsDetachedClientOnly() const { return m_bDetachedClientOnly; } + bool IsDetachedChannelOnly() const { return m_bDetachedChannelOnly; } const vector& GetSources() const { return m_vsSources; } CString GetSourcesStr() const { CString sRet; @@ -135,6 +139,8 @@ public: void SetTarget(const CString& s) { m_sTarget = s; } void SetPattern(const CString& s) { m_sPattern = s; } void SetDisabled(bool b = true) { m_bDisabled = b; } + void SetDetachedClientOnly(bool b = true) { m_bDetachedClientOnly = b; } + void SetDetachedChannelOnly(bool b = true) { m_bDetachedChannelOnly = b; } void SetSources(const CString& sSources) { VCString vsSources; VCString::iterator it; @@ -157,6 +163,8 @@ protected: CString m_sTarget; CString m_sPattern; bool m_bDisabled; + bool m_bDetachedClientOnly; + bool m_bDetachedChannelOnly; vector m_vsSources; }; @@ -271,6 +279,24 @@ public: } else { SetDisabled(sTok.ToUInt(), true); } + } else if (sCmdName.Equals("SETDETACHEDCLIENTONLY")) { + CString sTok = sCommand.Token(1); + bool bDetachedClientOnly = sCommand.Token(2).ToBool(); + + if (sTok == "*") { + SetDetachedClientOnly(~0, bDetachedClientOnly); + } else { + SetDetachedClientOnly(sTok.ToUInt(), bDetachedClientOnly); + } + } else if (sCmdName.Equals("SETDETACHEDCHANNELONLY")) { + CString sTok = sCommand.Token(1); + bool bDetachedchannelOnly = sCommand.Token(2).ToBool(); + + if (sTok == "*") { + SetDetachedChannelOnly(~0, bDetachedchannelOnly); + } else { + SetDetachedChannelOnly(sTok.ToUInt(), bDetachedchannelOnly); + } } else if (sCmdName.Equals("SETSOURCES")) { SetSources(sCommand.Token(1).ToUInt(), sCommand.Token(2, true)); } else if (sCmdName.Equals("CLEAR")) { @@ -295,10 +321,19 @@ public: private: void Process(const CNick& Nick, const CString& sMessage, const CString& sSource) { set sHandledTargets; + CChan* pChannel = m_pNetwork->FindChan(sSource); for (list::iterator it = m_lsWatchers.begin(); it != m_lsWatchers.end(); ++it) { CWatchEntry& WatchEntry = *it; + if (m_pNetwork->IsUserAttached() && WatchEntry.IsDetachedClientOnly()) { + continue; + } + + if (pChannel && !pChannel->IsDetached() && WatchEntry.IsDetachedChannelOnly()) { + continue; + } + if (WatchEntry.IsMatch(Nick, sMessage, sSource, m_pNetwork) && sHandledTargets.count(WatchEntry.GetTarget()) < 1) { if (m_pNetwork->IsUserAttached()) { @@ -337,6 +372,58 @@ private: Save(); } + void SetDetachedClientOnly(unsigned int uIdx, bool bDetachedClientOnly) { + if (uIdx == (unsigned int) ~0) { + for (list::iterator it = m_lsWatchers.begin(); it != m_lsWatchers.end(); ++it) { + (*it).SetDetachedClientOnly(bDetachedClientOnly); + } + + PutModule(CString("Set DetachedClientOnly for all entries to: ") + ((bDetachedClientOnly) ? "Yes" : "No")); + Save(); + return; + } + + uIdx--; // "convert" index to zero based + if (uIdx >= m_lsWatchers.size()) { + PutModule("Invalid Id"); + return; + } + + list::iterator it = m_lsWatchers.begin(); + for (unsigned int a = 0; a < uIdx; a++) + ++it; + + (*it).SetDetachedClientOnly(bDetachedClientOnly); + PutModule("Id " + CString(uIdx +1) + " set to: " + ((bDetachedClientOnly) ? "Yes" : "No")); + Save(); + } + + void SetDetachedChannelOnly(unsigned int uIdx, bool bDetachedChannelOnly) { + if (uIdx == (unsigned int) ~0) { + for (list::iterator it = m_lsWatchers.begin(); it != m_lsWatchers.end(); ++it) { + (*it).SetDetachedChannelOnly(bDetachedChannelOnly); + } + + PutModule(CString("Set DetachedChannelOnly for all entries to: ") + ((bDetachedChannelOnly) ? "Yes" : "No")); + Save(); + return; + } + + uIdx--; // "convert" index to zero based + if (uIdx >= m_lsWatchers.size()) { + PutModule("Invalid Id"); + return; + } + + list::iterator it = m_lsWatchers.begin(); + for (unsigned int a = 0; a < uIdx; a++) + ++it; + + (*it).SetDetachedChannelOnly(bDetachedChannelOnly); + PutModule("Id " + CString(uIdx +1) + " set to: " + ((bDetachedChannelOnly) ? "Yes" : "No")); + Save(); + } + void List() { CTable Table; Table.AddColumn("Id"); @@ -345,6 +432,8 @@ private: Table.AddColumn("Pattern"); Table.AddColumn("Sources"); Table.AddColumn("Off"); + Table.AddColumn("DetachedClientOnly"); + Table.AddColumn("DetachedChannelOnly"); unsigned int uIdx = 1; @@ -358,6 +447,8 @@ private: Table.SetCell("Pattern", WatchEntry.GetPattern()); Table.SetCell("Sources", WatchEntry.GetSourcesStr()); Table.SetCell("Off", (WatchEntry.IsDisabled()) ? "Off" : ""); + Table.SetCell("DetachedClientOnly", (WatchEntry.IsDetachedClientOnly()) ? "Yes" : "No"); + Table.SetCell("DetachedChannelOnly", (WatchEntry.IsDetachedChannelOnly()) ? "Yes" : "No"); } if (Table.size()) { @@ -392,6 +483,14 @@ private: if (WatchEntry.IsDisabled()) { PutModule("/msg " + GetModNick() + " DISABLE " + CString(uIdx)); } + + if (WatchEntry.IsDetachedClientOnly()) { + PutModule("/msg " + GetModNick() + " SETDETACHEDCLIENTONLY " + CString(uIdx) + " TRUE"); + } + + if (WatchEntry.IsDetachedChannelOnly()) { + PutModule("/msg " + GetModNick() + " SETDETACHEDCHANNELONLY " + CString(uIdx) + " TRUE"); + } } PutModule("---------------"); @@ -463,6 +562,14 @@ private: Table.SetCell("Command", "Disable "); Table.SetCell("Description", "Disable (but don't delete) an entry."); + Table.AddRow(); + Table.SetCell("Command", "SetDetachedClientOnly "); + Table.SetCell("Description", "Enable or disable detached client only for an entry."); + + Table.AddRow(); + Table.SetCell("Command", "SetDetachedChannelOnly "); + Table.SetCell("Description", "Enable or disable detached channel only for an entry."); + Table.AddRow(); Table.SetCell("Command", "Buffer [Count]"); Table.SetCell("Description", "Show/Set the amount of buffered lines while detached."); @@ -520,6 +627,8 @@ private: sSave += WatchEntry.GetTarget() + "\n"; sSave += WatchEntry.GetPattern() + "\n"; sSave += (WatchEntry.IsDisabled() ? "disabled\n" : "enabled\n"); + sSave += CString(WatchEntry.IsDetachedClientOnly()) + "\n"; + sSave += CString(WatchEntry.IsDetachedChannelOnly()) + "\n"; sSave += WatchEntry.GetSourcesStr(); // Without this, loading fails if GetSourcesStr() // returns an empty string @@ -541,7 +650,8 @@ private: VCString vList; it->first.Split("\n", vList); - if (vList.size() != 5) { + // Backwards compatibility with the old save format + if (vList.size() != 5 && vList.size() != 7) { bWarn = true; continue; } @@ -551,7 +661,15 @@ private: WatchEntry.SetDisabled(true); else WatchEntry.SetDisabled(false); - WatchEntry.SetSources(vList[4]); + + // Backwards compatibility with the old save format + if (vList.size() == 5) { + WatchEntry.SetSources(vList[4]); + } else { + WatchEntry.SetDetachedClientOnly(vList[4].ToBool()); + WatchEntry.SetDetachedChannelOnly(vList[5].ToBool()); + WatchEntry.SetSources(vList[6]); + } m_lsWatchers.push_back(WatchEntry); }