]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_safelist.cpp
Remove some debug (im on a crusade to make debug mode useful, but at the same time...
[user/henk/code/inspircd.git] / src / modules / m_safelist.cpp
index 32e68ff10590fe18fc44d0ae43d3888b41ab22ad..7441f0ea59f00b1a027952e58728a40af5c32fe0 100644 (file)
@@ -2,19 +2,14 @@
  *       | 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 "users.h"
 #include "channels.h"
@@ -41,6 +36,7 @@ class ListData : public classbase
  
 typedef std::vector<userrec *> UserList;
 UserList listusers;    /* vector of people doing a /list */
+class ListTimer *timer;
 
 /** To create a timer which recurs every second, we inherit from InspTimer.
  * InspTimer is only one-shot however, so at the end of each Tick() we simply
@@ -82,7 +78,7 @@ class ListTimer : public InspTimer
                                userrec* u = (userrec*)(*iter);
                                ListData* ld;
                                u->GetExt("safelist_cache", ld);
-                               if ((size_t)ld->list_position > ServerInstance->chanlist.size())
+                               if ((size_t)ld->list_position > ServerInstance->chanlist->size())
                                {
                                        u->Shrink("safelist_cache");
                                        DELETE(ld);
@@ -103,7 +99,19 @@ class ListTimer : public InspTimer
                                        chan = ServerInstance->GetChannelIndex(ld->list_position);
                                        /* spool details */
                                        bool has_user = (chan && chan->HasUser(u));
-                                       if ((chan) && (((!(chan->modes[CM_PRIVATE])) && (!(chan->modes[CM_SECRET]))) || (has_user)))
+                                       if ((chan) && (chan->modes[CM_PRIVATE]))
+                                       {
+                                               bool display = match(chan->name, ld->glob.c_str());
+                                               long users = chan->GetUserCounter();
+                                               if ((users) && (display))
+                                               {
+                                                       int counter = snprintf(buffer, MAXBUF, "322 %s *", u->nick);
+                                                       amount_sent += counter + ServerNameSize;
+                                                       ServerInstance->Log(DEBUG, "m_safelist.so: Sent %ld of safe %ld / 4", amount_sent, u->sendqmax);
+                                                       u->WriteServ(std::string(buffer));
+                                               }
+                                       }
+                                       else if ((chan) && (((!(chan->modes[CM_PRIVATE])) && (!(chan->modes[CM_SECRET]))) || (has_user)))
                                        {
                                                bool display = match(chan->name, ld->glob.c_str());
                                                long users = chan->GetUserCounter();
@@ -135,31 +143,35 @@ class ListTimer : public InspTimer
                        }
                }
 
-               ListTimer* MyTimer = new ListTimer(ServerInstance,1);
-               ServerInstance->Timers->AddTimer(MyTimer);
+               if (listusers.size())
+               {
+                       timer = new ListTimer(ServerInstance,1);
+                       ServerInstance->Timers->AddTimer(timer);
+               }
+               else
+               {
+                       timer = NULL;
+               }
        }
 };
 
 class ModuleSafeList : public Module
 {
- private:
-        
-        ListTimer* MyTimer;
  public:
        ModuleSafeList(InspIRCd* Me) : Module::Module(Me)
        {
-               MyTimer = new ListTimer(ServerInstance,1);
-               ServerInstance->Timers->AddTimer(MyTimer);
+               timer = NULL;
        }
  
        virtual ~ModuleSafeList()
        {
-               ServerInstance->Timers->DelTimer(MyTimer);
+               if (timer)
+                       ServerInstance->Timers->DelTimer(timer);
        }
  
        virtual Version GetVersion()
        {
-               return Version(1,0,0,0,VF_VENDOR,API_VERSION);
+               return Version(1,1,0,0,VF_VENDOR,API_VERSION);
        }
  
        void Implements(char* List)
@@ -200,6 +212,10 @@ class ModuleSafeList : public Module
                        return 1;
                }
 
+               /* Work around mIRC suckyness. YOU SUCK, KHALED! */
+               if ((pcnt == 1) && (*parameters[0] == '<'))
+                       pcnt = 0;
+
                time_t* last_list_time;
                user->GetExt("safelist_last", last_list_time);
                if (last_list_time)
@@ -207,6 +223,8 @@ class ModuleSafeList : public Module
                        if (ServerInstance->Time() < (*last_list_time)+60)
                        {
                                user->WriteServ("NOTICE %s :*** Woah there, slow down a little, you can't /LIST so often!",user->nick);
+                               user->WriteServ("321 %s Channel :Users Name",user->nick);
+                               user->WriteServ("323 %s :End of channel list.",user->nick);
                                return 1;
                        }
 
@@ -224,7 +242,13 @@ class ModuleSafeList : public Module
                time_t* llt = new time_t;
                *llt = ServerInstance->Time();
                user->Extend("safelist_last", llt);
-       
+
+               if (!timer)
+               {
+                       timer = new ListTimer(ServerInstance,1);
+                       ServerInstance->Timers->AddTimer(timer);
+               }
+
                return 1;
        }