]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_info/cmd_modules.cpp
Move src/commands/cmd_*.cpp to src/coremods[/core_*]/
[user/henk/code/inspircd.git] / src / coremods / core_info / 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.
25  */
26 class CommandModules : public Command
27 {
28  public:
29         /** Constructor for modules.
30          */
31         CommandModules(Module* parent) : Command(parent,"MODULES",0,0)
32         {
33                 Penalty = 4;
34                 syntax = "[<servername>]";
35         }
36
37         /** Handle command.
38          * @param parameters The parameters to the command
39          * @param user The user issuing the command
40          * @return A value from CmdResult to indicate command success or failure.
41          */
42         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
43         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
44         {
45                 if (parameters.size() >= 1)
46                         return ROUTE_UNICAST(parameters[0]);
47                 return ROUTE_LOCALONLY;
48         }
49 };
50
51 /** Handle /MODULES
52  */
53 CmdResult CommandModules::Handle (const std::vector<std::string>& parameters, User *user)
54 {
55         // Don't ask remote servers about their modules unless the local user asking is an oper
56         // 2.0 asks anyway, so let's handle that the same way
57         bool for_us = (parameters.empty() || parameters[0] == ServerInstance->Config->ServerName);
58         if ((!for_us) || (!IS_LOCAL(user)))
59         {
60                 if (!user->IsOper())
61                 {
62                         user->WriteNotice("*** You cannot check what modules other servers have loaded.");
63                         return CMD_FAILURE;
64                 }
65
66                 // From an oper and not for us, forward
67                 if (!for_us)
68                         return CMD_SUCCESS;
69         }
70
71         const ModuleManager::ModuleMap& mods = ServerInstance->Modules->GetModules();
72
73         for (ModuleManager::ModuleMap::const_iterator i = mods.begin(); i != mods.end(); ++i)
74         {
75                 Module* m = i->second;
76                 Version V = m->GetVersion();
77
78                 if (IS_LOCAL(user) && user->HasPrivPermission("servers/auspex"))
79                 {
80                         std::string flags("SvcC");
81                         int pos = 0;
82                         for (int mult = 1; mult <= VF_OPTCOMMON; mult *= 2, ++pos)
83                                 if (!(V.Flags & mult))
84                                         flags[pos] = '-';
85
86 #ifdef PURE_STATIC
87                         user->SendText(":%s 702 %s :%p %s %s :%s", ServerInstance->Config->ServerName.c_str(),
88                                 user->nick.c_str(), (void*)m, m->ModuleSourceFile.c_str(), flags.c_str(), V.description.c_str());
89 #else
90                         std::string srcrev = m->ModuleDLLManager->GetVersion();
91                         user->SendText(":%s 702 %s :%p %s %s :%s - %s", ServerInstance->Config->ServerName.c_str(),
92                                 user->nick.c_str(), (void*)m, m->ModuleSourceFile.c_str(), flags.c_str(), V.description.c_str(), srcrev.c_str());
93 #endif
94                 }
95                 else
96                 {
97                         user->SendText(":%s 702 %s :%s %s", ServerInstance->Config->ServerName.c_str(),
98                                 user->nick.c_str(), m->ModuleSourceFile.c_str(), V.description.c_str());
99                 }
100         }
101         user->SendText(":%s 703 %s :End of MODULES list", ServerInstance->Config->ServerName.c_str(), user->nick.c_str());
102
103         return CMD_SUCCESS;
104 }
105
106 COMMAND_INIT(CommandModules)