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 * ---------------------------------------------------
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 = "{[+|-]<mask>}";
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 std::string mask = parameters[0] + 1;
68 char action = *parameters[0];
72 // 'SILENCE +' or 'SILENCE -', assume *!*@*
76 ModeParser::CleanMask(mask);
80 // fetch their silence list
82 user->GetExt("silence_list", sl);
83 // does it contain any entries and does it exist?
88 for (silencelist::iterator i = sl->begin(); i != sl->end(); i++)
90 // search through for the item
91 irc::string listitem = i->c_str();
95 user->WriteServ("950 %s %s :Removed %s from silence list",user->nick, user->nick, mask.c_str());
102 // tidy up -- if a user's list is empty, theres no use having it
103 // hanging around in the user record.
105 user->Shrink("silence_list");
109 else if (action == '+')
111 // fetch the user's current silence list
113 user->GetExt("silence_list", sl);
114 // what, they dont have one??? WE'RE ALL GONNA DIE! ...no, we just create an empty one.
117 sl = new silencelist;
118 user->Extend(std::string("silence_list"), sl);
120 for (silencelist::iterator n = sl->begin(); n != sl->end(); n++)
122 irc::string listitem = n->c_str();
123 if (listitem == mask)
125 user->WriteServ("952 %s %s :%s is already on your silence list",user->nick, user->nick, mask.c_str());
130 user->WriteServ("951 %s %s :Added %s to silence list",user->nick, user->nick, mask.c_str());
138 class ModuleSilence : public Module
141 cmd_silence* mycommand;
144 ModuleSilence(InspIRCd* Me)
148 mycommand = new cmd_silence(ServerInstance);
149 ServerInstance->AddCommand(mycommand);
152 void Implements(char* List)
154 List[I_OnUserQuit] = List[I_On005Numeric] = List[I_OnUserPreNotice] = List[I_OnUserPreMessage] = 1;
157 virtual void OnUserQuit(userrec* user, const std::string &reason)
159 // when the user quits tidy up any silence list they might have just to keep things tidy
160 // and to prevent a HONKING BIG MEMORY LEAK!
162 user->GetExt("silence_list", sl);
166 user->Shrink("silence_list");
170 virtual void On005Numeric(std::string &output)
172 // we don't really have a limit...
173 output = output + " SILENCE=999";
176 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
178 // im not sure how unreal's silence operates but ours is sensible. It blocks notices and
179 // privmsgs from people on the silence list, directed privately at the user.
180 // channel messages are unaffected (ever tried to follow the flow of conversation in
181 // a channel when you've set an ignore on the two most talkative people?)
182 if (target_type == TYPE_USER)
184 userrec* u = (userrec*)dest;
186 u->GetExt("silence_list", sl);
189 for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
191 if (match(user->GetFullHost(), c->c_str()))
201 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
203 return OnUserPreNotice(user,dest,target_type,text,status);
206 virtual ~ModuleSilence()
210 virtual Version GetVersion()
212 return Version(1,0,0,1,VF_VENDOR);
217 class ModuleSilenceFactory : public ModuleFactory
220 ModuleSilenceFactory()
224 ~ModuleSilenceFactory()
228 virtual Module * CreateModule(InspIRCd* Me)
230 return new ModuleSilence(Me);
236 extern "C" void * init_module( void )
238 return new ModuleSilenceFactory;