1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 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 * ---------------------------------------------------
17 /* $ModDesc: Provides support for the /SILENCE command */
19 // This typedef holds a silence list. Each user may or may not have a
20 // silencelist, if a silence list is empty for a user, he/she does not
21 // have one of these structures associated with their user record.
22 typedef std::map<irc::string, time_t> silencelist;
24 class cmd_silence : public command_t
26 unsigned int& maxsilence;
28 cmd_silence (InspIRCd* Instance, unsigned int &max) : command_t(Instance,"SILENCE", 0, 0), maxsilence(max)
30 this->source = "m_silence.so";
31 syntax = "{[+|-]<mask>}";
32 TRANSLATE2(TR_TEXT, TR_END);
35 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
39 // no parameters, show the current silence list.
40 // Use Extensible::GetExt to fetch the silence list
42 user->GetExt("silence_list", sl);
43 // if the user has a silence list associated with their user record, show it
46 for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
48 user->WriteServ("271 %s %s %s :%lu",user->nick, user->nick, c->first.c_str(), (unsigned long)c->second);
51 user->WriteServ("272 %s :End of Silence List",user->nick);
57 // one or more parameters, add or delete entry from the list (only the first parameter is used)
58 std::string mask = parameters[0] + 1;
59 char action = *parameters[0];
63 // 'SILENCE +' or 'SILENCE -', assume *!*@*
67 ModeParser::CleanMask(mask);
71 // fetch their silence list
73 user->GetExt("silence_list", sl);
74 // does it contain any entries and does it exist?
77 silencelist::iterator i = sl->find(mask.c_str());
81 user->WriteServ("950 %s %s :Removed %s from silence list",user->nick, user->nick, mask.c_str());
84 // tidy up -- if a user's list is empty, theres no use having it
85 // hanging around in the user record.
87 user->Shrink("silence_list");
91 user->WriteServ("952 %s %s :%s does not exist on your silence list",user->nick, user->nick, mask.c_str());
94 else if (action == '+')
96 // fetch the user's current silence list
98 user->GetExt("silence_list", sl);
99 // what, they dont have one??? WE'RE ALL GONNA DIE! ...no, we just create an empty one.
102 sl = new silencelist;
103 user->Extend("silence_list", sl);
105 silencelist::iterator n = sl->find(mask.c_str());
108 user->WriteServ("952 %s %s :%s is already on your silence list",user->nick, user->nick, mask.c_str());
111 if (sl->size() >= maxsilence)
113 user->WriteServ("952 %s %s :Your silence list is full",user->nick, user->nick, mask.c_str());
116 sl->insert(std::make_pair<irc::string, time_t>(mask.c_str(), ServerInstance->Time()));
117 user->WriteServ("951 %s %s :Added %s to silence list",user->nick, user->nick, mask.c_str());
125 class ModuleSilence : public Module
128 cmd_silence* mycommand;
129 unsigned int maxsilence;
132 ModuleSilence(InspIRCd* Me)
133 : Module(Me), maxsilence(32)
136 mycommand = new cmd_silence(ServerInstance, maxsilence);
137 ServerInstance->AddCommand(mycommand);
140 void Implements(char* List)
142 List[I_OnRehash] = List[I_OnUserQuit] = List[I_On005Numeric] = List[I_OnUserPreNotice] = List[I_OnUserPreMessage] = 1;
145 virtual void OnRehash(userrec* user, const std::string ¶meter)
147 ConfigReader Conf(ServerInstance);
148 maxsilence = Conf.ReadInteger("silence", "maxentries", 0, true);
153 virtual void OnUserQuit(userrec* user, const std::string &reason, const std::string &oper_message)
155 // when the user quits tidy up any silence list they might have just to keep things tidy
156 // and to prevent a HONKING BIG MEMORY LEAK!
158 user->GetExt("silence_list", sl);
162 user->Shrink("silence_list");
166 virtual void On005Numeric(std::string &output)
168 // we don't really have a limit...
169 output = output + " SILENCE=" + ConvToStr(maxsilence);
172 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
174 // im not sure how unreal's silence operates but ours is sensible. It blocks notices and
175 // privmsgs from people on the silence list, directed privately at the user.
176 // channel messages are unaffected (ever tried to follow the flow of conversation in
177 // a channel when you've set an ignore on the two most talkative people?)
178 if ((target_type == TYPE_USER) && (IS_LOCAL(user)))
180 userrec* u = (userrec*)dest;
182 u->GetExt("silence_list", sl);
185 for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
187 if (match(user->GetFullHost(), c->first.c_str()))
197 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
199 return OnUserPreNotice(user,dest,target_type,text,status,exempt_list);
202 virtual ~ModuleSilence()
206 virtual Version GetVersion()
208 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
212 MODULE_INIT(ModuleSilence)