]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_vhost.cpp
Test for Craig
[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)
66                 : 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(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