From 0f30c2876e9ad16ef25745db21d7ecd8918643de Mon Sep 17 00:00:00 2001 From: Laz Date: Fri, 3 Feb 2023 19:17:11 +0000 Subject: [PATCH] Add reload plugin command for #169 --- include/FLHook.hpp | 3 +-- source/CCmds.cpp | 20 ++++++++++++++++++++ source/Features/PluginManager.cpp | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/FLHook.hpp b/include/FLHook.hpp index d1a26733c..8fed03a14 100644 --- a/include/FLHook.hpp +++ b/include/FLHook.hpp @@ -556,13 +556,12 @@ class CCmds void CmdSetAdmin(const std::variant& player, const std::wstring& wscRights); void CmdGetAdmin(const std::variant& player); void CmdDelAdmin(const std::variant& player); - void CmdRehash(); - void CmdUnload(const std::wstring& wscParam); void CmdLoadPlugins(); void CmdLoadPlugin(const std::wstring& wscPlugin); void CmdListPlugins(); void CmdUnloadPlugin(const std::wstring& wscPlugin); + void CmdReloadPlugin(const std::wstring& wscPlugin); void ExecuteCommandString(const std::wstring& wscCmd); void SetRightsByString(const std::string& scRightStr); diff --git a/source/CCmds.cpp b/source/CCmds.cpp index cd21cda43..9c19e55e2 100644 --- a/source/CCmds.cpp +++ b/source/CCmds.cpp @@ -723,6 +723,22 @@ void CCmds::CmdLoadPlugin(const std::wstring& wscPlugin) /////////////////////////////////////////////////////////////////////////////////////////////////////////////// +void CCmds::CmdReloadPlugin(const std::wstring& wscPlugin) +{ + RIGHT_CHECK(RIGHT_PLUGINS); + + if (const auto err = PluginManager::i()->unload(wstos(wscPlugin)); err.has_error()) + { + PrintError(err.error()); + return; + } + + PluginManager::i()->load(wscPlugin, this, false); + Print("OK"); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////// + void CCmds::CmdListPlugins() { RIGHT_CHECK(RIGHT_PLUGINS); @@ -1224,6 +1240,10 @@ void CCmds::ExecuteCommandString(const std::wstring& wscCmdStr) { CmdLoadPlugins(); } + else if (wscCmd == L"reloadplugin") + { + CmdReloadPlugin(ArgStrToEnd(1)); + } else if (wscCmd == L"loadplugin") { CmdLoadPlugin(ArgStrToEnd(1)); diff --git a/source/Features/PluginManager.cpp b/source/Features/PluginManager.cpp index 315cb9309..b5c87610a 100644 --- a/source/Features/PluginManager.cpp +++ b/source/Features/PluginManager.cpp @@ -227,6 +227,8 @@ void PluginManager::load(const std::wstring& fileName, CCmds* adminInterface, bo plugin.pInfo = std::move(pi); plugins_.push_back(plugin); + std::sort(plugins_.begin(), plugins_.end(), [](const PluginData& a, const PluginData& b) { return a.name < b.name; }); + adminInterface->Print(std::format("Plugin {} loaded ({})", plugin.shortName, wstos(plugin.dllName))); }