]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sethost.cpp
296c0788aecb5dfd665f212141b6fce14cfc48a9
[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                 if (strlen(parameters[0]) > 64)
44                 {
45                         user->WriteServ("NOTICE %s :*** SETHOST: Host too long",user->nick);
46                         return CMD_FAILURE;
47                 }
48                 for (unsigned int x = 0; x < strlen(parameters[0]); x++)
49                 {
50                         if (((tolower(parameters[0][x]) < 'a') || (tolower(parameters[0][x]) > 'z')) && (parameters[0][x] != '.'))
51                         {
52                                 if (((parameters[0][x] < '0') || (parameters[0][x]> '9')) && (parameters[0][x] != '-'))
53                                 {
54                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Invalid characters in hostname");
55                                         return CMD_FAILURE;
56                                 }
57                         }
58                 }
59                 if (user->ChangeDisplayedHost(parameters[0]))
60                 {
61                         ServerInstance->WriteOpers(std::string(user->nick)+" used SETHOST to change their displayed host to "+std::string(parameters[0]));
62                         return CMD_SUCCESS;
63                 }
64
65                 return CMD_FAILURE;
66         }
67 };
68
69
70 class ModuleSetHost : public Module
71 {
72         cmd_sethost*    mycommand;
73  public:
74         ModuleSetHost(InspIRCd* Me)
75                 : Module::Module(Me)
76         {
77                 
78                 mycommand = new cmd_sethost(ServerInstance);
79                 ServerInstance->AddCommand(mycommand);
80         }
81         
82         virtual ~ModuleSetHost()
83         {
84         }
85         
86         virtual Version GetVersion()
87         {
88                 return Version(1,0,0,1,VF_VENDOR);
89         }
90         
91 };
92
93 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
94
95 class ModuleSetHostFactory : public ModuleFactory
96 {
97  public:
98         ModuleSetHostFactory()
99         {
100         }
101         
102         ~ModuleSetHostFactory()
103         {
104         }
105         
106         virtual Module * CreateModule(InspIRCd* Me)
107         {
108                 return new ModuleSetHost(Me);
109         }
110         
111 };
112
113
114 extern "C" void * init_module( void )
115 {
116         return new ModuleSetHostFactory;
117 }
118