]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/snomasks.cpp
Fix snomask stacking, still needs to flush all snomasks on a timer to avoid messages...
[user/henk/code/inspircd.git] / src / snomasks.cpp
index 962e5a638c32fcaa0b8ec6417cb784f8ac3252a7..2af5fc8014451ac341ddf2788abb78349d6418f3 100644 (file)
  * ---------------------------------------------------
  */
 
+/* $Core: libIRCDsnomasks */
+
 #include "inspircd.h"
 #include <stdarg.h>
-#include "configreader.h"
-#include "users.h"
 #include "snomasks.h"
 
 SnomaskManager::SnomaskManager(InspIRCd* Instance) : ServerInstance(Instance)
@@ -27,11 +27,17 @@ SnomaskManager::~SnomaskManager()
 {
 }
 
+void SnomaskManager::FlushSnotices()
+{
+       // stub.. not yet written XXX
+}
+
 bool SnomaskManager::EnableSnomask(char letter, const std::string &type)
 {
        if (SnoMasks.find(letter) == SnoMasks.end())
        {
-               SnoMasks[letter] = type;
+               Snomask *s = new Snomask(ServerInstance, letter, type);
+               SnoMasks[letter] = s;
                return true;
        }
        return false;
@@ -42,6 +48,7 @@ bool SnomaskManager::DisableSnomask(char letter)
        SnoList::iterator n = SnoMasks.find(letter);
        if (n != SnoMasks.end())
        {
+               delete n->second; // destroy the snomask
                SnoMasks.erase(n);
                return true;
        }
@@ -54,16 +61,7 @@ void SnomaskManager::WriteToSnoMask(char letter, const std::string &text)
        SnoList::iterator n = SnoMasks.find(letter);
        if (n != SnoMasks.end())
        {
-               /* Only opers can receive snotices, so we iterate the oper list */
-               for (std::vector<userrec*>::iterator i = ServerInstance->all_opers.begin(); i != ServerInstance->all_opers.end(); i++)
-               {
-                       userrec* a = *i;
-                       if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsModeSet('n') && a->IsNoticeMaskSet(n->first))
-                       {
-                               /* send server notices to all with +ns */
-                               a->WriteServ("NOTICE %s :*** %s: %s",a->nick, n->second.c_str(), text.c_str());
-                       }
-               }
+               n->second->SendMessage(text);
        }
 }
 
@@ -100,3 +98,40 @@ void SnomaskManager::SetupDefaults()
        this->EnableSnomask('f',"FLOOD");                       /* Flooding notices */
 }
 
+/*************************************************************************************/
+
+void Snomask::SendMessage(const std::string &message)
+{
+       if (message != LastMessage)
+       {
+               this->Flush();
+               LastMessage = message;
+               Count = 1;
+       }
+       else
+       {
+               Count++;
+       }
+}
+
+void Snomask::Flush()
+{
+       if (this->LastMessage.empty())
+               return;
+
+       ServerInstance->Log(DEBUG, "Flusing snomask %s", this->Description.c_str());
+
+       /* Only opers can receive snotices, so we iterate the oper list */
+       for (std::list<User*>::iterator i = ServerInstance->all_opers.begin(); i != ServerInstance->all_opers.end(); i++)
+       {
+               User* a = *i;
+               if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsModeSet('n') && a->IsNoticeMaskSet(MySnomask))
+               {
+                       a->WriteServ("NOTICE %s :*** %s: %s", a->nick, this->Description.c_str(), this->LastMessage.c_str());
+                       if (Count > 1)
+                       {
+                               a->WriteServ("NOTICE %s :*** %s: (last message repeated %u times)", a->nick, this->Description.c_str(), Count);
+                       }
+               }
+       }
+}