]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_silence.cpp
Add config <options:disablehmac> to support disabling of HMAC, and tidy up to detect...
[user/henk/code/inspircd.git] / src / modules / m_silence.cpp
index 7f8b49287dfcf33c249c088306a84d9ba6f25df9..5c8e5fdefec45ca275057044ad87642c5637df9f 100644 (file)
@@ -2,20 +2,15 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- *                       E-mail:
- *                <brain@chatspike.net>
- *               <Craig@chatspike.net>
- *     
- * Written by Craig Edwards, Craig McLure, and others.
+ *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
  * This program is free but copyrighted software; see
  *            the file COPYING for details.
  *
  * ---------------------------------------------------
  */
 
-using namespace std;
-
 #include <stdio.h>
 #include <string>
 #include <vector>
@@ -28,22 +23,21 @@ using namespace std;
 
 /* $ModDesc: Provides support for the /SILENCE command */
 
-
 // This typedef holds a silence list. Each user may or may not have a
 // silencelist, if a silence list is empty for a user, he/she does not
 // have one of these structures associated with their user record.
-typedef std::vector<std::string> silencelist;
+typedef std::map<irc::string, time_t> silencelist;
 
 class cmd_silence : public command_t
 {
  public:
- cmd_silence (InspIRCd* Instance) : command_t(Instance,"SILENCE", 0, 0)
      cmd_silence (InspIRCd* Instance) : command_t(Instance,"SILENCE", 0, 0)
        {
                this->source = "m_silence.so";
                syntax = "{[+|-]<mask>}";
        }
 
-       void Handle (const char** parameters, int pcnt, userrec *user)
+       CmdResult Handle (const char** parameters, int pcnt, userrec *user)
        {
                if (!pcnt)
                {
@@ -54,12 +48,14 @@ class cmd_silence : public command_t
                        // if the user has a silence list associated with their user record, show it
                        if (sl)
                        {
-                               for (silencelist::const_iterator c = sl->begin(); c < sl->end(); c++)
+                               for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
                                {
-                                       user->WriteServ("271 %s %s %s",user->nick, user->nick,c->c_str());
+                                       user->WriteServ("271 %s %s %s :%lu",user->nick, user->nick, c->first.c_str(), (unsigned long)c->second);
                                }
                        }
                        user->WriteServ("272 %s :End of Silence List",user->nick);
+
+                       return CMD_SUCCESS;
                }
                else if (pcnt > 0)
                {
@@ -85,16 +81,11 @@ class cmd_silence : public command_t
                                {
                                        if (sl->size())
                                        {
-                                               for (silencelist::iterator i = sl->begin(); i != sl->end(); i++)
-                                               {
-                                                       // search through for the item
-                                                       irc::string listitem = i->c_str();
-                                                       if (listitem == mask)
-                                                       {
-                                                               sl->erase(i);
-                                                               user->WriteServ("950 %s %s :Removed %s from silence list",user->nick, user->nick, mask.c_str());
-                                                               break;
-                                                       }
+                                               silencelist::iterator i = sl->find(mask.c_str());
+                                               if (i != sl->end())
+                                               {
+                                                               sl->erase(i);
+                                                       user->WriteServ("950 %s %s :Removed %s from silence list",user->nick, user->nick, mask.c_str());
                                                }
                                        }
                                        else
@@ -115,23 +106,20 @@ class cmd_silence : public command_t
                                if (!sl)
                                {
                                        sl = new silencelist;
-                                       user->Extend(std::string("silence_list"), sl);
+                                       user->Extend("silence_list", sl);
                                }
-                               for (silencelist::iterator n = sl->begin(); n != sl->end();  n++)
+                               silencelist::iterator n = sl->find(mask.c_str());
+                               if (n != sl->end())
                                {
-                                       irc::string listitem = n->c_str();
-                                       if (listitem == mask)
-                                       {
-                                               user->WriteServ("952 %s %s :%s is already on your silence list",user->nick, user->nick, mask.c_str());
-                                               return;
-                                       }
+                                       user->WriteServ("952 %s %s :%s is already on your silence list",user->nick, user->nick, mask.c_str());
+                                       return CMD_FAILURE;
                                }
-                               sl->push_back(mask);
+                               sl->insert(std::make_pair<irc::string, time_t>(mask.c_str(), ServerInstance->Time()));
                                user->WriteServ("951 %s %s :Added %s to silence list",user->nick, user->nick, mask.c_str());
-                               return;
+                               return CMD_SUCCESS;
                        }
                }
-               return;
+               return CMD_SUCCESS;
        }
 };
 
@@ -154,7 +142,7 @@ class ModuleSilence : public Module
                List[I_OnUserQuit] = List[I_On005Numeric] = List[I_OnUserPreNotice] = List[I_OnUserPreMessage] = 1;
        }
 
-       virtual void OnUserQuit(userrec* user, const std::string &reason)
+       virtual void OnUserQuit(userrec* user, const std::string &reason, const std::string &oper_message)
        {
                // when the user quits tidy up any silence list they might have just to keep things tidy
                // and to prevent a HONKING BIG MEMORY LEAK!
@@ -173,13 +161,13 @@ class ModuleSilence : public Module
                output = output + " SILENCE=999";
        }
        
-       virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
+       virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
        {
                // im not sure how unreal's silence operates but ours is sensible. It blocks notices and
                // privmsgs from people on the silence list, directed privately at the user.
                // channel messages are unaffected (ever tried to follow the flow of conversation in
                // a channel when you've set an ignore on the two most talkative people?)
-               if (target_type == TYPE_USER)
+               if ((target_type == TYPE_USER) && (IS_LOCAL(user)))
                {
                        userrec* u = (userrec*)dest;
                        silencelist* sl;
@@ -188,7 +176,7 @@ class ModuleSilence : public Module
                        {
                                for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
                                {
-                                       if (match(user->GetFullHost(), c->c_str()))
+                                       if (match(user->GetFullHost(), c->first.c_str()))
                                        {
                                                return 1;
                                        }
@@ -198,9 +186,9 @@ class ModuleSilence : public Module
                return 0;
        }
 
-       virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
+       virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
        {
-               return OnUserPreNotice(user,dest,target_type,text,status);
+               return OnUserPreNotice(user,dest,target_type,text,status,exempt_list);
        }
 
        virtual ~ModuleSilence()
@@ -209,7 +197,7 @@ class ModuleSilence : public Module
        
        virtual Version GetVersion()
        {
-               return Version(1,0,0,1,VF_VENDOR);
+               return Version(1,1,0,1,VF_VENDOR,API_VERSION);
        }
 };