1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 /* $Core: libIRCDsnomasks */
20 SnomaskManager::SnomaskManager(InspIRCd* Instance) : ServerInstance(Instance)
23 this->SetupDefaults();
26 SnomaskManager::~SnomaskManager()
30 void SnomaskManager::FlushSnotices()
32 for (std::map<char, Snomask *>::iterator i = SnoMasks.begin(); i != SnoMasks.end(); i++)
38 bool SnomaskManager::EnableSnomask(char letter, const std::string &type)
40 if (SnoMasks.find(letter) == SnoMasks.end())
42 Snomask *s = new Snomask(ServerInstance, letter, type);
49 bool SnomaskManager::DisableSnomask(char letter)
51 SnoList::iterator n = SnoMasks.find(letter);
52 if (n != SnoMasks.end())
54 delete n->second; // destroy the snomask
61 void SnomaskManager::WriteToSnoMask(char letter, const std::string &text)
63 /* Only send to snomask chars which are enabled */
64 SnoList::iterator n = SnoMasks.find(letter);
65 if (n != SnoMasks.end())
67 n->second->SendMessage(text);
71 void SnomaskManager::WriteToSnoMask(char letter, const char* text, ...)
73 char textbuffer[MAXBUF];
76 va_start(argsPtr, text);
77 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
80 this->WriteToSnoMask(letter, std::string(textbuffer));
83 bool SnomaskManager::IsEnabled(char letter)
85 return (SnoMasks.find(letter) != SnoMasks.end());
88 void SnomaskManager::SetupDefaults()
90 this->EnableSnomask('c',"CONNECT"); /* Local connect notices */
91 this->EnableSnomask('C',"REMOTECONNECT"); /* Remote connect notices */
92 this->EnableSnomask('q',"QUIT"); /* Local quit notices */
93 this->EnableSnomask('Q',"REMOTEQUIT"); /* Remote quit notices */
94 this->EnableSnomask('k',"KILL"); /* Kill notices */
95 this->EnableSnomask('K',"REMOTEKILL"); /* Remote kill notices */
96 this->EnableSnomask('l',"LINK"); /* Link notices */
97 this->EnableSnomask('o',"OPER"); /* Oper up/down notices */
98 this->EnableSnomask('A',"ANNOUNCEMENT"); /* formerly WriteOpers() - generic notices to all opers */
99 this->EnableSnomask('d',"DEBUG"); /* Debug notices */
100 this->EnableSnomask('x',"XLINE"); /* Xline notice (g/z/q/k/e) */
101 this->EnableSnomask('t',"STATS"); /* Local or remote stats request */
102 this->EnableSnomask('f',"FLOOD"); /* Flooding notices */
105 /*************************************************************************************/
107 void Snomask::SendMessage(const std::string &message)
109 if (message != LastMessage)
112 LastMessage = message;
120 void Snomask::Flush()
122 if (this->LastMessage.empty())
125 ServerInstance->Logs->Log("SNOMASK", DEBUG, "Flushing snomask %s", this->Description.c_str());
127 /* Only opers can receive snotices, so we iterate the oper list */
128 for (std::list<User*>::iterator i = ServerInstance->Users->all_opers.begin(); i != ServerInstance->Users->all_opers.end(); i++)
131 if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsModeSet('n') && a->IsNoticeMaskSet(MySnomask) && !a->quitting)
133 a->WriteServ("NOTICE %s :*** %s: %s", a->nick, this->Description.c_str(), this->LastMessage.c_str());
136 a->WriteServ("NOTICE %s :*** %s: (last message repeated %u times)", a->nick, this->Description.c_str(), Count);