2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2018 linuxdaemon <linuxdaemon.irc@gmail.com>
5 * Copyright (C) 2017-2018 Sadie Powell <sadie@witchery.services>
6 * Copyright (C) 2013-2014, 2016 Attila Molnar <attilamolnar@hush.com>
7 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
8 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
9 * Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
10 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
11 * Copyright (C) 2006, 2010 Craig Edwards <brain@inspircd.org>
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.
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
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/>.
29 /** Handle /LOADMODULE.
31 class CommandLoadmodule : public Command
34 /** Constructor for loadmodule.
36 CommandLoadmodule(Module* parent)
37 : Command(parent,"LOADMODULE", 1, 1)
40 syntax = "<modulename>";
44 * @param parameters The parameters to the command
45 * @param user The user issuing the command
46 * @return A value from CmdResult to indicate command success or failure.
48 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
51 /** Handle /LOADMODULE
53 CmdResult CommandLoadmodule::Handle(User* user, const Params& parameters)
55 if (ServerInstance->Modules->Load(parameters[0]))
57 ServerInstance->SNO->WriteGlobalSno('a', "NEW MODULE: %s loaded %s",user->nick.c_str(), parameters[0].c_str());
58 user->WriteNumeric(RPL_LOADEDMODULE, parameters[0], "Module successfully loaded.");
63 user->WriteNumeric(ERR_CANTLOADMODULE, parameters[0], ServerInstance->Modules->LastError());
68 /** Handle /UNLOADMODULE.
70 class CommandUnloadmodule : public Command
75 /** Constructor for unloadmodule.
77 CommandUnloadmodule(Module* parent)
78 : Command(parent, "UNLOADMODULE", 1)
79 , allowcoreunload(false)
82 syntax = "<modulename>";
86 * @param parameters The parameters to the command
87 * @param user The user issuing the command
88 * @return A value from CmdResult to indicate command success or failure.
90 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
93 CmdResult CommandUnloadmodule::Handle(User* user, const Params& parameters)
95 if (!allowcoreunload && InspIRCd::Match(parameters[0], "core_*.so", ascii_case_insensitive_map))
97 user->WriteNumeric(ERR_CANTUNLOADMODULE, parameters[0], "You cannot unload core commands!");
101 Module* m = ServerInstance->Modules->Find(parameters[0]);
104 user->WriteNumeric(ERR_CANTUNLOADMODULE, parameters[0], "You cannot unload module loading commands!");
108 if (m && ServerInstance->Modules->Unload(m))
110 ServerInstance->SNO->WriteGlobalSno('a', "MODULE UNLOADED: %s unloaded %s", user->nick.c_str(), parameters[0].c_str());
111 user->WriteNumeric(RPL_UNLOADEDMODULE, parameters[0], "Module successfully unloaded.");
115 user->WriteNumeric(ERR_CANTUNLOADMODULE, parameters[0], (m ? ServerInstance->Modules->LastError() : "No such module"));
122 class CoreModLoadModule : public Module
124 CommandLoadmodule cmdloadmod;
125 CommandUnloadmodule cmdunloadmod;
129 : cmdloadmod(this), cmdunloadmod(this)
133 Version GetVersion() CXX11_OVERRIDE
135 return Version("Provides the LOADMODULE and UNLOADMODULE commands", VF_VENDOR|VF_CORE);
138 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
140 ConfigTag* tag = ServerInstance->Config->ConfValue("security");
141 cmdunloadmod.allowcoreunload = tag->getBool("allowcoreunload");
145 MODULE_INIT(CoreModLoadModule)