2018-12-28 06:50:34 -05:00
|
|
|
#pragma once
|
|
|
|
#include "loader/module_loader.hpp"
|
2022-03-10 14:50:36 -05:00
|
|
|
|
|
|
|
#include "game/structs.hpp"
|
|
|
|
#include "game/game.hpp"
|
|
|
|
|
2018-12-28 06:50:34 -05:00
|
|
|
#include "utils/memory.hpp"
|
|
|
|
|
|
|
|
class command final : public module
|
|
|
|
{
|
|
|
|
public:
|
2022-03-10 14:50:36 -05:00
|
|
|
class params
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
params();
|
|
|
|
|
|
|
|
int size() const;
|
|
|
|
const char* get(int index) const;
|
|
|
|
std::string join(int index) const;
|
|
|
|
|
|
|
|
const char* operator[](const int index) const
|
|
|
|
{
|
|
|
|
return this->get(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int nesting_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class params_sv
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
params_sv();
|
|
|
|
|
|
|
|
int size() const;
|
|
|
|
const char* get(int index) const;
|
|
|
|
std::string join(int index) const;
|
2018-12-28 06:50:34 -05:00
|
|
|
|
2022-03-10 14:50:36 -05:00
|
|
|
const char* operator[](const int index) const
|
|
|
|
{
|
|
|
|
return this->get(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int nesting_;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void add(const char* name, const std::function<void(const params&)>& callback);
|
|
|
|
static void add(const char* name, const std::function<void()>& callback);
|
|
|
|
|
|
|
|
static void add_sv(const char* name, std::function<void(game::native::gentity_s*, const params_sv&)> callback);
|
|
|
|
|
|
|
|
void post_load() override;
|
2018-12-28 06:50:34 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
static utils::memory::allocator allocator_;
|
|
|
|
|
2022-03-10 14:50:36 -05:00
|
|
|
static std::unordered_map<std::string, std::function<void(const params&)>> handlers;
|
|
|
|
static std::unordered_map<std::string, std::function<void(game::native::gentity_s*, params_sv&)>> handlers_sv;
|
|
|
|
|
|
|
|
static void main_handler();
|
|
|
|
|
|
|
|
static void client_command_stub(int client_num);
|
|
|
|
static void client_command_dedi_stub();
|
|
|
|
|
|
|
|
static void add_raw(const char* name, void (*callback)());
|
2018-12-28 06:50:34 -05:00
|
|
|
};
|