]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_vhost.cpp
fixed some indentation and spacing in modules
[user/henk/code/inspircd.git] / src / modules / m_vhost.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 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 CommandVhost : public Command
21 {
22  public:
23         CommandVhost (InspIRCd* Instance) : Command(Instance,"VHOST", 0, 2)
24         {
25                 this->source = "m_vhost.so";
26                 syntax = "<username> <password>";
27         }
28
29         CmdResult Handle (const std::vector<std::string> &parameters, User *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                         std::string hash = Conf->ReadValue("vhost","hash",index);
39
40                         if ((!strcmp(parameters[0].c_str(),username.c_str())) && !ServerInstance->PassCompare(user, pass.c_str(), parameters[1].c_str(), hash.c_str()))
41                         {
42                                 if (!mask.empty())
43                                 {
44                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your VHost: " + mask);
45                                         user->ChangeDisplayedHost(mask.c_str());
46                                         delete Conf;
47                                         return CMD_LOCALONLY;
48                                 }
49                         }
50                 }
51
52                 user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid username or password.");
53                 delete Conf;
54                 return CMD_FAILURE;
55         }
56 };
57
58 class ModuleVHost : public Module
59 {
60  private:
61
62         CommandVhost* mycommand;
63
64  public:
65         ModuleVHost(InspIRCd* Me) : Module(Me)
66         {
67                 mycommand = new CommandVhost(ServerInstance);
68                 ServerInstance->AddCommand(mycommand);
69
70         }
71
72         virtual ~ModuleVHost()
73         {
74         }
75
76
77         virtual Version GetVersion()
78         {
79                 return Version(1,2,0,1,VF_VENDOR,API_VERSION);
80         }
81
82 };
83
84 MODULE_INIT(ModuleVHost)
85