From bb2cc7d29efb5bb0e15f4a646a9df78695b3232e Mon Sep 17 00:00:00 2001 From: MrNen Date: Sun, 13 Aug 2023 12:52:40 -0500 Subject: [PATCH] Initial Implementation of External Command Processor --- .../Commands/ExternalCommandProcessor.hpp | 21 ++++++++++++++ include/Core/MessageHandler.hpp | 2 ++ include/PCH.hpp | 3 -- project/FLHook.vcxproj | 2 ++ project/FLHook.vcxproj.filters | 6 ++++ source/API/FLHook/MessageHandler.cpp | 4 +++ .../Commands/ExternalCommandProcessor.cpp | 28 +++++++++++++++++++ source/Core/Timers.cpp | 1 + 8 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 include/Core/Commands/ExternalCommandProcessor.hpp create mode 100644 source/Core/Commands/ExternalCommandProcessor.cpp diff --git a/include/Core/Commands/ExternalCommandProcessor.hpp b/include/Core/Commands/ExternalCommandProcessor.hpp new file mode 100644 index 000000000..a252721a7 --- /dev/null +++ b/include/Core/Commands/ExternalCommandProcessor.hpp @@ -0,0 +1,21 @@ +#pragma once + +class ExternalCommandProcessor +{ + // clang-format off + std::unordered_map> functions = + { + { + std::wstring(L"beam"), Beam + }, + { + + } + }; + // clang-format on + + static nlohmann::json Beam(const nlohmann::json& parameters); + + public: + std::optional ProcessCommand(const nlohmann::json& command); +}; diff --git a/include/Core/MessageHandler.hpp b/include/Core/MessageHandler.hpp index 5db2ca70f..c69e925ad 100644 --- a/include/Core/MessageHandler.hpp +++ b/include/Core/MessageHandler.hpp @@ -36,6 +36,7 @@ class MessageHandler final : public AMQP::ConnectionHandler, public Singleton(queue); } @@ -43,4 +44,5 @@ class MessageHandler final : public AMQP::ConnectionHandler, public Singleton #include - #include "Core/Templates/Constexpr.hpp" -#include "Core/Templates/Typedefs.hpp" #define MAGIC_ENUM_USING_ALIAS_STRING_VIEW using string_view = std::wstring_view; #define MAGIC_ENUM_USING_ALIAS_STRING using string = std::wstring; @@ -68,7 +66,6 @@ #include "Core/Codec.hpp" #include "Core/Action.hpp" -#include "Core/MessageHandler.hpp" #include "Core/TempBan.hpp" #include "Defs/ServerStats.hpp" diff --git a/project/FLHook.vcxproj b/project/FLHook.vcxproj index c91329768..0a4e11b84 100644 --- a/project/FLHook.vcxproj +++ b/project/FLHook.vcxproj @@ -33,6 +33,7 @@ + @@ -104,6 +105,7 @@ + diff --git a/project/FLHook.vcxproj.filters b/project/FLHook.vcxproj.filters index 6a479c156..ecf8402d6 100644 --- a/project/FLHook.vcxproj.filters +++ b/project/FLHook.vcxproj.filters @@ -262,6 +262,9 @@ Source\Hooks\ClientServerInterface + + Source\Core\Commands + @@ -405,5 +408,8 @@ Include\API + + Include\Core\Commands + \ No newline at end of file diff --git a/source/API/FLHook/MessageHandler.cpp b/source/API/FLHook/MessageHandler.cpp index 877014d21..d02003ce7 100644 --- a/source/API/FLHook/MessageHandler.cpp +++ b/source/API/FLHook/MessageHandler.cpp @@ -138,3 +138,7 @@ void MessageHandler::Publish(const std::wstring& jsonData, const std::wstring& e channel->publish(StringUtils::wstos(exchange), StringUtils::wstos(queue), StringUtils::wstos(jsonData)); } +void MessageHandler::RemoteProcedureCall(nlohmann::json call) +{ + +} \ No newline at end of file diff --git a/source/Core/Commands/ExternalCommandProcessor.cpp b/source/Core/Commands/ExternalCommandProcessor.cpp new file mode 100644 index 000000000..c30922fbf --- /dev/null +++ b/source/Core/Commands/ExternalCommandProcessor.cpp @@ -0,0 +1,28 @@ +#include "PCH.hpp" +#include "Core/Commands/ExternalCommandProcessor.hpp" +#include "API/API.hpp" + + + +std::optional ExternalCommandProcessor::ProcessCommand(const nlohmann::json& command) +{ + try + { + std::wstring functionName = command.at("command").get(); + + return functions[functionName](command); + } + catch (nlohmann::json::exception& ex) + { + Logger::i()->Log(LogLevel::Warn, std::format(L"Exception was thrown while trying to process an external command. {}",StringUtils::stows(ex.what()))); + } + +} + +nlohmann::json ExternalCommandProcessor::Beam(const nlohmann::json& parameters) +{ + const auto client = Hk::Client::GetClientIdFromCharName(parameters.at("characterName").get()).Handle(); + Hk::Player::Beam(client, parameters.at("baseName").get()); + + return {}; +} \ No newline at end of file diff --git a/source/Core/Timers.cpp b/source/Core/Timers.cpp index 8599e6fdd..31423288c 100644 --- a/source/Core/Timers.cpp +++ b/source/Core/Timers.cpp @@ -5,6 +5,7 @@ #include "Global.hpp" #include "API/API.hpp" +#include "Core/MessageHandler.hpp" PerfTimer::PerfTimer(const std::wstring& func, uint warn) : function(func), warning(warn) {}