ddnet/src/engine/console.h

114 lines
3.6 KiB
C
Raw Normal View History

2010-11-20 10:37:14 +00:00
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
2010-05-29 07:25:38 +00:00
#ifndef ENGINE_CONSOLE_H
#define ENGINE_CONSOLE_H
#include "kernel.h"
class IConsole : public IInterface
{
MACRO_INTERFACE("console", 0)
public:
// TODO: rework/cleanup
enum
{
OUTPUT_LEVEL_STANDARD=0,
OUTPUT_LEVEL_ADDINFO,
OUTPUT_LEVEL_DEBUG,
ACCESS_LEVEL_ADMIN=0,
ACCESS_LEVEL_MOD,
ACCESS_LEVEL_HELPER,
ACCESS_LEVEL_USER,
TEMPCMD_NAME_LENGTH=32,
TEMPCMD_HELP_LENGTH=96,
TEMPCMD_PARAMS_LENGTH=16,
2015-12-23 13:29:31 +00:00
TEMPCMD_USAGE_LENGTH=96,
2011-07-30 11:40:01 +00:00
MAX_PRINT_CB=4,
CLIENT_ID_GAME=-2,
CLIENT_ID_NO_GAME=-3,
};
2010-05-29 07:25:38 +00:00
// TODO: rework this interface to reduce the amount of virtual calls
class IResult
{
protected:
unsigned m_NumArgs;
public:
IResult() { m_NumArgs = 0; }
virtual ~IResult() {}
2010-05-29 07:25:38 +00:00
virtual int GetInteger(unsigned Index) = 0;
virtual float GetFloat(unsigned Index) = 0;
virtual const char *GetString(unsigned Index) = 0;
2010-05-29 07:25:38 +00:00
int NumArguments() const { return m_NumArgs; }
2011-08-26 18:03:30 +00:00
int m_ClientID;
2011-09-25 16:04:29 +00:00
// DDRace
virtual int GetVictim() = 0;
2010-05-29 07:25:38 +00:00
};
2010-05-29 07:25:38 +00:00
class CCommandInfo
{
protected:
int m_AccessLevel;
2010-05-29 07:25:38 +00:00
public:
2015-12-23 13:29:31 +00:00
CCommandInfo() { m_AccessLevel = ACCESS_LEVEL_ADMIN; m_pUsage = 0; }
virtual ~CCommandInfo() {}
2010-05-29 07:25:38 +00:00
const char *m_pName;
const char *m_pHelp;
const char *m_pParams;
2015-12-23 13:29:31 +00:00
const char *m_pUsage;
virtual const CCommandInfo *NextCommandInfo(int AccessLevel, int FlagMask) const = 0;
int GetAccessLevel() const { return m_AccessLevel; }
2010-05-29 07:25:38 +00:00
};
2014-12-20 12:37:11 +00:00
typedef void (*FPrintCallback)(const char *pStr, void *pUser, bool Highlighted);
2010-05-29 07:25:38 +00:00
typedef void (*FPossibleCallback)(const char *pCmd, void *pUser);
typedef void (*FCommandCallback)(IResult *pResult, void *pUserData);
2010-05-29 07:25:38 +00:00
typedef void (*FChainCommandCallback)(IResult *pResult, void *pUserData, FCommandCallback pfnCallback, void *pCallbackUserData);
virtual const CCommandInfo *FirstCommandInfo(int AccessLevel, int Flagmask) const = 0;
virtual const CCommandInfo *GetCommandInfo(const char *pName, int FlagMask, bool Temp) = 0;
virtual void PossibleCommands(const char *pStr, int FlagMask, bool Temp, FPossibleCallback pfnCallback, void *pUser) = 0;
2010-05-29 07:25:38 +00:00
virtual void ParseArguments(int NumArgs, const char **ppArguments) = 0;
2015-12-23 13:29:31 +00:00
virtual void Register(const char *pName, const char *pParams, int Flags, FCommandCallback pfnFunc, void *pUser, const char *pHelp, const char* pUsage = 0) = 0;
virtual void RegisterTemp(const char *pName, const char *pParams, int Flags, const char *pHelp, const char* pUsage = 0) = 0;
virtual void DeregisterTemp(const char *pName) = 0;
virtual void DeregisterTempAll() = 0;
2010-05-29 07:25:38 +00:00
virtual void Chain(const char *pName, FChainCommandCallback pfnChainFunc, void *pUser) = 0;
virtual void StoreCommands(bool Store) = 0;
virtual bool LineIsValid(const char *pStr) = 0;
2011-08-31 00:48:58 +00:00
virtual void ExecuteLine(const char *Sptr, int ClientID = -1) = 0;
2012-01-28 10:14:31 +00:00
virtual void ExecuteLineFlag(const char *Sptr, int FlasgMask, int ClientID = -1) = 0;
2011-08-31 00:48:58 +00:00
virtual void ExecuteLineStroked(int Stroke, const char *pStr, int ClientID = -1) = 0;
2011-08-26 18:03:30 +00:00
virtual void ExecuteFile(const char *pFilename, int ClientID = -1) = 0;
2011-07-30 11:40:01 +00:00
virtual int RegisterPrintCallback(int OutputLevel, FPrintCallback pfnPrintCallback, void *pUserData) = 0;
virtual void SetPrintOutputLevel(int Index, int OutputLevel) = 0;
2014-12-20 12:37:11 +00:00
virtual void Print(int Level, const char *pFrom, const char *pStr, bool Highlighted = false) = 0;
virtual void SetAccessLevel(int AccessLevel) = 0;
virtual void ResetServerGameSettings() = 0;
// DDRace
bool m_Cheated;
2011-08-31 13:41:32 +00:00
virtual void SetFlagMask(int FlagMask) = 0;
2010-05-29 07:25:38 +00:00
};
extern IConsole *CreateConsole(int FlagMask);
2010-05-29 07:25:38 +00:00
#endif // FILE_ENGINE_CONSOLE_H