]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_clones.cpp
Move the <disabled> tag out of the core to a new module.
[user/henk/code/inspircd.git] / src / modules / m_clones.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
7  *
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.
11  *
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
15  * details.
16  *
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/>.
19  */
20
21
22 #include "inspircd.h"
23 #include "modules/ircv3_batch.h"
24
25 enum
26 {
27         // InspIRCd-specific.
28         RPL_CLONES = 399
29 };
30
31 class CommandClones : public SplitCommand
32 {
33  private:
34         IRCv3::Batch::API batchmanager;
35         IRCv3::Batch::Batch batch;
36
37  public:
38         CommandClones(Module* Creator)
39                 : SplitCommand(Creator,"CLONES", 1)
40                 , batchmanager(Creator)
41                 , batch("inspircd.org/clones")
42         {
43                 flags_needed = 'o';
44                 syntax = "<limit>";
45         }
46
47         CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE
48         {
49                 unsigned int limit = ConvToNum<unsigned int>(parameters[0]);
50
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>
55
56                 if (batchmanager)
57                 {
58                         batchmanager->Start(batch);
59                         batch.GetBatchStartMessage().PushParam(ConvToStr(limit));
60                 }
61
62                 const UserManager::CloneMap& clonemap = ServerInstance->Users->GetCloneMap();
63                 for (UserManager::CloneMap::const_iterator i = clonemap.begin(); i != clonemap.end(); ++i)
64                 {
65                         const UserManager::CloneCounts& counts = i->second;
66                         if (counts.global < limit)
67                                 continue;
68
69                         Numeric::Numeric numeric(RPL_CLONES);
70                         numeric.push(counts.local);
71                         numeric.push(counts.global);
72                         numeric.push(i->first.str());
73
74                         ClientProtocol::Messages::Numeric numericmsg(numeric, user);
75                         batch.AddToBatch(numericmsg);
76                         user->Send(ServerInstance->GetRFCEvents().numeric, numericmsg);
77                 }
78
79                 if (batchmanager)
80                         batchmanager->End(batch);
81
82                 return CMD_SUCCESS;
83         }
84 };
85
86 class ModuleClones : public Module
87 {
88  public:
89         CommandClones cmd;
90
91  public:
92         ModuleClones()
93                 : cmd(this)
94         {
95         }
96
97         Version GetVersion() CXX11_OVERRIDE
98         {
99                 return Version("Provides the /CLONES command to retrieve information on clones.", VF_VENDOR);
100         }
101 };
102
103 MODULE_INIT(ModuleClones)