2016-08-07 10:50:04 -04:00
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
class Command : public Component
|
|
|
|
{
|
|
|
|
public:
|
2016-12-07 14:00:24 -05:00
|
|
|
class Params
|
2016-12-07 12:18:11 -05:00
|
|
|
{
|
|
|
|
public:
|
2016-12-07 14:00:24 -05:00
|
|
|
Params() {};
|
|
|
|
virtual ~Params() {};
|
|
|
|
virtual char* get(size_t index) = 0;
|
2016-12-07 12:18:11 -05:00
|
|
|
virtual size_t length() = 0;
|
2016-12-07 14:00:24 -05:00
|
|
|
|
2016-12-07 12:18:11 -05:00
|
|
|
virtual std::string join(size_t startIndex);
|
2016-12-07 14:00:24 -05:00
|
|
|
virtual char* operator[](size_t index);
|
2016-12-07 12:18:11 -05:00
|
|
|
};
|
|
|
|
|
2016-12-07 14:00:24 -05:00
|
|
|
class ClientParams : public Params
|
2016-12-07 12:18:11 -05:00
|
|
|
{
|
|
|
|
public:
|
2016-12-07 14:00:24 -05:00
|
|
|
ClientParams(unsigned int id) : commandId(id) {};
|
|
|
|
ClientParams(const ClientParams &obj) : commandId(obj.commandId) {};
|
|
|
|
ClientParams() : ClientParams(*Game::cmd_id) {};
|
2016-12-07 12:18:11 -05:00
|
|
|
|
2016-12-07 14:00:24 -05:00
|
|
|
char* get(size_t index) override;
|
2016-12-07 12:18:11 -05:00
|
|
|
size_t length() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned int commandId;
|
|
|
|
};
|
|
|
|
|
2016-12-07 14:00:24 -05:00
|
|
|
class ServerParams : public Params
|
2016-12-07 12:18:11 -05:00
|
|
|
{
|
|
|
|
public:
|
2016-12-07 14:00:24 -05:00
|
|
|
ServerParams(unsigned int id) : commandId(id) {};
|
|
|
|
ServerParams(const ServerParams &obj) : commandId(obj.commandId) {};
|
|
|
|
ServerParams() : ServerParams(*Game::cmd_id_sv) {};
|
2016-12-07 12:18:11 -05:00
|
|
|
|
2016-12-07 14:00:24 -05:00
|
|
|
char* get(size_t index) override;
|
2016-12-07 12:18:11 -05:00
|
|
|
size_t length() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned int commandId;
|
|
|
|
};
|
|
|
|
|
2016-12-07 14:00:24 -05:00
|
|
|
typedef void(Callback)(Command::Params* params);
|
2016-08-07 10:50:04 -04:00
|
|
|
|
|
|
|
Command();
|
|
|
|
~Command();
|
2016-08-15 10:40:30 -04:00
|
|
|
|
2016-09-16 05:04:28 -04:00
|
|
|
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
|
2016-11-25 07:00:48 -05:00
|
|
|
const char* getName() { return "Command"; };
|
2016-08-15 10:40:30 -04:00
|
|
|
#endif
|
2016-08-07 10:50:04 -04:00
|
|
|
|
2016-08-16 14:36:52 -04:00
|
|
|
static Game::cmd_function_t* Allocate();
|
|
|
|
|
2016-08-07 10:50:04 -04:00
|
|
|
static void Add(const char* name, Callback* callback);
|
|
|
|
static void AddSV(const char* name, Callback* callback);
|
2016-09-05 13:54:16 -04:00
|
|
|
static void AddRaw(const char* name, void(*callback)(), bool key = false);
|
2016-08-07 10:50:04 -04:00
|
|
|
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
|
|
|
|
2016-08-07 10:50:04 -04:00
|
|
|
static void MainCallback();
|
|
|
|
static void MainCallbackSV();
|
|
|
|
};
|
|
|
|
}
|