]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chghost.cpp
8cfc515cd77032ca8b8739e216c4bd356d972396
[user/henk/code/inspircd.git] / src / modules / m_chghost.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 CHGHOST command */
27
28 static Server *Srv;
29
30 class cmd_chghost : public command_t
31 {
32  public:
33          cmd_chghost () : command_t("CHGHOST",'o',2)
34          {
35                  this->source = "m_chghost.so";
36          }
37          
38         void Handle(char **parameters, int pcnt, userrec *user)
39         {
40                 if (strlen(parameters[1]) > 64)
41                 {
42                         WriteServ(user->fd,"NOTICE %s :*** CHGHOST: Host too long",user->nick);
43                         return;
44                 }
45                 for (unsigned int x = 0; x < strlen(parameters[1]); x++)
46                 {
47                         if (((tolower(parameters[1][x]) < 'a') || (tolower(parameters[1][x]) > 'z')) && (parameters[1][x] != '.'))
48                         {
49                                 if (((parameters[1][x] < '0') || (parameters[1][x]> '9')) && (parameters[1][x] != '-'))
50                                 {
51                                         Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** Invalid characters in hostname");
52                                         return;
53                                 }
54                         }
55                 }       
56                 userrec* dest = Srv->FindNick(std::string(parameters[0]));
57                 if (dest)
58                 {
59                         Srv->ChangeHost(dest,parameters[1]);
60                         if (!Srv->IsUlined(user->server))
61                         {
62                                 // fix by brain - ulines set hosts silently
63                                 Srv->SendOpers(std::string(user->nick)+" used CHGHOST to make the displayed host of "+std::string(dest->nick)+" become "+std::string(parameters[1]));
64                         }
65                 }
66         }
67 };
68
69
70 class ModuleChgHost : public Module
71 {
72         cmd_chghost* mycommand;
73  public:
74         ModuleChgHost(Server* Me)
75                 : Module::Module(Me)
76         {
77                 Srv = Me;
78                 mycommand = new cmd_chghost();
79                 Srv->AddCommand(mycommand);
80         }
81
82         void Implements(char* List)
83         {
84         }
85         
86         virtual ~ModuleChgHost()
87         {
88         }
89         
90         virtual Version GetVersion()
91         {
92                 return Version(1,2,0,1,VF_VENDOR);
93         }
94         
95 };
96
97 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
98
99 class ModuleChgHostFactory : public ModuleFactory
100 {
101  public:
102         ModuleChgHostFactory()
103         {
104         }
105         
106         ~ModuleChgHostFactory()
107         {
108         }
109         
110         virtual Module * CreateModule(Server* Me)
111         {
112                 return new ModuleChgHost(Me);
113         }
114         
115 };
116
117
118 extern "C" void * init_module( void )
119 {
120         return new ModuleChgHostFactory;
121 }
122