The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

m_clones.cpp

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *            the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 #include "inspircd.h"
00015 
00016 /* $ModDesc: Provides the /clones command to retrieve information on clones. */
00017 
00020 class CommandClones : public Command
00021 {
00022  public:
00023         CommandClones (InspIRCd* Instance) : Command(Instance,"CLONES", "o", 1)
00024         {
00025                 this->source = "m_clones.so";
00026                 syntax = "<limit>";
00027         }
00028 
00029         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
00030         {
00031 
00032                 std::string clonesstr = "304 " + std::string(user->nick) + " :CLONES";
00033 
00034                 unsigned long limit = atoi(parameters[0].c_str());
00035 
00036                 /*
00037                  * Syntax of a /clones reply:
00038                  *  :server.name 304 target :CLONES START
00039                  *  :server.name 304 target :CLONES <count> <ip>
00040                  *  :server.name 304 target :CHECK END
00041                  */
00042 
00043                 user->WriteServ(clonesstr + " START");
00044 
00045                 /* hostname or other */
00046                 // XXX I really don't like marking global_clones public for this. at all. -- w00t
00047                 for (clonemap::iterator x = ServerInstance->Users->global_clones.begin(); x != ServerInstance->Users->global_clones.end(); x++)
00048                 {
00049                         if (x->second >= limit)
00050                                 user->WriteServ(clonesstr + " "+ ConvToStr(x->second) + " " + assign(x->first));
00051                 }
00052 
00053                 user->WriteServ(clonesstr + " END");
00054 
00055                 return CMD_LOCALONLY;
00056         }
00057 };
00058 
00059 
00060 class ModuleClones : public Module
00061 {
00062  private:
00063         CommandClones *mycommand;
00064  public:
00065         ModuleClones(InspIRCd* Me) : Module(Me)
00066         {
00067 
00068                 mycommand = new CommandClones(ServerInstance);
00069                 ServerInstance->AddCommand(mycommand);
00070 
00071         }
00072 
00073         virtual ~ModuleClones()
00074         {
00075         }
00076 
00077         virtual Version GetVersion()
00078         {
00079                 return Version("$Id: m_clones.cpp 10291 2008-08-25 20:35:51Z w00t $", VF_VENDOR, API_VERSION);
00080         }
00081 
00082 
00083 };
00084 
00085 MODULE_INIT(ModuleClones)