]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chghost.cpp
6a5845e72efab1748ec35035f38d28ff72f99e4d
[user/henk/code/inspircd.git] / src / modules / m_chghost.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 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
25 /* $ModDesc: Provides support for the CHGHOST command */
26
27 Server *Srv;
28          
29 void handle_chghost(char **parameters, int pcnt, userrec *user)
30 {
31         for (unsigned int x = 0; x < strlen(parameters[1]); x++)
32         {
33                 if (((tolower(parameters[1][x]) < 'a') || (tolower(parameters[1][x]) > 'z')) && (parameters[1][x] != '.'))
34                 {
35                         if (((parameters[1][x] < '0') || (parameters[1][x]> '9')) && (parameters[1][x] != '-'))
36                         {
37                                 Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** Invalid characters in hostname");
38                                 return;
39                         }
40                 }
41         }       userrec* dest = Srv->FindNick(std::string(parameters[0]));
42         if (dest)
43         {
44                 Srv->ChangeHost(dest,parameters[1]);
45                 if (!Srv->IsUlined(user->server))
46                 {
47                         // fix by brain - ulines set hosts silently
48                         Srv->SendOpers(std::string(user->nick)+" used CHGHOST to make the displayed host of "+std::string(dest->nick)+" become "+std::string(parameters[1]));
49                 }
50         }
51 }
52
53
54 class ModuleChgHost : public Module
55 {
56  public:
57         ModuleChgHost(Server* Me)
58                 : Module::Module(Me)
59         {
60                 Srv = Me;
61                 Srv->AddCommand("CHGHOST",handle_chghost,'o',2,"m_chghost.so");
62         }
63         
64         virtual ~ModuleChgHost()
65         {
66         }
67         
68         virtual Version GetVersion()
69         {
70                 return Version(1,0,0,1,VF_VENDOR);
71         }
72         
73 };
74
75 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
76
77 class ModuleChgHostFactory : public ModuleFactory
78 {
79  public:
80         ModuleChgHostFactory()
81         {
82         }
83         
84         ~ModuleChgHostFactory()
85         {
86         }
87         
88         virtual Module * CreateModule(Server* Me)
89         {
90                 return new ModuleChgHost(Me);
91         }
92         
93 };
94
95
96 extern "C" void * init_module( void )
97 {
98         return new ModuleChgHostFactory;
99 }
100