m_sethost.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "inspircd.h"
00015
00016
00017
00020 class CommandSethost : public Command
00021 {
00022 private:
00023 char* hostmap;
00024 public:
00025 CommandSethost (InspIRCd* Instance, char* hmap) : Command(Instance,"SETHOST","o",1), hostmap(hmap)
00026 {
00027 this->source = "m_sethost.so";
00028 syntax = "<new-hostname>";
00029 TRANSLATE2(TR_TEXT, TR_END);
00030 }
00031
00032 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
00033 {
00034 size_t len = 0;
00035 for (std::string::const_iterator x = parameters[0].begin(); x != parameters[0].end(); x++, len++)
00036 {
00037 if (!hostmap[(const unsigned char)*x])
00038 {
00039 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** SETHOST: Invalid characters in hostname");
00040 return CMD_FAILURE;
00041 }
00042 }
00043 if (len == 0)
00044 {
00045 user->WriteServ("NOTICE %s :*** SETHOST: Host must be specified", user->nick.c_str());
00046 return CMD_FAILURE;
00047 }
00048 if (len > 64)
00049 {
00050 user->WriteServ("NOTICE %s :*** SETHOST: Host too long",user->nick.c_str());
00051 return CMD_FAILURE;
00052 }
00053
00054 if (user->ChangeDisplayedHost(parameters[0].c_str()))
00055 {
00056 ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick)+" used SETHOST to change their displayed host to "+user->dhost);
00057 return CMD_LOCALONLY;
00058 }
00059
00060 return CMD_FAILURE;
00061 }
00062 };
00063
00064
00065 class ModuleSetHost : public Module
00066 {
00067 CommandSethost* mycommand;
00068 char hostmap[256];
00069 public:
00070 ModuleSetHost(InspIRCd* Me)
00071 : Module(Me)
00072 {
00073 OnRehash(NULL,"");
00074 mycommand = new CommandSethost(ServerInstance, hostmap);
00075 ServerInstance->AddCommand(mycommand);
00076 Implementation eventlist[] = { I_OnRehash };
00077 ServerInstance->Modules->Attach(eventlist, this, 1);
00078 }
00079
00080
00081 void OnRehash(User* user, const std::string ¶meter)
00082 {
00083 ConfigReader Conf(ServerInstance);
00084 std::string hmap = Conf.ReadValue("hostname", "charmap", 0);
00085
00086 if (hmap.empty())
00087 hmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789";
00088
00089 memset(hostmap, 0, sizeof(hostmap));
00090 for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++)
00091 hostmap[(unsigned char)*n] = 1;
00092 }
00093
00094 virtual ~ModuleSetHost()
00095 {
00096 }
00097
00098 virtual Version GetVersion()
00099 {
00100 return Version("$Id: m_sethost.cpp 10291 2008-08-25 20:35:51Z w00t $", VF_COMMON | VF_VENDOR, API_VERSION);
00101 }
00102
00103 };
00104
00105 MODULE_INIT(ModuleSetHost)