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_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
|
|
|
|
2011-01-12 09:08:17 +00:00
|
|
|
#include <new>
|
|
|
|
|
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;
|
|
|
|
};
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
class CChain
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FChainCommandCallback m_pfnChainCallback;
|
|
|
|
FCommandCallback m_pfnCallback;
|
|
|
|
void *m_pCallbackUserData;
|
|
|
|
void *m_pUserData;
|
2011-04-13 18:37:12 +00:00
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
};
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CExecFile *m_pFirstExec;
|
|
|
|
class IStorage *m_pStorage;
|
|
|
|
|
2011-02-13 05:35:13 +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
|
|
|
|
2011-04-09 06:41:31 +00:00
|
|
|
//void ExecuteFileRecurse(const char *pFilename);
|
|
|
|
//void ExecuteLineStroked(int Stroke, const char *pStr);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
FPrintCallback m_pfnPrintCallback;
|
2011-04-12 20:18:15 +00:00
|
|
|
void *m_pPrintCallbackUserData;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2011-04-13 18:37:12 +00:00
|
|
|
CONSOLE_MAX_STR_LENGTH = 1024,
|
2010-05-29 07:25:38 +00:00
|
|
|
MAX_PARTS = (CONSOLE_MAX_STR_LENGTH+1)/2
|
|
|
|
};
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
class CResult : public IResult
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
char m_aStringStorage[CONSOLE_MAX_STR_LENGTH+1];
|
|
|
|
char *m_pArgsStart;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
const char *m_pCommand;
|
|
|
|
const char *m_apArgs[MAX_PARTS];
|
2011-01-07 18:33:29 +00:00
|
|
|
|
|
|
|
CResult() : IResult()
|
|
|
|
{
|
|
|
|
mem_zero(m_aStringStorage, sizeof(m_aStringStorage));
|
|
|
|
m_pArgsStart = 0;
|
|
|
|
m_pCommand = 0;
|
|
|
|
mem_zero(m_apArgs, sizeof(m_apArgs));
|
|
|
|
}
|
|
|
|
|
|
|
|
CResult &operator =(const CResult &Other)
|
|
|
|
{
|
|
|
|
if(this != &Other)
|
|
|
|
{
|
|
|
|
IResult::operator=(Other);
|
|
|
|
int Offset = m_aStringStorage - Other.m_aStringStorage;
|
|
|
|
mem_copy(m_aStringStorage, Other.m_aStringStorage, sizeof(m_aStringStorage));
|
|
|
|
m_pArgsStart = Other.m_pArgsStart + Offset;
|
|
|
|
m_pCommand = Other.m_pCommand + Offset;
|
2011-01-10 23:57:44 +00:00
|
|
|
for(unsigned i = 0; i < Other.m_NumArgs; ++i)
|
2011-01-07 18:33:29 +00:00
|
|
|
m_apArgs[i] = Other.m_apArgs[i] + Offset;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
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);
|
2011-04-09 06:41:31 +00:00
|
|
|
|
|
|
|
// DDRace
|
|
|
|
|
2010-11-16 15:07:45 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
VICTIM_NONE=-3,
|
|
|
|
VICTIM_ME=-2,
|
|
|
|
VICTIM_ALL=-1,
|
|
|
|
};
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2010-11-07 15:29:55 +00:00
|
|
|
int m_Victim;
|
|
|
|
void ResetVictim();
|
|
|
|
bool HasVictim();
|
|
|
|
void SetVictim(int Victim);
|
|
|
|
void SetVictim(const char *pVictim);
|
|
|
|
virtual int GetVictim();
|
2011-04-12 20:18:15 +00:00
|
|
|
|
|
|
|
IConsole::FPrintCallback m_pfnPrintCallback;
|
|
|
|
void *m_pPrintCallbackUserData;
|
|
|
|
virtual void Print(int Level, const char *pFrom, const char *pStr);
|
|
|
|
virtual void SetPrintCallback(IConsole::FPrintCallback pfnPrintCallback, void *pPrintCallbackUserData) { m_pfnPrintCallback = pfnPrintCallback; m_pPrintCallbackUserData = pPrintCallbackUserData; }
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
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;
|
2011-01-07 18:33:29 +00:00
|
|
|
if(!m_pFirst)
|
|
|
|
m_pFirst = pEntry;
|
|
|
|
if(m_pLast)
|
|
|
|
m_pLast->m_pNext = pEntry;
|
2010-08-07 18:22:25 +00:00
|
|
|
m_pLast = pEntry;
|
2011-01-07 18:33:29 +00:00
|
|
|
(void)new(&(pEntry->m_Result)) CResult;
|
2010-08-07 18:22:25 +00:00
|
|
|
}
|
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
m_Queue.Reset();
|
2011-01-07 18:33:29 +00:00
|
|
|
m_pFirst = m_pLast = 0;
|
2010-08-07 18:22:25 +00:00
|
|
|
}
|
|
|
|
} 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);
|
2011-02-13 05:35:13 +00:00
|
|
|
virtual void StoreCommands(bool Store, int ClientID);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-10-25 16:30:35 +00:00
|
|
|
virtual bool LineIsValid(const char *pStr);
|
2011-04-09 06:41:31 +00:00
|
|
|
//virtual void ExecuteLine(const char *pStr);
|
|
|
|
//virtual void ExecuteFile(const char *pFilename);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
virtual void RegisterPrintCallback(FPrintCallback pfnPrintCallback, void *pUserData);
|
2010-08-17 22:06:00 +00:00
|
|
|
virtual void Print(int Level, const char *pFrom, const char *pStr);
|
2011-04-09 06:41:31 +00:00
|
|
|
|
|
|
|
// DDRace
|
|
|
|
|
2011-04-12 20:18:15 +00:00
|
|
|
virtual void List(IConsole::IResult *pResult, int Level, int Flags);
|
|
|
|
/*virtual void ExecuteLine(const char *pStr, const int ClientLevel, const int ClientID, FPrintCallback pfnAlternativePrintCallback = 0, void *pUserData = 0, FPrintCallback pfnAlternativePrintResponseCallback = 0, void *pResponseUserData = 0);
|
2011-04-09 06:41:31 +00:00
|
|
|
virtual void ExecuteFile(const char *pFilename, FPrintCallback pfnAlternativePrintCallback = 0, void *pUserData = 0, FPrintCallback pfnAlternativePrintResponseCallback = 0, void *pResponseUserData = 0, int Level = 3);
|
2010-10-10 22:40:07 +00:00
|
|
|
virtual void RegisterAlternativePrintCallback(FPrintCallback pfnAlternativePrintCallback, void *pAlternativeUserData);
|
|
|
|
virtual void ReleaseAlternativePrintCallback();
|
|
|
|
|
|
|
|
virtual void RegisterPrintResponseCallback(FPrintCallback pfnPrintResponseCallback, void *pUserData);
|
|
|
|
virtual void RegisterAlternativePrintResponseCallback(FPrintCallback pfnAlternativePrintCallback, void *pAlternativeUserData);
|
2011-04-12 20:18:15 +00:00
|
|
|
virtual void ReleaseAlternativePrintResponseCallback(); */
|
|
|
|
|
|
|
|
virtual void ExecuteLine(const char *pStr, int ClientID, int Level, IConsole::FPrintCallback pfnPrintCallback, void *pPrintCallbackUserData);
|
|
|
|
virtual void ExecuteLine(const char *pStr, int ClientID, int Level, IConsole::IResult *pResult);
|
|
|
|
virtual void ExecuteLineStroked(int Stroke, const char *pStr, int ClientID, int Level, IConsole::FPrintCallback pfnPrintCallback, void *pPrintCallbackUserData);
|
|
|
|
virtual void ExecuteLineStroked(int Stroke, const char *pStr, int ClientID, int Level, IConsole::IResult *pResult);
|
|
|
|
virtual void ExecuteFile(const char *pFilename, int ClientID, int Level, IConsole::FPrintCallback pfnPrintCallback, void *pPrintCallbackUserData);
|
|
|
|
virtual void ExecuteFile(const char *pFilename, int ClientID, int Level, IConsole::IResult *pResult);
|
2010-11-07 15:29:55 +00:00
|
|
|
virtual void RegisterCompareClientsCallback(FCompareClientsCallback pfnCallback, void *pUserData);
|
|
|
|
virtual void RegisterClientOnlineCallback(FClientOnlineCallback pfnCallback, void *pUserData);
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2010-11-07 15:29:55 +00:00
|
|
|
virtual bool CompareClients(int ClientLevel, int Victim);
|
2011-02-13 05:35:13 +00:00
|
|
|
virtual bool ClientOnline(int ClientID);
|
2011-03-16 13:41:26 +00:00
|
|
|
bool m_Cheated;
|
2011-04-09 06:41:31 +00:00
|
|
|
|
|
|
|
private:
|
2011-04-12 20:18:15 +00:00
|
|
|
/*void ExecuteFileRecurse(const char *pFilename, FPrintCallback pfnAlternativePrintCallback = 0, void *pUserData = 0, FPrintCallback pfnAlternativePrintResponseCallback = 0, void *pResponseUserData = 0, int Level = 3);
|
2011-04-09 06:41:31 +00:00
|
|
|
virtual void ExecuteLineStroked(int Stroke, const char *pStr, const int ClientLevel, const int ClientID, FPrintCallback pfnAlternativePrintCallback = 0, void *pUserData = 0, FPrintCallback pfnAlternativePrintResponseCallback = 0, void *pResponseUserData = 0);
|
|
|
|
FPrintCallback m_pfnAlternativePrintCallback;
|
|
|
|
void *m_pAlternativePrintCallbackUserdata;
|
|
|
|
int m_PrintUsed;
|
|
|
|
FPrintCallback m_pfnPrintResponseCallback;
|
|
|
|
void *m_pPrintResponseCallbackUserdata;
|
|
|
|
FPrintCallback m_pfnAlternativePrintResponseCallback;
|
|
|
|
void *m_pAlternativePrintResponseCallbackUserdata;
|
2011-04-12 20:18:15 +00:00
|
|
|
int m_PrintResponseUsed; */
|
2011-04-09 06:41:31 +00:00
|
|
|
FCompareClientsCallback m_pfnCompareClientsCallback;
|
|
|
|
void *m_pCompareClientsUserdata;
|
|
|
|
FClientOnlineCallback m_pfnClientOnlineCallback;
|
|
|
|
void *m_pClientOnlineUserdata;
|
|
|
|
int m_aCommandCount[5];
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|