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