]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_clones.cpp
966f2970568e0223ab9a15be50eaab63d73b4e32
[user/henk/code/inspircd.git] / src / modules / m_clones.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /* $ModDesc: Provides the /clones command to retrieve information on clones. */
17
18 /** Handle /CHECK
19  */
20 class CommandClones : public Command
21 {
22  public:
23         CommandClones(Module* Creator) : Command(Creator,"CLONES", 1)
24         {
25                 flags_needed = 'o'; syntax = "<limit>";
26         }
27
28         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
29         {
30
31                 std::string clonesstr = "304 " + std::string(user->nick) + " :CLONES";
32
33                 unsigned long limit = atoi(parameters[0].c_str());
34
35                 /*
36                  * Syntax of a /clones reply:
37                  *  :server.name 304 target :CLONES START
38                  *  :server.name 304 target :CLONES <count> <ip>
39                  *  :server.name 304 target :CHECK END
40                  */
41
42                 user->WriteServ(clonesstr + " START");
43
44                 /* hostname or other */
45                 // XXX I really don't like marking global_clones public for this. at all. -- w00t
46                 for (clonemap::iterator x = ServerInstance->Users->global_clones.begin(); x != ServerInstance->Users->global_clones.end(); x++)
47                 {
48                         if (x->second >= limit)
49                                 user->WriteServ(clonesstr + " "+ ConvToStr(x->second) + " " + assign(x->first));
50                 }
51
52                 user->WriteServ(clonesstr + " END");
53
54                 return CMD_SUCCESS;
55         }
56 };
57
58
59 class ModuleClones : public Module
60 {
61  private:
62         CommandClones cmd;
63  public:
64         ModuleClones(InspIRCd* Me) : Module(Me), cmd(this)
65         {
66                 ServerInstance->AddCommand(&cmd);
67         }
68
69         virtual ~ModuleClones()
70         {
71         }
72
73         virtual Version GetVersion()
74         {
75                 return Version("Provides the /clones command to retrieve information on clones.", VF_VENDOR, API_VERSION);
76         }
77
78
79 };
80
81 MODULE_INIT(ModuleClones)