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