X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_sethost.cpp;h=dad8491530c59da43d3dfb32f4b6dfb90e647fe7;hb=e59cb85871f75b7603c63c6cd274d57536cf6794;hp=1425204b45f2e5f24e49a6988c51a03b417c1207;hpb=23e8bba13c55d33ce89d505780da36c9589e300a;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_sethost.cpp b/src/modules/m_sethost.cpp index 1425204b4..dad849153 100644 --- a/src/modules/m_sethost.cpp +++ b/src/modules/m_sethost.cpp @@ -21,43 +21,40 @@ #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 hostmap; + + CommandSethost(Module* Creator) + : Command(Creator,"SETHOST", 1) { allow_empty_last_param = false; - flags_needed = 'o'; syntax = ""; - TRANSLATE2(TR_TEXT, TR_END); + 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 > 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; } @@ -69,34 +66,25 @@ class CommandSethost : public Command class ModuleSetHost : public Module { CommandSethost cmd; - char hostmap[256]; public: ModuleSetHost() - : cmd(this, hostmap) - { - } - - void init() + : 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) + 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(*n)); } - virtual Version GetVersion() + Version GetVersion() CXX11_OVERRIDE { - return Version("Provides support for the SETHOST command", VF_VENDOR); + return Version("Provides the SETHOST command", VF_VENDOR); } };