]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_cloaking.cpp
c9fe717663cac051adf0da46c10a6d485d85e96a
[user/henk/code/inspircd.git] / src / modules / m_cloaking.cpp
1 #include <stdio.h>
2
3 #include "users.h"
4 #include "channels.h"
5 #include "modules.h"
6
7 /* $ModDesc: Provides masking of user hostnames */
8
9 class ModuleCloaking : public Module
10 {
11  private:
12
13          Server *Srv;
14          
15  public:
16         ModuleCloaking()
17         {
18                 Srv = new Server;
19                 
20                 // doesn't require oper, client umode with no params
21                 // (actually, you cant have params for a umode!)
22                 if (!Srv->AddExtendedMode('x',MT_CLIENT,false,0,0))
23                 {
24                         Srv->Log(DEFAULT,"*** m_cloaking: ERROR, failed to allocate user mode +x!");
25                         printf("Could not claim usermode +x for this module!");
26                         exit(0);
27                 }
28         }
29         
30         virtual ~ModuleCloaking()
31         {
32                 delete Srv;
33         }
34         
35         virtual Version GetVersion()
36         {
37                 return Version(1,0,0,1);
38         }
39         
40         virtual bool OnExtendedMode(userrec* user, chanrec* chan, char modechar, int type, bool mode_on, string_list &params)
41         {
42                 Srv->Log(DEBUG,"in mode handler");
43                 if ((modechar == 'x') && (type == MT_CLIENT))
44                 {
45                         Srv->Log(DEBUG,"this is my mode!");
46                         if (mode_on)
47                         {
48                                 Srv->Log(DEBUG,"mode being turned on");
49                                 if (strstr(user->host,"."))
50                                 {
51                                         std::string a = strstr(user->host,".");
52                                         char ra[64];
53                                         long seed,s2;
54                                         memcpy(&seed,user->host,sizeof(long));
55                                         memcpy(&s2,a.c_str(),sizeof(long));
56                                         sprintf(ra,"%.8X",seed*s2*strlen(user->host));
57                                         std::string b = Srv->GetNetworkName() + "-" + ra + a;
58                                         Srv->Log(DEBUG,"cloak: allocated "+b);
59                                         strcpy(user->dhost,b.c_str());
60                                 }
61                         }
62                         else
63                         {
64                                 Srv->Log(DEBUG,"cloak: de-allocated cloak");
65                                 strcpy(user->dhost,user->host);
66                         }
67                         return 1;
68                 }
69                 else
70                 {
71                         // this mode isn't ours, we have to bail and return 0 to not handle it.
72                         Srv->Log(DEBUG,"not my mode");
73                         return 0;
74                 }
75         }
76
77         virtual void OnUserConnect(userrec* user)
78         {
79                 Srv->Log(DEBUG,"Sending SAMODE +x for user");
80                 char* modes[2];
81                 modes[0] = user->nick;
82                 modes[1] = "+x";
83                 Srv->SendMode(modes,2,user);
84                 Srv->Log(DEBUG,"Sent SAMODE +x for user");
85         }
86
87 };
88
89
90 class ModuleCloakingFactory : public ModuleFactory
91 {
92  public:
93         ModuleCloakingFactory()
94         {
95         }
96         
97         ~ModuleCloakingFactory()
98         {
99         }
100         
101         virtual Module * CreateModule()
102         {
103                 return new ModuleCloaking;
104         }
105         
106 };
107
108
109 extern "C" void * init_module( void )
110 {
111         return new ModuleCloakingFactory;
112 }
113