]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_vhost.cpp
Fix potential for duplicate SID if the SID is auto generated.
[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 static ConfigReader* Conf;
19
20 /** Handle /VHOST
21  */
22 class cmd_vhost : public command_t
23 {
24  public:
25         cmd_vhost (InspIRCd* Instance) : command_t(Instance,"VHOST", 0, 2)
26         {
27                 this->source = "m_vhost.so";
28                 syntax = "<username> <password>";
29         }
30
31         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
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                                         return CMD_LOCALONLY;
46                                 }
47                         }
48                 }
49
50                 user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid username or password.");
51                 return CMD_FAILURE;
52         }
53 };
54
55 class ModuleVHost : public Module
56 {
57  private:
58
59         cmd_vhost* mycommand;
60          
61  public:
62         ModuleVHost(InspIRCd* Me) : Module(Me)
63         {
64                 
65                 Conf = new ConfigReader(ServerInstance);
66                 mycommand = new cmd_vhost(ServerInstance);
67                 ServerInstance->AddCommand(mycommand);
68         }
69         
70         virtual ~ModuleVHost()
71         {
72                 DELETE(Conf);
73         }
74
75         void Implements(char* List)
76         {
77                 List[I_OnRehash] = 1;
78         }
79
80         virtual void OnRehash(userrec* user, const std::string &parameter)
81         {
82                 DELETE(Conf);
83                 Conf = new ConfigReader(ServerInstance);
84         }
85         
86         virtual Version GetVersion()
87         {
88                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
89         }
90         
91 };
92
93 MODULE_INIT(ModuleVHost)
94