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"
29 /* $ModDesc: Provides support for the /SILENCE command */
32 // This typedef holds a silence list. Each user may or may not have a
33 // silencelist, if a silence list is empty for a user, he/she does not
34 // have one of these structures associated with their user record.
35 typedef std::vector<std::string> silencelist;
37 class cmd_silence : public command_t
40 cmd_silence (InspIRCd* Instance) : command_t(Instance,"SILENCE", 0, 0)
42 this->source = "m_silence.so";
43 syntax = "{[+|-]<nick>}";
46 void Handle (const char** parameters, int pcnt, userrec *user)
50 // no parameters, show the current silence list.
51 // Use Extensible::GetExt to fetch the silence list
53 user->GetExt("silence_list", sl);
54 // if the user has a silence list associated with their user record, show it
57 for (silencelist::const_iterator c = sl->begin(); c < sl->end(); c++)
59 user->WriteServ("271 %s %s %s!*@*",user->nick, user->nick,c->c_str());
62 user->WriteServ("272 %s :End of Silence List",user->nick);
66 // one or more parameters, add or delete entry from the list (only the first parameter is used)
67 const char *nick = parameters[0];
70 // removing an item from the list
72 // fetch their silence list
74 user->GetExt("silence_list", sl);
75 // does it contain any entries and does it exist?
80 for (silencelist::iterator i = sl->begin(); i != sl->end(); i++)
82 // search through for the item
83 irc::string listitem = i->c_str();
84 irc::string target = nick;
85 if (listitem == target)
88 user->WriteServ("950 %s %s :Removed %s!*@* from silence list",user->nick, user->nick,nick);
89 // we have modified the vector from within a loop, we must now bail out
96 // tidy up -- if a user's list is empty, theres no use having it
97 // hanging around in the user record.
99 user->Shrink("silence_list");
103 else if (nick[0] == '+')
106 // fetch the user's current silence list
108 user->GetExt("silence_list", sl);
109 // what, they dont have one??? WE'RE ALL GONNA DIE! ...no, we just create an empty one.
112 sl = new silencelist;
113 user->Extend(std::string("silence_list"), sl);
115 // add the nick to it -- silence only takes nicks for some reason even though its list shows masks
116 for (silencelist::iterator n = sl->begin(); n != sl->end(); n++)
118 irc::string listitem = n->c_str();
119 irc::string target = nick;
120 if (listitem == target)
122 user->WriteServ("952 %s %s :%s is already on your silence list",user->nick, user->nick,nick);
126 sl->push_back(std::string(nick));
127 user->WriteServ("951 %s %s :Added %s!*@* to silence list",user->nick, user->nick,nick);
135 class ModuleSilence : public Module
138 cmd_silence* mycommand;
141 ModuleSilence(InspIRCd* Me)
145 mycommand = new cmd_silence(ServerInstance);
146 ServerInstance->AddCommand(mycommand);
149 void Implements(char* List)
151 List[I_OnUserQuit] = List[I_On005Numeric] = List[I_OnUserPreNotice] = List[I_OnUserPreMessage] = 1;
154 virtual void OnUserQuit(userrec* user, const std::string &reason)
156 // when the user quits tidy up any silence list they might have just to keep things tidy
157 // and to prevent a HONKING BIG MEMORY LEAK!
159 user->GetExt("silence_list", sl);
163 user->Shrink("silence_list");
167 virtual void On005Numeric(std::string &output)
169 // we don't really have a limit...
170 output = output + " SILENCE=999";
173 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
175 // im not sure how unreal's silence operates but ours is sensible. It blocks notices and
176 // privmsgs from people on the silence list, directed privately at the user.
177 // channel messages are unaffected (ever tried to follow the flow of conversation in
178 // a channel when you've set an ignore on the two most talkative people?)
179 if (target_type == TYPE_USER)
181 userrec* u = (userrec*)dest;
183 u->GetExt("silence_list", sl);
186 for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
188 irc::string listitem = c->c_str();
189 irc::string target = user->nick;
190 if (listitem == target)
200 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
202 return OnUserPreNotice(user,dest,target_type,text,status);
205 virtual ~ModuleSilence()
209 virtual Version GetVersion()
211 return Version(1,0,0,1,VF_VENDOR);
216 class ModuleSilenceFactory : public ModuleFactory
219 ModuleSilenceFactory()
223 ~ModuleSilenceFactory()
227 virtual Module * CreateModule(InspIRCd* Me)
229 return new ModuleSilence(Me);
235 extern "C" void * init_module( void )
237 return new ModuleSilenceFactory;