From bea3d85e8c13a324017f42ba35afb6c13e2ba614 Mon Sep 17 00:00:00 2001 From: psychon Date: Sun, 22 Jun 2008 14:06:01 +0000 Subject: [PATCH] autoattach: Don't allow adding the same entry twice git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1100 726aef4b-f618-498e-8847-2d620e286838 --- modules/autoattach.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/modules/autoattach.cpp b/modules/autoattach.cpp index 731fa2ca..4d6ea561 100644 --- a/modules/autoattach.cpp +++ b/modules/autoattach.cpp @@ -61,7 +61,9 @@ public: if (sCommand.CaseCmp("ADD") == 0) { CString sChan = sLine.Token(1); - if (Add(sChan)) { + if (AlreadyAdded(sChan)) { + PutModule(sChan + " is already added"); + } else if (Add(sChan)) { PutModule("Added " + sChan + " to list"); } else { PutModule("Usage: Add [!]<#chan>"); @@ -70,7 +72,7 @@ public: CString sChan = sLine.Token(1); if (Del(sChan)) - PutModule("Remove " + sChan + " from list"); + PutModule("Removed " + sChan + " from list"); else PutModule("Usage: Del [!]<#chan>"); } else if (sCommand.CaseCmp("LIST") == 0) { @@ -127,6 +129,25 @@ public: } } + bool AlreadyAdded(const CString& sInput) { + vector::iterator it; + + if (sInput.Left(1) == "!") { + CString sChan = sInput.substr(1); + for (it = m_vsNegChans.begin(); it != m_vsNegChans.end(); + it++) { + if (*it == sChan) + return true; + } + } else { + for (it = m_vsChans.begin(); it != m_vsChans.end(); it++) { + if (*it == sInput) + return true; + } + } + return false; + } + bool Add(const CString& sChan) { if (sChan.empty() || sChan == "!") { return false; @@ -138,6 +159,7 @@ public: m_vsChans.push_back(sChan); } + // Also save it for next module load SetNV(sChan, ""); return true;