Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
Commands.cpp
Go to the documentation of this file.
1#include "Commands.h"
2
3#include "IBaseApi.h"
4
5namespace AsaApi
6{
7 void Commands::AddChatCommand(const FString& command,
8 const std::function<void(AShooterPlayerController*, FString*, int, int)>&callback)
9 {
10 chat_commands_.push_back(std::make_shared<ChatCommand>(command, callback));
11 }
12
13 void Commands::AddConsoleCommand(const FString& command,
14 const std::function<void(APlayerController*, FString*, bool)>& callback)
15 {
16 console_commands_.push_back(std::make_shared<ConsoleCommand>(command, callback));
17 }
18
19 void Commands::AddRconCommand(const FString& command, const std::function<void(RCONClientConnection*, RCONPacket*, UWorld*)>& callback)
20 {
21 rcon_commands_.push_back(std::make_shared<RconCommand>(command, callback));
22 }
23
24 void Commands::AddOnTickCallback(const FString& id, const std::function<void(float)>& callback)
25 {
26 on_tick_callbacks_.push_back(std::make_shared<OnTickCallback>(id, callback));
27 }
28
29 void Commands::AddOnTimerCallback(const FString& id, const std::function<void()>& callback)
30 {
31 on_timer_callbacks_.push_back(std::make_shared<OnTimerCallback>(id, callback));
32 }
33
34 void Commands::AddOnChatMessageCallback(const FString& id, const std::function<bool(AShooterPlayerController*, FString*, int, int, bool, bool)>& callback)
35 {
36 on_chat_message_callbacks_.push_back(std::make_shared<OnChatMessageCallback>(id, callback));
37 }
38
39 bool Commands::RemoveChatCommand(const FString& command)
40 {
41 return RemoveCommand<ChatCommand>(command, chat_commands_);
42 }
43
45 {
46 return RemoveCommand<ConsoleCommand>(command, console_commands_);
47 }
48
49 bool Commands::RemoveRconCommand(const FString& command)
50 {
51 return RemoveCommand<RconCommand>(command, rcon_commands_);
52 }
53
55 {
56 return RemoveCommand<OnTickCallback>(id, on_tick_callbacks_);
57 }
58
60 {
61 return RemoveCommand<OnTimerCallback>(id, on_timer_callbacks_);
62 }
63
65 {
66 return RemoveCommand<OnChatMessageCallback>(id, on_chat_message_callbacks_);
67 }
68
69 bool Commands::CheckChatCommands(AShooterPlayerController* shooter_player_controller, FString* message, int mode, int platform)
70 {
71 return CheckCommands<ChatCommand>(*message, chat_commands_, shooter_player_controller, message, mode, platform);
72 }
73
74 bool Commands::CheckConsoleCommands(APlayerController* a_player_controller, FString* cmd, bool write_to_log)
75 {
76 return CheckCommands<ConsoleCommand>(*cmd, console_commands_, a_player_controller, cmd, write_to_log);
77 }
78
79 bool Commands::CheckRconCommands(RCONClientConnection* rcon_client_connection, RCONPacket* rcon_packet,
80 UWorld* u_world)
81 {
82 return CheckCommands<RconCommand>(rcon_packet->Body, rcon_commands_, rcon_client_connection, rcon_packet,
83 u_world);
84 }
85
86 void Commands::CheckOnTickCallbacks(float delta_seconds)
87 {
88 const auto tmp_tick_callbacks = on_tick_callbacks_;
89 for (const auto& data : tmp_tick_callbacks)
90 {
91 if (data)
92 {
93 data->callback(delta_seconds);
94 }
95 }
96 }
97
99 {
100 const auto tmp_timer_callbacks = on_timer_callbacks_;
101 for (const auto& data : tmp_timer_callbacks)
102 {
103 if (data)
104 {
105 data->callback();
106 }
107 }
108 }
109
111 AShooterPlayerController* player_controller,
112 FString* message,
113 int mode,
114 int platform,
115 bool spam_check,
116 bool command_executed)
117 {
118 const auto tmp_chat_callbacks = on_chat_message_callbacks_;
119
120 bool prevent_default = false;
121 for (const auto& data : tmp_chat_callbacks)
122 {
123 prevent_default |= data->callback(player_controller, message, mode, platform, spam_check, command_executed);
124 }
125
126 return prevent_default;
127 }
128
129 // Free function
131 {
132 return *API::game_api->GetCommands();
133 }
134} // namespace AsaApi
void AddRconCommand(const FString &command, const std::function< void(RCONClientConnection *, RCONPacket *, UWorld *)> &callback) override
Adds a rcon command.
Definition Commands.cpp:19
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
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
void AddConsoleCommand(const FString &command, const std::function< void(APlayerController *, FString *, bool)> &callback) override
Adds a console command.
Definition Commands.cpp:13
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
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
ARK_API ICommands &APIENTRY GetCommands()
Definition Commands.cpp:130
Definition json.hpp:4518