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