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