1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 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 * ---------------------------------------------------
25 #include "helperfuncs.h"
28 /* $ModDesc: Provides support for the /SILENCE command */
31 // This typedef holds a silence list. Each user may or may not have a
32 // silencelist, if a silence list is empty for a user, he/she does not
33 // have one of these structures associated with their user record.
34 typedef std::vector<std::string> silencelist;
37 void handle_silence(char **parameters, int pcnt, userrec *user)
41 // no parameters, show the current silence list.
42 // Use Extensible::GetExt to fetch the silence list
43 silencelist* sl = (silencelist*)user->GetExt("silence_list");
44 // if the user has a silence list associated with their user record, show it
47 for (silencelist::const_iterator c = sl->begin(); c < sl->end(); c++)
49 WriteServ(user->fd,"271 %s %s %s!*@*",user->nick, user->nick,c->c_str());
52 WriteServ(user->fd,"272 %s :End of Silence List",user->nick);
56 // one or more parameters, add or delete entry from the list (only the first parameter is used)
57 char *nick = parameters[0];
60 // removing an item from the list
62 // fetch their silence list
63 silencelist* sl = (silencelist*)user->GetExt("silence_list");
64 // does it contain any entries and does it exist?
69 for (silencelist::iterator i = sl->begin(); i != sl->end(); i++)
71 // search through for the item
72 irc::string listitem = i->c_str();
73 irc::string target = nick;
74 if (listitem == target)
77 WriteServ(user->fd,"950 %s %s :Removed %s!*@* from silence list",user->nick, user->nick,nick);
78 // we have modified the vector from within a loop, we must now bail out
85 // tidy up -- if a user's list is empty, theres no use having it
86 // hanging around in the user record.
88 user->Shrink("silence_list");
92 else if (nick[0] == '+')
95 // fetch the user's current silence list
96 silencelist* sl = (silencelist*)user->GetExt("silence_list");
97 // what, they dont have one??? WE'RE ALL GONNA DIE! ...no, we just create an empty one.
100 sl = new silencelist;
101 user->Extend(std::string("silence_list"),(char*)sl);
103 // add the nick to it -- silence only takes nicks for some reason even though its list shows masks
104 for (silencelist::iterator n = sl->begin(); n != sl->end(); n++)
106 irc::string listitem = n->c_str();
107 irc::string target = nick;
108 if (listitem == target)
110 WriteServ(user->fd,"952 %s %s :%s is already on your silence list",user->nick, user->nick,nick);
114 sl->push_back(std::string(nick));
115 WriteServ(user->fd,"951 %s %s :Added %s!*@* to silence list",user->nick, user->nick,nick);
123 class ModuleSilence : public Module
131 Srv->AddCommand("SILENCE",handle_silence,0,0,"m_silence.so");
134 virtual void OnUserQuit(userrec* user)
136 // when the user quits tidy up any silence list they might have just to keep things tidy
137 // and to prevent a HONKING BIG MEMORY LEAK!
138 silencelist* sl = (silencelist*)user->GetExt("silence_list");
142 user->Shrink("silence_list");
146 virtual void On005Numeric(std::string &output)
148 // we don't really have a limit...
149 output = output + " SILENCE=999";
152 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
154 // im not sure how unreal's silence operates but ours is sensible. It blocks notices and
155 // privmsgs from people on the silence list, directed privately at the user.
156 // channel messages are unaffected (ever tried to follow the flow of conversation in
157 // a channel when you've set an ignore on the two most talkative people?)
158 if (target_type == TYPE_USER)
160 userrec* u = (userrec*)dest;
161 silencelist* sl = (silencelist*)u->GetExt("silence_list");
164 for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
166 irc::string listitem = c->c_str();
167 irc::string target = user->nick;
168 if (listitem == target)
178 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
180 if (target_type == TYPE_USER)
182 userrec* u = (userrec*)dest;
183 silencelist* sl = (silencelist*)u->GetExt("silence_list");
186 for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
188 irc::string listitem = c->c_str();
189 irc::string target = user->nick;
190 if (listitem == target)
200 virtual ~ModuleSilence()
205 virtual Version GetVersion()
207 return Version(1,0,0,1,VF_VENDOR);
212 class ModuleSilenceFactory : public ModuleFactory
215 ModuleSilenceFactory()
219 ~ModuleSilenceFactory()
223 virtual Module * CreateModule()
225 return new ModuleSilence;
231 extern "C" void * init_module( void )
233 return new ModuleSilenceFactory;