]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_silence.cpp
Windows support. Tested and working to compile on freebsd and linux. Next step is...
[user/henk/code/inspircd.git] / src / modules / m_silence.cpp
index 595c3505e7bb8515108de6e1e5d808f7d2431e5e..773d28ecec5991222301d6f5f578f27d24e5985d 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>
@@ -35,8 +30,9 @@ typedef std::map<irc::string, time_t> silencelist;
 
 class cmd_silence : public command_t
 {
+       unsigned int& maxsilence;
  public:
-       cmd_silence (InspIRCd* Instance) : command_t(Instance,"SILENCE", 0, 0)
+       cmd_silence (InspIRCd* Instance, unsigned int &max) : command_t(Instance,"SILENCE", 0, 0), maxsilence(max)
        {
                this->source = "m_silence.so";
                syntax = "{[+|-]<mask>}";
@@ -69,7 +65,7 @@ class cmd_silence : public command_t
                        char action = *parameters[0];
                        
                        if (!mask.length())
-                       {
+                       {
                                // 'SILENCE +' or 'SILENCE -', assume *!*@*
                                mask = "*!*@*";
                        }
@@ -84,22 +80,21 @@ class cmd_silence : public command_t
                                // does it contain any entries and does it exist?
                                if (sl)
                                {
-                                       if (sl->size())
+                                       silencelist::iterator i = sl->find(mask.c_str());
+                                       if (i != sl->end())
                                        {
-                                               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());
+                                               if (!sl->size())
                                                {
-                                                               sl->erase(i);
-                                                       user->WriteServ("950 %s %s :Removed %s from silence list",user->nick, user->nick, mask.c_str());
+                                                       // tidy up -- if a user's list is empty, theres no use having it
+                                                       // hanging around in the user record.
+                                                       DELETE(sl);
+                                                       user->Shrink("silence_list");
                                                }
                                        }
                                        else
-                                       {
-                                               // tidy up -- if a user's list is empty, theres no use having it
-                                               // hanging around in the user record.
-                                               DELETE(sl);
-                                               user->Shrink("silence_list");
-                                       }
+                                               user->WriteServ("952 %s %s :%s does not exist on your silence list",user->nick, user->nick, mask.c_str());
                                }
                        }
                        else if (action == '+')
@@ -119,6 +114,11 @@ class cmd_silence : public command_t
                                        user->WriteServ("952 %s %s :%s is already on your silence list",user->nick, user->nick, mask.c_str());
                                        return CMD_FAILURE;
                                }
+                               if (sl->size() >= maxsilence)
+                               {
+                                       user->WriteServ("952 %s %s :Your silence list is full",user->nick, user->nick, mask.c_str());
+                                       return CMD_FAILURE;
+                               }
                                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 CMD_SUCCESS;
@@ -132,22 +132,31 @@ class ModuleSilence : public Module
 {
        
        cmd_silence* mycommand;
+       unsigned int maxsilence;
  public:
  
        ModuleSilence(InspIRCd* Me)
-               : Module::Module(Me)
+               : Module(Me), maxsilence(32)
        {
-               
-               mycommand = new cmd_silence(ServerInstance);
+               OnRehash(NULL, "");
+               mycommand = new cmd_silence(ServerInstance, maxsilence);
                ServerInstance->AddCommand(mycommand);
        }
 
        void Implements(char* List)
        {
-               List[I_OnUserQuit] = List[I_On005Numeric] = List[I_OnUserPreNotice] = List[I_OnUserPreMessage] = 1;
+               List[I_OnRehash] = List[I_OnUserQuit] = List[I_On005Numeric] = List[I_OnUserPreNotice] = List[I_OnUserPreMessage] = 1;
+       }
+
+       virtual void OnRehash(userrec* user, const std::string &parameter)
+       {
+               ConfigReader Conf(ServerInstance);
+               maxsilence = Conf.ReadInteger("silence", "maxentries", 0, true);
+               if (!maxsilence)
+                       maxsilence = 32;
        }
 
-       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!
@@ -163,16 +172,16 @@ class ModuleSilence : public Module
        virtual void On005Numeric(std::string &output)
        {
                // we don't really have a limit...
-               output = output + " SILENCE=999";
+               output = output + " SILENCE=" + ConvToStr(maxsilence);
        }
        
-       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;
@@ -191,9 +200,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()
@@ -226,7 +235,7 @@ class ModuleSilenceFactory : public ModuleFactory
 };
 
 
-extern "C" void * init_module( void )
+extern "C" DllExport void * init_module( void )
 {
        return new ModuleSilenceFactory;
 }