]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operlevels.cpp
Fix to allow for OnRehash to know what user initiated the rehash
[user/henk/code/inspircd.git] / src / modules / m_operlevels.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "users.h"
15 #include "channels.h"
16 #include "modules.h"
17 #include <string>
18
19 #include "inspircd.h"
20
21 /* $ModDesc: Gives each oper type a 'level', cannot kill opers 'above' your level. */
22
23
24
25 class ModuleOperLevels : public Module
26 {
27
28         private:
29
30                 
31                 ConfigReader* conf;
32
33         public:
34
35                 ModuleOperLevels(InspIRCd* Me)
36                         : Module::Module(Me)
37                 {
38
39                         
40                         conf = new ConfigReader(ServerInstance);
41                 }
42
43                 virtual ~ModuleOperLevels()
44                 {
45                         DELETE(conf);
46                 }
47
48                 void Implements(char* List)
49                 {
50                         List[I_OnRehash] = List[I_OnKill] = 1;
51                 }
52
53                 virtual void OnRehash(userrec* user, const std::string &parameter)
54                 {
55                         DELETE(conf);
56                         conf = new ConfigReader(ServerInstance);
57                 }
58
59                 virtual Version GetVersion()
60                 {
61                         return Version(1,1,0,1,VF_VENDOR,API_VERSION);
62                 }
63
64                 virtual int OnKill(userrec* source, userrec* dest, const std::string &reason)
65                 {
66                         long dest_level = 0,source_level = 0;
67                         // oper killing an oper?
68                         if (*dest->oper)
69                         {
70                                 for (int j =0; j < conf->Enumerate("type"); j++)
71                                 {
72                                         std::string typen = conf->ReadValue("type","name",j);
73                                         if (!strcmp(typen.c_str(),dest->oper))
74                                         {
75                                                 dest_level = conf->ReadInteger("type","level",j,true);
76                                                 break;
77                                         }
78                                 }
79                                 for (int k =0; k < conf->Enumerate("type"); k++)
80                                 {
81                                         std::string typen = conf->ReadValue("type","name",k);
82                                         if (!strcmp(typen.c_str(),source->oper))
83                                         {
84                                                 source_level = conf->ReadInteger("type","level",k,true);
85                                                 break;
86                                         }
87                                 }
88                                 if (dest_level > source_level)
89                                 {
90                                         ServerInstance->WriteOpers("Oper %s (level %d) attempted to /kill a higher oper: %s (level %d): Reason: %s",source->nick,source_level,dest->nick,dest_level,reason.c_str());
91                                         dest->WriteServ("NOTICE %s :Oper %s attempted to /kill you!",dest->nick,source->nick);
92                                         source->WriteServ("481 %s :Permission Denied- Oper %s is a higher level than you",source->nick,dest->nick);
93                                         return 1;
94                                 }
95                         }
96                         return 0;
97                 }
98
99 };
100
101 class ModuleOperLevelsFactory : public ModuleFactory
102 {
103  public:
104         ModuleOperLevelsFactory()
105         {
106         }
107
108         ~ModuleOperLevelsFactory()
109         {
110         }
111
112         virtual Module * CreateModule(InspIRCd* Me)
113         {
114                 return new ModuleOperLevels(Me);
115         }
116
117 };
118
119 extern "C" void * init_module( void )
120 {
121         return new ModuleOperLevelsFactory;
122 }
123