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()
28 for (std::map<char, Snomask *>::iterator i = SnoMasks.begin(); i != SnoMasks.end(); i++)
35 void SnomaskManager::FlushSnotices()
37 for (std::map<char, Snomask *>::iterator i = SnoMasks.begin(); i != SnoMasks.end(); i++)
43 bool SnomaskManager::SetLocalOnly(char letter, bool local)
45 SnoList::iterator n = SnoMasks.find(letter);
46 if (n != SnoMasks.end())
48 n->second->LocalOnly = local;
49 return n->second->LocalOnly;
52 throw "snomask not found wtf";
55 bool SnomaskManager::EnableSnomask(char letter, const std::string &type, bool local)
57 if (SnoMasks.find(letter) == SnoMasks.end())
59 Snomask *s = new Snomask(ServerInstance, letter, type, local);
66 bool SnomaskManager::DisableSnomask(char letter)
68 SnoList::iterator n = SnoMasks.find(letter);
69 if (n != SnoMasks.end())
71 delete n->second; // destroy the snomask
78 void SnomaskManager::WriteToSnoMask(char letter, const std::string &text)
80 /* Only send to snomask chars which are enabled */
81 SnoList::iterator n = SnoMasks.find(letter);
82 if (n != SnoMasks.end())
84 n->second->SendMessage(text);
88 void SnomaskManager::WriteToSnoMask(char letter, const char* text, ...)
90 char textbuffer[MAXBUF];
93 va_start(argsPtr, text);
94 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
97 this->WriteToSnoMask(letter, std::string(textbuffer));
100 bool SnomaskManager::IsEnabled(char letter)
102 return (SnoMasks.find(letter) != SnoMasks.end());
105 void SnomaskManager::SetupDefaults()
107 this->EnableSnomask('c',"CONNECT", true); /* Local connect notices */
108 this->EnableSnomask('C',"REMOTECONNECT"); /* Remote connect notices */
109 this->EnableSnomask('q',"QUIT", true); /* Local quit notices */
110 this->EnableSnomask('Q',"REMOTEQUIT"); /* Remote quit notices */
111 this->EnableSnomask('k',"KILL", true); /* Kill notices */
112 this->EnableSnomask('K',"REMOTEKILL"); /* Remote kill notices */
113 this->EnableSnomask('l',"LINK"); /* Link notices */
114 this->EnableSnomask('o',"OPER"); /* Oper up/down notices */
115 this->EnableSnomask('A',"ANNOUNCEMENT"); /* formerly WriteOpers() - generic notices to all opers */
116 this->EnableSnomask('d',"DEBUG"); /* Debug notices */
117 this->EnableSnomask('x',"XLINE"); /* Xline notice (g/z/q/k/e) */
118 this->EnableSnomask('t',"STATS"); /* Local or remote stats request */
119 this->EnableSnomask('f',"FLOOD"); /* Flooding notices */
122 /*************************************************************************************/
124 void Snomask::SendMessage(const std::string &message)
126 if (message != LastMessage)
129 LastMessage = message;
137 void Snomask::Flush()
139 if (this->LastMessage.empty())
142 /* Only opers can receive snotices, so we iterate the oper list */
143 for (std::list<User*>::iterator i = ServerInstance->Users->all_opers.begin(); i != ServerInstance->Users->all_opers.end(); i++)
146 if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsModeSet('n') && a->IsNoticeMaskSet(MySnomask) && !a->quitting)
149 a->WriteServ("NOTICE %s :*** %s: %s", a->nick, this->Description.c_str(), this->LastMessage.c_str());
152 a->WriteServ("NOTICE %s :*** %s: (last message repeated %u times)", a->nick, this->Description.c_str(), Count);
159 // XXX this is a bit ugly.
163 ServerInstance->PI->SendSNONotice(sno, this->Description + ": " + this->LastMessage);
165 ServerInstance->PI->SendSNONotice(sno, this->Description + ": (last message repeated " + ConvToStr(Count) + " times)");