]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_vhost.cpp
Not required
[user/henk/code/inspircd.git] / src / modules / m_vhost.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 "users.h"
21 #include "channels.h"
22 #include "modules.h"
23
24 /* $ModDesc: Provides masking of user hostnames via traditional /VHOST command */
25
26 static ConfigReader *Conf;
27 static Server* Srv;
28
29 class cmd_vhost : public command_t
30 {
31  public:
32         cmd_vhost() : command_t("VHOST", 0, 2)
33         {
34                 this->source = "m_vhost.so";
35         }
36
37         void Handle (char **parameters, int pcnt, userrec *user)
38         {
39                 for (int index = 0; index < Conf->Enumerate("vhost"); index++)
40                 {
41                         std::string mask = Conf->ReadValue("vhost","host",index);
42                         std::string username = Conf->ReadValue("vhost","user",index);
43                         std::string pass = Conf->ReadValue("vhost","pass",index);
44                         if ((!strcmp(parameters[0],username.c_str())) && (!strcmp(parameters[1],pass.c_str())))
45                         {
46                                 if (mask != "")
47                                 {
48                                         Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :Setting your VHost: " + mask);
49                                         Srv->ChangeHost(user,mask);
50                                         return;
51                                 }
52                         }
53                 }
54                 Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :Invalid username or password.");
55         }
56 };
57
58 class ModuleVHost : public Module
59 {
60  private:
61
62         cmd_vhost* mycommand;
63          
64  public:
65         ModuleVHost(Server* Me) : Module::Module(Me)
66         {
67                 Srv = Me;
68                 Conf = new ConfigReader;
69                 mycommand = new cmd_vhost();
70                 Srv->AddCommand(mycommand);
71         }
72         
73         virtual ~ModuleVHost()
74         {
75                 delete Conf;
76         }
77
78         void Implements(char* List)
79         {
80                 List[I_OnRehash] = 1;
81         }
82
83         virtual void OnRehash(const std::string &parameter)
84         {
85                 delete Conf;
86                 Conf = new ConfigReader;
87         }
88         
89         virtual Version GetVersion()
90         {
91                 // returns the version number of the module to be
92                 // listed in /MODULES
93                 return Version(1,0,0,1,VF_VENDOR);
94         }
95         
96 };
97
98 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
99
100 class ModuleVHostFactory : public ModuleFactory
101 {
102  public:
103         ModuleVHostFactory()
104         {
105         }
106         
107         ~ModuleVHostFactory()
108         {
109         }
110         
111         virtual Module * CreateModule(Server* Me)
112         {
113                 return new ModuleVHost(Me);
114         }
115         
116 };
117
118
119 extern "C" void * init_module( void )
120 {
121         return new ModuleVHostFactory;
122 }
123