]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermodes.cpp
Gah, im forgetting to SetMode!
[user/henk/code/inspircd.git] / src / modules / m_opermodes.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 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 "inspircd.h"
23 #include "modules.h"
24
25 /* $ModDesc: Sets (and unsets) modes on opers when they oper up */
26
27 class ModuleModesOnOper : public Module
28 {
29  private:
30
31         Server *Srv;
32         ConfigReader *Conf;
33
34  public:
35         ModuleModesOnOper(Server* Me)
36                 : Module::Module(Me)
37         {
38                 Srv = Me;
39                 Conf = new ConfigReader;
40         }
41
42         void Implements(char* List)
43         {
44                 List[I_OnPostOper] = List[I_OnRehash] = 1;
45         }
46
47         virtual void OnRehash(const std::string &parameter)
48         {
49                 DELETE(Conf);
50                 Conf = new ConfigReader;
51         }
52         
53         virtual ~ModuleModesOnOper()
54         {
55                 DELETE(Conf);
56         }
57         
58         virtual Version GetVersion()
59         {
60                 return Version(1,0,0,1,VF_VENDOR);
61         }
62         
63         virtual void OnPostOper(userrec* user, const std::string &opertype)
64         {
65                 // whenever a user opers, go through the oper types, find their <type:modes>,
66                 // and if they have one apply their modes. The mode string can contain +modes
67                 // to add modes to the user or -modes to take modes from the user.
68                 for (int j =0; j < Conf->Enumerate("type"); j++)
69                 {
70                         std::string typen = Conf->ReadValue("type","name",j);
71                         if (!strcmp(typen.c_str(),user->oper))
72                         {
73                                 std::string ThisOpersModes = Conf->ReadValue("type","modes",j);
74                                 char first = *(ThisOpersModes.c_str());
75                                 if ((first != '+') && (first != '-'))
76                                         ThisOpersModes = "+" + ThisOpersModes;
77                                 if (ThisOpersModes != "")
78                                 {
79                                         char* modes[2];
80                                         modes[0] = user->nick;
81                                         modes[1] = (char*)ThisOpersModes.c_str();
82                                         Srv->SendMode(modes,2,user);
83                                 }
84                                 break;
85                         }
86                 }
87         }
88 };
89
90 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
91
92 class ModuleModesOnOperFactory : public ModuleFactory
93 {
94  public:
95         ModuleModesOnOperFactory()
96         {
97         }
98         
99         ~ModuleModesOnOperFactory()
100         {
101         }
102         
103         virtual Module * CreateModule(Server* Me)
104         {
105                 return new ModuleModesOnOper(Me);
106         }
107         
108 };
109
110
111 extern "C" void * init_module( void )
112 {
113         return new ModuleModesOnOperFactory;
114 }
115