]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermodes.cpp
Changed behaviour of module API to pass Server* to the constructor, rather than have...
[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 #include <stdio.h>
20 #include "users.h"
21 #include "channels.h"
22 #include "modules.h"
23
24 /* $ModDesc: Sets (and unsets) modes on opers when they oper up */
25
26 class ModuleModesOnOper : public Module
27 {
28  private:
29
30         Server *Srv;
31         ConfigReader *Conf;
32
33  public:
34         ModuleModesOnOper(Server* Me)
35                 : Module::Module(Me)
36         {
37                 Srv = Me;
38                 Conf = new ConfigReader;
39         }
40         
41         virtual ~ModuleModesOnOper()
42         {
43                 delete Conf;
44         }
45         
46         virtual Version GetVersion()
47         {
48                 return Version(1,0,0,1,VF_VENDOR);
49         }
50         
51         virtual void OnOper(userrec* user, std::string opertype)
52         {
53                 // whenever a user opers, go through the oper types, find their <type:modes>,
54                 // and if they have one apply their modes. The mode string can contain +modes
55                 // to add modes to the user or -modes to take modes from the user.
56                 for (int j =0; j < Conf->Enumerate("type"); j++)
57                 {
58                         std::string typen = Conf->ReadValue("type","name",j);
59                         if (!strcmp(typen.c_str(),user->oper))
60                         {
61                                 std::string ThisOpersModes = Conf->ReadValue("type","modes",j);
62                                 if (ThisOpersModes != "")
63                                 {
64                                         char* modes[2];
65                                         modes[0] = user->nick;
66                                         modes[1] = (char*)ThisOpersModes.c_str();
67                                         Srv->SendMode(modes,2,user);
68                                 }
69                                 break;
70                         }
71                 }
72         }
73 };
74
75 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
76
77 class ModuleModesOnOperFactory : public ModuleFactory
78 {
79  public:
80         ModuleModesOnOperFactory()
81         {
82         }
83         
84         ~ModuleModesOnOperFactory()
85         {
86         }
87         
88         virtual Module * CreateModule(Server* Me)
89         {
90                 return new ModuleModesOnOper(Me);
91         }
92         
93 };
94
95
96 extern "C" void * init_module( void )
97 {
98         return new ModuleModesOnOperFactory;
99 }
100