iw5-mod/src/module/command.hpp

73 lines
1.8 KiB
C++
Raw Normal View History

2018-12-28 12:50:34 +01:00
#pragma once
class command final : public module
{
public:
2022-03-10 19:50:36 +00: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 12:50:34 +01:00
2022-03-10 19:50:36 +00: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);
2022-03-11 14:30:00 +00:00
static void add_sp_sv(const char* name, std::function<void(game::native::sp::gentity_s*, const params_sv&)> callback);
2022-03-10 19:50:36 +00:00
2022-03-14 23:54:41 +00:00
static void execute(std::string command, bool sync = false);
2022-03-10 19:50:36 +00:00
void post_load() override;
2018-12-28 12:50:34 +01:00
private:
2022-03-10 19:50:36 +00:00
static std::unordered_map<std::string, std::function<void(const params&)>> handlers;
2022-12-19 13:13:13 +01:00
static std::unordered_map<std::string, std::function<void(game::native::gentity_s*, const params_sv&)>> handlers_sv;
static std::unordered_map<std::string, std::function<void(game::native::sp::gentity_s*, const params_sv&)>> handlers_sp_sv;
2022-03-10 19:50:36 +00:00
static void main_handler();
static void client_command_stub(int client_num);
2022-03-11 14:30:00 +00:00
static void client_command_sp(int client_num, const char* s);
static void client_command_sp_stub();
2022-03-10 19:50:36 +00:00
static void add_raw(const char* name, void (*callback)());
2022-03-11 14:30:00 +00:00
static void add_sp_commands();
2018-12-28 12:50:34 +01:00
};
#define Cmd_AddCommand(cmd_name, function) \
{ \
static game::native::cmd_function_s function##_VAR; \
game::native::Cmd_AddCommandInternal(cmd_name, function, &function##_VAR); \
}