]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_clones.cpp
Merge insp20
[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
24 /** Handle /CLONES
25  */
26 class CommandClones : public Command
27 {
28  public:
29         CommandClones(Module* Creator) : Command(Creator,"CLONES", 1)
30         {
31                 flags_needed = 'o'; syntax = "<limit>";
32         }
33
34         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
35         {
36
37                 std::string clonesstr = "304 " + user->nick + " :CLONES";
38
39                 unsigned long limit = atoi(parameters[0].c_str());
40
41                 /*
42                  * Syntax of a /clones reply:
43                  *  :server.name 304 target :CLONES START
44                  *  :server.name 304 target :CLONES <count> <ip>
45                  *  :server.name 304 target :CLONES END
46                  */
47
48                 user->WriteServ(clonesstr + " START");
49
50                 /* hostname or other */
51                 const UserManager::CloneMap& clonemap = ServerInstance->Users->GetCloneMap();
52                 for (UserManager::CloneMap::const_iterator i = clonemap.begin(); i != clonemap.end(); ++i)
53                 {
54                         const UserManager::CloneCounts& counts = i->second;
55                         if (counts.global >= limit)
56                                 user->WriteServ(clonesstr + " " + ConvToStr(counts.global) + " " + i->first.str());
57                 }
58
59                 user->WriteServ(clonesstr + " END");
60
61                 return CMD_SUCCESS;
62         }
63 };
64
65 class ModuleClones : public Module
66 {
67         CommandClones cmd;
68  public:
69         ModuleClones() : cmd(this)
70         {
71         }
72
73         Version GetVersion() CXX11_OVERRIDE
74         {
75                 return Version("Provides the /CLONES command to retrieve information on clones.", VF_VENDOR);
76         }
77 };
78
79 MODULE_INIT(ModuleClones)