]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sethost.cpp
Abstracted host/gecos changing to Server:: methods
[user/henk/code/inspircd.git] / src / modules / m_sethost.cpp
1 /*
2  *  SETHOST module for InspIRCD
3  *  Author: brain
4  *  Version: 1.0.0.0
5  *
6  *  Syntax: /SETHOST [new host]
7  *  Changes the user's DHOST who issues the command
8  *  (oper only)
9  *  
10  */
11
12 #include <stdio.h>
13 #include <string>
14 #include "users.h"
15 #include "channels.h"
16 #include "modules.h"
17
18 /* $ModDesc: Provides support for the SETHOST command */
19
20 Server *Srv;
21          
22 void handle_sethost(char **parameters, int pcnt, userrec *user)
23 {
24         for (int x = 0; x < strlen(parameters[0]); x++)
25         {
26                 if (((tolower(parameters[0][x]) < 'a') || (tolower(parameters[0][x]) > 'z')) && (parameters[0][x] != '.'))
27                 {
28                         if (((parameters[0][x] < '0') || (parameters[0][x]> '9')) && (parameters[0][x] != '-'))
29                         {
30                                 Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** Invalid characters in hostname");
31                                 return;
32                         }
33                 }
34         }
35         Srv->ChangeHost(user,parameters[0]);
36         Srv->SendOpers(std::string(user->nick)+" used SETHOST to change their displayed host to "+std::string(parameters[0]));
37 }
38
39
40 class ModuleSetHost : public Module
41 {
42  public:
43         ModuleSetHost()
44         {
45                 Srv = new Server;
46                 Srv->AddCommand("SETHOST",handle_sethost,'o',1);
47         }
48         
49         virtual ~ModuleSetHost()
50         {
51                 delete Srv;
52         }
53         
54         virtual Version GetVersion()
55         {
56                 return Version(1,0,0,0);
57         }
58         
59 };
60
61 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
62
63 class ModuleSetHostFactory : public ModuleFactory
64 {
65  public:
66         ModuleSetHostFactory()
67         {
68         }
69         
70         ~ModuleSetHostFactory()
71         {
72         }
73         
74         virtual Module * CreateModule()
75         {
76                 return new ModuleSetHost;
77         }
78         
79 };
80
81
82 extern "C" void * init_module( void )
83 {
84         return new ModuleSetHostFactory;
85 }
86