]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_chghost.cpp
Add a metric assload of TRANSLATE macros to modules.
[user/henk/code/inspircd.git] / src / modules / m_chghost.cpp
index e0f69faba5e1ccb5218185a9daf84db930409be6..5f56236826931a9e4a556314e727a6547a625319 100644 (file)
  * ---------------------------------------------------
  */
 
-#include <stdio.h>
-#include <string>
-#include "users.h"
-#include "channels.h"
-#include "modules.h"
-
 #include "inspircd.h"
 
 /* $ModDesc: Provides support for the CHGHOST command */
@@ -32,6 +26,7 @@ class cmd_chghost : public command_t
        {
                this->source = "m_chghost.so";
                syntax = "<nick> <newhost>";
+               TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
        }
  
        CmdResult Handle(const char** parameters, int pcnt, userrec *user)
@@ -42,27 +37,38 @@ class cmd_chghost : public command_t
                {
                        if (!hostmap[(unsigned char)*x])
                        {
-                               user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Invalid characters in hostname");
+                               user->WriteServ("NOTICE "+std::string(user->nick)+" :*** CHGHOST: Invalid characters in hostname");
                                return CMD_FAILURE;
                        }
                }
+               if (!*parameters[0])
+               {
+                       user->WriteServ("NOTICE %s :*** CHGHOST: Host must be specified", user->nick);
+                       return CMD_FAILURE;
+               }
+               
                if ((parameters[1] - x) > 63)
                {
-                       user->WriteServ("NOTICE %s :*** CHGHOST: Host too long",user->nick);
+                       user->WriteServ("NOTICE %s :*** CHGHOST: Host too long", user->nick);
                        return CMD_FAILURE;
                }
                userrec* dest = ServerInstance->FindNick(parameters[0]);
-               if (dest)
+
+               if (!dest)
                {
-                       if ((dest->ChangeDisplayedHost(parameters[1])) && (!ServerInstance->ULine(user->server)))
-                       {
-                               // fix by brain - ulines set hosts silently
-                               ServerInstance->WriteOpers(std::string(user->nick)+" used CHGHOST to make the displayed host of "+dest->nick+" become "+dest->dhost);
-                       }
-                       return CMD_SUCCESS;
+                       user->WriteServ("401 %s %s :No such nick/channel", user->nick, parameters[0]);
+                       return CMD_FAILURE;
                }
 
-               return CMD_FAILURE;
+               if ((dest->ChangeDisplayedHost(parameters[1])) && (!ServerInstance->ULine(user->server)))
+               {
+                       // fix by brain - ulines set hosts silently
+                       ServerInstance->WriteOpers(std::string(user->nick)+" used CHGHOST to make the displayed host of "+dest->nick+" become "+dest->dhost);
+               }
+
+               /* route it! */
+               return CMD_SUCCESS;
+
        }
 };
 
@@ -73,9 +79,9 @@ class ModuleChgHost : public Module
        char hostmap[256];
  public:
        ModuleChgHost(InspIRCd* Me)
-               : Module::Module(Me)
+               : Module(Me)
        {
-               OnRehash("");
+               OnRehash(NULL,"");
                mycommand = new cmd_chghost(ServerInstance, hostmap);
                ServerInstance->AddCommand(mycommand);
        }
@@ -85,7 +91,7 @@ class ModuleChgHost : public Module
                List[I_OnRehash] = 1;
        }
        
-       void OnRehash(const std::string &parameter)
+       void OnRehash(userrec* user, const std::string &parameter)
        {
                ConfigReader Conf(ServerInstance);
                std::string hmap = Conf.ReadValue("hostname", "charmap", 0);
@@ -100,38 +106,13 @@ class ModuleChgHost : public Module
 
        ~ModuleChgHost()
        {
-               delete[] hostmap;
        }
        
        Version GetVersion()
        {
-               return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
+               return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
        }
        
 };
 
-
-class ModuleChgHostFactory : public ModuleFactory
-{
- public:
-       ModuleChgHostFactory()
-       {
-       }
-       
-       ~ModuleChgHostFactory()
-       {
-       }
-       
-       virtual Module * CreateModule(InspIRCd* Me)
-       {
-               return new ModuleChgHost(Me);
-       }
-       
-};
-
-
-extern "C" void * init_module( void )
-{
-       return new ModuleChgHostFactory;
-}
-
+MODULE_INIT(ModuleChgHost)