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 sl->push_back(std::string(nick));
99 WriteServ(user->fd,"951 %s %s :Added %s!*@* to silence list",user->nick, user->nick,nick);
107 class ModuleSilence : public Module
115 Srv->AddCommand("SILENCE",handle_silence,0,0);
118 virtual void OnUserQuit(userrec* user)
120 // when the user quits tidy up any silence list they might have just to keep things tidy
121 // and to prevent a HONKING BIG MEMORY LEAK!
122 silencelist* sl = (silencelist*)user->GetExt("silence_list");
126 user->Shrink("silence_list");
130 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
132 // im not sure how unreal's silence operates but ours is sensible. It blocks notices and
133 // privmsgs from people on the silence list, directed privately at the user.
134 // channel messages are unaffected (ever tried to follow the flow of conversation in
135 // a channel when you've set an ignore on the two most talkative people?)
136 if (target_type == TYPE_USER)
138 userrec* u = (userrec*)dest;
139 silencelist* sl = (silencelist*)u->GetExt("silence_list");
142 for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
144 if (!strcasecmp(c->c_str(),user->nick))
154 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
156 if (target_type == TYPE_USER)
158 userrec* u = (userrec*)dest;
159 silencelist* sl = (silencelist*)u->GetExt("silence_list");
162 for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
164 if (!strcasecmp(c->c_str(),user->nick))
174 virtual ~ModuleSilence()
179 virtual Version GetVersion()
181 return Version(1,0,0,0);
186 class ModuleSilenceFactory : public ModuleFactory
189 ModuleSilenceFactory()
193 ~ModuleSilenceFactory()
197 virtual Module * CreateModule()
199 return new ModuleSilence;
205 extern "C" void * init_module( void )
207 return new ModuleSilenceFactory;