]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_vhost.cpp
Remove VF_SERVICEPROVIDER, prevent heap allocation of ConfigReader
[user/henk/code/inspircd.git] / src / modules / m_vhost.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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 CommandVhost : public Command
21 {
22  public:
23         CommandVhost(Module* Creator) : Command(Creator,"VHOST", 2)
24         {
25                 syntax = "<username> <password>";
26         }
27
28         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
29         {
30                 for (int index = 0;; index++)
31                 {
32                         ConfigTag* tag = ServerInstance->Config->ConfValue("vhost", index);
33                         if (!tag)
34                                 break;
35                         std::string mask = tag->getString("host");
36                         std::string username = tag->getString("user");
37                         std::string pass = tag->getString("pass");
38                         std::string hash = tag->getString("hash");
39
40                         if (parameters[0] == username && !ServerInstance->PassCompare(user, pass, parameters[1], hash))
41                         {
42                                 if (!mask.empty())
43                                 {
44                                         user->WriteServ("NOTICE "+user->nick+" :Setting your VHost: " + mask);
45                                         user->ChangeDisplayedHost(mask.c_str());
46                                         return CMD_SUCCESS;
47                                 }
48                         }
49                 }
50
51                 user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid username or password.");
52                 return CMD_FAILURE;
53         }
54 };
55
56 class ModuleVHost : public Module
57 {
58  private:
59         CommandVhost cmd;
60
61  public:
62         ModuleVHost() : cmd(this)
63         {
64                 ServerInstance->AddCommand(&cmd);
65         }
66
67         virtual ~ModuleVHost()
68         {
69         }
70
71
72         virtual Version GetVersion()
73         {
74                 return Version("Provides masking of user hostnames via traditional /VHOST command",VF_VENDOR);
75         }
76
77 };
78
79 MODULE_INIT(ModuleVHost)
80