]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_info/cmd_modules.cpp
Improve the /MODULES output.
[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 #include "core_info.h"
24
25 enum
26 {
27         // From ircd-ratbox with an InspIRCd-specific format.
28         RPL_MODLIST = 702,
29         RPL_ENDOFMODLIST = 703
30 };
31
32 CommandModules::CommandModules(Module* parent)
33         : ServerTargetCommand(parent, "MODULES")
34 {
35         Penalty = 4;
36         syntax = "[<servername>]";
37 }
38
39 /** Handle /MODULES
40  */
41 CmdResult CommandModules::Handle (const std::vector<std::string>& parameters, User *user)
42 {
43         // Don't ask remote servers about their modules unless the local user asking is an oper
44         // 2.0 asks anyway, so let's handle that the same way
45         bool for_us = (parameters.empty() || parameters[0] == ServerInstance->Config->ServerName);
46         if ((!for_us) || (!IS_LOCAL(user)))
47         {
48                 if (!user->IsOper())
49                 {
50                         user->WriteNotice("*** You cannot check what modules other servers have loaded.");
51                         return CMD_FAILURE;
52                 }
53
54                 // From an oper and not for us, forward
55                 if (!for_us)
56                         return CMD_SUCCESS;
57         }
58
59         const ModuleManager::ModuleMap& mods = ServerInstance->Modules->GetModules();
60
61         for (ModuleManager::ModuleMap::const_iterator i = mods.begin(); i != mods.end(); ++i)
62         {
63                 Module* m = i->second;
64                 Version V = m->GetVersion();
65
66                 if (IS_LOCAL(user) && user->HasPrivPermission("servers/auspex"))
67                 {
68                         std::string flags("vcC");
69                         int pos = 0;
70                         for (int mult = 2; mult <= VF_OPTCOMMON; mult *= 2, ++pos)
71                                 if (!(V.Flags & mult))
72                                         flags[pos] = '-';
73
74 #ifdef INSPIRCD_STATIC
75                         user->WriteRemoteNumeric(RPL_MODLIST, m->ModuleSourceFile, INSPIRCD_VERSION, flags, V.description);
76 #else
77                         std::string srcrev = m->ModuleDLLManager->GetVersion();
78                         user->WriteRemoteNumeric(RPL_MODLIST, m->ModuleSourceFile, srcrev.empty() ? "*" : srcrev, flags, V.description);
79 #endif
80                 }
81                 else
82                 {
83                         user->WriteRemoteNumeric(RPL_MODLIST, m->ModuleSourceFile, '*', '*', V.description);
84                 }
85         }
86         user->WriteRemoteNumeric(RPL_ENDOFMODLIST, "End of MODULES list");
87
88         return CMD_SUCCESS;
89 }