]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_vhost.cpp
and a little tweak to remote MOTD too.
[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                         if ((!strcmp(parameters[0],username.c_str())) && (!strcmp(parameters[1],pass.c_str())))
42                         {
43                                 if (mask != "")
44                                 {
45                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your VHost: " + mask);
46                                         user->ChangeDisplayedHost(mask.c_str());
47                                         return CMD_FAILURE;
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
60         cmd_vhost* mycommand;
61          
62  public:
63         ModuleVHost(InspIRCd* Me) : Module(Me)
64         {
65                 
66                 Conf = new ConfigReader(ServerInstance);
67                 mycommand = new cmd_vhost(ServerInstance);
68                 ServerInstance->AddCommand(mycommand);
69         }
70         
71         virtual ~ModuleVHost()
72         {
73                 DELETE(Conf);
74         }
75
76         void Implements(char* List)
77         {
78                 List[I_OnRehash] = 1;
79         }
80
81         virtual void OnRehash(userrec* user, const std::string &parameter)
82         {
83                 DELETE(Conf);
84                 Conf = new ConfigReader(ServerInstance);
85         }
86         
87         virtual Version GetVersion()
88         {
89                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
90         }
91         
92 };
93
94 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
95
96 class ModuleVHostFactory : public ModuleFactory
97 {
98  public:
99         ModuleVHostFactory()
100         {
101         }
102         
103         ~ModuleVHostFactory()
104         {
105         }
106         
107         virtual Module * CreateModule(InspIRCd* Me)
108         {
109                 return new ModuleVHost(Me);
110         }
111         
112 };
113
114
115 extern "C" DllExport void * init_module( void )
116 {
117         return new ModuleVHostFactory;
118 }
119