]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_vhost.cpp
Windows support. Tested and working to compile on freebsd and linux. Next step is...
[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 <stdio.h>
15 #include "users.h"
16 #include "channels.h"
17 #include "modules.h"
18 #include "inspircd.h"
19
20 /* $ModDesc: Provides masking of user hostnames via traditional /VHOST command */
21
22 static ConfigReader* Conf;
23
24 /** Handle /VHOST
25  */
26 class cmd_vhost : public command_t
27 {
28  public:
29         cmd_vhost (InspIRCd* Instance) : command_t(Instance,"VHOST", 0, 2)
30         {
31                 this->source = "m_vhost.so";
32                 syntax = "<username> <password>";
33         }
34
35         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
36         {
37                 for (int index = 0; index < Conf->Enumerate("vhost"); index++)
38                 {
39                         std::string mask = Conf->ReadValue("vhost","host",index);
40                         std::string username = Conf->ReadValue("vhost","user",index);
41                         std::string pass = Conf->ReadValue("vhost","pass",index);
42                         if ((!strcmp(parameters[0],username.c_str())) && (!strcmp(parameters[1],pass.c_str())))
43                         {
44                                 if (mask != "")
45                                 {
46                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your VHost: " + mask);
47                                         user->ChangeDisplayedHost(mask.c_str());
48                                         return CMD_FAILURE;
49                                 }
50                         }
51                 }
52                 user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid username or password.");
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                 
67                 Conf = new ConfigReader(ServerInstance);
68                 mycommand = new cmd_vhost(ServerInstance);
69                 ServerInstance->AddCommand(mycommand);
70         }
71         
72         virtual ~ModuleVHost()
73         {
74                 DELETE(Conf);
75         }
76
77         void Implements(char* List)
78         {
79                 List[I_OnRehash] = 1;
80         }
81
82         virtual void OnRehash(userrec* user, const std::string &parameter)
83         {
84                 DELETE(Conf);
85                 Conf = new ConfigReader(ServerInstance);
86         }
87         
88         virtual Version GetVersion()
89         {
90                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
91         }
92         
93 };
94
95 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
96
97 class ModuleVHostFactory : public ModuleFactory
98 {
99  public:
100         ModuleVHostFactory()
101         {
102         }
103         
104         ~ModuleVHostFactory()
105         {
106         }
107         
108         virtual Module * CreateModule(InspIRCd* Me)
109         {
110                 return new ModuleVHost(Me);
111         }
112         
113 };
114
115
116 extern "C" DllExport void * init_module( void )
117 {
118         return new ModuleVHostFactory;
119 }
120