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