X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fsnomasks.cpp;h=2af5fc8014451ac341ddf2788abb78349d6418f3;hb=d138843fe0b95bbb1d58baf8c0886a6b3622d0d0;hp=ba6d3d7d53148b7d9b70760324bfc1d819dc273b;hpb=f2acdbc3820f0f4f5ef76a0a64e73d2a320df91f;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/snomasks.cpp b/src/snomasks.cpp index ba6d3d7d5..2af5fc801 100644 --- a/src/snomasks.cpp +++ b/src/snomasks.cpp @@ -11,10 +11,10 @@ * --------------------------------------------------- */ +/* $Core: libIRCDsnomasks */ + #include "inspircd.h" #include -#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::iterator i = ServerInstance->all_opers.begin(); i != ServerInstance->all_opers.end(); i++) - { - userrec* a = *i; - if (IS_LOCAL(a) && a->modes[UM_SERVERNOTICE] && a->modes[UM_SNOMASK] && 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::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); + } + } + } +}