]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_vhost.cpp
Note: FOR THE MOMENT, this is BROKEN. It wont run right until im done.
[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                 syntax = "<username> <password>";
37         }
38
39         void Handle (const char** parameters, int pcnt, userrec *user)
40         {
41                 for (int index = 0; index < Conf->Enumerate("vhost"); index++)
42                 {
43                         std::string mask = Conf->ReadValue("vhost","host",index);
44                         std::string username = Conf->ReadValue("vhost","user",index);
45                         std::string pass = Conf->ReadValue("vhost","pass",index);
46                         if ((!strcmp(parameters[0],username.c_str())) && (!strcmp(parameters[1],pass.c_str())))
47                         {
48                                 if (mask != "")
49                                 {
50                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your VHost: " + mask);
51                                         user->ChangeDisplayedHost(mask.c_str());
52                                         return;
53                                 }
54                         }
55                 }
56                 user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid username or password.");
57         }
58 };
59
60 class ModuleVHost : public Module
61 {
62  private:
63
64         cmd_vhost* mycommand;
65          
66  public:
67         ModuleVHost(InspIRCd* Me) : Module::Module(Me)
68         {
69                 
70                 Conf = new ConfigReader;
71                 mycommand = new cmd_vhost();
72                 Srv->AddCommand(mycommand);
73         }
74         
75         virtual ~ModuleVHost()
76         {
77                 DELETE(Conf);
78         }
79
80         void Implements(char* List)
81         {
82                 List[I_OnRehash] = 1;
83         }
84
85         virtual void OnRehash(const std::string &parameter)
86         {
87                 DELETE(Conf);
88                 Conf = new ConfigReader;
89         }
90         
91         virtual Version GetVersion()
92         {
93                 // returns the version number of the module to be
94                 // listed in /MODULES
95                 return Version(1,0,0,1,VF_VENDOR);
96         }
97         
98 };
99
100 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
101
102 class ModuleVHostFactory : public ModuleFactory
103 {
104  public:
105         ModuleVHostFactory()
106         {
107         }
108         
109         ~ModuleVHostFactory()
110         {
111         }
112         
113         virtual Module * CreateModule(InspIRCd* Me)
114         {
115                 return new ModuleVHost(Me);
116         }
117         
118 };
119
120
121 extern "C" void * init_module( void )
122 {
123         return new ModuleVHostFactory;
124 }
125