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