]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operlevels.cpp
In the grand tradition of huge fucking commits:
[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                 }
37
38                 virtual ~ModuleOperLevels()
39                 {
40                         DELETE(conf);
41                 }
42
43                 void Implements(char* List)
44                 {
45                         List[I_OnRehash] = List[I_OnKill] = 1;
46                 }
47
48                 virtual void OnRehash(User* user, const std::string &parameter)
49                 {
50                         DELETE(conf);
51                         conf = new ConfigReader(ServerInstance);
52                 }
53
54                 virtual Version GetVersion()
55                 {
56                         return Version(1,1,0,1,VF_VENDOR,API_VERSION);
57                 }
58
59                 virtual int OnKill(User* source, User* dest, const std::string &reason)
60                 {
61                         long dest_level = 0,source_level = 0;
62
63                         // oper killing an oper?
64                         if (IS_OPER(dest) && IS_OPER(source))
65                         {
66                                 for (int j =0; j < conf->Enumerate("type"); j++)
67                                 {
68                                         std::string typen = conf->ReadValue("type","name",j);
69                                         if (!strcmp(typen.c_str(),dest->oper))
70                                         {
71                                                 dest_level = conf->ReadInteger("type","level",j,true);
72                                                 break;
73                                         }
74                                 }
75                                 for (int k =0; k < conf->Enumerate("type"); k++)
76                                 {
77                                         std::string typen = conf->ReadValue("type","name",k);
78                                         if (!strcmp(typen.c_str(),source->oper))
79                                         {
80                                                 source_level = conf->ReadInteger("type","level",k,true);
81                                                 break;
82                                         }
83                                 }
84                                 if (dest_level > source_level)
85                                 {
86                                         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());
87                                         dest->WriteServ("NOTICE %s :Oper %s attempted to /kill you!",dest->nick,source->nick);
88                                         source->WriteServ("481 %s :Permission Denied - Oper %s is a higher level than you",source->nick,dest->nick);
89                                         return 1;
90                                 }
91                         }
92                         return 0;
93                 }
94
95 };
96
97 MODULE_INIT(ModuleOperLevels)
98