]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spy.cpp
Fix potential for duplicate SID if the SID is auto generated.
[user/henk/code/inspircd.git] / src / modules / m_spy.cpp
index 53a7f0d7f960e9131a7e804c0d8311b401058153..e912fe6a1b4e32cadf06a4dba32bd9a5ebf2f24a 100644 (file)
@@ -2,31 +2,17 @@
  *       | 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.
+ *            the file COPYING for details.
  *
  * ---------------------------------------------------
  */
 
-/* NO, THIS MODULE DOES NOT SPY ON CHANNELS OR USERS.
- * IT JUST ALLOWS OPERS TO SEE +s CHANNELS IN LIST AND
- * WHOIS, WHICH IS SUPPORTED BY MOST IRCDS IN CORE.
- */
-
-using namespace std;
-
 /* $ModDesc: Provides SPYLIST and SPYNAMES capability, allowing opers to see who's in +s channels */
 
-#include "inspircd_config.h"
-#include "users.h" 
-#include "channels.h"
-#include "modules.h"
 #include "inspircd.h"
 #include "wildcard.h"
 
@@ -42,23 +28,9 @@ void spy_userlist(userrec *user, chanrec *c)
 
        CUList *ulist= c->GetUsers();
 
-       /* Improvement by Brain - this doesnt change in value, so why was it inside
-        * the loop?
-        */
-       bool has_user = c->HasUser(user);
-
        for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
        {
-               if ((!has_user) && (i->second->modes[UM_INVISIBLE]))
-               {
-                       /*
-                        * user is +i, and source not on the channel, does not show
-                        * nick in NAMES list
-                        */
-                       continue;
-               }
-
-               size_t ptrlen = snprintf(ptr, MAXBUF, "%s%s ", c->GetPrefixChar(i->second), i->second->nick);
+               size_t ptrlen = snprintf(ptr, MAXBUF, "%s%s ", c->GetPrefixChar(i->first), i->first->nick);
 
                curlen += ptrlen;
                ptr += ptrlen;
@@ -89,21 +61,22 @@ void spy_userlist(userrec *user, chanrec *c)
 
 }
 
-
+/** Handle /SPYLIST
+ */
 class cmd_spylist : public command_t
 {
   public:
        cmd_spylist (InspIRCd* Instance) : command_t(Instance,"SPYLIST", 'o', 0)
        {
                this->source = "m_spy.so";
-               syntax = "";
+               syntax.clear();
        }
 
        CmdResult Handle (const char** parameters, int pcnt, userrec *user)
        {
                ServerInstance->WriteOpers("*** Oper %s used SPYLIST to list +s/+p channels and keys.",user->nick);
                user->WriteServ("321 %s Channel :Users Name",user->nick);
-               for (chan_hash::const_iterator i = ServerInstance->chanlist.begin(); i != ServerInstance->chanlist.end(); i++)
+               for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); i++)
                {
                        if (pcnt && !match(i->second->name, parameters[0]))
                                continue;
@@ -112,10 +85,12 @@ class cmd_spylist : public command_t
                user->WriteServ("323 %s :End of channel list.",user->nick);
 
                /* Dont send out across the network */
-               return CMD_FAILURE;
+               return CMD_LOCALONLY;
        }
 };
 
+/** Handle /SPYNAMES
+ */
 class cmd_spynames : public command_t
 {
   public:
@@ -143,14 +118,13 @@ class cmd_spynames : public command_t
                {
                        ServerInstance->WriteOpers("*** Oper %s used SPYNAMES to view the users on %s", user->nick, parameters[0]);
                        spy_userlist(user,c);
-                       user->WriteServ("366 %s %s :End of /NAMES list.", user->nick, c->name);
                }
                else
                {
                        user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
                }
 
-               return CMD_FAILURE;
+               return CMD_LOCALONLY;
        }
 };
 
@@ -159,7 +133,7 @@ class ModuleSpy : public Module
        cmd_spylist *mycommand;
        cmd_spynames *mycommand2;
  public:
-       ModuleSpy(InspIRCd* Me) : Module::Module(Me)
+       ModuleSpy(InspIRCd* Me) : Module(Me)
        {
                
                mycommand = new cmd_spylist(ServerInstance);
@@ -174,31 +148,8 @@ class ModuleSpy : public Module
        
        virtual Version GetVersion()
        {
-               return Version(1, 0, 0, 0, VF_VENDOR, API_VERSION);
-       }
-};
-
-
-class ModuleSpyFactory : public ModuleFactory
-{
- public:
-       ModuleSpyFactory()
-       {
-       }
-       
-       ~ModuleSpyFactory()
-       {
+               return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
        }
-       
-       virtual Module * CreateModule(InspIRCd* Me)
-       {
-               return new ModuleSpy(Me);
-       }
-       
 };
 
-
-extern "C" void * init_module( void )
-{
-       return new ModuleSpyFactory;
-}
+MODULE_INIT(ModuleSpy)