]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_silence.cpp
Convert WriteNumeric() calls to pass the parameters of the numeric as method parameters
[user/henk/code/inspircd.git] / src / modules / m_silence.cpp
index 22de0ac8b6de76cf1ca9e6c4d2eb0626aaea6009..7d3b3f90ce091d20b2d07713a5664ad6c9fdc27d 100644 (file)
@@ -45,8 +45,8 @@
 // pair of hostmask and flags
 typedef std::pair<std::string, int> silenceset;
 
-// deque list of pairs
-typedef std::deque<silenceset> silencelist;
+// list of pairs
+typedef std::vector<silenceset> silencelist;
 
 // intmasks for flags
 static int SILENCE_PRIVATE     = 0x0001; /* p  private messages      */
@@ -106,7 +106,8 @@ class CommandSilence : public Command
  public:
        SimpleExtItem<silencelist> ext;
        CommandSilence(Module* Creator, unsigned int &max) : Command(Creator, "SILENCE", 0),
-               maxsilence(max), ext("silence_list", Creator)
+               maxsilence(max)
+               , ext("silence_list", ExtensionItem::EXT_USER, Creator)
        {
                allow_empty_last_param = false;
                syntax = "{[+|-]<mask> <p|c|i|n|t|a|x>}";
@@ -124,10 +125,10 @@ class CommandSilence : public Command
                                for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
                                {
                                        std::string decomppattern = DecompPattern(c->second);
-                                       user->WriteNumeric(271, "%s %s %s", user->nick.c_str(),c->first.c_str(), decomppattern.c_str());
+                                       user->WriteNumeric(271, user->nick, c->first, decomppattern);
                                }
                        }
-                       user->WriteNumeric(272, ":End of Silence List");
+                       user->WriteNumeric(272, "End of Silence List");
 
                        return CMD_SUCCESS;
                }
@@ -173,7 +174,7 @@ class CommandSilence : public Command
                                                if (listitem == mask && i->second == pattern)
                                                {
                                                        sl->erase(i);
-                                                       user->WriteNumeric(950, "%s :Removed %s %s from silence list", user->nick.c_str(), mask.c_str(), decomppattern.c_str());
+                                                       user->WriteNumeric(950, user->nick, InspIRCd::Format("Removed %s %s from silence list", mask.c_str(), decomppattern.c_str()));
                                                        if (!sl->size())
                                                        {
                                                                ext.unset(user);
@@ -182,7 +183,7 @@ class CommandSilence : public Command
                                                }
                                        }
                                }
-                               user->WriteNumeric(952, "%s :%s %s does not exist on your silence list", user->nick.c_str(), mask.c_str(), decomppattern.c_str());
+                               user->WriteNumeric(952, user->nick, InspIRCd::Format("%s %s does not exist on your silence list", mask.c_str(), decomppattern.c_str()));
                        }
                        else if (action == '+')
                        {
@@ -195,7 +196,7 @@ class CommandSilence : public Command
                                }
                                if (sl->size() > maxsilence)
                                {
-                                       user->WriteNumeric(952, "%s :Your silence list is full",user->nick.c_str());
+                                       user->WriteNumeric(952, user->nick, "Your silence list is full");
                                        return CMD_FAILURE;
                                }
 
@@ -205,19 +206,19 @@ class CommandSilence : public Command
                                        irc::string listitem = n->first.c_str();
                                        if (listitem == mask && n->second == pattern)
                                        {
-                                               user->WriteNumeric(952, "%s :%s %s is already on your silence list", user->nick.c_str(), mask.c_str(), decomppattern.c_str());
+                                               user->WriteNumeric(952, user->nick, InspIRCd::Format("%s %s is already on your silence list", mask.c_str(), decomppattern.c_str()));
                                                return CMD_FAILURE;
                                        }
                                }
                                if (((pattern & SILENCE_EXCLUDE) > 0))
                                {
-                                       sl->push_front(silenceset(mask,pattern));
+                                       sl->insert(sl->begin(), silenceset(mask, pattern));
                                }
                                else
                                {
                                        sl->push_back(silenceset(mask,pattern));
                                }
-                               user->WriteNumeric(951, "%s :Added %s %s to silence list", user->nick.c_str(), mask.c_str(), decomppattern.c_str());
+                               user->WriteNumeric(951, user->nick, InspIRCd::Format("Added %s %s to silence list", mask.c_str(), decomppattern.c_str()));
                                return CMD_SUCCESS;
                        }
                }
@@ -290,6 +291,7 @@ class CommandSilence : public Command
 class ModuleSilence : public Module
 {
        unsigned int maxsilence;
+       bool ExemptULine;
        CommandSilence cmdsilence;
        CommandSVSSilence cmdsvssilence;
  public:
@@ -301,9 +303,13 @@ class ModuleSilence : public Module
 
        void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
-               maxsilence = ServerInstance->Config->ConfValue("silence")->getInt("maxentries", 32);
+               ConfigTag* tag = ServerInstance->Config->ConfValue("silence");
+
+               maxsilence = tag->getInt("maxentries", 32);
                if (!maxsilence)
                        maxsilence = 32;
+
+               ExemptULine = tag->getBool("exemptuline", true);
        }
 
        void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
@@ -312,7 +318,7 @@ class ModuleSilence : public Module
                tokens["SILENCE"] = ConvToStr(maxsilence);
        }
 
-       void OnBuildExemptList(MessageType message_type, Channel* chan, User* sender, char status, CUList &exempt_list, const std::string &text)
+       void BuildExemptList(MessageType message_type, Channel* chan, User* sender, CUList& exempt_list)
        {
                int public_silence = (message_type == MSG_PRIVMSG ? SILENCE_CHANNEL : SILENCE_CNOTICE);
 
@@ -338,7 +344,7 @@ class ModuleSilence : public Module
                else if (target_type == TYPE_CHANNEL)
                {
                        Channel* chan = (Channel*)dest;
-                       this->OnBuildExemptList(msgtype, chan, user, status, exempt_list, "");
+                       BuildExemptList(msgtype, chan, user, exempt_list);
                }
                return MOD_RES_PASSTHRU;
        }
@@ -350,6 +356,9 @@ class ModuleSilence : public Module
 
        ModResult MatchPattern(User* dest, User* source, int pattern)
        {
+               if (ExemptULine && source->server->IsULine())
+                       return MOD_RES_PASSTHRU;
+
                silencelist* sl = cmdsilence.ext.get(dest);
                if (sl)
                {