]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_vhost.cpp
Tidy up strlens which are not required
[user/henk/code/inspircd.git] / src / modules / m_vhost.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18
19 #include <stdio.h>
20 #include "users.h"
21 #include "channels.h"
22 #include "modules.h"
23 #include "inspircd.h"
24
25 /* $ModDesc: Provides masking of user hostnames via traditional /VHOST command */
26
27 static ConfigReader *Conf;
28
29
30 class cmd_vhost : public command_t
31 {
32  public:
33  cmd_vhost (InspIRCd* Instance) : command_t(Instance,"VHOST", 0, 2)
34         {
35                 this->source = "m_vhost.so";
36                 syntax = "<username> <password>";
37         }
38
39         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
40         {
41                 for (int index = 0; index < Conf->Enumerate("vhost"); index++)
42                 {
43                         std::string mask = Conf->ReadValue("vhost","host",index);
44                         std::string username = Conf->ReadValue("vhost","user",index);
45                         std::string pass = Conf->ReadValue("vhost","pass",index);
46                         if ((!strcmp(parameters[0],username.c_str())) && (!strcmp(parameters[1],pass.c_str())))
47                         {
48                                 if (mask != "")
49                                 {
50                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your VHost: " + mask);
51                                         user->ChangeDisplayedHost(mask.c_str());
52                                         return CMD_FAILURE;
53                                 }
54                         }
55                 }
56                 user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid username or password.");
57                 return CMD_FAILURE;
58         }
59 };
60
61 class ModuleVHost : public Module
62 {
63  private:
64
65         cmd_vhost* mycommand;
66          
67  public:
68         ModuleVHost(InspIRCd* Me) : Module::Module(Me)
69         {
70                 
71                 Conf = new ConfigReader(ServerInstance);
72                 mycommand = new cmd_vhost(ServerInstance);
73                 ServerInstance->AddCommand(mycommand);
74         }
75         
76         virtual ~ModuleVHost()
77         {
78                 DELETE(Conf);
79         }
80
81         void Implements(char* List)
82         {
83                 List[I_OnRehash] = 1;
84         }
85
86         virtual void OnRehash(const std::string &parameter)
87         {
88                 DELETE(Conf);
89                 Conf = new ConfigReader(ServerInstance);
90         }
91         
92         virtual Version GetVersion()
93         {
94                 return Version(1,0,0,1,VF_VENDOR,API_VERSION);
95         }
96         
97 };
98
99 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
100
101 class ModuleVHostFactory : public ModuleFactory
102 {
103  public:
104         ModuleVHostFactory()
105         {
106         }
107         
108         ~ModuleVHostFactory()
109         {
110         }
111         
112         virtual Module * CreateModule(InspIRCd* Me)
113         {
114                 return new ModuleVHost(Me);
115         }
116         
117 };
118
119
120 extern "C" void * init_module( void )
121 {
122         return new ModuleVHostFactory;
123 }
124