2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
5 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
8 * This file is part of InspIRCd. InspIRCd is free software: you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation, version 2.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "modules/ircv3_batch.h"
31 class CommandClones : public SplitCommand
34 IRCv3::Batch::API batchmanager;
35 IRCv3::Batch::Batch batch;
38 CommandClones(Module* Creator)
39 : SplitCommand(Creator,"CLONES", 1)
40 , batchmanager(Creator)
41 , batch("inspircd.org/clones")
47 CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE
49 unsigned int limit = ConvToNum<unsigned int>(parameters[0]);
51 // Syntax of a CLONES reply:
52 // :irc.example.com BATCH +<id> inspircd.org/clones :<min-count>
53 // @batch=<id> :irc.example.com 399 <client> <local-count> <remote-count> <cidr-mask>
54 /// :irc.example.com BATCH :-<id>
58 batchmanager->Start(batch);
59 batch.GetBatchStartMessage().PushParam(ConvToStr(limit));
62 const UserManager::CloneMap& clonemap = ServerInstance->Users->GetCloneMap();
63 for (UserManager::CloneMap::const_iterator i = clonemap.begin(); i != clonemap.end(); ++i)
65 const UserManager::CloneCounts& counts = i->second;
66 if (counts.global < limit)
69 Numeric::Numeric numeric(RPL_CLONES);
70 numeric.push(counts.local);
71 numeric.push(counts.global);
72 numeric.push(i->first.str());
74 ClientProtocol::Messages::Numeric numericmsg(numeric, user);
75 batch.AddToBatch(numericmsg);
76 user->Send(ServerInstance->GetRFCEvents().numeric, numericmsg);
80 batchmanager->End(batch);
86 class ModuleClones : public Module
97 Version GetVersion() CXX11_OVERRIDE
99 return Version("Provides the /CLONES command to retrieve information on clones.", VF_VENDOR);
103 MODULE_INIT(ModuleClones)