summaryrefslogtreecommitdiff
path: root/src/modules/m_cloaking.cpp
blob: c9fe717663cac051adf0da46c10a6d485d85e96a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <stdio.h>

#include "users.h"
#include "channels.h"
#include "modules.h"

/* $ModDesc: Provides masking of user hostnames */

class ModuleCloaking : public Module
{
 private:

	 Server *Srv;
	 
 public:
	ModuleCloaking()
	{
		Srv = new Server;
		
		// doesn't require oper, client umode with no params
		// (actually, you cant have params for a umode!)
		if (!Srv->AddExtendedMode('x',MT_CLIENT,false,0,0))
		{
			Srv->Log(DEFAULT,"*** m_cloaking: ERROR, failed to allocate user mode +x!");
			printf("Could not claim usermode +x for this module!");
			exit(0);
		}
	}
	
	virtual ~ModuleCloaking()
	{
		delete Srv;
	}
	
	virtual Version GetVersion()
	{
		return Version(1,0,0,1);
	}
	
	virtual bool OnExtendedMode(userrec* user, chanrec* chan, char modechar, int type, bool mode_on, string_list &params)
	{
		Srv->Log(DEBUG,"in mode handler");
		if ((modechar == 'x') && (type == MT_CLIENT))
  		{
			Srv->Log(DEBUG,"this is my mode!");
			if (mode_on)
			{
				Srv->Log(DEBUG,"mode being turned on");
				if (strstr(user->host,"."))
				{
					std::string a = strstr(user->host,".");
					char ra[64];
					long seed,s2;
					memcpy(&seed,user->host,sizeof(long));
					memcpy(&s2,a.c_str(),sizeof(long));
					sprintf(ra,"%.8X",seed*s2*strlen(user->host));
					std::string b = Srv->GetNetworkName() + "-" + ra + a;
					Srv->Log(DEBUG,"cloak: allocated "+b);
					strcpy(user->dhost,b.c_str());
				}
			}
			else
  			{
				Srv->Log(DEBUG,"cloak: de-allocated cloak");
  				strcpy(user->dhost,user->host);
			}
			return 1;
		}
		else
		{
			// this mode isn't ours, we have to bail and return 0 to not handle it.
			Srv->Log(DEBUG,"not my mode");
			return 0;
		}
	}

	virtual void OnUserConnect(userrec* user)
	{
		Srv->Log(DEBUG,"Sending SAMODE +x for user");
		char* modes[2];
		modes[0] = user->nick;
		modes[1] = "+x";
		Srv->SendMode(modes,2,user);
		Srv->Log(DEBUG,"Sent SAMODE +x for user");
	}

};


class ModuleCloakingFactory : public ModuleFactory
{
 public:
	ModuleCloakingFactory()
	{
	}
	
	~ModuleCloakingFactory()
	{
	}
	
	virtual Module * CreateModule()
	{
		return new ModuleCloaking;
	}
	
};


extern "C" void * init_module( void )
{
	return new ModuleCloakingFactory;
}