]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_info/cmd_modules.cpp
7624ce05f0d26275526c467243d956e7f3be3135
[user/henk/code/inspircd.git] / src / coremods / core_info / cmd_modules.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2017-2020 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2013-2016 Attila Molnar <attilamolnar@hush.com>
6  *   Copyright (C) 2013 Daniel Vassdal <shutter@canternet.org>
7  *   Copyright (C) 2012 Robby <robby@chatbelgie.be>
8  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
9  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
10  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
11  *   Copyright (C) 2005, 2007-2008 Craig Edwards <brain@inspircd.org>
12  *
13  * This file is part of InspIRCd.  InspIRCd is free software: you can
14  * redistribute it and/or modify it under the terms of the GNU General Public
15  * License as published by the Free Software Foundation, version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but WITHOUT
18  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
20  * details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24  */
25
26
27 #include "inspircd.h"
28 #include "core_info.h"
29
30 enum
31 {
32         // From ircd-ratbox with an InspIRCd-specific format.
33         RPL_MODLIST = 702,
34         RPL_ENDOFMODLIST = 703
35 };
36
37 CommandModules::CommandModules(Module* parent)
38         : ServerTargetCommand(parent, "MODULES")
39 {
40         Penalty = 4;
41         syntax = "[<servername>]";
42 }
43
44 /** Handle /MODULES
45  */
46 CmdResult CommandModules::Handle(User* user, const Params& parameters)
47 {
48         // Don't ask remote servers about their modules unless the local user asking is an oper
49         // 2.0 asks anyway, so let's handle that the same way
50         bool for_us = (parameters.empty() || irc::equals(parameters[0], ServerInstance->Config->ServerName));
51         if ((!for_us) || (!IS_LOCAL(user)))
52         {
53                 if (!user->IsOper())
54                 {
55                         user->WriteNotice("*** You cannot check what modules other servers have loaded.");
56                         return CMD_FAILURE;
57                 }
58
59                 // From an oper and not for us, forward
60                 if (!for_us)
61                         return CMD_SUCCESS;
62         }
63
64         const ModuleManager::ModuleMap& mods = ServerInstance->Modules->GetModules();
65
66         for (ModuleManager::ModuleMap::const_iterator i = mods.begin(); i != mods.end(); ++i)
67         {
68                 Module* m = i->second;
69                 Version V = m->GetVersion();
70
71                 if (IS_LOCAL(user) && user->HasPrivPermission("servers/auspex"))
72                 {
73                         std::string flags("VCO");
74                         size_t pos = 0;
75                         for (int mult = 2; mult <= VF_OPTCOMMON; mult *= 2, ++pos)
76                                 if (!(V.Flags & mult))
77                                         flags[pos] = '-';
78
79                         const char* srcrev = m->ModuleDLLManager->GetVersion();
80                         user->WriteRemoteNumeric(RPL_MODLIST, m->ModuleSourceFile, srcrev ? srcrev : "*", flags, V.description);
81                 }
82                 else
83                 {
84                         user->WriteRemoteNumeric(RPL_MODLIST, m->ModuleSourceFile, '*', '*', V.description);
85                 }
86         }
87         user->WriteRemoteNumeric(RPL_ENDOFMODLIST, "End of MODULES list");
88
89         return CMD_SUCCESS;
90 }