2010-05-29 07:25:38 +00:00
|
|
|
#ifndef ENGINE_SHARED_CONSOLE_H
|
|
|
|
#define ENGINE_SHARED_CONSOLE_H
|
|
|
|
|
|
|
|
#include <engine/console.h>
|
2010-08-07 18:22:25 +00:00
|
|
|
#include "memheap.h"
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
class CConsole : public IConsole
|
|
|
|
{
|
|
|
|
class CCommand : public CCommandInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCommand *m_pNext;
|
|
|
|
int m_Flags;
|
|
|
|
FCommandCallback m_pfnCallback;
|
|
|
|
void *m_pUserData;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CChain
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FChainCommandCallback m_pfnChainCallback;
|
|
|
|
FCommandCallback m_pfnCallback;
|
|
|
|
void *m_pCallbackUserData;
|
|
|
|
void *m_pUserData;
|
|
|
|
};
|
|
|
|
|
2010-06-18 18:32:52 +00:00
|
|
|
int m_FlagMask;
|
2010-08-07 18:22:25 +00:00
|
|
|
bool m_StoreCommands;
|
|
|
|
const char *m_paStrokeStr[2];
|
2010-05-29 07:25:38 +00:00
|
|
|
CCommand *m_pFirstCommand;
|
|
|
|
|
|
|
|
class CExecFile
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
const char *m_pFilename;
|
|
|
|
struct CExecFile *m_pPrev;
|
|
|
|
};
|
|
|
|
|
|
|
|
CExecFile *m_pFirstExec;
|
|
|
|
class IStorage *m_pStorage;
|
|
|
|
|
2010-07-29 05:21:18 +00:00
|
|
|
static void Con_Chain(IResult *pResult, void *pUserData, int ClientId);
|
|
|
|
static void Con_Echo(IResult *pResult, void *pUserData, int ClientId);
|
|
|
|
static void Con_Exec(IResult *pResult, void *pUserData, int ClientId);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
void ExecuteFileRecurse(const char *pFilename);
|
2010-07-29 05:21:18 +00:00
|
|
|
void ExecuteLineStroked(int Stroke, const char *pStr, const int ClientLevel, const int ClientId);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
FPrintCallback m_pfnPrintCallback;
|
|
|
|
void *m_pPrintCallbackUserdata;
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
CONSOLE_MAX_STR_LENGTH = 1024,
|
|
|
|
MAX_PARTS = (CONSOLE_MAX_STR_LENGTH+1)/2
|
|
|
|
};
|
|
|
|
|
|
|
|
class CResult : public IResult
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
char m_aStringStorage[CONSOLE_MAX_STR_LENGTH+1];
|
|
|
|
char *m_pArgsStart;
|
|
|
|
|
|
|
|
const char *m_pCommand;
|
|
|
|
const char *m_apArgs[MAX_PARTS];
|
|
|
|
|
|
|
|
void AddArgument(const char *pArg)
|
|
|
|
{
|
|
|
|
m_apArgs[m_NumArgs++] = pArg;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual const char *GetString(unsigned Index);
|
|
|
|
virtual int GetInteger(unsigned Index);
|
|
|
|
virtual float GetFloat(unsigned Index);
|
|
|
|
};
|
|
|
|
|
|
|
|
int ParseStart(CResult *pResult, const char *pString, int Length);
|
|
|
|
int ParseArgs(CResult *pResult, const char *pFormat);
|
|
|
|
|
2010-08-07 18:22:25 +00:00
|
|
|
class CExecutionQueue
|
|
|
|
{
|
|
|
|
CHeap m_Queue;
|
|
|
|
|
|
|
|
public:
|
|
|
|
struct CQueueEntry
|
|
|
|
{
|
|
|
|
CQueueEntry *m_pNext;
|
|
|
|
FCommandCallback m_pfnCommandCallback;
|
|
|
|
void *m_pCommandUserData;
|
|
|
|
CResult m_Result;
|
|
|
|
} *m_pFirst, *m_pLast;
|
|
|
|
|
|
|
|
void AddEntry()
|
|
|
|
{
|
|
|
|
CQueueEntry *pEntry = static_cast<CQueueEntry *>(m_Queue.Allocate(sizeof(CQueueEntry)));
|
|
|
|
pEntry->m_pNext = 0;
|
|
|
|
m_pLast->m_pNext = pEntry;
|
|
|
|
m_pLast = pEntry;
|
|
|
|
}
|
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
m_Queue.Reset();
|
|
|
|
m_pFirst = m_pLast = static_cast<CQueueEntry *>(m_Queue.Allocate(sizeof(CQueueEntry)));
|
|
|
|
m_pLast->m_pNext = 0;
|
|
|
|
}
|
|
|
|
} m_ExecutionQueue;
|
|
|
|
|
2010-06-18 18:32:52 +00:00
|
|
|
CCommand *FindCommand(const char *pName, int FlagMask);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
public:
|
2010-06-18 18:32:52 +00:00
|
|
|
CConsole(int FlagMask);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2010-06-18 18:32:52 +00:00
|
|
|
virtual CCommandInfo *GetCommandInfo(const char *pName, int FlagMask);
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void PossibleCommands(const char *pStr, int FlagMask, FPossibleCallback pfnCallback, void *pUser) ;
|
|
|
|
|
|
|
|
virtual void ParseArguments(int NumArgs, const char **ppArguments);
|
2010-07-29 05:21:18 +00:00
|
|
|
virtual void Register(const char *pName, const char *pParams, int Flags, FCommandCallback pfnFunc, void *pUser, const char *pHelp, const int Level);
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void Chain(const char *pName, FChainCommandCallback pfnChainFunc, void *pUser);
|
2010-08-09 14:54:42 +00:00
|
|
|
virtual void StoreCommands(bool Store, int ClientId);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2010-07-29 05:21:18 +00:00
|
|
|
virtual void ExecuteLine(const char *pStr, const int ClientLevel, const int ClientId);
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void ExecuteFile(const char *pFilename);
|
|
|
|
|
|
|
|
virtual void RegisterPrintCallback(FPrintCallback pfnPrintCallback, void *pUserData);
|
|
|
|
virtual void Print(const char *pStr);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|