]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operlevels.cpp
Some more to fix still, modules probably wont load correctly atm
[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
16 /* $ModDesc: Gives each oper type a 'level', cannot kill opers 'above' your level. */
17
18
19
20 class ModuleOperLevels : public Module
21 {
22
23         private:
24
25                 
26                 ConfigReader* conf;
27
28         public:
29
30                 ModuleOperLevels(InspIRCd* Me)
31                         : Module(Me)
32                 {
33
34                         
35                         conf = new ConfigReader(ServerInstance);
36                 Implementation eventlist[] = { I_OnRehash, I_OnKill };
37                 ServerInstance->Modules->Attach(eventlist, this, 2);
38                 }
39
40                 virtual ~ModuleOperLevels()
41                 {
42                         DELETE(conf);
43                 }
44
45                 void Implements(char* List)
46                 {
47                         List[I_OnRehash] = List[I_OnKill] = 1;
48                 }
49
50                 virtual void OnRehash(User* user, const std::string &parameter)
51                 {
52                         DELETE(conf);
53                         conf = new ConfigReader(ServerInstance);
54                 }
55
56                 virtual Version GetVersion()
57                 {
58                         return Version(1,1,0,1,VF_VENDOR,API_VERSION);
59                 }
60
61                 virtual int OnKill(User* source, User* dest, const std::string &reason)
62                 {
63                         long dest_level = 0,source_level = 0;
64
65                         // oper killing an oper?
66                         if (IS_OPER(dest) && IS_OPER(source))
67                         {
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(),dest->oper))
72                                         {
73                                                 dest_level = conf->ReadInteger("type","level",j,true);
74                                                 break;
75                                         }
76                                 }
77                                 for (int k =0; k < conf->Enumerate("type"); k++)
78                                 {
79                                         std::string typen = conf->ReadValue("type","name",k);
80                                         if (!strcmp(typen.c_str(),source->oper))
81                                         {
82                                                 source_level = conf->ReadInteger("type","level",k,true);
83                                                 break;
84                                         }
85                                 }
86                                 if (dest_level > source_level)
87                                 {
88                                         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());
89                                         dest->WriteServ("NOTICE %s :Oper %s attempted to /kill you!",dest->nick,source->nick);
90                                         source->WriteServ("481 %s :Permission Denied - Oper %s is a higher level than you",source->nick,dest->nick);
91                                         return 1;
92                                 }
93                         }
94                         return 0;
95                 }
96
97 };
98
99 MODULE_INIT(ModuleOperLevels)
100