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::WriteToSnoMask(char letter, const char* text, ...)
78 char textbuffer[MAXBUF];
81 va_start(argsPtr, text);
82 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
85 this->WriteToSnoMask(letter, std::string(textbuffer));
88 bool SnomaskManager::IsEnabled(char letter)
90 return (SnoMasks.find(letter) != SnoMasks.end());
93 void SnomaskManager::SetupDefaults()
95 this->EnableSnomask('c',"CONNECT"); /* Local connect notices */
96 this->EnableSnomask('C',"REMOTECONNECT"); /* Remote connect notices */
97 this->EnableSnomask('q',"QUIT"); /* Local quit notices */
98 this->EnableSnomask('Q',"REMOTEQUIT"); /* Remote quit notices */
99 this->EnableSnomask('k',"KILL"); /* Kill notices */
100 this->EnableSnomask('K',"REMOTEKILL"); /* Remote kill notices */
101 this->EnableSnomask('l',"LINK"); /* Linking notices */
102 this->EnableSnomask('L',"REMOTELINK"); /* Remote linking notices */
103 this->EnableSnomask('o',"OPER"); /* Oper up/down notices */
104 this->EnableSnomask('O',"REMOTEOPER"); /* Remote oper up/down notices */
105 this->EnableSnomask('a',"ANNOUNCEMENT"); /* formerly WriteOpers() - generic notices to all opers */
106 this->EnableSnomask('A',"REMOTEANNOUNCEMENT"); /* formerly WriteOpers() - generic notices to all opers */
107 this->EnableSnomask('d',"DEBUG"); /* Debug notices */
108 this->EnableSnomask('x',"XLINE"); /* Xline notice (g/z/q/k/e) */
109 this->EnableSnomask('t',"STATS"); /* Local or remote stats request */
110 this->EnableSnomask('f',"FLOOD"); /* Flooding notices */
113 /*************************************************************************************/
115 void Snomask::SendMessage(const std::string &message)
117 if (message != LastMessage)
120 LastMessage = message;
122 std::string desc = this->Description;
124 char mysnomask = MySnomask;
125 ServerInstance->Logs->Log("snomask", DEFAULT, "%s: %s", desc.c_str(), message.c_str());
127 FOREACH_RESULT(I_OnSendSnotice, OnSendSnotice(mysnomask, desc, message));
129 LastBlocked = (MOD_RESULT == 1); // 1 blocks the message
133 /* Only opers can receive snotices, so we iterate the oper list */
134 std::list<User*>::iterator i = ServerInstance->Users->all_opers.begin();
136 while (i != ServerInstance->Users->all_opers.end())
139 if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsNoticeMaskSet(mysnomask) && !a->quitting)
141 a->WriteServ("NOTICE %s :*** %s: %s", a->nick.c_str(), desc.c_str(), message.c_str());
151 void Snomask::Flush()
155 std::string desc = this->Description;
156 std::string mesg = "(last message repeated "+ConvToStr(Count)+" times)";
157 char mysnomask = MySnomask;
159 ServerInstance->Logs->Log("snomask", DEFAULT, "%s: %s", desc.c_str(), mesg.c_str());
161 FOREACH_MOD(I_OnSendSnotice, OnSendSnotice(mysnomask, desc, mesg));
165 /* Only opers can receive snotices, so we iterate the oper list */
166 std::list<User*>::iterator i = ServerInstance->Users->all_opers.begin();
168 while (i != ServerInstance->Users->all_opers.end())
171 if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsNoticeMaskSet(mysnomask) && !a->quitting)
173 a->WriteServ("NOTICE %s :*** %s: %s", a->nick.c_str(), desc.c_str(), mesg.c_str());