]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_userip.cpp
Add VF_COMMON to a lot modules which require it. Reported by danielg in bug #369...
[user/henk/code/inspircd.git] / src / modules / m_userip.cpp
index fa5fdd5a5237302e0ee01e3b75e1900930a2e3f2..5223a1af1b9194b7f6a79ea86fe39db010d232c3 100644 (file)
@@ -2,97 +2,85 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  Inspire is copyright (C) 2002-2004 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 "inspircd.h"
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
-#include "helperfuncs.h"
 
 /* $ModDesc: Provides support for USERIP command */
 
-Server *Srv;
-        
-void handle_userip(char **parameters, int pcnt, userrec *user)
+/** Handle /USERIP
+ */
+class cmd_userip : public command_t
 {
-        char Return[MAXBUF],junk[MAXBUF];
-        snprintf(Return,MAXBUF,"340 %s :",user->nick);
-        for (int i = 0; i < pcnt; i++)
-        {
-                userrec *u = Find(parameters[i]);
-                if (u)
-                {
-                        snprintf(junk,MAXBUF,"%s%s=+%s@%s ",u->nick,strchr(u->modes,'o') ? "*" : "",u->ident,u->ip);
-                        strlcat(Return,junk,MAXBUF);
-                }
-        }
-        WriteServ(user->fd,Return);
-}
+ public:
+       cmd_userip (InspIRCd* Instance) : command_t(Instance,"USERIP", 'o', 1)
+       {
+               this->source = "m_userip.so";
+               syntax = "<nick>{,<nick>}";
+       }
+
+       CmdResult Handle (const char** parameters, int pcnt, userrec *user)
+       {
+               std::string retbuf = std::string("340 ") + user->nick + " :";
 
+               for (int i = 0; i < pcnt; i++)
+               {
+                       userrec *u = ServerInstance->FindNick(parameters[i]);
+                       if ((u) && (u->registered == REG_ALL))
+                       {
+                               retbuf = retbuf + u->nick + (IS_OPER(u) ? "*" : "") + "=+" + u->ident + "@" + u->GetIPString() + " ";
+                       }
+               }
+
+               user->WriteServ(retbuf);
+
+               /* Dont send to the network */
+               return CMD_LOCALONLY;
+       }
+};
 
 class ModuleUserIP : public Module
 {
+       cmd_userip* mycommand;
  public:
-       ModuleUserIP()
+       ModuleUserIP(InspIRCd* Me)
+               : Module(Me)
        {
-               Srv = new Server;
-               Srv->AddCommand("USERIP",handle_userip,'o',1,"m_userip.so");
+               
+               mycommand = new cmd_userip(ServerInstance);
+               ServerInstance->AddCommand(mycommand);
        }
 
-        virtual void On005Numeric(std::string &output)
-        {
-               output = output + std::string(" USERIP");
-        }
-       
-       virtual ~ModuleUserIP()
+       void Implements(char* List)
        {
-               delete Srv;
+               List[I_On005Numeric] = 1;
        }
-       
-       virtual Version GetVersion()
-       {
-               return Version(1,0,0,1,VF_VENDOR);
-       }
-       
-};
-
-// stuff down here is the module-factory stuff. For basic modules you can ignore this.
 
-class ModuleUserIPFactory : public ModuleFactory
-{
- public:
-       ModuleUserIPFactory()
+       virtual void On005Numeric(std::string &output)
        {
+               output = output + std::string(" USERIP");
        }
        
-       ~ModuleUserIPFactory()
+       virtual ~ModuleUserIP()
        {
        }
        
-       virtual Module * CreateModule()
+       virtual Version GetVersion()
        {
-               return new ModuleUserIP;
+               return Version(1,1,0,1,VF_VENDOR,API_VERSION);
        }
        
 };
 
-
-extern "C" void * init_module( void )
-{
-       return new ModuleUserIPFactory;
-}
+MODULE_INIT(ModuleUserIP)