iw4x-client/src/Components/Modules/Command.hpp

48 lines
1.3 KiB
C++
Raw Normal View History

2016-08-07 10:50:04 -04:00
namespace Components
{
class Command : public Component
{
public:
class Params
{
public:
Params(bool sv, DWORD id) : CommandId(id), IsSV(sv) {};
Params(bool sv) : Params(sv, (sv ? *Game::cmd_id_sv : *Game::cmd_id)) {};
Params(const Params &obj) : CommandId(obj.CommandId), IsSV(obj.IsSV) {};
Params() : Params(false, *Game::cmd_id) {};
char* operator[](size_t index);
size_t Length();
std::string Join(size_t startIndex);
private:
bool IsSV;
DWORD CommandId;
};
typedef void(Callback)(Command::Params params);
Command();
~Command();
const char* GetName() { return "Command"; };
static void Add(const char* name, Callback* callback);
static void AddSV(const char* name, Callback* callback);
static void AddRaw(const char* name, void(*callback)());
static void AddRawSV(const char* name, void(*callback)());
static void Execute(std::string command, bool sync = true);
2016-08-07 12:25:44 -04:00
static Game::cmd_function_t* Find(std::string command);
2016-08-07 10:50:04 -04:00
private:
2016-08-13 10:39:05 -04:00
static Utils::Memory::Allocator MemAllocator;
2016-08-07 10:50:04 -04:00
static std::map<std::string, wink::slot<Callback>> FunctionMap;
static std::map<std::string, wink::slot<Callback>> FunctionMapSV;
2016-08-13 10:39:05 -04:00
static Game::cmd_function_t* Allocate();
2016-08-07 10:50:04 -04:00
static void MainCallback();
static void MainCallbackSV();
};
}