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