diff options
-rw-r--r-- | include/snomasks.h | 14 | ||||
-rw-r--r-- | src/snomasks.cpp | 49 |
2 files changed, 47 insertions, 16 deletions
diff --git a/include/snomasks.h b/include/snomasks.h index f7602f8fc..4545c1ed7 100644 --- a/include/snomasks.h +++ b/include/snomasks.h @@ -24,11 +24,15 @@ class Snomask { private: InspIRCd *ServerInstance; + + /** Sends out a pending message + */ + void Flush(); public: char MySnomask; std::string Description; -// std::string LastMessage; -// unsigned int Count; + std::string LastMessage; + unsigned int Count; /** Create a new Snomask */ @@ -38,12 +42,14 @@ class Snomask Description = description; } - + /** Sends a message to all opers with this snomask. + */ + void SendMessage(const std::string &message); }; /** A list of snomasks which are valid, and their descriptive texts */ -typedef std::map<char, std::string> SnoList; +typedef std::map<char, Snomask *> SnoList; /** Snomask manager handles routing of SNOMASK (usermode +n) messages to opers. * Modules and the core can enable and disable snomask characters. If they do, diff --git a/src/snomasks.cpp b/src/snomasks.cpp index 88714cf2d..f922703f2 100644 --- a/src/snomasks.cpp +++ b/src/snomasks.cpp @@ -29,14 +29,15 @@ 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; @@ -47,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; } @@ -59,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::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(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); } } @@ -105,3 +98,35 @@ 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() +{ + /* 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); + } + } + } +} |