gdle/Source/ClientCommands.h

128 lines
3.9 KiB
C
Raw Permalink Normal View History

2018-11-11 13:03:57 -06:00
#pragma once
2018-03-29 17:01:57 -04:00
using namespace std;
class CPlayerWeenie;
class CClient;
class CPhysicsObj;
class CommandBase;
class ClientCommand;
class ServerCommand;
//Note: Server commands don't require a source player.
2018-07-12 14:41:21 -07:00
typedef bool(*pfnCommandCallback)(class CClient *player_client, class CPlayerWeenie *player_weenie, class CPhysicsObj *player_physobj, char* argv[], int argc);
2018-03-29 17:01:57 -04:00
enum AccessLevels
{
BASIC_ACCESS = 1,
DONOR_ACCESS,
ADVOCATE_ACCESS,
SENTINEL_ACCESS,
PRIVILEGED_ACCESS,
ADMIN_ACCESS,
SERVER_ACCESS,
DUMMY_ACCESS
};
enum AccessFlags
{
DevelopmentCommands_Flag = 1,
KickBanCommands_Flag = 2,
TeleportCommands_Flag = 4,
AffectOtherCommands_Flag = 8,
ExperimentCommands_Flag = 0x10,
ServerEventCommands_Flag = 0x20,
DatabaseCommands_Flag = 0x40,
ServerRestartCommands_Flag = 0x80,
SpawnCommands_Flag = 0x100,
GiveXPCommands_Flag = 0x200,
InvincibleCommands_Flag = 0x400
};
2018-11-12 15:12:45 -06:00
enum CommandCategory
{
HIDDEN_CATEGORY = 0,
GENERAL_CATEGORY,
EXPLORE_CATEGORY,
SPAWN_CATEGORY,
CHARACTER_CATEGORY,
SERVER_CATEGORY,
};
2018-03-29 17:01:57 -04:00
#define MAX_ARGUMENTS 12
struct CommandEntry {
const char* name;
const char* args;
const char* help;
pfnCommandCallback func;
int access;
int category;
2018-03-29 17:01:57 -04:00
bool source;
};
typedef map<string, CommandEntry> CommandMap;
class CommandBase
{
friend class ClientCommand;
friend class ServerCommand;
public:
static bool Execute(char *command, CClient *client);
protected:
2018-11-12 15:12:45 -06:00
CommandBase()
{
}
static void Create(const char* szName, const char* szArguments, const char* szHelp, pfnCommandCallback pCallback, int iAccessLevel, int iCategory, bool bSource);
2018-03-29 17:01:57 -04:00
static const char* Info(CommandEntry* pCommand);
static CommandEntry* FindCommand(const char* szName, int iAccessLevel = -1);
2018-11-12 15:12:45 -06:00
static void PrintCommandList(CWeenieObject* sendto, int category, int access_level, char* cmdName);
//static CommandMap m_mCommands;
static CommandMap& GetCommandMap()
{
static CommandMap commands;
return commands;
}
2018-03-29 17:01:57 -04:00
};
class ClientCommand : CommandBase
{
friend class CommandBase;
public:
ClientCommand(const char* szName, const char* szArguments, const char* szHelp, pfnCommandCallback pCallback, int iAccessLevel, int iCategory);
2018-03-29 17:01:57 -04:00
};
class ServerCommand : CommandBase
{
friend class CommandBase;
public:
ServerCommand(const char* szName, const char* szArguments, const char* szHelp, pfnCommandCallback pCallback, int iAccessLevel, int iCategory);
2018-03-29 17:01:57 -04:00
};
#define CLIENT_COMMAND( name, args, help, access, category ) \
2018-07-12 14:41:21 -07:00
static bool name(CClient *player_client, CPlayerWeenie *pPlayer, CPhysicsObj *player_physobj, char* argv[], int argc); \
static ClientCommand name##_command( #name, args, help, name, access, category ); \
2018-07-12 14:41:21 -07:00
static bool name(CClient *player_client, CPlayerWeenie *pPlayer, CPhysicsObj *player_physobj, char* argv[], int argc)
2018-03-29 17:01:57 -04:00
#define CLIENT_COMMAND_WITH_CUSTOM_NAME( name, command, args, help, access, category ) \
2018-07-12 14:41:21 -07:00
static bool name(CClient *player_client, CPlayerWeenie *pPlayer, CPhysicsObj *player_physobj, char* argv[], int argc); \
static ClientCommand name##_command( #command, args, help, name, access, category ); \
2018-07-12 14:41:21 -07:00
static bool name(CClient *player_client, CPlayerWeenie *pPlayer, CPhysicsObj *player_physobj, char* argv[], int argc)
2018-03-29 17:01:57 -04:00
#define SERVER_COMMAND( name, args, help, access, category ) \
2018-07-12 14:41:21 -07:00
static bool name(CClient *player_client, CPlayerWeenie *pPlayer, CPhysicsObj *player_physobj, char* argv[], int argc); \
static ServerCommand name##_command( #name, args, help, name, access, category ); \
2018-07-12 14:41:21 -07:00
static bool name(CClient *player_client, CPlayerWeenie *pPlayer, CPhysicsObj *player_physobj, char* argv[], int argc)
2018-03-29 17:01:57 -04:00
#define SERVER_COMMAND_WITH_CUSTOM_NAME( name, command, args, help, access, category ) \
2018-07-12 14:41:21 -07:00
static bool name(CClient *player_client, CPlayerWeenie *pPlayer, CPhysicsObj *player_physobj, char* argv[], int argc); \
static ServerCommand name##_command( #command, args, help, name, access, category ); \
2018-07-12 14:41:21 -07:00
static bool name(CClient *player_client, CPlayerWeenie *pPlayer, CPhysicsObj *player_physobj, char* argv[], int argc)
2018-03-29 17:01:57 -04:00