]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chghost.cpp
18853ac2dd1008b65f116144ad7aae10ebc03663
[user/henk/code/inspircd.git] / src / modules / m_chghost.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18
19 #include <stdio.h>
20 #include <string>
21 #include "users.h"
22 #include "channels.h"
23 #include "modules.h"
24
25 #include "inspircd.h"
26
27 /* $ModDesc: Provides support for the CHGHOST command */
28
29
30
31 class cmd_chghost : public command_t
32 {
33  public:
34  cmd_chghost (InspIRCd* Instance) : command_t(Instance,"CHGHOST",'o',2)
35         {
36                 this->source = "m_chghost.so";
37                 syntax = "<nick> <newhost>";
38         }
39          
40         CmdResult Handle(const char** parameters, int pcnt, userrec *user)
41         {
42                 const char * x = parameters[1];
43
44                 for (; *x; x++)
45                 {
46                         if (((tolower(*x) < 'a') || (tolower(*x) > 'z')) && (*x != '.'))
47                         {
48                                 if (((*x < '0') || (*x > '9')) && (*x != '-'))
49                                 {
50                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Invalid characters in hostname");
51                                         return CMD_FAILURE;
52                                 }
53                         }
54                 }
55                 if ((parameters[1] - x) > 63)
56                 {
57                         user->WriteServ("NOTICE %s :*** CHGHOST: Host too long",user->nick);
58                         return CMD_FAILURE;
59                 }
60                 userrec* dest = ServerInstance->FindNick(parameters[0]);
61                 if (dest)
62                 {
63                         if ((dest->ChangeDisplayedHost(parameters[1])) && (!ServerInstance->ULine(user->server)))
64                         {
65                                 // fix by brain - ulines set hosts silently
66                                 ServerInstance->WriteOpers(std::string(user->nick)+" used CHGHOST to make the displayed host of "+dest->nick+" become "+dest->dhost);
67                         }
68                         return CMD_SUCCESS;
69                 }
70
71                 return CMD_FAILURE;
72         }
73 };
74
75
76 class ModuleChgHost : public Module
77 {
78         cmd_chghost* mycommand;
79  public:
80         ModuleChgHost(InspIRCd* Me)
81                 : Module::Module(Me)
82         {
83                 
84                 mycommand = new cmd_chghost(ServerInstance);
85                 ServerInstance->AddCommand(mycommand);
86         }
87
88         void Implements(char* List)
89         {
90         }
91         
92         virtual ~ModuleChgHost()
93         {
94         }
95         
96         virtual Version GetVersion()
97         {
98                 return Version(1,2,0,1,VF_VENDOR);
99         }
100         
101 };
102
103 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
104
105 class ModuleChgHostFactory : public ModuleFactory
106 {
107  public:
108         ModuleChgHostFactory()
109         {
110         }
111         
112         ~ModuleChgHostFactory()
113         {
114         }
115         
116         virtual Module * CreateModule(InspIRCd* Me)
117         {
118                 return new ModuleChgHost(Me);
119         }
120         
121 };
122
123
124 extern "C" void * init_module( void )
125 {
126         return new ModuleChgHostFactory;
127 }
128