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:
|
2023-01-02 12:04:34 -05:00
|
|
|
static_assert(sizeof(Game::cmd_function_s) == 0x18);
|
2022-05-29 04:19:48 -04:00
|
|
|
|
2017-01-19 16:23:59 -05:00
|
|
|
class Params
|
|
|
|
{
|
|
|
|
public:
|
2022-04-12 08:34:51 -04:00
|
|
|
Params() = default;
|
|
|
|
virtual ~Params() = default;
|
2022-03-15 20:44:59 -04:00
|
|
|
|
2023-01-09 17:51:28 -05:00
|
|
|
Params(Params&&) = delete;
|
|
|
|
Params(const Params&) = delete;
|
|
|
|
Params& operator=(Params&&) = delete;
|
|
|
|
Params& operator=(const Params&) = delete;
|
|
|
|
|
|
|
|
[[nodiscard]] virtual int size() const noexcept = 0;
|
|
|
|
[[nodiscard]] virtual const char* get(int index) const noexcept = 0;
|
2022-08-21 12:52:54 -04:00
|
|
|
[[nodiscard]] virtual std::string join(int index) const;
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2022-03-17 14:50:20 -04:00
|
|
|
virtual const char* operator[](const int index)
|
|
|
|
{
|
|
|
|
return this->get(index);
|
|
|
|
}
|
2017-01-19 16:23:59 -05:00
|
|
|
};
|
|
|
|
|
2022-04-12 08:34:51 -04:00
|
|
|
class ClientParams final : public Params
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
|
|
|
public:
|
2022-03-17 14:50:20 -04:00
|
|
|
ClientParams();
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2023-01-09 17:51:28 -05:00
|
|
|
[[nodiscard]] int size() const noexcept override;
|
|
|
|
[[nodiscard]] const char* get(int index) const noexcept override;
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
private:
|
2022-03-17 14:50:20 -04:00
|
|
|
int nesting_;
|
2017-01-19 16:23:59 -05:00
|
|
|
};
|
|
|
|
|
2022-04-12 08:34:51 -04:00
|
|
|
class ServerParams final : public Params
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
|
|
|
public:
|
2022-03-17 14:50:20 -04:00
|
|
|
ServerParams();
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2023-01-09 17:51:28 -05:00
|
|
|
[[nodiscard]] int size() const noexcept override;
|
|
|
|
[[nodiscard]] const char* get(int index) const noexcept override;
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
private:
|
2022-03-17 14:50:20 -04:00
|
|
|
int nesting_;
|
2017-01-19 16:23:59 -05:00
|
|
|
};
|
|
|
|
|
2022-05-29 04:19:48 -04:00
|
|
|
Command() = default;
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2023-01-02 12:04:34 -05:00
|
|
|
static Game::cmd_function_s* Allocate();
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2022-06-12 18:02:20 -04:00
|
|
|
static void Add(const char* name, const std::function<void()>& callback);
|
|
|
|
static void Add(const char* name, const std::function<void(Command::Params*)>& callback);
|
2017-01-19 16:23:59 -05:00
|
|
|
static void AddRaw(const char* name, void(*callback)(), bool key = false);
|
2022-06-16 10:15:26 -04:00
|
|
|
static void AddSV(const char* name, const std::function<void(Command::Params*)>& callback);
|
2017-01-19 16:23:59 -05:00
|
|
|
static void Execute(std::string command, bool sync = true);
|
|
|
|
|
2023-01-02 12:04:34 -05:00
|
|
|
static Game::cmd_function_s* Find(const std::string& command);
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
private:
|
2022-04-12 08:34:51 -04:00
|
|
|
static std::unordered_map<std::string, std::function<void(Command::Params*)>> FunctionMap;
|
|
|
|
static std::unordered_map<std::string, std::function<void(Command::Params*)>> FunctionMapSV;
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2022-06-16 10:15:26 -04:00
|
|
|
static void AddRawSV(const char* name, void(*callback)());
|
|
|
|
|
2017-01-19 16:23:59 -05:00
|
|
|
static void MainCallback();
|
|
|
|
static void MainCallbackSV();
|
|
|
|
};
|
|
|
|
}
|