DDraceNetwork Docs
console.h
Go to the documentation of this file.
1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#ifndef ENGINE_CONSOLE_H
4#define ENGINE_CONSOLE_H
5
6#include "kernel.h"
7#include <base/color.h>
8#include <engine/storage.h>
9
10#include <memory>
11
12static const ColorRGBA gs_ConsoleDefaultColor(1, 1, 1, 1);
13
14enum LEVEL : char;
15struct CChecksumData;
16
17class IConsole : public IInterface
18{
19 MACRO_INTERFACE("console")
20public:
21 // TODO: rework/cleanup
22 enum
23 {
27
32
36
38
41 };
42
43 // TODO: rework this interface to reduce the amount of virtual calls
44 class IResult
45 {
46 protected:
47 unsigned m_NumArgs;
48
49 public:
50 IResult(int ClientId) :
51 m_NumArgs(0),
52 m_ClientId(ClientId) {}
53 IResult(const IResult &Other) :
54 m_NumArgs(Other.m_NumArgs),
55 m_ClientId(Other.m_ClientId) {}
56 virtual ~IResult() {}
57
58 virtual int GetInteger(unsigned Index) const = 0;
59 virtual float GetFloat(unsigned Index) const = 0;
60 virtual const char *GetString(unsigned Index) const = 0;
61 virtual std::optional<ColorHSLA> GetColor(unsigned Index, float DarkestLighting) const = 0;
62
63 virtual void RemoveArgument(unsigned Index) = 0;
64
65 int NumArguments() const { return m_NumArgs; }
67
68 // DDRace
69
70 virtual int GetVictim() const = 0;
71 };
72
74 {
75 protected:
77
78 public:
80 virtual ~CCommandInfo() {}
81 const char *m_pName;
82 const char *m_pHelp;
83 const char *m_pParams;
84
85 virtual const CCommandInfo *NextCommandInfo(int AccessLevel, int FlagMask) const = 0;
86
87 int GetAccessLevel() const { return m_AccessLevel; }
88 };
89
90 typedef void (*FTeeHistorianCommandCallback)(int ClientId, int FlagMask, const char *pCmd, IResult *pResult, void *pUser);
91 typedef void (*FPossibleCallback)(int Index, const char *pCmd, void *pUser);
92 typedef void (*FCommandCallback)(IResult *pResult, void *pUserData);
93 typedef void (*FChainCommandCallback)(IResult *pResult, void *pUserData, FCommandCallback pfnCallback, void *pCallbackUserData);
94 typedef bool (*FUnknownCommandCallback)(const char *pCommand, void *pUser); // returns true if the callback has handled the argument
95
96 static void EmptyPossibleCommandCallback(int Index, const char *pCmd, void *pUser) {}
97 static bool EmptyUnknownCommandCallback(const char *pCommand, void *pUser) { return false; }
98
99 virtual void Init() = 0;
100 virtual const CCommandInfo *FirstCommandInfo(int AccessLevel, int Flagmask) const = 0;
101 virtual const CCommandInfo *GetCommandInfo(const char *pName, int FlagMask, bool Temp) = 0;
102 virtual int PossibleCommands(const char *pStr, int FlagMask, bool Temp, FPossibleCallback pfnCallback = EmptyPossibleCommandCallback, void *pUser = nullptr) = 0;
103 virtual void ParseArguments(int NumArgs, const char **ppArguments) = 0;
104
105 virtual void Register(const char *pName, const char *pParams, int Flags, FCommandCallback pfnFunc, void *pUser, const char *pHelp) = 0;
106 virtual void RegisterTemp(const char *pName, const char *pParams, int Flags, const char *pHelp) = 0;
107 virtual void DeregisterTemp(const char *pName) = 0;
108 virtual void DeregisterTempAll() = 0;
109 virtual void Chain(const char *pName, FChainCommandCallback pfnChainFunc, void *pUser) = 0;
110 virtual void StoreCommands(bool Store) = 0;
111
112 virtual bool LineIsValid(const char *pStr) = 0;
113 virtual void ExecuteLine(const char *pStr, int ClientId = -1, bool InterpretSemicolons = true) = 0;
114 virtual void ExecuteLineFlag(const char *pStr, int FlasgMask, int ClientId = -1, bool InterpretSemicolons = true) = 0;
115 virtual void ExecuteLineStroked(int Stroke, const char *pStr, int ClientId = -1, bool InterpretSemicolons = true) = 0;
116 virtual bool ExecuteFile(const char *pFilename, int ClientId = -1, bool LogFailure = false, int StorageType = IStorage::TYPE_ALL) = 0;
117
124 virtual void Print(int Level, const char *pFrom, const char *pStr, ColorRGBA PrintColor = gs_ConsoleDefaultColor) const = 0;
125 virtual void SetTeeHistorianCommandCallback(FTeeHistorianCommandCallback pfnCallback, void *pUser) = 0;
126 virtual void SetUnknownCommandCallback(FUnknownCommandCallback pfnCallback, void *pUser) = 0;
127 virtual void InitChecksum(CChecksumData *pData) const = 0;
128
129 virtual void SetAccessLevel(int AccessLevel) = 0;
130
131 static LEVEL ToLogLevel(int ConsoleLevel);
132 static int ToLogLevelFilter(int ConsoleLevel);
133
134 // DDRace
135
136 virtual bool Cheated() const = 0;
137
138 virtual int FlagMask() const = 0;
139 virtual void SetFlagMask(int FlagMask) = 0;
140};
141
142std::unique_ptr<IConsole> CreateConsole(int FlagMask);
143
144#endif // FILE_ENGINE_CONSOLE_H
Definition: color.h:210
Definition: console.h:74
const char * m_pParams
Definition: console.h:83
int m_AccessLevel
Definition: console.h:76
virtual ~CCommandInfo()
Definition: console.h:80
const char * m_pHelp
Definition: console.h:82
int GetAccessLevel() const
Definition: console.h:87
CCommandInfo()
Definition: console.h:79
const char * m_pName
Definition: console.h:81
virtual const CCommandInfo * NextCommandInfo(int AccessLevel, int FlagMask) const =0
Definition: console.h:45
IResult(int ClientId)
Definition: console.h:50
virtual int GetInteger(unsigned Index) const =0
int NumArguments() const
Definition: console.h:65
virtual float GetFloat(unsigned Index) const =0
int m_ClientId
Definition: console.h:66
virtual void RemoveArgument(unsigned Index)=0
virtual std::optional< ColorHSLA > GetColor(unsigned Index, float DarkestLighting) const =0
unsigned m_NumArgs
Definition: console.h:47
virtual ~IResult()
Definition: console.h:56
IResult(const IResult &Other)
Definition: console.h:53
virtual int GetVictim() const =0
virtual const char * GetString(unsigned Index) const =0
Definition: console.h:18
virtual void DeregisterTemp(const char *pName)=0
virtual const CCommandInfo * FirstCommandInfo(int AccessLevel, int Flagmask) const =0
virtual void ExecuteLine(const char *pStr, int ClientId=-1, bool InterpretSemicolons=true)=0
static bool EmptyUnknownCommandCallback(const char *pCommand, void *pUser)
Definition: console.h:97
virtual void StoreCommands(bool Store)=0
virtual const CCommandInfo * GetCommandInfo(const char *pName, int FlagMask, bool Temp)=0
virtual void InitChecksum(CChecksumData *pData) const =0
virtual void ParseArguments(int NumArgs, const char **ppArguments)=0
bool(* FUnknownCommandCallback)(const char *pCommand, void *pUser)
Definition: console.h:94
virtual void ExecuteLineFlag(const char *pStr, int FlasgMask, int ClientId=-1, bool InterpretSemicolons=true)=0
void(* FChainCommandCallback)(IResult *pResult, void *pUserData, FCommandCallback pfnCallback, void *pCallbackUserData)
Definition: console.h:93
virtual void Chain(const char *pName, FChainCommandCallback pfnChainFunc, void *pUser)=0
virtual int PossibleCommands(const char *pStr, int FlagMask, bool Temp, FPossibleCallback pfnCallback=EmptyPossibleCommandCallback, void *pUser=nullptr)=0
virtual void Print(int Level, const char *pFrom, const char *pStr, ColorRGBA PrintColor=gs_ConsoleDefaultColor) const =0
virtual void Register(const char *pName, const char *pParams, int Flags, FCommandCallback pfnFunc, void *pUser, const char *pHelp)=0
static int ToLogLevelFilter(int ConsoleLevel)
Definition: console.cpp:311
static void EmptyPossibleCommandCallback(int Index, const char *pCmd, void *pUser)
Definition: console.h:96
virtual bool ExecuteFile(const char *pFilename, int ClientId=-1, bool LogFailure=false, int StorageType=IStorage::TYPE_ALL)=0
virtual void ExecuteLineStroked(int Stroke, const char *pStr, int ClientId=-1, bool InterpretSemicolons=true)=0
void(* FPossibleCallback)(int Index, const char *pCmd, void *pUser)
Definition: console.h:91
virtual void RegisterTemp(const char *pName, const char *pParams, int Flags, const char *pHelp)=0
virtual void DeregisterTempAll()=0
virtual bool Cheated() const =0
virtual void SetTeeHistorianCommandCallback(FTeeHistorianCommandCallback pfnCallback, void *pUser)=0
void(* FCommandCallback)(IResult *pResult, void *pUserData)
Definition: console.h:92
virtual void Init()=0
@ TEMPCMD_HELP_LENGTH
Definition: console.h:34
@ ACCESS_LEVEL_ADMIN
Definition: console.h:28
@ OUTPUT_LEVEL_ADDINFO
Definition: console.h:25
@ ACCESS_LEVEL_HELPER
Definition: console.h:30
@ OUTPUT_LEVEL_DEBUG
Definition: console.h:26
@ CLIENT_ID_NO_GAME
Definition: console.h:40
@ ACCESS_LEVEL_USER
Definition: console.h:31
@ TEMPCMD_PARAMS_LENGTH
Definition: console.h:35
@ CLIENT_ID_GAME
Definition: console.h:39
@ CMDLINE_LENGTH
Definition: console.h:37
@ TEMPCMD_NAME_LENGTH
Definition: console.h:33
@ ACCESS_LEVEL_MOD
Definition: console.h:29
@ OUTPUT_LEVEL_STANDARD
Definition: console.h:24
virtual void SetUnknownCommandCallback(FUnknownCommandCallback pfnCallback, void *pUser)=0
virtual int FlagMask() const =0
virtual void SetFlagMask(int FlagMask)=0
virtual bool LineIsValid(const char *pStr)=0
static LEVEL ToLogLevel(int ConsoleLevel)
Definition: console.cpp:296
virtual void SetAccessLevel(int AccessLevel)=0
void(* FTeeHistorianCommandCallback)(int ClientId, int FlagMask, const char *pCmd, IResult *pResult, void *pUser)
Definition: console.h:90
Definition: kernel.h:10
@ TYPE_ALL
Definition: storage.h:26
std::unique_ptr< IConsole > CreateConsole(int FlagMask)
Definition: console.cpp:1053
static const ColorRGBA gs_ConsoleDefaultColor(1, 1, 1, 1)
#define MACRO_INTERFACE(Name)
Definition: kernel.h:25
LEVEL
Definition: log.h:14
Definition: checksum.h:7