2017-01-20 08:36:52 -05:00
|
|
|
#pragma once
|
|
|
|
|
2017-01-19 16:23:59 -05:00
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
class Command : public Component
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class Params
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Params() {};
|
|
|
|
virtual ~Params() {};
|
2022-01-17 12:21:51 -05:00
|
|
|
virtual const char* get(size_t index) = 0;
|
2017-01-19 16:23:59 -05:00
|
|
|
virtual size_t length() = 0;
|
|
|
|
|
|
|
|
virtual std::string join(size_t startIndex);
|
2022-01-17 12:21:51 -05:00
|
|
|
virtual const char* operator[](size_t index);
|
2017-01-19 16:23:59 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
class ClientParams : public Params
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ClientParams(unsigned int id) : commandId(id) {};
|
|
|
|
ClientParams(const ClientParams &obj) : commandId(obj.commandId) {};
|
|
|
|
ClientParams() : ClientParams(*Game::cmd_id) {};
|
|
|
|
|
2022-01-17 12:21:51 -05:00
|
|
|
const char* get(size_t index) override;
|
2017-01-19 16:23:59 -05:00
|
|
|
size_t length() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned int commandId;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ServerParams : public Params
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ServerParams(unsigned int id) : commandId(id) {};
|
|
|
|
ServerParams(const ServerParams &obj) : commandId(obj.commandId) {};
|
|
|
|
ServerParams() : ServerParams(*Game::cmd_id_sv) {};
|
|
|
|
|
2022-01-17 12:21:51 -05:00
|
|
|
const char* get(size_t index) override;
|
2017-01-19 16:23:59 -05:00
|
|
|
size_t length() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned int commandId;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef void(Callback)(Command::Params* params);
|
|
|
|
|
|
|
|
Command();
|
|
|
|
~Command();
|
|
|
|
|
|
|
|
static Game::cmd_function_t* Allocate();
|
|
|
|
|
|
|
|
static void Add(const char* name, Utils::Slot<Callback> callback);
|
|
|
|
static void AddSV(const char* name, Utils::Slot<Callback> callback);
|
|
|
|
static void AddRaw(const char* name, void(*callback)(), bool key = false);
|
|
|
|
static void AddRawSV(const char* name, void(*callback)());
|
|
|
|
static void Execute(std::string command, bool sync = true);
|
|
|
|
|
2018-12-17 08:29:18 -05:00
|
|
|
static Game::cmd_function_t* Find(const std::string& command);
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
static std::unordered_map<std::string, Utils::Slot<Callback>> FunctionMap;
|
|
|
|
static std::unordered_map<std::string, Utils::Slot<Callback>> FunctionMapSV;
|
|
|
|
|
|
|
|
static void MainCallback();
|
|
|
|
static void MainCallbackSV();
|
|
|
|
};
|
|
|
|
}
|