1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
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::EnableSnomask(char letter, const std::string &type)
45 if (SnoMasks.find(letter) == SnoMasks.end())
47 Snomask *s = new Snomask(ServerInstance, letter, type);
54 bool SnomaskManager::DisableSnomask(char letter)
56 SnoList::iterator n = SnoMasks.find(letter);
57 if (n != SnoMasks.end())
59 delete n->second; // destroy the snomask
66 void SnomaskManager::WriteToSnoMask(char letter, const std::string &text)
68 /* Only send to snomask chars which are enabled */
69 SnoList::iterator n = SnoMasks.find(letter);
70 if (n != SnoMasks.end())
72 n->second->SendMessage(text);
76 void SnomaskManager::WriteGlobalSno(char letter, const std::string& text)
78 WriteToSnoMask(letter, text);
79 letter = toupper(letter);
80 ServerInstance->PI->SendSNONotice(std::string(1, letter), text);
83 void SnomaskManager::WriteToSnoMask(char letter, const char* text, ...)
85 char textbuffer[MAXBUF];
88 va_start(argsPtr, text);
89 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
92 this->WriteToSnoMask(letter, std::string(textbuffer));
95 void SnomaskManager::WriteGlobalSno(char letter, const char* text, ...)
97 char textbuffer[MAXBUF];
100 va_start(argsPtr, text);
101 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
104 this->WriteGlobalSno(letter, std::string(textbuffer));
107 bool SnomaskManager::IsEnabled(char letter)
109 return (SnoMasks.find(letter) != SnoMasks.end());
112 void SnomaskManager::SetupDefaults()
114 this->EnableSnomask('c',"CONNECT"); /* Local connect notices */
115 this->EnableSnomask('C',"REMOTECONNECT"); /* Remote connect notices */
116 this->EnableSnomask('q',"QUIT"); /* Local quit notices */
117 this->EnableSnomask('Q',"REMOTEQUIT"); /* Remote quit notices */
118 this->EnableSnomask('k',"KILL"); /* Kill notices */
119 this->EnableSnomask('K',"REMOTEKILL"); /* Remote kill notices */
120 this->EnableSnomask('l',"LINK"); /* Linking notices */
121 this->EnableSnomask('L',"REMOTELINK"); /* Remote linking notices */
122 this->EnableSnomask('o',"OPER"); /* Oper up/down notices */
123 this->EnableSnomask('O',"REMOTEOPER"); /* Remote oper up/down notices */
124 this->EnableSnomask('a',"ANNOUNCEMENT"); /* formerly WriteOpers() - generic notices to all opers */
125 this->EnableSnomask('A',"REMOTEANNOUNCEMENT"); /* formerly WriteOpers() - generic notices to all opers */
126 this->EnableSnomask('d',"DEBUG"); /* Debug notices */
127 this->EnableSnomask('x',"XLINE"); /* Xline notice (g/z/q/k/e) */
128 this->EnableSnomask('t',"STATS"); /* Local or remote stats request */
129 this->EnableSnomask('f',"FLOOD"); /* Flooding notices */
132 /*************************************************************************************/
134 void Snomask::SendMessage(const std::string &message)
136 if (message != LastMessage)
139 LastMessage = message;
141 std::string desc = this->Description;
143 char mysnomask = MySnomask;
144 ServerInstance->Logs->Log("snomask", DEFAULT, "%s: %s", desc.c_str(), message.c_str());
146 FOREACH_RESULT(I_OnSendSnotice, OnSendSnotice(mysnomask, desc, message));
148 LastBlocked = (MOD_RESULT == 1); // 1 blocks the message
152 /* Only opers can receive snotices, so we iterate the oper list */
153 std::list<User*>::iterator i = ServerInstance->Users->all_opers.begin();
155 while (i != ServerInstance->Users->all_opers.end())
158 if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsNoticeMaskSet(mysnomask) && !a->quitting)
160 a->WriteServ("NOTICE %s :*** %s: %s", a->nick.c_str(), desc.c_str(), message.c_str());
170 void Snomask::Flush()
174 std::string desc = this->Description;
175 std::string mesg = "(last message repeated "+ConvToStr(Count)+" times)";
176 char mysnomask = MySnomask;
178 ServerInstance->Logs->Log("snomask", DEFAULT, "%s: %s", desc.c_str(), mesg.c_str());
180 FOREACH_MOD(I_OnSendSnotice, OnSendSnotice(mysnomask, desc, mesg));
184 /* Only opers can receive snotices, so we iterate the oper list */
185 std::list<User*>::iterator i = ServerInstance->Users->all_opers.begin();
187 while (i != ServerInstance->Users->all_opers.end())
190 if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsNoticeMaskSet(mysnomask) && !a->quitting)
192 a->WriteServ("NOTICE %s :*** %s: %s", a->nick.c_str(), desc.c_str(), mesg.c_str());