1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 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;
36 class cmd_silence : public command_t
39 cmd_silence() : command_t("SILENCE", 0, 1)
41 this->source = "m_silence.so";
44 void Handle (char **parameters, int pcnt, userrec *user)
48 // no parameters, show the current silence list.
49 // Use Extensible::GetExt to fetch the silence list
50 silencelist* sl = (silencelist*)user->GetExt("silence_list");
51 // if the user has a silence list associated with their user record, show it
54 for (silencelist::const_iterator c = sl->begin(); c < sl->end(); c++)
56 WriteServ(user->fd,"271 %s %s %s!*@*",user->nick, user->nick,c->c_str());
59 WriteServ(user->fd,"272 %s :End of Silence List",user->nick);
63 // one or more parameters, add or delete entry from the list (only the first parameter is used)
64 char *nick = parameters[0];
67 // removing an item from the list
69 // fetch their silence list
70 silencelist* sl = (silencelist*)user->GetExt("silence_list");
71 // does it contain any entries and does it exist?
76 for (silencelist::iterator i = sl->begin(); i != sl->end(); i++)
78 // search through for the item
79 irc::string listitem = i->c_str();
80 irc::string target = nick;
81 if (listitem == target)
84 WriteServ(user->fd,"950 %s %s :Removed %s!*@* from silence list",user->nick, user->nick,nick);
85 // we have modified the vector from within a loop, we must now bail out
92 // tidy up -- if a user's list is empty, theres no use having it
93 // hanging around in the user record.
95 user->Shrink("silence_list");
99 else if (nick[0] == '+')
102 // fetch the user's current silence list
103 silencelist* sl = (silencelist*)user->GetExt("silence_list");
104 // what, they dont have one??? WE'RE ALL GONNA DIE! ...no, we just create an empty one.
107 sl = new silencelist;
108 user->Extend(std::string("silence_list"),(char*)sl);
110 // add the nick to it -- silence only takes nicks for some reason even though its list shows masks
111 for (silencelist::iterator n = sl->begin(); n != sl->end(); n++)
113 irc::string listitem = n->c_str();
114 irc::string target = nick;
115 if (listitem == target)
117 WriteServ(user->fd,"952 %s %s :%s is already on your silence list",user->nick, user->nick,nick);
121 sl->push_back(std::string(nick));
122 WriteServ(user->fd,"951 %s %s :Added %s!*@* to silence list",user->nick, user->nick,nick);
130 class ModuleSilence : public Module
133 cmd_silence* mycommand;
136 ModuleSilence(Server* Me)
140 mycommand = new cmd_silence();
141 Srv->AddCommand(mycommand);
144 void Implements(char* List)
146 List[I_OnUserQuit] = List[I_On005Numeric] = List[I_OnUserPreNotice] = List[I_OnUserPreMessage] = 1;
149 virtual void OnUserQuit(userrec* user, std::string reason)
151 // when the user quits tidy up any silence list they might have just to keep things tidy
152 // and to prevent a HONKING BIG MEMORY LEAK!
153 silencelist* sl = (silencelist*)user->GetExt("silence_list");
157 user->Shrink("silence_list");
161 virtual void On005Numeric(std::string &output)
163 // we don't really have a limit...
164 output = output + " SILENCE=999";
167 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
169 // im not sure how unreal's silence operates but ours is sensible. It blocks notices and
170 // privmsgs from people on the silence list, directed privately at the user.
171 // channel messages are unaffected (ever tried to follow the flow of conversation in
172 // a channel when you've set an ignore on the two most talkative people?)
173 if (target_type == TYPE_USER)
175 userrec* u = (userrec*)dest;
176 silencelist* sl = (silencelist*)u->GetExt("silence_list");
179 for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
181 irc::string listitem = c->c_str();
182 irc::string target = user->nick;
183 if (listitem == target)
193 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
195 return OnUserPreNotice(user,dest,target_type,text,status);
198 virtual ~ModuleSilence()
202 virtual Version GetVersion()
204 return Version(1,0,0,1,VF_VENDOR);
209 class ModuleSilenceFactory : public ModuleFactory
212 ModuleSilenceFactory()
216 ~ModuleSilenceFactory()
220 virtual Module * CreateModule(Server* Me)
222 return new ModuleSilence(Me);
228 extern "C" void * init_module( void )
230 return new ModuleSilenceFactory;