]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_sethost.cpp
Some more text fixes and improvements (#1618).
[user/henk/code/inspircd.git] / src / modules / m_sethost.cpp
index bc17010495e4f8cdd320aa00cc3d66b3c78b487e..dad8491530c59da43d3dfb32f4b6dfb90e647fe7 100644 (file)
 
 #include "inspircd.h"
 
-/* $ModDesc: Provides support for the SETHOST command */
-
 /** Handle /SETHOST
  */
 class CommandSethost : public Command
 {
-       char* hostmap;
-
  public:
-       CommandSethost(Module* Creator, char* hmap) : Command(Creator,"SETHOST", 1), hostmap(hmap)
+       std::bitset<UCHAR_MAX> hostmap;
+
+       CommandSethost(Module* Creator)
+               : Command(Creator,"SETHOST", 1)
        {
                allow_empty_last_param = false;
-               flags_needed = 'o'; syntax = "<new-hostname>";
+               flags_needed = 'o'; syntax = "<host>";
        }
 
-       CmdResult Handle (const std::vector<std::string>& parameters, User *user)
+       CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
        {
-               size_t len = 0;
-               for (std::string::const_iterator x = parameters[0].begin(); x != parameters[0].end(); x++, len++)
+               if (parameters[0].length() > ServerInstance->Config->Limits.MaxHost)
+               {
+                       user->WriteNotice("*** SETHOST: Host too long");
+                       return CMD_FAILURE;
+               }
+
+               for (std::string::const_iterator x = parameters[0].begin(); x != parameters[0].end(); x++)
                {
-                       if (!hostmap[(const unsigned char)*x])
+                       if (!hostmap.test(static_cast<unsigned char>(*x)))
                        {
                                user->WriteNotice("*** SETHOST: Invalid characters in hostname");
                                return CMD_FAILURE;
                        }
                }
 
-               if (len > 64)
+               if (user->ChangeDisplayedHost(parameters[0]))
                {
-                       user->WriteNotice("*** SETHOST: Host too long");
-                       return CMD_FAILURE;
-               }
-
-               if (user->ChangeDisplayedHost(parameters[0].c_str()))
-               {
-                       ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used SETHOST to change their displayed host to "+user->dhost);
+                       ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used SETHOST to change their displayed host to "+user->GetDisplayedHost());
                        return CMD_SUCCESS;
                }
 
@@ -68,34 +66,25 @@ class CommandSethost : public Command
 class ModuleSetHost : public Module
 {
        CommandSethost cmd;
-       char hostmap[256];
 
  public:
        ModuleSetHost()
-               : cmd(this, hostmap)
-       {
-       }
-
-       void init() CXX11_OVERRIDE
+               : cmd(this)
        {
-               OnRehash(NULL);
-               ServerInstance->Modules->AddService(cmd);
-               Implementation eventlist[] = { I_OnRehash };
-               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       void OnRehash(User* user) CXX11_OVERRIDE
+       void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
                std::string hmap = ServerInstance->Config->ConfValue("hostname")->getString("charmap", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789");
 
-               memset(hostmap, 0, sizeof(hostmap));
+               cmd.hostmap.reset();
                for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++)
-                       hostmap[(unsigned char)*n] = 1;
+                       cmd.hostmap.set(static_cast<unsigned char>(*n));
        }
 
        Version GetVersion() CXX11_OVERRIDE
        {
-               return Version("Provides support for the SETHOST command", VF_VENDOR);
+               return Version("Provides the SETHOST command", VF_VENDOR);
        }
 };