]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operlevels.cpp
Move static map of extensions into ServerInstance, add const-correctness
[user/henk/code/inspircd.git] / src / modules / m_operlevels.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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 class ModuleOperLevels : public Module
18 {
19         private:
20                 ConfigReader* conf;
21         public:
22                 ModuleOperLevels()
23                                         {
24                         conf = new ConfigReader;
25                         Implementation eventlist[] = { I_OnRehash, I_OnKill };
26                         ServerInstance->Modules->Attach(eventlist, this, 2);
27                 }
28
29                 virtual ~ModuleOperLevels()
30                 {
31                         delete conf;
32                 }
33
34
35                 virtual void OnRehash(User* user)
36                 {
37                         delete conf;
38                         conf = new ConfigReader;
39                 }
40
41                 virtual Version GetVersion()
42                 {
43                         return Version("Gives each oper type a 'level', cannot kill opers 'above' your level.", VF_VENDOR, API_VERSION);
44                 }
45
46                 virtual ModResult OnKill(User* source, User* dest, const std::string &reason)
47                 {
48                         long dest_level = 0,source_level = 0;
49
50                         // oper killing an oper?
51                         if (IS_OPER(dest) && IS_OPER(source))
52                         {
53                                 for (int j =0; j < conf->Enumerate("type"); j++)
54                                 {
55                                         std::string typen = conf->ReadValue("type","name",j);
56                                         if (typen == dest->oper)
57                                         {
58                                                 dest_level = conf->ReadInteger("type","level",j,true);
59                                                 break;
60                                         }
61                                 }
62                                 for (int k =0; k < conf->Enumerate("type"); k++)
63                                 {
64                                         std::string typen = conf->ReadValue("type","name",k);
65                                         if (typen == source->oper)
66                                         {
67                                                 source_level = conf->ReadInteger("type","level",k,true);
68                                                 break;
69                                         }
70                                 }
71                                 if (dest_level > source_level)
72                                 {
73                                         if (IS_LOCAL(source)) ServerInstance->SNO->WriteGlobalSno('a', "Oper %s (level %ld) attempted to /kill a higher oper: %s (level %ld): Reason: %s",source->nick.c_str(),source_level,dest->nick.c_str(),dest_level,reason.c_str());
74                                         dest->WriteServ("NOTICE %s :*** Oper %s attempted to /kill you!",dest->nick.c_str(),source->nick.c_str());
75                                         source->WriteNumeric(ERR_NOPRIVILEGES, "%s :Permission Denied - Oper %s is a higher level than you",source->nick.c_str(),dest->nick.c_str());
76                                         return MOD_RES_DENY;
77                                 }
78                         }
79                         return MOD_RES_PASSTHRU;
80                 }
81
82 };
83
84 MODULE_INIT(ModuleOperLevels)
85