X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_sethost.cpp;h=dad8491530c59da43d3dfb32f4b6dfb90e647fe7;hb=e59cb85871f75b7603c63c6cd274d57536cf6794;hp=75dbe1c6a6c00f84a4ce09661b720c4327d60210;hpb=5267fb9d362aeb326c9e64f7171c957f76776f90;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_sethost.cpp b/src/modules/m_sethost.cpp index 75dbe1c6a..dad849153 100644 --- a/src/modules/m_sethost.cpp +++ b/src/modules/m_sethost.cpp @@ -25,36 +25,36 @@ */ class CommandSethost : public Command { - char* hostmap; - public: - CommandSethost(Module* Creator, char* hmap) : Command(Creator,"SETHOST", 1), hostmap(hmap) + std::bitset hostmap; + + CommandSethost(Module* Creator) + : Command(Creator,"SETHOST", 1) { allow_empty_last_param = false; - flags_needed = 'o'; syntax = ""; + flags_needed = 'o'; syntax = ""; } - CmdResult Handle (const std::vector& 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(*x))) { user->WriteNotice("*** SETHOST: Invalid characters in hostname"); return CMD_FAILURE; } } - if (len > ServerInstance->Config->Limits.MaxHost) - { - user->WriteNotice("*** SETHOST: Host too long"); - return CMD_FAILURE; - } - if (user->ChangeDisplayedHost(parameters[0])) { - 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; } @@ -66,11 +66,10 @@ class CommandSethost : public Command class ModuleSetHost : public Module { CommandSethost cmd; - char hostmap[256]; public: ModuleSetHost() - : cmd(this, hostmap) + : cmd(this) { } @@ -78,14 +77,14 @@ class ModuleSetHost : public Module { 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(*n)); } Version GetVersion() CXX11_OVERRIDE { - return Version("Provides support for the SETHOST command", VF_VENDOR); + return Version("Provides the SETHOST command", VF_VENDOR); } };