]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_modules.cpp
Merge pull request #109 from Justasic/insp20
[user/henk/code/inspircd.git] / src / commands / cmd_modules.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
6  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
7  *
8  * This file is part of InspIRCd.  InspIRCd is free software: you can
9  * redistribute it and/or modify it under the terms of the GNU General Public
10  * License as published by the Free Software Foundation, version 2.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21
22 #include "inspircd.h"
23
24 /** Handle /MODULES. These command handlers can be reloaded by the core,
25  * and handle basic RFC1459 commands. Commands within modules work
26  * the same way, however, they can be fully unloaded, where these
27  * may not.
28  */
29 class CommandModules : public Command
30 {
31  public:
32         /** Constructor for modules.
33          */
34         CommandModules ( Module* parent) : Command(parent,"MODULES",0,0) { syntax = "[server]"; }
35         /** Handle command.
36          * @param parameters The parameters to the comamnd
37          * @param pcnt The number of parameters passed to teh command
38          * @param user The user issuing the command
39          * @return A value from CmdResult to indicate command success or failure.
40          */
41         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
42         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
43         {
44                 if (parameters.size() >= 1)
45                         return ROUTE_UNICAST(parameters[0]);
46                 return ROUTE_LOCALONLY;
47         }
48 };
49
50 /** Handle /MODULES
51  */
52 CmdResult CommandModules::Handle (const std::vector<std::string>&, User *user)
53 {
54         std::vector<std::string> module_names = ServerInstance->Modules->GetAllModuleNames(0);
55
56         for (unsigned int i = 0; i < module_names.size(); i++)
57         {
58                 Module* m = ServerInstance->Modules->Find(module_names[i]);
59                 Version V = m->GetVersion();
60
61                 if (user->HasPrivPermission("servers/auspex"))
62                 {
63                         std::string flags("SvcC");
64                         int pos = 0;
65                         for (int mult = 1; mult <= VF_OPTCOMMON; mult *= 2, ++pos)
66                                 if (!(V.Flags & mult))
67                                         flags[pos] = '-';
68
69 #ifdef PURE_STATIC
70                         user->SendText(":%s 702 %s :%p %s %s :%s", ServerInstance->Config->ServerName.c_str(),
71                                 user->nick.c_str(), (void*)m, module_names[i].c_str(), flags.c_str(), V.description.c_str());
72 #else
73                         std::string srcrev = m->ModuleDLLManager->GetVersion();
74                         user->SendText(":%s 702 %s :%p %s %s :%s - %s", ServerInstance->Config->ServerName.c_str(),
75                                 user->nick.c_str(), (void*)m, module_names[i].c_str(), flags.c_str(), V.description.c_str(), srcrev.c_str());
76 #endif
77                 }
78                 else
79                 {
80                         user->SendText(":%s 702 %s :%s %s", ServerInstance->Config->ServerName.c_str(),
81                                 user->nick.c_str(), module_names[i].c_str(), V.description.c_str());
82                 }
83         }
84         user->SendText(":%s 703 %s :End of MODULES list", ServerInstance->Config->ServerName.c_str(), user->nick.c_str());
85
86         return CMD_SUCCESS;
87 }
88
89 COMMAND_INIT(CommandModules)