5 #include "../../config/exports.h" 6 #include "../../DCS_Utils/include/DCS_ModuleUtils.h" 7 #include "../../config/registry.h" 9 #include <unordered_map> 248 using MapType = std::map<std::string, Command>;
249 using RunCB = std::function<void(bool*)>;
255 Command(
const char *DCL,
const char *help =
"", RunCB cb =
nullptr)
261 if (!IsCommand(cmd_name))
262 cmd_reg.emplace(cmd_name, *
this);
264 LOG_WARNING(
"Attempted to create command %s. But it was already registered. Ignoring...", DCL);
271 static Command *Get(std::string name)
273 MapType::iterator it = cmd_reg.find(name);
275 if (it != cmd_reg.end())
284 static bool IsCommand(std::string name)
286 MapType::iterator it = cmd_reg.find(name);
287 return it != cmd_reg.end();
295 static Command *Closest(std::string name);
301 static std::vector<std::string> ListCommands()
303 std::vector<std::string> cmds;
304 for (
auto &p : cmd_reg)
306 cmds.push_back(p.second.cmd_name +
" - " + p.second.help_string);
315 inline const std::string getName()
const 324 inline void Run(
bool* brk)
326 if (to_run !=
nullptr)
335 inline static MapType cmd_reg;
338 std::string cmd_name;
339 std::string help_string;
351 #endif _DCS_NETWORK_H Stop server thread without waiting for the client to disconnect (force shutdown server-side).
A class that holds possible future data.
Definition: DCS_ModuleUtils.h:246
Send back a response to the client.
#define DCS_API
Defines the export interface acessible via the dll-interface. Only important for SHARED LIB Compile M...
Definition: exports.h:116
DCS_API bool GetStatus()
Check if the Network module is initilized.
Definition: socket.cpp:14
Holds messages return types.
Definition: registry.h:383
Operation
Defines the message operation modes in the tcp/ip connection.
Definition: DCS_ModuleNetwork.h:186
DCS_API DCS::Utils::AsyncItem< DCS::Registry::SVReturn > SendAsync(Operation op, u8 *data, i32 size)
Sends an asynchronous message to the server.
Definition: message.cpp:132
DCS_API Socket GetConnectedClient()
Returns the currently server connected client.
Definition: server.cpp:457
DCS::GenericHandle Socket
A generic socket.
Definition: DCS_ModuleNetwork.h:34
Send or receive data only.
DCS_API bool StartThread(Socket client)
Starts the server thread on a established connection.
Definition: server.cpp:205
DCS_API void StopListening(Socket server)
Closes the server listening socket, no longer accepting new connections.
Definition: server.cpp:101
CON_VALID
Server connection validity message.
Definition: internal.h:178
DCS_API bool IsRunning()
Checks if the server is running.
Definition: server.cpp:467
Class responsible for keeping the state of a declared command to use in the server console...
Definition: DCS_ModuleNetwork.h:245
DCS_API void Spin()
Make the current thread wait for, and process, console commands.
Definition: cli.cpp:208
NO_OP
Ping the server only.
Definition: internal.h:171
DCS_API Registry::SVReturn SendSync(Operation op, u8 *data, i32 size)
Sends a synchronous message to the server.
Definition: message.cpp:155
EVT_SUB
Subscribe to a server-side event.
Definition: internal.h:176
void * GenericHandle
A generic opaque handle that is only meaningful for the API.
Definition: DCS_ModuleUtils.h:66
signed long i32
Equivalent to int_32t.
Definition: DCS_ModuleUtils.h:53
EVT_UNSUB
Unsubscribe from a previously subscribed event.
Definition: internal.h:178
A wrapper class used to export a simple string to the client side.
Definition: DCS_ModuleUtils.h:73
DCS_API Socket Connect(DCS::Utils::String host, i32 port)
Connect to a running server.
Definition: client.cpp:32
StopMode
Dictates how the server thread should stop.
Definition: DCS_ModuleNetwork.h:59
DCS_API void Init()
Initializes the Network module.
Definition: socket.cpp:4
DCS_API void Destroy()
Destroys the Network module.
Definition: socket.cpp:19
DCS_API void Authenticate(Socket socket, DCS::Utils::String username, DCS::Utils::String password)
Authenticates a valid connection. Call after Connect.
Definition: client.cpp:47
Definition: registry.h:70
#define LOG_WARNING(msg,...)
Alias to LOG_LVL(Warning, msg, VA_ARGS)
Definition: DCS_ModuleUtils.h:36
DCS_API void WaitForConnections(Socket server)
Wait for any client to connect to the server connection Socket.
Definition: server.cpp:79
DCS_API i16 GetMillisLatency()
Gets the current connection latency in milliseconds.
Definition: client.cpp:360
unsigned char u8
Equivalent to uint_8t.
Definition: DCS_ModuleUtils.h:58
DCS_API Socket Create(i32 port)
Create server listening port.
Definition: server.cpp:62
Request a function call to the server.
#define DCS_REGISTER_EVENT
Append this definition before function declarations (or anywhere in the code) to register a tcp conne...
Definition: exports.h:95
OP_ERROR
Send an error to the client/server.
Definition: internal.h:178
DCS_REGISTER_EVENT DCS_API void FibSeqEvt()
A Sample Event possible to implement in the server/API. When called, returns the next number in the F...
Definition: server.cpp:27
short i16
Equivalent to int_16t.
Definition: DCS_ModuleUtils.h:55
DCS_API Socket GetListenSocket()
Returns the server listen socket.
Definition: server.cpp:462
Stop server after waiting for the client to disconnect (blocking the calling thread).
DCS_API void StopThread(Socket client, StopMode mode=StopMode::IMMEDIATE)
Stops the server thread on a established connection (Forces disconnect).
Definition: server.cpp:406