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