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