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

44 lines
1.1 KiB
C++
Raw Normal View History

2015-12-23 08:45:53 -05:00
namespace Components
{
class Command : public Component
{
public:
class Params
{
public:
2016-03-04 08:48:31 -05:00
Params(bool sv, DWORD id) : CommandId(id), IsSV(sv) {};
Params(const Params &obj) : CommandId(obj.CommandId), IsSV(obj.IsSV) {};
Params() : Params(false, *Game::cmd_id) {};
2015-12-23 08:45:53 -05:00
2015-12-23 16:21:03 -05:00
char* operator[](size_t index);
2015-12-23 08:45:53 -05:00
size_t Length();
2016-02-19 10:02:43 -05:00
std::string Join(size_t startIndex);
2015-12-23 08:45:53 -05:00
private:
2016-03-04 08:48:31 -05:00
bool IsSV;
2015-12-23 08:45:53 -05:00
DWORD CommandId;
};
typedef void(Callback)(Command::Params params);
2015-12-23 08:45:53 -05:00
Command();
~Command();
const char* GetName() { return "Command"; };
static void Add(const char* name, Callback* callback);
2016-03-04 08:48:31 -05:00
static void AddSV(const char* name, Callback* callback);
static void AddRaw(const char* name, void(*callback)());
static void AddRawSV(const char* name, void(*callback)());
2015-12-25 15:42:35 -05:00
static void Execute(std::string command, bool sync = true);
2015-12-23 08:45:53 -05:00
private:
static Game::cmd_function_t* Allocate();
static std::vector<Game::cmd_function_t*> Functions;
static std::map<std::string, wink::slot<Callback>> FunctionMap;
2016-03-04 08:48:31 -05:00
static std::map<std::string, wink::slot<Callback>> FunctionMapSV;
2015-12-23 08:45:53 -05:00
static void MainCallback();
2016-03-04 08:48:31 -05:00
static void MainCallbackSV();
2015-12-23 08:45:53 -05:00
};
}