1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 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 * ---------------------------------------------------
17 void SnomaskManager::FlushSnotices()
19 for (int i=0; i < 26; i++)
23 void SnomaskManager::EnableSnomask(char letter, const std::string &type)
25 if (letter >= 'a' && letter <= 'z')
26 masks[letter - 'a'].Description = type;
29 void SnomaskManager::WriteToSnoMask(char letter, const std::string &text)
31 if (letter >= 'a' && letter <= 'z')
32 masks[letter - 'a'].SendMessage(text, letter);
33 if (letter >= 'A' && letter <= 'Z')
34 masks[letter - 'A'].SendMessage(text, letter);
37 void SnomaskManager::WriteGlobalSno(char letter, const std::string& text)
39 WriteToSnoMask(letter, text);
40 letter = toupper(letter);
41 ServerInstance->PI->SendSNONotice(std::string(1, letter), text);
44 void SnomaskManager::WriteToSnoMask(char letter, const char* text, ...)
46 char textbuffer[MAXBUF];
49 va_start(argsPtr, text);
50 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
53 this->WriteToSnoMask(letter, std::string(textbuffer));
56 void SnomaskManager::WriteGlobalSno(char letter, const char* text, ...)
58 char textbuffer[MAXBUF];
61 va_start(argsPtr, text);
62 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
65 this->WriteGlobalSno(letter, std::string(textbuffer));
68 SnomaskManager::SnomaskManager()
70 EnableSnomask('c',"CONNECT"); /* Local connect notices */
71 EnableSnomask('q',"QUIT"); /* Local quit notices */
72 EnableSnomask('k',"KILL"); /* Kill notices */
73 EnableSnomask('l',"LINK"); /* Linking notices */
74 EnableSnomask('o',"OPER"); /* Oper up/down notices */
75 EnableSnomask('a',"ANNOUNCEMENT"); /* formerly WriteOpers() - generic notices to all opers */
76 EnableSnomask('d',"DEBUG"); /* Debug notices */
77 EnableSnomask('x',"XLINE"); /* Xline notice (g/z/q/k/e) */
78 EnableSnomask('t',"STATS"); /* Local or remote stats request */
79 EnableSnomask('f',"FLOOD"); /* Flooding notices */
82 /*************************************************************************************/
84 void Snomask::SendMessage(const std::string &message, char mysnomask)
86 if (message != LastMessage || mysnomask != LastLetter)
89 LastMessage = message;
90 LastLetter = mysnomask;
92 std::string desc = Description;
94 desc = "SNO-" + tolower(mysnomask);
95 if (isupper(mysnomask))
96 desc = "REMOTE" + desc;
98 ServerInstance->Logs->Log("snomask", DEFAULT, "%s: %s", desc.c_str(), message.c_str());
100 FIRST_MOD_RESULT(OnSendSnotice, MOD_RESULT, (mysnomask, desc, message));
102 LastBlocked = (MOD_RESULT == MOD_RES_DENY);
106 /* Only opers can receive snotices, so we iterate the oper list */
107 std::list<User*>::iterator i = ServerInstance->Users->all_opers.begin();
109 while (i != ServerInstance->Users->all_opers.end())
112 if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsNoticeMaskSet(mysnomask) && !a->quitting)
114 a->WriteServ("NOTICE %s :*** %s: %s", a->nick.c_str(), desc.c_str(), message.c_str());
124 void Snomask::Flush()
128 std::string desc = Description;
130 desc = "SNO-" + tolower(LastLetter);
131 if (isupper(LastLetter))
132 desc = "REMOTE" + desc;
133 std::string mesg = "(last message repeated "+ConvToStr(Count)+" times)";
135 ServerInstance->Logs->Log("snomask", DEFAULT, "%s: %s", desc.c_str(), mesg.c_str());
137 FOREACH_MOD(I_OnSendSnotice, OnSendSnotice(LastLetter, desc, mesg));
141 /* Only opers can receive snotices, so we iterate the oper list */
142 std::list<User*>::iterator i = ServerInstance->Users->all_opers.begin();
144 while (i != ServerInstance->Users->all_opers.end())
147 if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsNoticeMaskSet(LastLetter) && !a->quitting)
149 a->WriteServ("NOTICE %s :*** %s: %s", a->nick.c_str(), desc.c_str(), mesg.c_str());