]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_modules.cpp
eb93d2927de9363739c4732337bf5ed83f45d611
[user/henk/code/inspircd.git] / src / commands / cmd_modules.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 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 /** Handle /MODULES. These command handlers can be reloaded by the core,
17  * and handle basic RFC1459 commands. Commands within modules work
18  * the same way, however, they can be fully unloaded, where these
19  * may not.
20  */
21 class CommandModules : public Command
22 {
23  public:
24         /** Constructor for modules.
25          */
26         CommandModules ( Module* parent) : Command(parent,"MODULES",0,0) { syntax = "[server]"; }
27         /** Handle command.
28          * @param parameters The parameters to the comamnd
29          * @param pcnt The number of parameters passed to teh command
30          * @param user The user issuing the command
31          * @return A value from CmdResult to indicate command success or failure.
32          */
33         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
34         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
35         {
36                 if (parameters.size() >= 1)
37                         return ROUTE_UNICAST(parameters[0]);
38                 return ROUTE_LOCALONLY;
39         }
40 };
41
42 /** Handle /MODULES
43  */
44 CmdResult CommandModules::Handle (const std::vector<std::string>&, User *user)
45 {
46         std::vector<std::string> module_names = ServerInstance->Modules->GetAllModuleNames(0);
47
48         for (unsigned int i = 0; i < module_names.size(); i++)
49         {
50                 Module* m = ServerInstance->Modules->Find(module_names[i]);
51                 Version V = m->GetVersion();
52
53                 if (user->HasPrivPermission("servers/auspex"))
54                 {
55                         std::string flags("SvcC");
56                         int pos = 0;
57                         for (int mult = 1; mult <= VF_OPTCOMMON; mult *= 2, ++pos)
58                                 if (!(V.Flags & mult))
59                                         flags[pos] = '-';
60
61 #ifdef PURE_STATIC
62                         user->SendText(":%s 702 %s :%p %s %s :%s", ServerInstance->Config->ServerName.c_str(),
63                                 user->nick.c_str(), (void*)m, module_names[i].c_str(), flags.c_str(), V.description.c_str());
64 #else
65                         std::string srcrev = m->ModuleDLLManager->GetVersion();
66                         user->SendText(":%s 702 %s :%p %s %s :%s - %s", ServerInstance->Config->ServerName.c_str(),
67                                 user->nick.c_str(), (void*)m, module_names[i].c_str(), flags.c_str(), V.description.c_str(), srcrev.c_str());
68 #endif
69                 }
70                 else
71                 {
72                         user->SendText(":%s 702 %s :%s %s", ServerInstance->Config->ServerName.c_str(),
73                                 user->nick.c_str(), module_names[i].c_str(), V.description.c_str());
74                 }
75         }
76         user->SendText(":%s 703 %s :End of MODULES list", ServerInstance->Config->ServerName.c_str(), user->nick.c_str());
77
78         return CMD_SUCCESS;
79 }
80
81 COMMAND_INIT(CommandModules)