]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_chgident.cpp
Fix crash on propogation after routed squit has reached it's destination. Thx HiroP.
[user/henk/code/inspircd.git] / src / modules / m_chgident.cpp
index 52bfd237cfe9f0fa61043470935d5ebfe9d3895a..740eeadf144e0e1933af8677f39902bdcaa48ba9 100644 (file)
@@ -1,43 +1,54 @@
-#include <string>
+/*       +------------------------------------+
+ *       | Inspire Internet Relay Chat Daemon |
+ *       +------------------------------------+
+ *
+ *  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.
+ *
+ * ---------------------------------------------------
+ */
+
+#include "inspircd.h"
 #include "users.h"
 #include "modules.h"
-#include "helperfuncs.h"
 
 /* $ModDesc: Provides support for the CHGIDENT command */
 
-Server *Srv;
-
-
+/** Handle /CHGIDENT
+ */
 class cmd_chgident : public command_t
 {
  public:
-       cmd_chgident() : command_t("CHGIDENT", 'o', 2)
+       cmd_chgident (InspIRCd* Instance) : command_t(Instance,"CHGIDENT", 'o', 2)
        {
                this->source = "m_chgident.so";
+               syntax = "<nick> <newident>";
        }
        
-       void Handle(char **parameters, int pcnt, userrec *user)
+       CmdResult Handle(const char** parameters, int pcnt, userrec *user)
        {
-               userrec* dest = Srv->FindNick(std::string(parameters[0]));
-               
-               if(dest)
+               userrec* dest = ServerInstance->FindNick(parameters[0]);
+
+               if (!dest)
                {
-                       for(unsigned int x = 0; x < strlen(parameters[1]); x++)
-                       {
-                               if(((parameters[1][x] >= 'A') && (parameters[1][x] <= '}')) || strchr(".-0123456789", parameters[1][x]))
-                                       continue;
-                       
-                               WriteServ(user->fd, "NOTICE %s :*** Invalid characters in ident", user->nick);
-                               return;
-                       }
-               
-                       WriteOpers("%s used CHGIDENT to change %s's ident from '%s' to '%s'", user->nick, dest->nick, dest->ident, parameters[1]);
-                       strlcpy(dest->ident, parameters[1], IDENTMAX+2);
+                       user->WriteServ("401 %s %s :No such nick/channel", user->nick, parameters[0]);
+                       return CMD_FAILURE;
                }
-               else
+
+               if(!ServerInstance->IsIdent(parameters[1]))
                {
-                       WriteServ(user->fd, "401 %s %s :No such nick/channel", user->nick, parameters[0]);
+                       user->WriteServ("NOTICE %s :*** Invalid characters in ident", user->nick);
+                       return CMD_FAILURE;
                }
+
+               dest->ChangeIdent(parameters[1]);
+               ServerInstance->WriteOpers("%s used CHGIDENT to change %s's ident to '%s'", user->nick, dest->nick, dest->ident);
+
+               /* route it! */
+               return CMD_SUCCESS;
        }
 };
 
@@ -46,12 +57,12 @@ class ModuleChgIdent : public Module
 {
        cmd_chgident* mycommand;
        
+       
 public:
-       ModuleChgIdent(Server* Me) : Module::Module(Me)
+       ModuleChgIdent(InspIRCd* Me) : Module(Me)
        {
-               Srv = Me;
-               mycommand = new cmd_chgident();
-               Srv->AddCommand(mycommand);
+               mycommand = new cmd_chgident(ServerInstance);
+               ServerInstance->AddCommand(mycommand);
        }
        
        virtual ~ModuleChgIdent()
@@ -60,7 +71,7 @@ public:
        
        virtual Version GetVersion()
        {
-               return Version(1,0,0,0,VF_VENDOR);
+               return Version(1,1,0,0,VF_VENDOR,API_VERSION);
        }
        
 };
@@ -78,7 +89,7 @@ class ModuleChgIdentFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule(Server* Me)
+       virtual Module * CreateModule(InspIRCd* Me)
        {
                return new ModuleChgIdent(Me);
        }
@@ -86,7 +97,7 @@ class ModuleChgIdentFactory : public ModuleFactory
 };
 
 
-extern "C" void * init_module( void )
+extern "C" DllExport void * init_module( void )
 {
        return new ModuleChgIdentFactory;
 }