]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermodes.cpp
f0c8dfa0711fec32cf05781ba13f62d9ab65d99d
[user/henk/code/inspircd.git] / src / modules / m_opermodes.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 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 // Hostname ModesOnOper (+x mode) module for inspircd.
20 // version 1.0.0.1 by brain (C. J. Edwards) Mar 2004.
21 //
22 // When loaded this module will automatically set the
23 // +x mode on all connecting clients.
24 //
25 // Setting +x on a client causes the module to change the
26 // dhost entry (displayed host) for each user who has the
27 // mode, ModesOnOper their host. Unlike unreal, the algorithm
28 // is non-reversible as uncloaked hosts are passed along
29 // the server->server link, and all encoding of hosts is
30 // done locally on the server by this module.
31
32 #include <stdio.h>
33 #include "users.h"
34 #include "channels.h"
35 #include "modules.h"
36
37 /* $ModDesc: Sets (and unsets) modes on opers when they oper up */
38
39 class ModuleModesOnOper : public Module
40 {
41  private:
42
43         Server *Srv;
44         ConfigReader *Conf;
45
46  public:
47         ModuleModesOnOper()
48         {
49                 Srv = new Server;
50                 Conf = new ConfigReader;
51         }
52         
53         virtual ~ModuleModesOnOper()
54         {
55                 delete Conf;
56                 delete Srv;
57         }
58         
59         virtual Version GetVersion()
60         {
61                 return Version(1,0,0,1,VF_VENDOR);
62         }
63         
64         virtual void OnOper(userrec* user)
65         {
66                 // whenever a user opers, go through the oper types, find their <type:modes>,
67                 // and if they have one apply their modes. The mode string can contain +modes
68                 // to add modes to the user or -modes to take modes from the user.
69                 for (int j =0; j < Conf->Enumerate("type"); j++)
70                 {
71                         std::string typen = Conf->ReadValue("type","name",j);
72                         if (!strcmp(typen.c_str(),user->oper))
73                         {
74                                 std::string ThisOpersModes = Conf->ReadValue("type","modes",j);
75                                 if (ThisOpersModes != "")
76                                 {
77                                         char* modes[2];
78                                         modes[0] = user->nick;
79                                         modes[1] = (char*)ThisOpersModes.c_str();
80                                         Srv->SendMode(modes,2,user);
81                                 }
82                                 break;
83                         }
84                 }
85         }
86 };
87
88 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
89
90 class ModuleModesOnOperFactory : public ModuleFactory
91 {
92  public:
93         ModuleModesOnOperFactory()
94         {
95         }
96         
97         ~ModuleModesOnOperFactory()
98         {
99         }
100         
101         virtual Module * CreateModule()
102         {
103                 return new ModuleModesOnOper;
104         }
105         
106 };
107
108
109 extern "C" void * init_module( void )
110 {
111         return new ModuleModesOnOperFactory;
112 }
113