]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_globops.cpp
ec008c437a9d3923e3170387c93206d14976e02b
[user/henk/code/inspircd.git] / src / modules / m_globops.cpp
1 // Hostname cloaking (+x mode) module for inspircd.
2 // version 1.0.0.1 by brain (C. J. Edwards) Mar 2004.
3 //
4 // When loaded this module will automatically set the
5 // +x mode on all connecting clients.
6 //
7 // Setting +x on a client causes the module to change the
8 // dhost entry (displayed host) for each user who has the
9 // mode, cloaking their host. Unlike unreal, the algorithm
10 // is non-reversible as uncloaked hosts are passed along
11 // the server->server link, and all encoding of hosts is
12 // done locally on the server by this module.
13
14 #include <stdio.h>
15 #include <string>
16 #include "users.h"
17 #include "channels.h"
18 #include "modules.h"
19
20 /* $ModDesc: Provides masking of user hostnames */
21
22 Server *Srv;
23          
24 void handle_globops(char **parameters, int pcnt, userrec *user)
25 {
26         std::string line = "";
27         for (int i = 0; i < pcnt; i++)
28         {
29                 line = line + string(parameters[i]) + " ";
30         }
31         Srv->SendToModeMask("g",WM_OR,line);
32 }
33
34
35 class ModuleGlobops : public Module
36 {
37  public:
38         ModuleGlobops()
39         {
40                 Srv = new Server;
41                 
42                 if (!Srv->AddExtendedMode('g',MT_CLIENT,true,0,0))
43                 {
44                         Srv->Log(DEFAULT,"*** m_globops: ERROR, failed to allocate user mode +g!");
45                         printf("Could not claim usermode +g for this module!");
46                         exit(0);
47                 }
48                 Srv->AddCommand("GLOBOPS",handle_globops,'o',1);
49         }
50         
51         virtual ~ModuleGlobops()
52         {
53                 delete Srv;
54         }
55         
56         virtual Version GetVersion()
57         {
58                 return Version(1,0,0,1);
59         }
60         
61         virtual bool OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
62         {
63                 // check if this is our mode character...
64                 if ((modechar == 'g') && (type == MT_CLIENT))
65                 {
66                         // we dont actually do anything with the mode in this module -
67                         // just tell the core its been claimed and is ok to give users.                         
68                         return 1;
69                 }
70                 else
71                 {
72                         // this mode isn't ours, we have to bail and return 0 to not handle it.
73                         return 0;
74                 }
75         }
76
77         virtual void OnOper(userrec* user)
78         {
79                 char* modes[2];                 // only two parameters
80                 modes[0] = user->nick;          // first parameter is the nick
81                 modes[1] = "+g";                // second parameter is the mode
82                 Srv->SendMode(modes,2,user);    // send these, forming the command "MODE <nick> +g"
83         }
84
85 };
86
87 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
88
89 class ModuleGlobopsFactory : public ModuleFactory
90 {
91  public:
92         ModuleGlobopsFactory()
93         {
94         }
95         
96         ~ModuleGlobopsFactory()
97         {
98         }
99         
100         virtual Module * CreateModule()
101         {
102                 return new ModuleGlobops;
103         }
104         
105 };
106
107
108 extern "C" void * init_module( void )
109 {
110         return new ModuleGlobopsFactory;
111 }
112