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 */
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::map<irc::string, time_t> silencelist;
36 class cmd_silence : public command_t
39 cmd_silence (InspIRCd* Instance) : command_t(Instance,"SILENCE", 0, 0)
41 this->source = "m_silence.so";
42 syntax = "{[+|-]<mask>}";
45 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
49 // no parameters, show the current silence list.
50 // Use Extensible::GetExt to fetch the silence list
52 user->GetExt("silence_list", sl);
53 // if the user has a silence list associated with their user record, show it
56 for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
58 user->WriteServ("271 %s %s %s :%lu",user->nick, user->nick, c->first.c_str(), (unsigned long)c->second);
61 user->WriteServ("272 %s :End of Silence List",user->nick);
67 // one or more parameters, add or delete entry from the list (only the first parameter is used)
68 std::string mask = parameters[0] + 1;
69 char action = *parameters[0];
73 // 'SILENCE +' or 'SILENCE -', assume *!*@*
77 ModeParser::CleanMask(mask);
81 // fetch their silence list
83 user->GetExt("silence_list", sl);
84 // does it contain any entries and does it exist?
89 silencelist::iterator i = sl->find(mask.c_str());
93 user->WriteServ("950 %s %s :Removed %s from silence list",user->nick, user->nick, mask.c_str());
98 // tidy up -- if a user's list is empty, theres no use having it
99 // hanging around in the user record.
101 user->Shrink("silence_list");
105 else if (action == '+')
107 // fetch the user's current silence list
109 user->GetExt("silence_list", sl);
110 // what, they dont have one??? WE'RE ALL GONNA DIE! ...no, we just create an empty one.
113 sl = new silencelist;
114 user->Extend("silence_list", sl);
116 silencelist::iterator n = sl->find(mask.c_str());
119 user->WriteServ("952 %s %s :%s is already on your silence list",user->nick, user->nick, mask.c_str());
122 sl->insert(std::make_pair<irc::string, time_t>(mask.c_str(), ServerInstance->Time()));
123 user->WriteServ("951 %s %s :Added %s to silence list",user->nick, user->nick, mask.c_str());
131 class ModuleSilence : public Module
134 cmd_silence* mycommand;
137 ModuleSilence(InspIRCd* Me)
141 mycommand = new cmd_silence(ServerInstance);
142 ServerInstance->AddCommand(mycommand);
145 void Implements(char* List)
147 List[I_OnUserQuit] = List[I_On005Numeric] = List[I_OnUserPreNotice] = List[I_OnUserPreMessage] = 1;
150 virtual void OnUserQuit(userrec* user, const std::string &reason)
152 // when the user quits tidy up any silence list they might have just to keep things tidy
153 // and to prevent a HONKING BIG MEMORY LEAK!
155 user->GetExt("silence_list", sl);
159 user->Shrink("silence_list");
163 virtual void On005Numeric(std::string &output)
165 // we don't really have a limit...
166 output = output + " SILENCE=999";
169 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
171 // im not sure how unreal's silence operates but ours is sensible. It blocks notices and
172 // privmsgs from people on the silence list, directed privately at the user.
173 // channel messages are unaffected (ever tried to follow the flow of conversation in
174 // a channel when you've set an ignore on the two most talkative people?)
175 if (target_type == TYPE_USER)
177 userrec* u = (userrec*)dest;
179 u->GetExt("silence_list", sl);
182 for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
184 if (match(user->GetFullHost(), c->first.c_str()))
194 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
196 return OnUserPreNotice(user,dest,target_type,text,status,exempt_list);
199 virtual ~ModuleSilence()
203 virtual Version GetVersion()
205 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
210 class ModuleSilenceFactory : public ModuleFactory
213 ModuleSilenceFactory()
217 ~ModuleSilenceFactory()
221 virtual Module * CreateModule(InspIRCd* Me)
223 return new ModuleSilence(Me);
229 extern "C" void * init_module( void )
231 return new ModuleSilenceFactory;