]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sethost.cpp
Tidy up strlens which are not required
[user/henk/code/inspircd.git] / src / modules / m_sethost.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 SETHOST command */
28
29
30
31
32 class cmd_sethost : public command_t
33 {
34  public:
35         cmd_sethost (InspIRCd* Instance) : command_t(Instance,"SETHOST",'o',1)
36         {
37                 this->source = "m_sethost.so";
38                 syntax = "<new-hostname>";
39         }
40
41         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
42         {
43                 size_t len = 0;
44                 for (const char* x = parameters[0]; *x; x++, len++)
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 (len > 64)
56                 {
57                         user->WriteServ("NOTICE %s :*** SETHOST: Host too long",user->nick);
58                         return CMD_FAILURE;
59                 }
60                 if (user->ChangeDisplayedHost(parameters[0]))
61                 {
62                         ServerInstance->WriteOpers(std::string(user->nick)+" used SETHOST to change their displayed host to "+user->dhost);
63                         return CMD_SUCCESS;
64                 }
65
66                 return CMD_FAILURE;
67         }
68 };
69
70
71 class ModuleSetHost : public Module
72 {
73         cmd_sethost*    mycommand;
74  public:
75         ModuleSetHost(InspIRCd* Me)
76                 : Module::Module(Me)
77         {
78                 
79                 mycommand = new cmd_sethost(ServerInstance);
80                 ServerInstance->AddCommand(mycommand);
81         }
82         
83         virtual ~ModuleSetHost()
84         {
85         }
86         
87         virtual Version GetVersion()
88         {
89                 return Version(1,0,0,1,VF_VENDOR,API_VERSION);
90         }
91         
92 };
93
94 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
95
96 class ModuleSetHostFactory : public ModuleFactory
97 {
98  public:
99         ModuleSetHostFactory()
100         {
101         }
102         
103         ~ModuleSetHostFactory()
104         {
105         }
106         
107         virtual Module * CreateModule(InspIRCd* Me)
108         {
109                 return new ModuleSetHost(Me);
110         }
111         
112 };
113
114
115 extern "C" void * init_module( void )
116 {
117         return new ModuleSetHostFactory;
118 }
119