]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sethost.cpp
3803c716c0fac06c829b40e325304058997ceaaa
[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 #include "helperfuncs.h"
25 #include "inspircd.h"
26
27 /* $ModDesc: Provides support for the SETHOST command */
28
29
30 extern InspIRCd* ServerInstance;
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         void 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;
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;
56                                 }
57                         }
58                 }
59                 if (user->ChangeDisplayedHost(parameters[0]))
60                         ServerInstance->WriteOpers(std::string(user->nick)+" used SETHOST to change their displayed host to "+std::string(parameters[0]));
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,0,0,1,VF_VENDOR);
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