]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operlevels.cpp
Update copyright headers.
[user/henk/code/inspircd.git] / src / modules / m_operlevels.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013, 2018 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2012-2013, 2016 Attila Molnar <attilamolnar@hush.com>
6  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
7  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
8  *   Copyright (C) 2009 Thomas Stagner <aquanight@inspircd.org>
9  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
10  *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
11  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
12  *   Copyright (C) 2005-2006, 2010 Craig Edwards <brain@inspircd.org>
13  *
14  * This file is part of InspIRCd.  InspIRCd is free software: you can
15  * redistribute it and/or modify it under the terms of the GNU General Public
16  * License as published by the Free Software Foundation, version 2.
17  *
18  * This program is distributed in the hope that it will be useful, but WITHOUT
19  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
21  * details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25  */
26
27
28 #include "inspircd.h"
29
30 class ModuleOperLevels : public Module
31 {
32         public:
33                 Version GetVersion() CXX11_OVERRIDE
34                 {
35                         return Version("Allows the server administrator to define ranks for server operators which prevent lower ranked server operators from using /KILL on higher ranked server operators.", VF_VENDOR);
36                 }
37
38                 ModResult OnKill(User* source, User* dest, const std::string &reason) CXX11_OVERRIDE
39                 {
40                         // oper killing an oper?
41                         if (dest->IsOper() && source->IsOper())
42                         {
43                                 unsigned long dest_level = ConvToNum<unsigned long>(dest->oper->getConfig("level"));
44                                 unsigned long source_level = ConvToNum<unsigned long>(source->oper->getConfig("level"));
45
46                                 if (dest_level > source_level)
47                                 {
48                                         if (IS_LOCAL(source))
49                                         {
50                                                 ServerInstance->SNO->WriteGlobalSno('a', "Oper %s (level %lu) attempted to /KILL a higher level oper: %s (level %lu), reason: %s",
51                                                         source->nick.c_str(), source_level, dest->nick.c_str(), dest_level, reason.c_str());
52                                         }
53                                         dest->WriteNotice("*** Oper " + source->nick + " attempted to /KILL you!");
54                                         source->WriteNumeric(ERR_NOPRIVILEGES, InspIRCd::Format("Permission Denied - Oper %s is a higher level than you", dest->nick.c_str()));
55                                         return MOD_RES_DENY;
56                                 }
57                         }
58                         return MOD_RES_PASSTHRU;
59                 }
60 };
61
62 MODULE_INIT(ModuleOperLevels)