Ark Server API (ASE) - 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 ArkApi
6{
7 void Commands::AddChatCommand(const FString& command,
8 const std::function<void(AShooterPlayerController*, FString*, EChatSendMode::Type)>&
9 callback)
10 {
11 chat_commands_.push_back(std::make_shared<ChatCommand>(command, callback));
12 }
13
14 void Commands::AddConsoleCommand(const FString& command,
15 const std::function<void(APlayerController*, FString*, bool)>& callback)
16 {
17 console_commands_.push_back(std::make_shared<ConsoleCommand>(command, callback));
18 }
19
20 void Commands::AddRconCommand(const FString& command,
21 const std::function<void(RCONClientConnection*, RCONPacket*, UWorld*)>& callback)
22 {
23 rcon_commands_.push_back(std::make_shared<RconCommand>(command, callback));
24 }
25
26 void Commands::AddOnTickCallback(const FString& id, const std::function<void(float)>& callback)
27 {
28 on_tick_callbacks_.push_back(std::make_shared<OnTickCallback>(id, callback));
29 }
30
31 void Commands::AddOnTimerCallback(const FString& id, const std::function<void()>& callback)
32 {
33 on_timer_callbacks_.push_back(std::make_shared<OnTimerCallback>(id, callback));
34 }
35
37 const std::function<bool(AShooterPlayerController*, FString*,
38 EChatSendMode::Type, bool, bool)>& callback)
39 {
40 on_chat_message_callbacks_.push_back(std::make_shared<OnChatMessageCallback>(id, callback));
41 }
42
43 bool Commands::RemoveChatCommand(const FString& command)
44 {
45 return RemoveCommand<ChatCommand>(command, chat_commands_);
46 }
47
49 {
50 return RemoveCommand<ConsoleCommand>(command, console_commands_);
51 }
52
53 bool Commands::RemoveRconCommand(const FString& command)
54 {
55 return RemoveCommand<RconCommand>(command, rcon_commands_);
56 }
57
59 {
60 return RemoveCommand<OnTickCallback>(id, on_tick_callbacks_);
61 }
62
64 {
65 return RemoveCommand<OnTimerCallback>(id, on_timer_callbacks_);
66 }
67
69 {
70 return RemoveCommand<OnChatMessageCallback>(id, on_chat_message_callbacks_);
71 }
72
73 bool Commands::CheckChatCommands(AShooterPlayerController* shooter_player_controller, FString* message,
74 EChatSendMode::Type mode)
75 {
76 return CheckCommands<ChatCommand>(*message, chat_commands_, shooter_player_controller, message, mode);
77 }
78
79 bool Commands::CheckConsoleCommands(APlayerController* a_player_controller, FString* cmd, bool write_to_log)
80 {
81 return CheckCommands<ConsoleCommand>(*cmd, console_commands_, a_player_controller, cmd, write_to_log);
82 }
83
84 bool Commands::CheckRconCommands(RCONClientConnection* rcon_client_connection, RCONPacket* rcon_packet,
85 UWorld* u_world)
86 {
87 return CheckCommands<RconCommand>(rcon_packet->Body, rcon_commands_, rcon_client_connection, rcon_packet,
88 u_world);
89 }
90
91 void Commands::CheckOnTickCallbacks(float delta_seconds)
92 {
93 const auto tmp_tick_callbacks = on_tick_callbacks_;
94 for (const auto& data : tmp_tick_callbacks)
95 {
96 if (data)
97 {
98 data->callback(delta_seconds);
99 }
100 }
101 }
102
104 {
105 const auto tmp_timer_callbacks = on_timer_callbacks_;
106 for (const auto& data : tmp_timer_callbacks)
107 {
108 if (data)
109 {
110 data->callback();
111 }
112 }
113 }
114
116 AShooterPlayerController* player_controller,
117 FString* message,
118 EChatSendMode::Type mode,
119 bool spam_check,
120 bool command_executed)
121 {
122 const auto tmp_chat_callbacks = on_chat_message_callbacks_;
123
124 bool prevent_default = false;
125 for (const auto& data : tmp_chat_callbacks)
126 {
127 prevent_default |= data->callback(player_controller, message, mode, spam_check, command_executed);
128 }
129
130 return prevent_default;
131 }
132
133 // Free function
135 {
137 }
138} // namespace ArkApi
virtual std::unique_ptr< ArkApi::ICommands > & GetCommands()=0
std::vector< std::shared_ptr< OnTickCallback > > on_tick_callbacks_
Definition Commands.h:128
std::vector< std::shared_ptr< OnChatMessageCallback > > on_chat_message_callbacks_
Definition Commands.h:130
std::vector< std::shared_ptr< RconCommand > > rcon_commands_
Definition Commands.h:126
bool RemoveOnTickCallback(const FString &id) override
Removes a on-tick callback.
Definition Commands.cpp:58
bool RemoveOnChatMessageCallback(const FString &id) override
Removes an on-chat-message callback.
Definition Commands.cpp:68
void AddConsoleCommand(const FString &command, const std::function< void(APlayerController *, FString *, bool)> &callback) override
Adds a console command.
Definition Commands.cpp:14
void CheckOnTimerCallbacks()
Definition Commands.cpp:103
std::vector< std::shared_ptr< ConsoleCommand > > console_commands_
Definition Commands.h:125
std::vector< std::shared_ptr< OnTimerCallback > > on_timer_callbacks_
Definition Commands.h:129
void AddRconCommand(const FString &command, const std::function< void(RCONClientConnection *, RCONPacket *, UWorld *)> &callback) override
Adds a rcon command.
Definition Commands.cpp:20
bool CheckConsoleCommands(APlayerController *a_player_controller, FString *cmd, bool write_to_log)
Definition Commands.cpp:79
bool RemoveRconCommand(const FString &command) override
Removes a rcon command.
Definition Commands.cpp:53
bool RemoveConsoleCommand(const FString &command) override
Removes a console command.
Definition Commands.cpp:48
std::vector< std::shared_ptr< ChatCommand > > chat_commands_
Definition Commands.h:124
bool CheckRconCommands(RCONClientConnection *rcon_client_connection, RCONPacket *rcon_packet, UWorld *u_world)
Definition Commands.cpp:84
bool RemoveChatCommand(const FString &command) override
Removes a chat command.
Definition Commands.cpp:43
void AddOnChatMessageCallback(const FString &id, const std::function< bool(AShooterPlayerController *, FString *, EChatSendMode::Type, bool, bool)> &callback) override
Added function will be called for AShooterPlayerController->ServerSendChatMessage events.
Definition Commands.cpp:36
bool CheckOnChatMessageCallbacks(AShooterPlayerController *player_controller, FString *message, EChatSendMode::Type mode, bool spam_check, bool command_executed)
Definition Commands.cpp:115
void AddOnTimerCallback(const FString &id, const std::function< void()> &callback) override
Added function will be called every second.
Definition Commands.cpp:31
bool RemoveOnTimerCallback(const FString &id) override
Removes an on-timer callback.
Definition Commands.cpp:63
void AddOnTickCallback(const FString &id, const std::function< void(float)> &callback) override
Added function will be called every frame.
Definition Commands.cpp:26
bool CheckChatCommands(AShooterPlayerController *shooter_player_controller, FString *message, EChatSendMode::Type mode)
Definition Commands.cpp:73
void CheckOnTickCallbacks(float delta_seconds)
Definition Commands.cpp:91
void AddChatCommand(const FString &command, const std::function< void(AShooterPlayerController *, FString *, EChatSendMode::Type)> &callback) override
Adds a chat command.
Definition Commands.cpp:7
Definition IBaseApi.h:9
std::unique_ptr< IBaseApi > game_api
Definition IBaseApi.h:25
ARK_API ICommands &APIENTRY GetCommands()
Definition Commands.cpp:134
Definition json.hpp:4518
FString Body
Definition Other.h:131