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"
26 /* $ModDesc: Provides support for the /SILENCE command */
29 // This typedef holds a silence list. Each user may or may not have a
30 // silencelist, if a silence list is empty for a user, he/she does not
31 // have one of these structures associated with their user record.
32 typedef std::vector<std::string> silencelist;
35 void handle_silence(char **parameters, int pcnt, userrec *user)
39 // no parameters, show the current silence list.
40 // Use Extensible::GetExt to fetch the silence list
41 silencelist* sl = (silencelist*)user->GetExt("silence_list");
42 // if the user has a silence list associated with their user record, show it
45 for (silencelist::const_iterator c = sl->begin(); c < sl->end(); c++)
47 WriteServ(user->fd,"271 %s %s %s!*@*",user->nick, user->nick,c->c_str());
50 WriteServ(user->fd,"272 %s :End of Silence List",user->nick);
54 // one or more parameters, add or delete entry from the list (only the first parameter is used)
55 char *nick = parameters[0];
58 // removing an item from the list
60 // fetch their silence list
61 silencelist* sl = (silencelist*)user->GetExt("silence_list");
62 // does it contain any entries and does it exist?
67 for (silencelist::iterator i = sl->begin(); i != sl->end(); i++)
69 // search through for the item
70 irc::string listitem = i->c_str();
71 irc::string target = nick;
72 if (listitem == target)
75 WriteServ(user->fd,"950 %s %s :Removed %s!*@* from silence list",user->nick, user->nick,nick);
76 // we have modified the vector from within a loop, we must now bail out
83 // tidy up -- if a user's list is empty, theres no use having it
84 // hanging around in the user record.
86 user->Shrink("silence_list");
90 else if (nick[0] == '+')
93 // fetch the user's current silence list
94 silencelist* sl = (silencelist*)user->GetExt("silence_list");
95 // what, they dont have one??? WE'RE ALL GONNA DIE! ...no, we just create an empty one.
99 user->Extend(std::string("silence_list"),(char*)sl);
101 // add the nick to it -- silence only takes nicks for some reason even though its list shows masks
102 for (silencelist::iterator n = sl->begin(); n != sl->end(); n++)
104 irc::string listitem = n->c_str();
105 irc::string target = nick;
106 if (listitem == target)
108 WriteServ(user->fd,"952 %s %s :%s is already on your silence list",user->nick, user->nick,nick);
112 sl->push_back(std::string(nick));
113 WriteServ(user->fd,"951 %s %s :Added %s!*@* to silence list",user->nick, user->nick,nick);
121 class ModuleSilence : public Module
129 Srv->AddCommand("SILENCE",handle_silence,0,0,"m_silence.so");
132 virtual void OnUserQuit(userrec* user)
134 // when the user quits tidy up any silence list they might have just to keep things tidy
135 // and to prevent a HONKING BIG MEMORY LEAK!
136 silencelist* sl = (silencelist*)user->GetExt("silence_list");
140 user->Shrink("silence_list");
144 virtual void On005Numeric(std::string &output)
146 // we don't really have a limit...
147 output = output + " SILENCE=999";
150 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
152 // im not sure how unreal's silence operates but ours is sensible. It blocks notices and
153 // privmsgs from people on the silence list, directed privately at the user.
154 // channel messages are unaffected (ever tried to follow the flow of conversation in
155 // a channel when you've set an ignore on the two most talkative people?)
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 irc::string listitem = c->c_str();
165 irc::string target = user->nick;
166 if (listitem == target)
176 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
178 if (target_type == TYPE_USER)
180 userrec* u = (userrec*)dest;
181 silencelist* sl = (silencelist*)u->GetExt("silence_list");
184 for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
186 irc::string listitem = c->c_str();
187 irc::string target = user->nick;
188 if (listitem == target)
198 virtual ~ModuleSilence()
203 virtual Version GetVersion()
205 return Version(1,0,0,1,VF_VENDOR);
210 class ModuleSilenceFactory : public ModuleFactory
213 ModuleSilenceFactory()
217 ~ModuleSilenceFactory()
221 virtual Module * CreateModule()
223 return new ModuleSilence;
229 extern "C" void * init_module( void )
231 return new ModuleSilenceFactory;