m_chghost.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 CommandChghost : public Command
00021 {
00022 private:
00023 char* hostmap;
00024 public:
00025 CommandChghost (InspIRCd* Instance, char* hmap) : Command(Instance,"CHGHOST","o",2), hostmap(hmap)
00026 {
00027 this->source = "m_chghost.so";
00028 syntax = "<nick> <newhost>";
00029 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
00030 }
00031
00032 CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
00033 {
00034 const char * x = parameters[1].c_str();
00035
00036 for (; *x; x++)
00037 {
00038 if (!hostmap[(unsigned char)*x])
00039 {
00040 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** CHGHOST: Invalid characters in hostname");
00041 return CMD_FAILURE;
00042 }
00043 }
00044 if (parameters[0].empty())
00045 {
00046 user->WriteServ("NOTICE %s :*** CHGHOST: Host must be specified", user->nick.c_str());
00047 return CMD_FAILURE;
00048 }
00049
00050 if ((parameters[1].c_str() - x) > 63)
00051 {
00052 user->WriteServ("NOTICE %s :*** CHGHOST: Host too long", user->nick.c_str());
00053 return CMD_FAILURE;
00054 }
00055 User* dest = ServerInstance->FindNick(parameters[0]);
00056
00057 if (!dest)
00058 {
00059 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel", user->nick.c_str(), parameters[0].c_str());
00060 return CMD_FAILURE;
00061 }
00062
00063 if (IS_LOCAL(dest))
00064 {
00065 if ((dest->ChangeDisplayedHost(parameters[1].c_str())) && (!ServerInstance->ULine(user->server)))
00066 {
00067
00068 ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick)+" used CHGHOST to make the displayed host of "+dest->nick+" become "+dest->dhost);
00069 }
00070
00071
00072 return CMD_LOCALONLY;
00073 }
00074
00075
00076 return CMD_SUCCESS;
00077
00078 }
00079 };
00080
00081
00082 class ModuleChgHost : public Module
00083 {
00084 CommandChghost* mycommand;
00085 char hostmap[256];
00086 public:
00087 ModuleChgHost(InspIRCd* Me)
00088 : Module(Me)
00089 {
00090 OnRehash(NULL,"");
00091 mycommand = new CommandChghost(ServerInstance, hostmap);
00092 ServerInstance->AddCommand(mycommand);
00093 Implementation eventlist[] = { I_OnRehash };
00094 ServerInstance->Modules->Attach(eventlist, this, 1);
00095 }
00096
00097
00098 void OnRehash(User* user, const std::string ¶meter)
00099 {
00100 ConfigReader Conf(ServerInstance);
00101 std::string hmap = Conf.ReadValue("hostname", "charmap", 0);
00102
00103 if (hmap.empty())
00104 hmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789";
00105
00106 memset(hostmap, 0, sizeof(hostmap));
00107 for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++)
00108 hostmap[(unsigned char)*n] = 1;
00109 }
00110
00111 ~ModuleChgHost()
00112 {
00113 }
00114
00115 Version GetVersion()
00116 {
00117 return Version("$Id: m_chghost.cpp 10291 2008-08-25 20:35:51Z w00t $", VF_COMMON | VF_VENDOR, API_VERSION);
00118 }
00119
00120 };
00121
00122 MODULE_INIT(ModuleChgHost)