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 * ---------------------------------------------------
23 #include "helperfuncs.h"
25 /* $ModDesc: Provides support for the /SILENCE command */
28 // This typedef holds a silence list. Each user may or may not have a
29 // silencelist, if a silence list is empty for a user, he/she does not
30 // have one of these structures associated with their user record.
31 typedef std::vector<std::string> silencelist;
34 void handle_silence(char **parameters, int pcnt, userrec *user)
38 // no parameters, show the current silence list.
39 // Use Extensible::GetExt to fetch the silence list
40 silencelist* sl = (silencelist*)user->GetExt("silence_list");
41 // if the user has a silence list associated with their user record, show it
44 for (silencelist::const_iterator c = sl->begin(); c < sl->end(); c++)
46 WriteServ(user->fd,"271 %s %s %s!*@*",user->nick, user->nick,c->c_str());
49 WriteServ(user->fd,"272 %s :End of Silence List",user->nick);
53 // one or more parameters, add or delete entry from the list (only the first parameter is used)
54 char *nick = parameters[0];
57 // removing an item from the list
59 // fetch their silence list
60 silencelist* sl = (silencelist*)user->GetExt("silence_list");
61 // does it contain any entries and does it exist?
66 for (silencelist::iterator i = sl->begin(); i != sl->end(); i++)
68 // search through for the item
69 if (!strcasecmp(i->c_str(),nick))
72 WriteServ(user->fd,"950 %s %s :Removed %s!*@* from silence list",user->nick, user->nick,nick);
73 // we have modified the vector from within a loop, we must now bail out
80 // tidy up -- if a user's list is empty, theres no use having it
81 // hanging around in the user record.
83 user->Shrink("silence_list");
87 else if (nick[0] == '+')
90 // fetch the user's current silence list
91 silencelist* sl = (silencelist*)user->GetExt("silence_list");
92 // what, they dont have one??? WE'RE ALL GONNA DIE! ...no, we just create an empty one.
96 user->Extend(std::string("silence_list"),(char*)sl);
98 // add the nick to it -- silence only takes nicks for some reason even though its list shows masks
99 for (silencelist::iterator n = sl->begin(); n != sl->end(); n++)
101 if (!strcasecmp(n->c_str(),nick))
103 WriteServ(user->fd,"952 %s %s :%s is already on your silence list",user->nick, user->nick,nick);
107 sl->push_back(std::string(nick));
108 WriteServ(user->fd,"951 %s %s :Added %s!*@* to silence list",user->nick, user->nick,nick);
116 class ModuleSilence : public Module
124 Srv->AddCommand("SILENCE",handle_silence,0,0,"m_silence.so");
127 virtual void OnUserQuit(userrec* user)
129 // when the user quits tidy up any silence list they might have just to keep things tidy
130 // and to prevent a HONKING BIG MEMORY LEAK!
131 silencelist* sl = (silencelist*)user->GetExt("silence_list");
135 user->Shrink("silence_list");
139 virtual void On005Numeric(std::string &output)
141 // we don't really have a limit...
142 output = output + " SILENCE=999";
145 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
147 // im not sure how unreal's silence operates but ours is sensible. It blocks notices and
148 // privmsgs from people on the silence list, directed privately at the user.
149 // channel messages are unaffected (ever tried to follow the flow of conversation in
150 // a channel when you've set an ignore on the two most talkative people?)
151 if (target_type == TYPE_USER)
153 userrec* u = (userrec*)dest;
154 silencelist* sl = (silencelist*)u->GetExt("silence_list");
157 for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
159 if (!strcasecmp(c->c_str(),user->nick))
169 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
171 if (target_type == TYPE_USER)
173 userrec* u = (userrec*)dest;
174 silencelist* sl = (silencelist*)u->GetExt("silence_list");
177 for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
179 if (!strcasecmp(c->c_str(),user->nick))
189 virtual ~ModuleSilence()
194 virtual Version GetVersion()
196 return Version(1,0,0,1,VF_VENDOR);
201 class ModuleSilenceFactory : public ModuleFactory
204 ModuleSilenceFactory()
208 ~ModuleSilenceFactory()
212 virtual Module * CreateModule()
214 return new ModuleSilence;
220 extern "C" void * init_module( void )
222 return new ModuleSilenceFactory;