Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #388 from Lunatrius/master

Add detached only support to the watch module.
  • Loading branch information...
commit 79b33ea15d1647e3b75473d0e2c953e732c91c77 2 parents e8e95d7 + 88f826d
@DarthGandalf DarthGandalf authored
Showing with 120 additions and 2 deletions.
  1. +120 −2 modules/watch.cpp
View
122 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 @@ class CWatchEntry {
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<CWatchSource>& GetSources() const { return m_vsSources; }
CString GetSourcesStr() const {
CString sRet;
@@ -135,6 +139,8 @@ class CWatchEntry {
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 @@ class CWatchEntry {
CString m_sTarget;
CString m_sPattern;
bool m_bDisabled;
+ bool m_bDetachedClientOnly;
+ bool m_bDetachedChannelOnly;
vector<CWatchSource> m_vsSources;
};
@@ -271,6 +279,24 @@ class CWatcherMod : public CModule {
} 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 @@ class CWatcherMod : public CModule {
private:
void Process(const CNick& Nick, const CString& sMessage, const CString& sSource) {
set<CString> sHandledTargets;
+ CChan* pChannel = m_pNetwork->FindChan(sSource);
for (list<CWatchEntry>::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 @@ class CWatcherMod : public CModule {
Save();
}
+ void SetDetachedClientOnly(unsigned int uIdx, bool bDetachedClientOnly) {
+ if (uIdx == (unsigned int) ~0) {
+ for (list<CWatchEntry>::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<CWatchEntry>::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<CWatchEntry>::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<CWatchEntry>::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 @@ class CWatcherMod : public CModule {
Table.AddColumn("Pattern");
Table.AddColumn("Sources");
Table.AddColumn("Off");
+ Table.AddColumn("DetachedClientOnly");
+ Table.AddColumn("DetachedChannelOnly");
unsigned int uIdx = 1;
@@ -358,6 +447,8 @@ class CWatcherMod : public CModule {
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 @@ class CWatcherMod : public CModule {
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("---------------");
@@ -464,6 +563,14 @@ class CWatcherMod : public CModule {
Table.SetCell("Description", "Disable (but don't delete) an entry.");
Table.AddRow();
+ Table.SetCell("Command", "SetDetachedClientOnly <Id | *> <True | False>");
+ Table.SetCell("Description", "Enable or disable detached client only for an entry.");
+
+ Table.AddRow();
+ Table.SetCell("Command", "SetDetachedChannelOnly <Id | *> <True | False>");
+ 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 @@ class CWatcherMod : public CModule {
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 @@ class CWatcherMod : public CModule {
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 @@ class CWatcherMod : public CModule {
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);
}
Please sign in to comment.
Something went wrong with that request. Please try again.