]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_clones.cpp
58ecff17d22ab6b547d934d2622dfd2ac2e351f3
[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 (InspIRCd* Instance) : Command(Instance,"CLONES", "o", 1)
24         {
25                 this->source = "m_clones.so";
26                 syntax = "<limit>";
27         }
28
29         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
30         {
31
32                 std::string clonesstr = "304 " + std::string(user->nick) + " :CLONES";
33
34                 unsigned long limit = atoi(parameters[0].c_str());
35
36                 /*
37                  * Syntax of a /clones reply:
38                  *  :server.name 304 target :CLONES START
39                  *  :server.name 304 target :CLONES <count> <ip>
40                  *  :server.name 304 target :CHECK END
41                  */
42
43                 user->WriteServ(clonesstr + " START");
44
45                 /* hostname or other */
46                 // XXX I really don't like marking global_clones public for this. at all. -- w00t
47                 for (clonemap::iterator x = ServerInstance->Users->global_clones.begin(); x != ServerInstance->Users->global_clones.end(); x++)
48                 {
49                         if (x->second >= limit)
50                                 user->WriteServ(clonesstr + " "+ ConvToStr(x->second) + " " + assign(x->first));
51                 }
52
53                 user->WriteServ(clonesstr + " END");
54
55                 return CMD_LOCALONLY;
56         }
57 };
58
59
60 class ModuleClones : public Module
61 {
62  private:
63         CommandClones cmd;
64  public:
65         ModuleClones(InspIRCd* Me) : Module(Me), cmd(Me)
66         {
67                 ServerInstance->AddCommand(&cmd);
68         }
69
70         virtual ~ModuleClones()
71         {
72         }
73
74         virtual Version GetVersion()
75         {
76                 return Version("$Id$", VF_VENDOR, API_VERSION);
77         }
78
79
80 };
81
82 MODULE_INIT(ModuleClones)