-/* +------------------------------------+\r * | Inspire Internet Relay Chat Daemon |\r * +------------------------------------+\r *\r * InspIRCd: (C) 2002-2007 InspIRCd Development Team\r * See: http://www.inspircd.org/wiki/index.php/Credits\r *\r * This program is free but copyrighted software; see\r * the file COPYING for details.\r *\r * ---------------------------------------------------\r */\r\r#include "inspircd.h"\r#include "users.h"\r#include "channels.h"\r#include "modules.h"\r\r/* $ModDesc: Gives each oper type a 'level', cannot kill opers 'above' your level. */\r\r\r\rclass ModuleOperLevels : public Module\r{\r\r private:\r\r \r ConfigReader* conf;\r\r public:\r\r ModuleOperLevels(InspIRCd* Me)\r : Module(Me)\r {\r\r \r conf = new ConfigReader(ServerInstance);\r }\r\r virtual ~ModuleOperLevels()\r {\r DELETE(conf);\r }\r\r void Implements(char* List)\r {\r List[I_OnRehash] = List[I_OnKill] = 1;\r }\r\r virtual void OnRehash(userrec* user, const std::string ¶meter)\r {\r DELETE(conf);\r conf = new ConfigReader(ServerInstance);\r }\r\r virtual Version GetVersion()\r {\r return Version(1,1,0,1,VF_VENDOR,API_VERSION);\r }\r\r virtual int OnKill(userrec* source, userrec* dest, const std::string &reason)\r {\r long dest_level = 0,source_level = 0;\r\r // oper killing an oper?\r if (IS_OPER(dest) && IS_OPER(source))\r {\r for (int j =0; j < conf->Enumerate("type"); j++)\r {\r std::string typen = conf->ReadValue("type","name",j);\r if (!strcmp(typen.c_str(),dest->oper))\r {\r dest_level = conf->ReadInteger("type","level",j,true);\r break;\r }\r }\r for (int k =0; k < conf->Enumerate("type"); k++)\r {\r std::string typen = conf->ReadValue("type","name",k);\r if (!strcmp(typen.c_str(),source->oper))\r {\r source_level = conf->ReadInteger("type","level",k,true);\r break;\r }\r }\r if (dest_level > source_level)\r {\r 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());\r dest->WriteServ("NOTICE %s :Oper %s attempted to /kill you!",dest->nick,source->nick);\r source->WriteServ("481 %s :Permission Denied - Oper %s is a higher level than you",source->nick,dest->nick);\r return 1;\r }\r }\r return 0;\r }\r\r};\r\rclass ModuleOperLevelsFactory : public ModuleFactory\r{\r public:\r ModuleOperLevelsFactory()\r {\r }\r\r ~ModuleOperLevelsFactory()\r {\r }\r\r virtual Module * CreateModule(InspIRCd* Me)\r {\r return new ModuleOperLevels(Me);\r }\r\r};\r\rextern "C" DllExport void * init_module( void )\r{\r return new ModuleOperLevelsFactory;\r}\r\r
\ No newline at end of file
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ * Copyright (C) 2006-2007 Robin Burchell <robin+git@viroteck.net>
+ * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ * Copyright (C) 2005 Craig Edwards <craigedwards@brainbox.cc>
+ *
+ * This file is part of InspIRCd. InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "inspircd.h"
+
+class ModuleOperLevels : public Module
+{
+ public:
+ void init() CXX11_OVERRIDE
+ {
+ ServerInstance->Modules->Attach(I_OnKill, this);
+ }
+
+ Version GetVersion() CXX11_OVERRIDE
+ {
+ return Version("Gives each oper type a 'level', cannot kill opers 'above' your level.", VF_VENDOR);
+ }
+
+ ModResult OnKill(User* source, User* dest, const std::string &reason) CXX11_OVERRIDE
+ {
+ // oper killing an oper?
+ if (dest->IsOper() && source->IsOper())
+ {
+ std::string level = dest->oper->getConfig("level");
+ long dest_level = atol(level.c_str());
+ level = source->oper->getConfig("level");
+ long source_level = atol(level.c_str());
+
+ if (dest_level > source_level)
+ {
+ 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());
+ dest->WriteNotice("*** Oper " + source->nick + " attempted to /kill you!");
+ source->WriteNumeric(ERR_NOPRIVILEGES, "%s :Permission Denied - Oper %s is a higher level than you",source->nick.c_str(),dest->nick.c_str());
+ return MOD_RES_DENY;
+ }
+ }
+ return MOD_RES_PASSTHRU;
+ }
+};
+
+MODULE_INIT(ModuleOperLevels)