]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_clones.cpp
Fix the cloaking module on C++98 compilers.
[user/henk/code/inspircd.git] / src / modules / m_clones.cpp
index 429b9c2b900b693c0b877f8712201007ce3abea5..1210c7c126adddcf04922ace4ddf405a5399192e 100644 (file)
@@ -1 +1,107 @@
-/*       +------------------------------------+\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#include "wildcard.h"\r\r/* $ModDesc: Provides the /clones command to retrieve information on a user, channel, or IP address */\r\r/** Handle /CHECK\r */\rclass cmd_clones : public command_t\r{\r public:\r   cmd_clones (InspIRCd* Instance) : command_t(Instance,"CLONES", 'o', 1)\r {\r              this->source = "m_clones.so";\r          syntax = "<limit>";\r    }\r\r     std::string FindMatchingIP(const irc::string &ipaddr)\r  {\r              std::string n = assign(ipaddr);\r                for (user_hash::const_iterator a = ServerInstance->clientlist->begin(); a != ServerInstance->clientlist->end(); a++)\r                   if (a->second->GetIPString() == n)\r                             return a->second->GetFullRealHost();\r           return "<?>";\r  }\r\r     CmdResult Handle (const char** parameters, int pcnt, userrec *user)\r    {\r\r             std::string clonesstr = "304 " + std::string(user->nick) + " :CLONES";\r\r                unsigned long limit = atoi(parameters[0]);\r\r            /*\r              * Syntax of a /clones reply:\r           *  :server.name 304 target :CLONES START\r               *  :server.name 304 target :CLONES <count> <ip> <fullhost>\r             *  :server.name 304 target :CHECK END\r          */\r\r           user->WriteServ(clonesstr + " START");\r\r                /* hostname or other */\r                for (clonemap::iterator x = ServerInstance->global_clones.begin(); x != ServerInstance->global_clones.end(); x++)\r              {\r                      if (x->second >= limit)\r                                user->WriteServ(clonesstr + " "+ ConvToStr(x->second) + " " + assign(x->first) + " " + FindMatchingIP(x->first));\r              }\r\r             user->WriteServ(clonesstr + " END");\r\r          return CMD_LOCALONLY;\r  }\r};\r\r\rclass ModuleClones : public Module\r{\r private:\r  cmd_clones *mycommand;\r public:\r        ModuleClones(InspIRCd* Me) : Module(Me)\r        {\r              \r               mycommand = new cmd_clones(ServerInstance);\r            ServerInstance->AddCommand(mycommand);\r }\r      \r       virtual ~ModuleClones()\r        {\r      }\r      \r       virtual Version GetVersion()\r   {\r              return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);\r    }\r\r     void Implements(char* List)\r    {\r              /* we don't hook anything, nothing required */\r }\r      \r};\r\rMODULE_INIT(ModuleClones)\r
\ No newline at end of file
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2013, 2018 Sadie Powell <sadie@witchery.services>
+ *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
+ *   Copyright (C) 2012, 2014 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
+ *   Copyright (C) 2007, 2010 Craig Edwards <brain@inspircd.org>
+ *   Copyright (C) 2007 Dennis Friis <peavey@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"
+#include "modules/ircv3_batch.h"
+
+enum
+{
+       // InspIRCd-specific.
+       RPL_CLONES = 399
+};
+
+class CommandClones : public SplitCommand
+{
+ private:
+       IRCv3::Batch::API batchmanager;
+       IRCv3::Batch::Batch batch;
+
+ public:
+       CommandClones(Module* Creator)
+               : SplitCommand(Creator,"CLONES", 1)
+               , batchmanager(Creator)
+               , batch("inspircd.org/clones")
+       {
+               flags_needed = 'o';
+               syntax = "<limit>";
+       }
+
+       CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE
+       {
+               unsigned int limit = ConvToNum<unsigned int>(parameters[0]);
+
+               // Syntax of a CLONES reply:
+               // :irc.example.com BATCH +<id> inspircd.org/clones :<min-count>
+               // @batch=<id> :irc.example.com 399 <client> <local-count> <remote-count> <cidr-mask>
+               /// :irc.example.com BATCH :-<id>
+
+               if (batchmanager)
+               {
+                       batchmanager->Start(batch);
+                       batch.GetBatchStartMessage().PushParam(ConvToStr(limit));
+               }
+
+               const UserManager::CloneMap& clonemap = ServerInstance->Users->GetCloneMap();
+               for (UserManager::CloneMap::const_iterator i = clonemap.begin(); i != clonemap.end(); ++i)
+               {
+                       const UserManager::CloneCounts& counts = i->second;
+                       if (counts.global < limit)
+                               continue;
+
+                       Numeric::Numeric numeric(RPL_CLONES);
+                       numeric.push(counts.local);
+                       numeric.push(counts.global);
+                       numeric.push(i->first.str());
+
+                       ClientProtocol::Messages::Numeric numericmsg(numeric, user);
+                       batch.AddToBatch(numericmsg);
+                       user->Send(ServerInstance->GetRFCEvents().numeric, numericmsg);
+               }
+
+               if (batchmanager)
+                       batchmanager->End(batch);
+
+               return CMD_SUCCESS;
+       }
+};
+
+class ModuleClones : public Module
+{
+ public:
+       CommandClones cmd;
+
+ public:
+       ModuleClones()
+               : cmd(this)
+       {
+       }
+
+       Version GetVersion() CXX11_OVERRIDE
+       {
+               return Version("Adds the /CLONES command which allows server operators to view IP addresses from which there are more than a specified number of connections.", VF_VENDOR);
+       }
+};
+
+MODULE_INIT(ModuleClones)