]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermodes.cpp
628f0a40d14193961b65affc1cf980543bc9b9d4
[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         void Implements(char* List)
42         {
43                 List[I_OnOper] = 1;
44         }
45         
46         virtual ~ModuleModesOnOper()
47         {
48                 delete Conf;
49         }
50         
51         virtual Version GetVersion()
52         {
53                 return Version(1,0,0,1,VF_VENDOR);
54         }
55         
56         virtual void OnOper(userrec* user, std::string opertype)
57         {
58                 // whenever a user opers, go through the oper types, find their <type:modes>,
59                 // and if they have one apply their modes. The mode string can contain +modes
60                 // to add modes to the user or -modes to take modes from the user.
61                 for (int j =0; j < Conf->Enumerate("type"); j++)
62                 {
63                         std::string typen = Conf->ReadValue("type","name",j);
64                         if (!strcmp(typen.c_str(),user->oper))
65                         {
66                                 std::string ThisOpersModes = Conf->ReadValue("type","modes",j);
67                                 if (ThisOpersModes != "")
68                                 {
69                                         char* modes[2];
70                                         modes[0] = user->nick;
71                                         modes[1] = (char*)ThisOpersModes.c_str();
72                                         Srv->SendMode(modes,2,user);
73                                 }
74                                 break;
75                         }
76                 }
77         }
78 };
79
80 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
81
82 class ModuleModesOnOperFactory : public ModuleFactory
83 {
84  public:
85         ModuleModesOnOperFactory()
86         {
87         }
88         
89         ~ModuleModesOnOperFactory()
90         {
91         }
92         
93         virtual Module * CreateModule(Server* Me)
94         {
95                 return new ModuleModesOnOper(Me);
96         }
97         
98 };
99
100
101 extern "C" void * init_module( void )
102 {
103         return new ModuleModesOnOperFactory;
104 }
105