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 * ---------------------------------------------------
24 /* $ModDesc: Provides support for the /SILENCE command */
27 // This typedef holds a silence list. Each user may or may not have a
28 // silencelist, if a silence list is empty for a user, he/she does not
29 // have one of these structures associated with their user record.
30 typedef std::vector<std::string> silencelist;
33 void handle_silence(char **parameters, int pcnt, userrec *user)
37 // no parameters, show the current silence list.
38 // Use Extensible::GetExt to fetch the silence list
39 silencelist* sl = (silencelist*)user->GetExt("silence_list");
40 // if the user has a silence list associated with their user record, show it
43 for (silencelist::const_iterator c = sl->begin(); c < sl->end(); c++)
45 WriteServ(user->fd,"271 %s %s %s!*@*",user->nick, user->nick,c->c_str());
48 WriteServ(user->fd,"272 %s :End of Silence List",user->nick);
52 // one or more parameters, add or delete entry from the list (only the first parameter is used)
53 char *nick = parameters[0];
56 // removing an item from the list
58 // fetch their silence list
59 silencelist* sl = (silencelist*)user->GetExt("silence_list");
60 // does it contain any entries and does it exist?
65 for (silencelist::iterator i = sl->begin(); i != sl->end(); i++)
67 // search through for the item
68 if (!strcasecmp(i->c_str(),nick))
71 WriteServ(user->fd,"950 %s %s :Removed %s!*@* from silence list",user->nick, user->nick,nick);
72 // we have modified the vector from within a loop, we must now bail out
79 // tidy up -- if a user's list is empty, theres no use having it
80 // hanging around in the user record.
82 user->Shrink("silence_list");
86 else if (nick[0] == '+')
89 // fetch the user's current silence list
90 silencelist* sl = (silencelist*)user->GetExt("silence_list");
91 // what, they dont have one??? WE'RE ALL GONNA DIE! ...no, we just create an empty one.
95 user->Extend(std::string("silence_list"),(char*)sl);
97 // add the nick to it -- silence only takes nicks for some reason even though its list shows masks
98 for (silencelist::iterator n = sl->begin(); n != sl->end(); n++)
100 if (!strcasecmp(n->c_str(),nick))
102 WriteServ(user->fd,"952 %s %s :%s is already on your silence list",user->nick, user->nick,nick);
106 sl->push_back(std::string(nick));
107 WriteServ(user->fd,"951 %s %s :Added %s!*@* to silence list",user->nick, user->nick,nick);
115 class ModuleSilence : public Module
123 Srv->AddCommand("SILENCE",handle_silence,0,0,"m_silence.so");
126 virtual void OnUserQuit(userrec* user)
128 // when the user quits tidy up any silence list they might have just to keep things tidy
129 // and to prevent a HONKING BIG MEMORY LEAK!
130 silencelist* sl = (silencelist*)user->GetExt("silence_list");
134 user->Shrink("silence_list");
138 virtual void On005Numeric(std::string &output)
140 // we don't really have a limit...
141 output = output + " SILENCE=999";
144 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
146 // im not sure how unreal's silence operates but ours is sensible. It blocks notices and
147 // privmsgs from people on the silence list, directed privately at the user.
148 // channel messages are unaffected (ever tried to follow the flow of conversation in
149 // a channel when you've set an ignore on the two most talkative people?)
150 if (target_type == TYPE_USER)
152 userrec* u = (userrec*)dest;
153 silencelist* sl = (silencelist*)u->GetExt("silence_list");
156 for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
158 if (!strcasecmp(c->c_str(),user->nick))
168 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
170 if (target_type == TYPE_USER)
172 userrec* u = (userrec*)dest;
173 silencelist* sl = (silencelist*)u->GetExt("silence_list");
176 for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
178 if (!strcasecmp(c->c_str(),user->nick))
188 virtual ~ModuleSilence()
193 virtual Version GetVersion()
195 return Version(1,0,0,1,VF_VENDOR);
200 class ModuleSilenceFactory : public ModuleFactory
203 ModuleSilenceFactory()
207 ~ModuleSilenceFactory()
211 virtual Module * CreateModule()
213 return new ModuleSilence;
219 extern "C" void * init_module( void )
221 return new ModuleSilenceFactory;