]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sethost.cpp
Removed a pointless check in ./configure --clean that made it only work with one...
[user/henk/code/inspircd.git] / src / modules / m_sethost.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 SETHOST command */
23
24 /** Handle /SETHOST
25  */
26 class cmd_sethost : public command_t
27 {
28  public:
29         cmd_sethost (InspIRCd* Instance) : command_t(Instance,"SETHOST",'o',1)
30         {
31                 this->source = "m_sethost.so";
32                 syntax = "<new-hostname>";
33         }
34
35         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
36         {
37                 size_t len = 0;
38                 for (const char* x = parameters[0]; *x; x++, len++)
39                 {
40                         if (((tolower(*x) < 'a') || (tolower(*x) > 'z')) && (*x != '.'))
41                         {
42                                 if (((*x < '0') || (*x> '9')) && (*x != '-'))
43                                 {
44                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Invalid characters in hostname");
45                                         return CMD_FAILURE;
46                                 }
47                         }
48                 }
49                 if (len > 64)
50                 {
51                         user->WriteServ("NOTICE %s :*** SETHOST: Host too long",user->nick);
52                         return CMD_FAILURE;
53                 }
54                 if (user->ChangeDisplayedHost(parameters[0]))
55                 {
56                         ServerInstance->WriteOpers(std::string(user->nick)+" used SETHOST to change their displayed host to "+user->dhost);
57                         return CMD_SUCCESS;
58                 }
59
60                 return CMD_FAILURE;
61         }
62 };
63
64
65 class ModuleSetHost : public Module
66 {
67         cmd_sethost*    mycommand;
68  public:
69         ModuleSetHost(InspIRCd* Me)
70                 : Module::Module(Me)
71         {
72                 
73                 mycommand = new cmd_sethost(ServerInstance);
74                 ServerInstance->AddCommand(mycommand);
75         }
76         
77         virtual ~ModuleSetHost()
78         {
79         }
80         
81         virtual Version GetVersion()
82         {
83                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
84         }
85         
86 };
87
88 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
89
90 class ModuleSetHostFactory : public ModuleFactory
91 {
92  public:
93         ModuleSetHostFactory()
94         {
95         }
96         
97         ~ModuleSetHostFactory()
98         {
99         }
100         
101         virtual Module * CreateModule(InspIRCd* Me)
102         {
103                 return new ModuleSetHost(Me);
104         }
105         
106 };
107
108
109 extern "C" void * init_module( void )
110 {
111         return new ModuleSetHostFactory;
112 }
113