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