]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_operlevels.cpp
Only assign NewServices once the duplicate check is done.
[user/henk/code/inspircd.git] / src / modules / m_operlevels.cpp
index 6d3aa7b14bfcede8ba29fea1b81c17de13566bbf..c83dd6ee8d32685e02b3d054d48366ae97c88291 100644 (file)
@@ -1 +1,62 @@
-/*       +------------------------------------+\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 &parameter)\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) 2013, 2018 Sadie Powell <sadie@witchery.services>
+ *   Copyright (C) 2012-2013, 2016 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
+ *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
+ *   Copyright (C) 2009 Thomas Stagner <aquanight@inspircd.org>
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
+ *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2006, 2010 Craig Edwards <brain@inspircd.org>
+ *
+ * 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:
+               Version GetVersion() CXX11_OVERRIDE
+               {
+                       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);
+               }
+
+               ModResult OnKill(User* source, User* dest, const std::string &reason) CXX11_OVERRIDE
+               {
+                       // oper killing an oper?
+                       if (dest->IsOper() && source->IsOper())
+                       {
+                               unsigned long dest_level = ConvToNum<unsigned long>(dest->oper->getConfig("level"));
+                               unsigned long source_level = ConvToNum<unsigned long>(source->oper->getConfig("level"));
+
+                               if (dest_level > source_level)
+                               {
+                                       if (IS_LOCAL(source))
+                                       {
+                                               ServerInstance->SNO->WriteGlobalSno('a', "Oper %s (level %lu) attempted to /KILL a higher level oper: %s (level %lu), 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, InspIRCd::Format("Permission Denied - Oper %s is a higher level than you", dest->nick.c_str()));
+                                       return MOD_RES_DENY;
+                               }
+                       }
+                       return MOD_RES_PASSTHRU;
+               }
+};
+
+MODULE_INIT(ModuleOperLevels)