]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_clones.cpp
72a7ca7e832abc643480967e225139c182d055a3
[user/henk/code/inspircd.git] / src / modules / m_clones.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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 #include "users.h"
16 #include "channels.h"
17 #include "modules.h"
18 #include "wildcard.h"
19
20 /* $ModDesc: Provides the /clones command to retrieve information on a user, channel, or IP address */
21
22 /** Handle /CHECK
23  */
24 class cmd_clones : public command_t
25 {
26  public:
27         cmd_clones (InspIRCd* Instance) : command_t(Instance,"CLONES", 'o', 1)
28         {
29                 this->source = "m_clones.so";
30                 syntax = "<limit>";
31         }
32
33         std::string FindMatchingIP(const irc::string &ipaddr)
34         {
35                 std::string n = assign(ipaddr);
36                 for (user_hash::const_iterator a = ServerInstance->clientlist->begin(); a != ServerInstance->clientlist->end(); a++)
37                         if (a->second->GetIPString() == n)
38                                 return a->second->GetFullRealHost();
39                 return "<?>";
40         }
41
42         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
43         {
44
45                 std::string clonesstr = "304 " + std::string(user->nick) + " :CLONES";
46
47                 unsigned long limit = atoi(parameters[0]);
48
49                 /*
50                  * Syntax of a /clones reply:
51                  *  :server.name 304 target :CLONES START
52                  *  :server.name 304 target :CLONES <count> <ip> <fullhost>
53                  *  :server.name 304 target :CHECK END
54                  */
55
56                 user->WriteServ(clonesstr + " START");
57
58                 /* hostname or other */
59                 for (clonemap::iterator x = ServerInstance->global_clones.begin(); x != ServerInstance->global_clones.end(); x++)
60                 {
61                         if (x->second >= limit)
62                                 user->WriteServ(clonesstr + " "+ ConvToStr(x->second) + " " + assign(x->first) + " " + FindMatchingIP(x->first));
63                 }
64
65                 user->WriteServ(clonesstr + " END");
66
67                 return CMD_LOCALONLY;
68         }
69 };
70
71
72 class ModuleClones : public Module
73 {
74  private:
75         cmd_clones *mycommand;
76  public:
77         ModuleClones(InspIRCd* Me) : Module(Me)
78         {
79                 
80                 mycommand = new cmd_clones(ServerInstance);
81                 ServerInstance->AddCommand(mycommand);
82         }
83         
84         virtual ~ModuleClones()
85         {
86         }
87         
88         virtual Version GetVersion()
89         {
90                 return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
91         }
92
93         void Implements(char* List)
94         {
95                 /* we don't hook anything, nothing required */
96         }
97         
98 };
99
100 MODULE_INIT(ModuleClones)