]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_hostchange.cpp
I repeat, missing semicolons are bad
[user/henk/code/inspircd.git] / src / modules / m_hostchange.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
24 /* $ModDesc: Provides masking of user hostnames in a different way to m_cloaking */
25
26 class ModuleHostChange : public Module
27 {
28  private:
29
30         Server *Srv;
31         ConfigReader *Conf;
32         std::string MySuffix;
33          
34  public:
35         ModuleHostChange(Server* Me)
36                 : Module::Module(Me)
37         {
38                 Srv = Me;
39                 Conf = new ConfigReader;
40                 MySuffix = Conf->ReadValue("host","suffix",0);
41         }
42         
43         virtual ~ModuleHostChange()
44         {
45                 delete Conf;
46         }
47
48         Priority Prioritize()
49         {
50                 return (Priority)Srv->PriorityAfter("m_cloaking.so");
51         }
52
53         void Implements(char* List)
54         {
55                 List[I_OnRehash] = List[I_OnUserConnect] = 1;
56         }
57
58         virtual void OnRehash(std::string parameter)
59         {
60                 delete Conf;
61                 Conf = new ConfigReader;
62                 MySuffix = Conf->ReadValue("host","suffix",0);
63         }
64         
65         virtual Version GetVersion()
66         {
67                 // returns the version number of the module to be
68                 // listed in /MODULES
69                 return Version(1,0,0,1,VF_VENDOR);
70         }
71         
72         virtual void OnUserConnect(userrec* user)
73         {
74                 for (int index = 0; index < Conf->Enumerate("hostchange"); index++)
75                 {
76                         std::string mask = Conf->ReadValue("hostchange","mask",index);
77                         if (Srv->MatchText(std::string(user->ident)+"@"+std::string(user->host),mask))
78                         {
79                                 std::string newhost = "";
80                                 // host of new user matches a hostchange tag's mask
81                                 std::string action = Conf->ReadValue("hostchange","action",index);
82                                 if (action == "set")
83                                 {
84                                         newhost = Conf->ReadValue("hostchange","value",index);
85                                 }
86                                 else if (action == "suffix")
87                                 {
88                                         newhost = MySuffix;
89                                 }
90                                 else if (action == "addnick")
91                                 {
92                                         // first take their nick and strip out non-dns, leaving just [A-Z0-9\-]
93                                         std::string complete = "";
94                                         std::string old = user->nick;
95                                         for (unsigned int j = 0; j < old.length(); j++)
96                                         {
97                                                 if  (((old[j] >= 'A') && (old[j] <= 'Z')) ||
98                                                     ((old[j] >= 'a') && (old[j] <= 'z')) ||
99                                                     ((old[j] >= '0') && (old[j] <= '9')) ||
100                                                     (old[j] == '-'))
101                                                 {
102                                                         complete = complete + old[j];
103                                                 }
104                                         }
105                                         if (complete == "")
106                                                 complete = "i-have-a-lame-nick";
107                                         newhost = complete + "." + MySuffix;
108                                 }
109                                 if (newhost != "")
110                                 {
111                                         Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :Setting your VHost: " + newhost);
112                                         Srv->ChangeHost(user,newhost);
113                                         return;
114                                 }
115                         }
116                 }
117         }
118 };
119
120 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
121
122 class ModuleHostChangeFactory : public ModuleFactory
123 {
124  public:
125         ModuleHostChangeFactory()
126         {
127         }
128         
129         ~ModuleHostChangeFactory()
130         {
131         }
132         
133         virtual Module * CreateModule(Server* Me)
134         {
135                 return new ModuleHostChange(Me);
136         }
137         
138 };
139
140
141 extern "C" void * init_module( void )
142 {
143         return new ModuleHostChangeFactory;
144 }
145