1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
24 /* $ModDesc: Provides support for the /SILENCE command */
26 // This typedef holds a silence list. Each user may or may not have a
27 // silencelist, if a silence list is empty for a user, he/she does not
28 // have one of these structures associated with their user record.
29 typedef std::map<irc::string, time_t> silencelist;
31 class cmd_silence : public command_t
34 cmd_silence (InspIRCd* Instance) : command_t(Instance,"SILENCE", 0, 0)
36 this->source = "m_silence.so";
37 syntax = "{[+|-]<mask>}";
40 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
44 // no parameters, show the current silence list.
45 // Use Extensible::GetExt to fetch the silence list
47 user->GetExt("silence_list", sl);
48 // if the user has a silence list associated with their user record, show it
51 for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
53 user->WriteServ("271 %s %s %s :%lu",user->nick, user->nick, c->first.c_str(), (unsigned long)c->second);
56 user->WriteServ("272 %s :End of Silence List",user->nick);
62 // one or more parameters, add or delete entry from the list (only the first parameter is used)
63 std::string mask = parameters[0] + 1;
64 char action = *parameters[0];
68 // 'SILENCE +' or 'SILENCE -', assume *!*@*
72 ModeParser::CleanMask(mask);
76 // fetch their silence list
78 user->GetExt("silence_list", sl);
79 // does it contain any entries and does it exist?
82 silencelist::iterator i = sl->find(mask.c_str());
86 user->WriteServ("950 %s %s :Removed %s from silence list",user->nick, user->nick, mask.c_str());
89 // tidy up -- if a user's list is empty, theres no use having it
90 // hanging around in the user record.
92 user->Shrink("silence_list");
96 user->WriteServ("952 %s %s :%s does not exist on your silence list",user->nick, user->nick, mask.c_str());
99 else if (action == '+')
101 // fetch the user's current silence list
103 user->GetExt("silence_list", sl);
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("silence_list", sl);
110 silencelist::iterator n = sl->find(mask.c_str());
113 user->WriteServ("952 %s %s :%s is already on your silence list",user->nick, user->nick, mask.c_str());
116 sl->insert(std::make_pair<irc::string, time_t>(mask.c_str(), ServerInstance->Time()));
117 user->WriteServ("951 %s %s :Added %s to silence list",user->nick, user->nick, mask.c_str());
125 class ModuleSilence : public Module
128 cmd_silence* mycommand;
131 ModuleSilence(InspIRCd* Me)
135 mycommand = new cmd_silence(ServerInstance);
136 ServerInstance->AddCommand(mycommand);
139 void Implements(char* List)
141 List[I_OnUserQuit] = List[I_On005Numeric] = List[I_OnUserPreNotice] = List[I_OnUserPreMessage] = 1;
144 virtual void OnUserQuit(userrec* user, const std::string &reason, const std::string &oper_message)
146 // when the user quits tidy up any silence list they might have just to keep things tidy
147 // and to prevent a HONKING BIG MEMORY LEAK!
149 user->GetExt("silence_list", sl);
153 user->Shrink("silence_list");
157 virtual void On005Numeric(std::string &output)
159 // we don't really have a limit...
160 output = output + " SILENCE=999";
163 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
165 // im not sure how unreal's silence operates but ours is sensible. It blocks notices and
166 // privmsgs from people on the silence list, directed privately at the user.
167 // channel messages are unaffected (ever tried to follow the flow of conversation in
168 // a channel when you've set an ignore on the two most talkative people?)
169 if ((target_type == TYPE_USER) && (IS_LOCAL(user)))
171 userrec* u = (userrec*)dest;
173 u->GetExt("silence_list", sl);
176 for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
178 if (match(user->GetFullHost(), c->first.c_str()))
188 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
190 return OnUserPreNotice(user,dest,target_type,text,status,exempt_list);
193 virtual ~ModuleSilence()
197 virtual Version GetVersion()
199 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
204 class ModuleSilenceFactory : public ModuleFactory
207 ModuleSilenceFactory()
211 ~ModuleSilenceFactory()
215 virtual Module * CreateModule(InspIRCd* Me)
217 return new ModuleSilence(Me);
223 extern "C" void * init_module( void )
225 return new ModuleSilenceFactory;