]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_vhost.cpp
92aeb3401e2939b1a3bb97eab9d2e5742e60a3eb
[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
16 /* $ModDesc: Provides masking of user hostnames via traditional /VHOST command */
17
18 /** Handle /VHOST
19  */
20 class cmd_vhost : public Command
21 {
22  public:
23         cmd_vhost (InspIRCd* Instance) : Command(Instance,"VHOST", 0, 2)
24         {
25                 this->source = "m_vhost.so";
26                 syntax = "<username> <password>";
27         }
28
29         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
30         {
31                 ConfigReader *Conf = new ConfigReader(ServerInstance);
32
33                 for (int index = 0; index < Conf->Enumerate("vhost"); index++)
34                 {
35                         std::string mask = Conf->ReadValue("vhost","host",index);
36                         std::string username = Conf->ReadValue("vhost","user",index);
37                         std::string pass = Conf->ReadValue("vhost","pass",index);
38
39                         if ((!strcmp(parameters[0],username.c_str())) && (!strcmp(parameters[1],pass.c_str())))
40                         {
41                                 if (!mask.empty())
42                                 {
43                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your VHost: " + mask);
44                                         user->ChangeDisplayedHost(mask.c_str());
45                                         delete Conf;
46                                         return CMD_LOCALONLY;
47                                 }
48                         }
49                 }
50
51                 user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid username or password.");
52                 delete Conf;
53                 return CMD_FAILURE;
54         }
55 };
56
57 class ModuleVHost : public Module
58 {
59  private:
60
61         cmd_vhost* mycommand;
62          
63  public:
64         ModuleVHost(InspIRCd* Me) : Module(Me)
65         {
66                 mycommand = new cmd_vhost(ServerInstance);
67                 ServerInstance->AddCommand(mycommand);
68         }
69         
70         virtual ~ModuleVHost()
71         {
72         }
73
74         void Implements(char* List)
75         {
76         }
77
78         virtual Version GetVersion()
79         {
80                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
81         }
82         
83 };
84
85 MODULE_INIT(ModuleVHost)
86