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) : Command(parent,"LOADMODULE",1,1) { flags_needed='o'; syntax = "<modulename>"; }
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.
42 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
45 /** Handle /LOADMODULE
47 CmdResult CommandLoadmodule::Handle(User* user, const Params& parameters)
49 if (ServerInstance->Modules->Load(parameters[0]))
51 ServerInstance->SNO->WriteGlobalSno('a', "NEW MODULE: %s loaded %s",user->nick.c_str(), parameters[0].c_str());
52 user->WriteNumeric(RPL_LOADEDMODULE, parameters[0], "Module successfully loaded.");
57 user->WriteNumeric(ERR_CANTLOADMODULE, parameters[0], ServerInstance->Modules->LastError());
62 /** Handle /UNLOADMODULE.
64 class CommandUnloadmodule : public Command
69 /** Constructor for unloadmodule.
71 CommandUnloadmodule(Module* parent)
72 : Command(parent, "UNLOADMODULE", 1)
73 , allowcoreunload(false)
76 syntax = "<modulename>";
80 * @param parameters The parameters to the command
81 * @param user The user issuing the command
82 * @return A value from CmdResult to indicate command success or failure.
84 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
87 CmdResult CommandUnloadmodule::Handle(User* user, const Params& parameters)
89 if (!allowcoreunload && InspIRCd::Match(parameters[0], "core_*.so", ascii_case_insensitive_map))
91 user->WriteNumeric(ERR_CANTUNLOADMODULE, parameters[0], "You cannot unload core commands!");
95 Module* m = ServerInstance->Modules->Find(parameters[0]);
98 user->WriteNumeric(ERR_CANTUNLOADMODULE, parameters[0], "You cannot unload module loading commands!");
102 if (m && ServerInstance->Modules->Unload(m))
104 ServerInstance->SNO->WriteGlobalSno('a', "MODULE UNLOADED: %s unloaded %s", user->nick.c_str(), parameters[0].c_str());
105 user->WriteNumeric(RPL_UNLOADEDMODULE, parameters[0], "Module successfully unloaded.");
109 user->WriteNumeric(ERR_CANTUNLOADMODULE, parameters[0], (m ? ServerInstance->Modules->LastError() : "No such module"));
116 class CoreModLoadModule : public Module
118 CommandLoadmodule cmdloadmod;
119 CommandUnloadmodule cmdunloadmod;
123 : cmdloadmod(this), cmdunloadmod(this)
127 Version GetVersion() CXX11_OVERRIDE
129 return Version("Provides the LOADMODULE and UNLOADMODULE commands", VF_VENDOR|VF_CORE);
132 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
134 ConfigTag* tag = ServerInstance->Config->ConfValue("security");
135 cmdunloadmod.allowcoreunload = tag->getBool("allowcoreunload");
139 MODULE_INIT(CoreModLoadModule)