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