]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operlevels.cpp
ConfigReader and FileReader now take InspIRCd* to their constructors
[user/henk/code/inspircd.git] / src / modules / m_operlevels.cpp
1 using namespace std;
2
3 #include "users.h"
4 #include "channels.h"
5 #include "modules.h"
6 #include <string>
7 #include "helperfuncs.h"
8 #include "inspircd.h"
9
10 /* $ModDesc: Gives each oper type a 'level', cannot kill opers 'above' your level. */
11
12
13
14 class ModuleOperLevels : public Module
15 {
16
17         private:
18
19                 
20                 ConfigReader* conf;
21
22         public:
23
24                 ModuleOperLevels(InspIRCd* Me)
25                         : Module::Module(Me)
26                 {
27
28                         
29                         conf = new ConfigReader(ServerInstance);
30                 }
31
32                 virtual ~ModuleOperLevels()
33                 {
34                         DELETE(conf);
35                 }
36
37                 void Implements(char* List)
38                 {
39                         List[I_OnRehash] = List[I_OnKill] = 1;
40                 }
41
42                 virtual void OnRehash(const std::string &parameter)
43                 {
44                         DELETE(conf);
45                         conf = new ConfigReader(ServerInstance);
46                 }
47
48                 virtual Version GetVersion()
49                 {
50                         return Version(1,0,0,1,VF_VENDOR);
51                 }
52
53                 virtual int OnKill(userrec* source, userrec* dest, const std::string &reason)
54                 {
55                         long dest_level = 0,source_level = 0;
56                         // oper killing an oper?
57                         if (*dest->oper)
58                         {
59                                 for (int j =0; j < conf->Enumerate("type"); j++)
60                                 {
61                                         std::string typen = conf->ReadValue("type","name",j);
62                                         if (!strcmp(typen.c_str(),dest->oper))
63                                         {
64                                                 dest_level = conf->ReadInteger("type","level",j,true);
65                                                 break;
66                                         }
67                                 }
68                                 for (int k =0; k < conf->Enumerate("type"); k++)
69                                 {
70                                         std::string typen = conf->ReadValue("type","name",k);
71                                         if (!strcmp(typen.c_str(),source->oper))
72                                         {
73                                                 source_level = conf->ReadInteger("type","level",k,true);
74                                                 break;
75                                         }
76                                 }
77                                 if (dest_level > source_level)
78                                 {
79                                         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());
80                                         dest->WriteServ("NOTICE %s :Oper %s attempted to /kill you!",dest->nick,source->nick);
81                                         source->WriteServ("481 %s :Permission Denied- Oper %s is a higher level than you",source->nick,dest->nick);
82                                         return 1;
83                                 }
84                         }
85                         return 0;
86                 }
87
88 };
89
90 class ModuleOperLevelsFactory : public ModuleFactory
91 {
92  public:
93         ModuleOperLevelsFactory()
94         {
95         }
96
97         ~ModuleOperLevelsFactory()
98         {
99         }
100
101         virtual Module * CreateModule(InspIRCd* Me)
102         {
103                 log(DEBUG,"CreateModule");
104                 return new ModuleOperLevels(Me);
105         }
106
107 };
108
109 extern "C" void * init_module( void )
110 {
111         return new ModuleOperLevelsFactory;
112 }
113