Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
Requests.h
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4#include <vector>
5#include <mutex>
6#include "API/Base.h"
7
8
9namespace API
10{
12 {
13 public:
14 ARK_API static Requests& Get();
15
16 Requests();
17 ~Requests();
18
19 Requests(const Requests&) = delete;
20 Requests(Requests&&) = delete;
21 Requests& operator=(const Requests&) = delete;
22 Requests& operator=(Requests&&) = delete;
23
24 /**
25 * \brief Creates an async GET Request that runs in another thread but calls the callback from the main thread
26 * \param request URL
27 * \param the callback function, binds sucess(bool) and result(string), result is error code if request failed and the response otherwise
28 * \param included headers
29 */
30 ARK_API bool CreateGetRequest(const std::string& url,
31 const std::function<void(bool, std::string)>& callback,
32 std::vector<std::string> headers = {});
33
34 /**
35 * \brief Creates an async POST Request with application/x-www-form-urlencoded content type that runs in another thread but calls the callback from the main thread
36 * \param request URL
37 * \param the callback function, binds sucess(bool) and result(string), result is error code if request failed and the response otherwise
38 * \param data to post
39 * \param included headers
40 */
41 ARK_API bool CreatePostRequest(const std::string& url,
42 const std::function<void(bool, std::string)>& callback,
43 const std::string& post_data,
44 std::vector<std::string> headers = {});
45
46 /**
47 * \brief Creates an async POST Request that runs in another thread but calls the callback from the main thread
48 * \param request URL
49 * \param the callback function, binds sucess(bool) and result(string), result is error code if request failed and the response otherwise
50 * \param data to post
51 * \param content type
52 * \param included headers
53 */
54 ARK_API bool CreatePostRequest(const std::string& url,
55 const std::function<void(bool, std::string)>& callback,
56 const std::string& post_data,
57 const std::string& content_type,
58 std::vector<std::string> headers = {});
59
60 /**
61 * \brief Creates an async POST Request that runs in another thread but calls the callback from the main thread
62 * \param request URL
63 * \param the callback function, binds sucess(bool) and result(string), result is error code if request failed and the response otherwise
64 * \param data key
65 * \param data value
66 * \param included headers
67 */
68 ARK_API bool CreatePostRequest(const std::string& url,
69 const std::function<void(bool, std::string)>& callback,
70 const std::vector<std::string>& post_ids,
71 const std::vector<std::string>& post_data,
72 std::vector<std::string> headers = {});
73
74 /**
75 * \brief Creates an async DELETE Request that runs in another thread but calls the callback from the main thread
76 * \param request URL
77 * \param the callback function, binds sucess(bool) and result(string), result is error code if request failed and the response otherwise
78 * \param included headers
79 */
80 ARK_API bool CreateDeleteRequest(const std::string& url,
81 const std::function<void(bool, std::string)>& callback,
82 std::vector<std::string> headers = {});
83
84 static bool DownloadFile(const std::string& url, const std::string& localPath, std::vector<std::string> headers = {});
85 private:
86 class impl;
88 };
89} // namespace API
#define ARK_API
Definition Ark.h:16
static void SetServerID(RCONClientConnection *, RCONPacket *, UWorld *)
std::string GetApiName() override
bool DownloadCacheFiles(const std::filesystem::path downloadFile, const std::filesystem::path localFile)
std::unique_ptr< AsaApi::IApiUtils > & GetApiUtils() override
static void LoadPluginCmd(APlayerController *, FString *, bool)
std::unique_ptr< AsaApi::ICommands > commands_
Definition ArkBaseApi.h:45
void RegisterCommands() override
float GetVersion() override
~ArkBaseApi() override=default
static FString LoadPlugin(FString *cmd)
static void UnloadPluginRcon(RCONClientConnection *, RCONPacket *, UWorld *)
nlohmann::json GetConfig()
std::unique_ptr< AsaApi::IApiUtils > api_utils_
Definition ArkBaseApi.h:47
bool Init() override
static void UnloadPluginCmd(APlayerController *, FString *, bool)
static void LoadPluginRcon(RCONClientConnection *, RCONPacket *, UWorld *)
static FString UnloadPlugin(FString *cmd)
std::unique_ptr< AsaApi::ICommands > & GetCommands() override
std::unique_ptr< AsaApi::IHooks > & GetHooks() override
std::unique_ptr< AsaApi::IHooks > hooks_
Definition ArkBaseApi.h:46
Hooks(const Hooks &)=delete
Hooks & operator=(const Hooks &)=delete
std::unordered_map< std::string, std::vector< std::shared_ptr< Hook > > > all_hooks_
Definition Hooks.h:41
~Hooks() override=default
Hooks & operator=(Hooks &&)=delete
bool DisableHook(const std::string &func_name, LPVOID detour) override
Removes a hook from a function.
Definition Hooks.cpp:66
bool SetHookInternal(const std::string &func_name, LPVOID detour, LPVOID *original) override
Definition Hooks.cpp:18
Hooks(Hooks &&)=delete
std::vector< std::shared_ptr< Plugin > > loaded_plugins_
std::vector< std::shared_ptr< Plugin > >::const_iterator FindPlugin(const std::string &plugin_name)
Find plugin by it's name.
PluginManager & operator=(const PluginManager &)=delete
PluginManager()=default
PluginManager(const PluginManager &)=delete
PluginManager(PluginManager &&)=delete
void LoadAllPlugins()
Find and load all plugins.
static PluginManager & Get()
static nlohmann::json ReadPluginInfo(const std::string &plugin_name)
bool IsPluginLoaded(const std::string &plugin_name)
Returns true if plugin was loaded, false otherwise.
std::shared_ptr< Plugin > & LoadPlugin(const std::string &plugin_name) noexcept(false)
Load plugin by it's name.
static void DetectPluginChangesTimerCallback()
Checks for auto plugin reloads.
void UnloadPlugin(const std::string &plugin_name) noexcept(false)
Unload plugin by it's name. Plugin must free all used resources.
PluginManager & operator=(PluginManager &&)=delete
~PluginManager()=default
static nlohmann::json ReadSettingsConfig()
Requests(Requests &&)=delete
ARK_API bool CreateGetRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, std::vector< std::string > headers={})
Creates an async GET Request that runs in another thread but calls the callback from the main thread.
Definition Requests.cpp:140
ARK_API bool CreatePostRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, const std::vector< std::string > &post_ids, const std::vector< std::string > &post_data, std::vector< std::string > headers={})
Creates an async POST Request that runs in another thread but calls the callback from the main thread...
Definition Requests.cpp:249
Requests & operator=(Requests &&)=delete
ARK_API bool CreateDeleteRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, std::vector< std::string > headers={})
Creates an async DELETE Request that runs in another thread but calls the callback from the main thre...
Definition Requests.cpp:303
Requests & operator=(const Requests &)=delete
ARK_API bool CreatePostRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, const std::string &post_data, std::vector< std::string > headers={})
Creates an async POST Request with application/x-www-form-urlencoded content type that runs in anothe...
Definition Requests.cpp:173
static ARK_API Requests & Get()
Definition Requests.cpp:78
ARK_API bool CreatePostRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, const std::string &post_data, const std::string &content_type, std::vector< std::string > headers={})
Creates an async POST Request that runs in another thread but calls the callback from the main thread...
Definition Requests.cpp:211
std::unique_ptr< impl > pimpl
Definition Requests.h:87
Requests(const Requests &)=delete
static bool DownloadFile(const std::string &url, const std::string &localPath, std::vector< std::string > headers={})
Definition Requests.cpp:336
void AddRconCommand(const FString &command, const std::function< void(RCONClientConnection *, RCONPacket *, UWorld *)> &callback) override
Adds a rcon command.
Definition Commands.cpp:19
std::vector< std::shared_ptr< OnTickCallback > > on_tick_callbacks_
Definition Commands.h:118
bool CheckCommands(const FString &message, const std::vector< std::shared_ptr< T > > &commands, Args &&... args)
Definition Commands.h:89
~Commands() override=default
std::vector< std::shared_ptr< ConsoleCommand > > console_commands_
Definition Commands.h:115
Commands()=default
void CheckOnTickCallbacks(float delta_seconds)
Definition Commands.cpp:86
bool CheckRconCommands(RCONClientConnection *rcon_client_connection, RCONPacket *rcon_packet, UWorld *u_world)
Definition Commands.cpp:79
void CheckOnTimerCallbacks()
Definition Commands.cpp:98
void AddOnTimerCallback(const FString &id, const std::function< void()> &callback) override
Added function will be called every second.
Definition Commands.cpp:29
bool CheckChatCommands(AShooterPlayerController *shooter_player_controller, FString *message, int mode, int platform)
Definition Commands.cpp:69
void AddOnChatMessageCallback(const FString &id, const std::function< bool(AShooterPlayerController *, FString *, int, int, bool, bool)> &callback) override
Added function will be called for AShooterPlayerController->ServerSendChatMessage events.
Definition Commands.cpp:34
std::vector< std::shared_ptr< ChatCommand > > chat_commands_
Definition Commands.h:114
std::vector< std::shared_ptr< OnTimerCallback > > on_timer_callbacks_
Definition Commands.h:119
Commands & operator=(const Commands &)=delete
std::vector< std::shared_ptr< OnChatMessageCallback > > on_chat_message_callbacks_
Definition Commands.h:120
bool RemoveConsoleCommand(const FString &command) override
Removes a console command.
Definition Commands.cpp:44
void AddChatCommand(const FString &command, const std::function< void(AShooterPlayerController *, FString *, int, int)> &callback) override
Adds a chat command.
Definition Commands.cpp:7
Commands(Commands &&)=delete
Commands(const Commands &)=delete
Commands & operator=(Commands &&)=delete
void AddConsoleCommand(const FString &command, const std::function< void(APlayerController *, FString *, bool)> &callback) override
Adds a console command.
Definition Commands.cpp:13
bool RemoveCommand(const FString &command, std::vector< std::shared_ptr< T > > &commands)
Definition Commands.h:70
bool RemoveRconCommand(const FString &command) override
Removes a rcon command.
Definition Commands.cpp:49
bool CheckConsoleCommands(APlayerController *a_player_controller, FString *cmd, bool write_to_log)
Definition Commands.cpp:74
void AddOnTickCallback(const FString &id, const std::function< void(float)> &callback) override
Added function will be called every frame.
Definition Commands.cpp:24
bool RemoveChatCommand(const FString &command) override
Removes a chat command.
Definition Commands.cpp:39
bool RemoveOnTimerCallback(const FString &id) override
Removes an on-timer callback.
Definition Commands.cpp:59
bool CheckOnChatMessageCallbacks(AShooterPlayerController *player_controller, FString *message, int mode, int platform, bool spam_check, bool command_executed)
Definition Commands.cpp:110
std::vector< std::shared_ptr< RconCommand > > rcon_commands_
Definition Commands.h:116
bool RemoveOnChatMessageCallback(const FString &id) override
Removes an on-chat-message callback.
Definition Commands.cpp:64
bool RemoveOnTickCallback(const FString &id) override
Removes a on-tick callback.
Definition Commands.cpp:54
static const FColor Green
Definition ColorList.h:24
UE_NODISCARD FORCEINLINE const TCHAR * operator*() const UE_LIFETIMEBOUND
Definition IBaseApi.h:9
constexpr float api_version
ARK_API std::string GetCurrentDir()
Definition Tools.cpp:8
IApiUtils & GetApiUtils()
Definition ApiUtils.cpp:206
void InitHooks()
Definition HooksImpl.cpp:43
Definition json.hpp:4518
LPVOID target
Definition Hooks.h:36
LPVOID * original
Definition Hooks.h:38
Hook(LPVOID target, LPVOID detour, LPVOID *original)
Definition Hooks.h:29
LPVOID detour
Definition Hooks.h:37
std::string description
std::vector< std::string > dependencies
Plugin(HINSTANCE h_module, std::string name, std::string full_name, std::string description, float version, float min_api_version, std::vector< std::string > dependencies)
HINSTANCE h_module
float min_api_version
std::string full_name
std::string name
Command(FString command, std::function< T > callback)
Definition Commands.h:51
std::function< T > callback
Definition Commands.h:58
void SendMessageW(int Id, int Type, FString *OutGoingMessage)
Definition Other.h:38
int Id
Definition Other.h:13