+ SilenceMessage(const std::string& mask, const std::string& flags)
+ : ClientProtocol::Message("SILENCE")
+ {
+ PushParam(mask);
+ PushParam(flags);
+ }
+};
+
+class CommandSilence : public SplitCommand
+{
+ private:
+ ClientProtocol::EventProvider msgprov;
+
+ CmdResult AddSilence(LocalUser* user, const std::string& mask, uint32_t flags)
+ {
+ SilenceList* list = ext.get(user);
+ if (list && list->size() > ext.maxsilence)
+ {
+ user->WriteNumeric(ERR_SILELISTFULL, mask, SilenceEntry::BitsToFlags(flags), "Your SILENCE list is full");
+ return CMD_FAILURE;
+ }
+ else if (!list)
+ {
+ // There is no list; create it.
+ list = new SilenceList();
+ ext.set(user, list);
+ }
+
+ if (!list->insert(SilenceEntry(flags, mask)).second)
+ {
+ user->WriteNumeric(ERR_SILENCE, mask, SilenceEntry::BitsToFlags(flags), "The SILENCE entry you specified already exists");
+ return CMD_FAILURE;
+ }
+
+ SilenceMessage msg("+" + mask, SilenceEntry::BitsToFlags(flags));
+ user->Send(msgprov, msg);
+ return CMD_SUCCESS;
+ }
+
+ CmdResult RemoveSilence(LocalUser* user, const std::string& mask, uint32_t flags)
+ {
+ SilenceList* list = ext.get(user);
+ if (list)
+ {
+ for (SilenceList::iterator iter = list->begin(); iter != list->end(); ++iter)
+ {
+ if (!irc::equals(iter->mask, mask) || iter->flags != flags)
+ continue;
+
+ list->erase(iter);
+ SilenceMessage msg("-" + mask, SilenceEntry::BitsToFlags(flags));
+ user->Send(msgprov, msg);
+ return CMD_SUCCESS;
+ }
+ }
+
+ user->WriteNumeric(ERR_SILENCE, mask, SilenceEntry::BitsToFlags(flags), "The SILENCE entry you specified could not be found");
+ return CMD_FAILURE;
+ }
+
+ CmdResult ShowSilenceList(LocalUser* user)
+ {
+ SilenceList* list = ext.get(user);
+ if (list)
+ {
+ for (SilenceList::const_iterator iter = list->begin(); iter != list->end(); ++iter)
+ {
+ user->WriteNumeric(RPL_SILELIST, iter->mask, SilenceEntry::BitsToFlags(iter->flags));
+ }
+ }
+ user->WriteNumeric(RPL_ENDOFSILELIST, "End of SILENCE list");
+ return CMD_SUCCESS;
+ }
+
+ public:
+ SilenceExtItem ext;
+
+ CommandSilence(Module* Creator)
+ : SplitCommand(Creator, "SILENCE")
+ , msgprov(Creator, "SILENCE")
+ , ext(Creator)