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 ServerInstance->Logs->Log("SNOMASK", DEFAULT, "Snomask %d not found, unmatched modules?", letter);
56 bool SnomaskManager::EnableSnomask(char letter, const std::string &type, bool local)
58 if (SnoMasks.find(letter) == SnoMasks.end())
60 Snomask *s = new Snomask(ServerInstance, letter, type, local);
67 bool SnomaskManager::DisableSnomask(char letter)
69 SnoList::iterator n = SnoMasks.find(letter);
70 if (n != SnoMasks.end())
72 delete n->second; // destroy the snomask
79 void SnomaskManager::WriteToSnoMask(char letter, const std::string &text)
81 /* Only send to snomask chars which are enabled */
82 SnoList::iterator n = SnoMasks.find(letter);
83 if (n != SnoMasks.end())
85 n->second->SendMessage(text);
89 void SnomaskManager::WriteToSnoMask(char letter, const char* text, ...)
91 char textbuffer[MAXBUF];
94 va_start(argsPtr, text);
95 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
98 this->WriteToSnoMask(letter, std::string(textbuffer));
101 bool SnomaskManager::IsEnabled(char letter)
103 return (SnoMasks.find(letter) != SnoMasks.end());
106 void SnomaskManager::SetupDefaults()
108 this->EnableSnomask('c',"CONNECT", true); /* Local connect notices */
109 this->EnableSnomask('C',"REMOTECONNECT", true); /* Remote connect notices */
110 this->EnableSnomask('q',"QUIT", true); /* Local quit notices */
111 this->EnableSnomask('Q',"REMOTEQUIT", true); /* Remote quit notices */
112 this->EnableSnomask('k',"KILL", true); /* Kill notices */
113 this->EnableSnomask('K',"REMOTEKILL"); /* Remote kill notices */
114 this->EnableSnomask('l',"LINK"); /* Link notices */
115 this->EnableSnomask('o',"OPER"); /* Oper up/down notices */
116 this->EnableSnomask('A',"ANNOUNCEMENT"); /* formerly WriteOpers() - generic notices to all opers */
117 this->EnableSnomask('d',"DEBUG", true); /* Debug notices */
118 this->EnableSnomask('x',"XLINE"); /* Xline notice (g/z/q/k/e) */
119 this->EnableSnomask('t',"STATS"); /* Local or remote stats request */
120 this->EnableSnomask('f',"FLOOD"); /* Flooding notices */
123 /*************************************************************************************/
125 void Snomask::SendMessage(const std::string &message)
127 if (message != LastMessage)
130 LastMessage = message;
138 void Snomask::Flush()
140 if (this->LastMessage.empty())
143 /* Only opers can receive snotices, so we iterate the oper list */
144 for (std::list<User*>::iterator i = ServerInstance->Users->all_opers.begin(); i != ServerInstance->Users->all_opers.end(); i++)
147 if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsModeSet('n') && a->IsNoticeMaskSet(MySnomask) && !a->quitting)
150 a->WriteServ("NOTICE %s :*** %s: %s", a->nick, this->Description.c_str(), this->LastMessage.c_str());
153 a->WriteServ("NOTICE %s :*** %s: (last message repeated %u times)", a->nick, this->Description.c_str(), Count);
160 // XXX this is a bit ugly.
164 ServerInstance->PI->SendSNONotice(sno, this->Description + ": " + this->LastMessage);
166 ServerInstance->PI->SendSNONotice(sno, this->Description + ": (last message repeated " + ConvToStr(Count) + " times)");