1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
29 /* $ModDesc: Provides support for the /SILENCE command */
32 // This typedef holds a silence list. Each user may or may not have a
33 // silencelist, if a silence list is empty for a user, he/she does not
34 // have one of these structures associated with their user record.
35 typedef std::vector<std::string> silencelist;
37 class cmd_silence : public command_t
40 cmd_silence (InspIRCd* Instance) : command_t(Instance,"SILENCE", 0, 0)
42 this->source = "m_silence.so";
43 syntax = "{[+|-]<mask>}";
46 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
50 // no parameters, show the current silence list.
51 // Use Extensible::GetExt to fetch the silence list
53 user->GetExt("silence_list", sl);
54 // if the user has a silence list associated with their user record, show it
57 for (silencelist::const_iterator c = sl->begin(); c < sl->end(); c++)
59 user->WriteServ("271 %s %s %s",user->nick, user->nick,c->c_str());
62 user->WriteServ("272 %s :End of Silence List",user->nick);
68 // one or more parameters, add or delete entry from the list (only the first parameter is used)
69 std::string mask = parameters[0] + 1;
70 char action = *parameters[0];
74 // 'SILENCE +' or 'SILENCE -', assume *!*@*
78 ModeParser::CleanMask(mask);
82 // fetch their silence list
84 user->GetExt("silence_list", sl);
85 // does it contain any entries and does it exist?
90 for (silencelist::iterator i = sl->begin(); i != sl->end(); i++)
92 // search through for the item
93 irc::string listitem = i->c_str();
97 user->WriteServ("950 %s %s :Removed %s from silence list",user->nick, user->nick, mask.c_str());
104 // tidy up -- if a user's list is empty, theres no use having it
105 // hanging around in the user record.
107 user->Shrink("silence_list");
111 else if (action == '+')
113 // fetch the user's current silence list
115 user->GetExt("silence_list", sl);
116 // what, they dont have one??? WE'RE ALL GONNA DIE! ...no, we just create an empty one.
119 sl = new silencelist;
120 user->Extend(std::string("silence_list"), sl);
122 for (silencelist::iterator n = sl->begin(); n != sl->end(); n++)
124 irc::string listitem = n->c_str();
125 if (listitem == mask)
127 user->WriteServ("952 %s %s :%s is already on your silence list",user->nick, user->nick, mask.c_str());
132 user->WriteServ("951 %s %s :Added %s to silence list",user->nick, user->nick, mask.c_str());
140 class ModuleSilence : public Module
143 cmd_silence* mycommand;
146 ModuleSilence(InspIRCd* Me)
150 mycommand = new cmd_silence(ServerInstance);
151 ServerInstance->AddCommand(mycommand);
154 void Implements(char* List)
156 List[I_OnUserQuit] = List[I_On005Numeric] = List[I_OnUserPreNotice] = List[I_OnUserPreMessage] = 1;
159 virtual void OnUserQuit(userrec* user, const std::string &reason)
161 // when the user quits tidy up any silence list they might have just to keep things tidy
162 // and to prevent a HONKING BIG MEMORY LEAK!
164 user->GetExt("silence_list", sl);
168 user->Shrink("silence_list");
172 virtual void On005Numeric(std::string &output)
174 // we don't really have a limit...
175 output = output + " SILENCE=999";
178 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
180 // im not sure how unreal's silence operates but ours is sensible. It blocks notices and
181 // privmsgs from people on the silence list, directed privately at the user.
182 // channel messages are unaffected (ever tried to follow the flow of conversation in
183 // a channel when you've set an ignore on the two most talkative people?)
184 if (target_type == TYPE_USER)
186 userrec* u = (userrec*)dest;
188 u->GetExt("silence_list", sl);
191 for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
193 if (match(user->GetFullHost(), c->c_str()))
203 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
205 return OnUserPreNotice(user,dest,target_type,text,status);
208 virtual ~ModuleSilence()
212 virtual Version GetVersion()
214 return Version(1,0,0,1,VF_VENDOR);
219 class ModuleSilenceFactory : public ModuleFactory
222 ModuleSilenceFactory()
226 ~ModuleSilenceFactory()
230 virtual Module * CreateModule(InspIRCd* Me)
232 return new ModuleSilence(Me);
238 extern "C" void * init_module( void )
240 return new ModuleSilenceFactory;