]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_vhost.cpp
3ce910456bdde89c1acdb251094bf7a425531bcd
[user/henk/code/inspircd.git] / src / modules / m_vhost.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "users.h"
16 #include "channels.h"
17 #include "modules.h"
18
19 /* $ModDesc: Provides masking of user hostnames via traditional /VHOST command */
20
21 static ConfigReader* Conf;
22
23 /** Handle /VHOST
24  */
25 class cmd_vhost : public command_t
26 {
27  public:
28         cmd_vhost (InspIRCd* Instance) : command_t(Instance,"VHOST", 0, 2)
29         {
30                 this->source = "m_vhost.so";
31                 syntax = "<username> <password>";
32         }
33
34         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
35         {
36                 for (int index = 0; index < Conf->Enumerate("vhost"); index++)
37                 {
38                         std::string mask = Conf->ReadValue("vhost","host",index);
39                         std::string username = Conf->ReadValue("vhost","user",index);
40                         std::string pass = Conf->ReadValue("vhost","pass",index);
41
42                         if ((!strcmp(parameters[0],username.c_str())) && (!strcmp(parameters[1],pass.c_str())))
43                         {
44                                 if (!mask.empty())
45                                 {
46                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your VHost: " + mask);
47                                         user->ChangeDisplayedHost(mask.c_str());
48                                         return CMD_LOCALONLY;
49                                 }
50                         }
51                 }
52
53                 user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid username or password.");
54                 return CMD_FAILURE;
55         }
56 };
57
58 class ModuleVHost : public Module
59 {
60  private:
61
62         cmd_vhost* mycommand;
63          
64  public:
65         ModuleVHost(InspIRCd* Me) : Module(Me)
66         {
67                 
68                 Conf = new ConfigReader(ServerInstance);
69                 mycommand = new cmd_vhost(ServerInstance);
70                 ServerInstance->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(userrec* user, const std::string &parameter)
84         {
85                 DELETE(Conf);
86                 Conf = new ConfigReader(ServerInstance);
87         }
88         
89         virtual Version GetVersion()
90         {
91                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
92         }
93         
94 };
95
96 MODULE_INIT(ModuleVHost)
97