2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013, 2018 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
6 * Copyright (C) 2012, 2014 Attila Molnar <attilamolnar@hush.com>
7 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
8 * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
9 * Copyright (C) 2007, 2010 Craig Edwards <brain@inspircd.org>
10 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
12 * This file is part of InspIRCd. InspIRCd is free software: you can
13 * redistribute it and/or modify it under the terms of the GNU General Public
14 * License as published by the Free Software Foundation, version 2.
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include "modules/ircv3_batch.h"
35 class CommandClones : public SplitCommand
38 IRCv3::Batch::API batchmanager;
39 IRCv3::Batch::Batch batch;
42 CommandClones(Module* Creator)
43 : SplitCommand(Creator,"CLONES", 1)
44 , batchmanager(Creator)
45 , batch("inspircd.org/clones")
51 CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE
53 unsigned int limit = ConvToNum<unsigned int>(parameters[0]);
55 // Syntax of a CLONES reply:
56 // :irc.example.com BATCH +<id> inspircd.org/clones :<min-count>
57 // @batch=<id> :irc.example.com 399 <client> <local-count> <remote-count> <cidr-mask>
58 /// :irc.example.com BATCH :-<id>
62 batchmanager->Start(batch);
63 batch.GetBatchStartMessage().PushParam(ConvToStr(limit));
66 const UserManager::CloneMap& clonemap = ServerInstance->Users->GetCloneMap();
67 for (UserManager::CloneMap::const_iterator i = clonemap.begin(); i != clonemap.end(); ++i)
69 const UserManager::CloneCounts& counts = i->second;
70 if (counts.global < limit)
73 Numeric::Numeric numeric(RPL_CLONES);
74 numeric.push(counts.local);
75 numeric.push(counts.global);
76 numeric.push(i->first.str());
78 ClientProtocol::Messages::Numeric numericmsg(numeric, user);
79 batch.AddToBatch(numericmsg);
80 user->Send(ServerInstance->GetRFCEvents().numeric, numericmsg);
84 batchmanager->End(batch);
90 class ModuleClones : public Module
101 Version GetVersion() CXX11_OVERRIDE
103 return Version("Provides the CLONES command to retrieve information on clones", VF_VENDOR);
107 MODULE_INIT(ModuleClones)