Skip to content

Commit

Permalink
Add reload plugin command for #169
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazrius committed Feb 3, 2023
1 parent 5199168 commit 0f30c28
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 1 addition & 2 deletions include/FLHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,13 +556,12 @@ class CCmds
void CmdSetAdmin(const std::variant<uint, std::wstring>& player, const std::wstring& wscRights);
void CmdGetAdmin(const std::variant<uint, std::wstring>& player);
void CmdDelAdmin(const std::variant<uint, std::wstring>& 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);
Expand Down
20 changes: 20 additions & 0 deletions source/CCmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions source/Features/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

Expand Down

0 comments on commit 0f30c28

Please sign in to comment.