]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_silence.cpp
Allow commands to optionally route themselves using ENCAP
[user/henk/code/inspircd.git] / src / modules / m_silence.cpp
index 1a554cf633fcb15702e92639945735d80149496c..0786c4da4fa60e274b3890fed69ff14a94a190e3 100644 (file)
@@ -2,8 +2,8 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
+ *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ * See: http://wiki.inspircd.org/Credits
  *
  * This program is free but copyrighted software; see
  *            the file COPYING for details.
@@ -12,7 +12,6 @@
  */
 
 #include "inspircd.h"
-#include "wildcard.h"
 
 /* $ModDesc: Provides support for the /SILENCE command */
 
@@ -61,7 +60,7 @@ class CommandSVSSilence : public Command
                TRANSLATE3(TR_NICK, TR_TEXT, TR_END); /* we watch for a nick. not a UID. */
        }
 
-       CmdResult Handle (const char* const* parameters, int pcnt, User *user)
+       CmdResult Handle (const std::vector<std::string>& parameters, User *user)
        {
                /*
                 * XXX: thought occurs to me
@@ -72,16 +71,16 @@ class CommandSVSSilence : public Command
                 */
                if (!ServerInstance->ULine(user->server))
                        return CMD_FAILURE;
-                       
+
                User *u = ServerInstance->FindNick(parameters[0]);
                if (!u)
                        return CMD_FAILURE;
-                       
+
                if (IS_LOCAL(u))
                {
-                       ServerInstance->Parser->CallHandler("SILENCE", &parameters[1], 1, u);
+                       ServerInstance->Parser->CallHandler("SILENCE", std::vector<std::string>(++parameters.begin(), parameters.end()), u);
                }
-               
+
                return CMD_SUCCESS;
        }
 };
@@ -92,14 +91,14 @@ class CommandSilence : public Command
  public:
        CommandSilence (InspIRCd* Instance, unsigned int &max) : Command(Instance,"SILENCE", 0, 0), maxsilence(max)
        {
-               this->source = "m_silence_ext.so";
+               this->source = "m_silence.so";
                syntax = "{[+|-]<mask> <p|c|i|n|t|a|x>}";
                TRANSLATE3(TR_TEXT, TR_TEXT, TR_END);
        }
 
-       CmdResult Handle (const char* const* parameters, int pcnt, User *user)
+       CmdResult Handle (const std::vector<std::string>& parameters, User *user)
        {
-               if (!pcnt)
+               if (!parameters.size())
                {
                        // no parameters, show the current silence list.
                        // Use Extensible::GetExt to fetch the silence list
@@ -110,32 +109,32 @@ class CommandSilence : public Command
                        {
                                for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
                                {
-                                       user->WriteNumeric(271, "%s %s %s %s",user->nick, user->nick,c->first.c_str(), DecompPattern(c->second).c_str());
+                                       user->WriteNumeric(271, "%s %s %s %s",user->nick.c_str(), user->nick.c_str(),c->first.c_str(), DecompPattern(c->second).c_str());
                                }
                        }
-                       user->WriteNumeric(272, "%s :End of Silence List",user->nick);
+                       user->WriteNumeric(272, "%s :End of Silence List",user->nick.c_str());
 
                        return CMD_LOCALONLY;
                }
-               else if (pcnt > 0)
+               else if (parameters.size() > 0)
                {
                        // one or more parameters, add or delete entry from the list (only the first parameter is used)
-                       std::string mask = parameters[0] + 1;
-                       char action = *parameters[0];
+                       std::string mask = parameters[0].substr(1);
+                       char action = parameters[0][0];
                        // Default is private and notice so clients do not break
                        int pattern = CompilePattern("pn");
 
                        // if pattern supplied, use it
-                       if (pcnt > 1) {
-                               pattern = CompilePattern(parameters[1]);
+                       if (parameters.size() > 1) {
+                               pattern = CompilePattern(parameters[1].c_str());
                        }
-                       
+
                        if (!mask.length())
                        {
                                // 'SILENCE +' or 'SILENCE -', assume *!*@*
                                mask = "*!*@*";
                        }
-                       
+
                        ModeParser::CleanMask(mask);
 
                        if (action == '-')
@@ -153,7 +152,7 @@ class CommandSilence : public Command
                                                if (listitem == mask && i->second == pattern)
                                                {
                                                        sl->erase(i);
-                                                       user->WriteNumeric(950, "%s %s :Removed %s %s from silence list",user->nick, user->nick, mask.c_str(), DecompPattern(pattern).c_str());
+                                                       user->WriteNumeric(950, "%s %s :Removed %s %s from silence list",user->nick.c_str(), user->nick.c_str(), mask.c_str(), DecompPattern(pattern).c_str());
                                                        if (!sl->size())
                                                        {
                                                                delete sl;
@@ -163,7 +162,7 @@ class CommandSilence : public Command
                                                }
                                        }
                                }
-                               user->WriteNumeric(952, "%s %s :%s %s does not exist on your silence list",user->nick, user->nick, mask.c_str(), DecompPattern(pattern).c_str());
+                               user->WriteNumeric(952, "%s %s :%s %s does not exist on your silence list",user->nick.c_str(), user->nick.c_str(), mask.c_str(), DecompPattern(pattern).c_str());
                        }
                        else if (action == '+')
                        {
@@ -178,7 +177,7 @@ class CommandSilence : public Command
                                }
                                if (sl->size() > maxsilence)
                                {
-                                       user->WriteNumeric(952, "%s %s :Your silence list is full",user->nick, user->nick);
+                                       user->WriteNumeric(952, "%s %s :Your silence list is full",user->nick.c_str(), user->nick.c_str());
                                        return CMD_FAILURE;
                                }
                                for (silencelist::iterator n = sl->begin(); n != sl->end();  n++)
@@ -186,7 +185,7 @@ class CommandSilence : public Command
                                        irc::string listitem = n->first.c_str();
                                        if (listitem == mask && n->second == pattern)
                                        {
-                                               user->WriteNumeric(952, "%s %s :%s %s is already on your silence list",user->nick, user->nick, mask.c_str(), DecompPattern(pattern).c_str());
+                                               user->WriteNumeric(952, "%s %s :%s %s is already on your silence list",user->nick.c_str(), user->nick.c_str(), mask.c_str(), DecompPattern(pattern).c_str());
                                                return CMD_FAILURE;
                                        }
                                }
@@ -198,7 +197,7 @@ class CommandSilence : public Command
                                {
                                        sl->push_back(silenceset(mask,pattern));
                                }
-                               user->WriteNumeric(951, "%s %s :Added %s %s to silence list",user->nick, user->nick, mask.c_str(), DecompPattern(pattern).c_str());
+                               user->WriteNumeric(951, "%s %s :Added %s %s to silence list",user->nick.c_str(), user->nick.c_str(), mask.c_str(), DecompPattern(pattern).c_str());
                                return CMD_SUCCESS;
                        }
                }
@@ -219,7 +218,7 @@ class CommandSilence : public Command
                                case 'c':
                                        p |= SILENCE_CHANNEL;
                                        break;
-                               case 'i': 
+                               case 'i':
                                        p |= SILENCE_INVITE;
                                        break;
                                case 'n':
@@ -267,25 +266,23 @@ class CommandSilence : public Command
 
 class ModuleSilence : public Module
 {
-       CommandSilence* cmdsilence;
-       CommandSVSSilence *cmdsvssilence;
        unsigned int maxsilence;
+       CommandSilence cmdsilence;
+       CommandSVSSilence cmdsvssilence;
  public:
+
        ModuleSilence(InspIRCd* Me)
-               : Module(Me), maxsilence(32)
+               : Module(Me), maxsilence(32), cmdsilence(Me, maxsilence), cmdsvssilence(Me)
        {
-               OnRehash(NULL, "");
-               cmdsilence = new CommandSilence(ServerInstance,maxsilence);
-               cmdsvssilence = new CommandSVSSilence(ServerInstance);
-               ServerInstance->AddCommand(cmdsilence);
-               ServerInstance->AddCommand(cmdsvssilence);
+               OnRehash(NULL);
+               ServerInstance->AddCommand(&cmdsilence);
+               ServerInstance->AddCommand(&cmdsvssilence);
 
                Implementation eventlist[] = { I_OnRehash, I_OnBuildExemptList, I_OnUserQuit, I_On005Numeric, I_OnUserPreNotice, I_OnUserPreMessage, I_OnUserPreInvite };
                ServerInstance->Modules->Attach(eventlist, this, 7);
        }
 
-       virtual void OnRehash(User* user, const std::string &parameter)
+       virtual void OnRehash(User* user)
        {
                ConfigReader Conf(ServerInstance);
                maxsilence = Conf.ReadInteger("silence", "maxentries", 0, true);
@@ -346,10 +343,7 @@ class ModuleSilence : public Module
 
        virtual int PreText(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list, int silence_type)
        {
-               if (!IS_LOCAL(user))
-                       return 0;
-
-               if (target_type == TYPE_USER)
+               if (target_type == TYPE_USER && IS_LOCAL(((User*)dest)))
                {
                        return MatchPattern((User*)dest, user, silence_type);
                }
@@ -382,7 +376,7 @@ class ModuleSilence : public Module
        int MatchPattern(User* dest, User* source, int pattern)
        {
                /* Server source */
-               if (!source)
+               if (!source || !dest)
                        return 1;
 
                silencelist* sl;
@@ -391,7 +385,7 @@ class ModuleSilence : public Module
                {
                        for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
                        {
-                               if (((((c->second & pattern) > 0)) || ((c->second & SILENCE_ALL) > 0)) && (ServerInstance->MatchText(source->GetFullHost(), c->first)))
+                               if (((((c->second & pattern) > 0)) || ((c->second & SILENCE_ALL) > 0)) && (InspIRCd::Match(source->GetFullHost(), c->first)))
                                        return !(((c->second & SILENCE_EXCLUDE) > 0));
                        }
                }
@@ -401,10 +395,10 @@ class ModuleSilence : public Module
        virtual ~ModuleSilence()
        {
        }
-       
+
        virtual Version GetVersion()
        {
-               return Version(1, 2, 0, 1, VF_COMMON | VF_VENDOR, API_VERSION);
+               return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
        }
 };