]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_vhost.cpp
233def0b6de359cacd298a6df9eebee0c946e1cb
[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
29 /** Handle /VHOST
30  */
31 class cmd_vhost : public command_t
32 {
33  public:
34         cmd_vhost (InspIRCd* Instance) : command_t(Instance,"VHOST", 0, 2)
35         {
36                 this->source = "m_vhost.so";
37                 syntax = "<username> <password>";
38         }
39
40         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
41         {
42                 for (int index = 0; index < Conf->Enumerate("vhost"); index++)
43                 {
44                         std::string mask = Conf->ReadValue("vhost","host",index);
45                         std::string username = Conf->ReadValue("vhost","user",index);
46                         std::string pass = Conf->ReadValue("vhost","pass",index);
47                         if ((!strcmp(parameters[0],username.c_str())) && (!strcmp(parameters[1],pass.c_str())))
48                         {
49                                 if (mask != "")
50                                 {
51                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your VHost: " + mask);
52                                         user->ChangeDisplayedHost(mask.c_str());
53                                         return CMD_FAILURE;
54                                 }
55                         }
56                 }
57                 user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid username or password.");
58                 return CMD_FAILURE;
59         }
60 };
61
62 class ModuleVHost : public Module
63 {
64  private:
65
66         cmd_vhost* mycommand;
67          
68  public:
69         ModuleVHost(InspIRCd* Me) : Module::Module(Me)
70         {
71                 
72                 Conf = new ConfigReader(ServerInstance);
73                 mycommand = new cmd_vhost(ServerInstance);
74                 ServerInstance->AddCommand(mycommand);
75         }
76         
77         virtual ~ModuleVHost()
78         {
79                 DELETE(Conf);
80         }
81
82         void Implements(char* List)
83         {
84                 List[I_OnRehash] = 1;
85         }
86
87         virtual void OnRehash(const std::string &parameter)
88         {
89                 DELETE(Conf);
90                 Conf = new ConfigReader(ServerInstance);
91         }
92         
93         virtual Version GetVersion()
94         {
95                 return Version(1,0,0,1,VF_VENDOR,API_VERSION);
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