ddnet/src/engine/shared/console.h
GreYFoX 0df6d0541f Merge branch 'master' of git://github.com/oy/teeworlds into HEAD
Conflicts:
	bam.lua
	src/engine/console.h
	src/engine/server.h
	src/engine/server/server.cpp
	src/engine/shared/config.h
	src/engine/shared/config_variables.h
	src/engine/shared/console.cpp
	src/engine/shared/console.h
	src/game/client/components/binds.cpp
	src/game/client/components/chat.h
	src/game/client/components/console.cpp
	src/game/client/components/console.h
	src/game/client/components/controls.cpp
	src/game/client/components/emoticon.h
	src/game/client/components/maplayers.cpp
	src/game/client/components/menus.h
	src/game/client/components/scoreboard.h
	src/game/client/components/spectator.h
	src/game/client/components/voting.h
	src/game/client/gameclient.cpp
	src/game/client/gameclient.h
	src/game/client/render.h
	src/game/collision.cpp
	src/game/editor/ed_layer_tiles.cpp
	src/game/gamecore.cpp
	src/game/gamecore.h
	src/game/layers.cpp
	src/game/layers.h
	src/game/mapitems.h
	src/game/server/entities/character.cpp
	src/game/server/entities/laser.cpp
	src/game/server/entities/laser.h
	src/game/server/entities/pickup.cpp
	src/game/server/entities/pickup.h
	src/game/server/entities/projectile.cpp
	src/game/server/gamecontext.cpp
	src/game/server/gamecontroller.cpp
	src/game/server/gamecontroller.h
	src/game/server/gameworld.cpp
	src/game/server/gameworld.h
	src/game/server/player.cpp
	src/game/variables.h
2011-04-14 01:27:49 +02:00

224 lines
7.6 KiB
C++

/* (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. */
#ifndef ENGINE_SHARED_CONSOLE_H
#define ENGINE_SHARED_CONSOLE_H
#include <engine/console.h>
#include "memheap.h"
#include <new>
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;
};
int m_FlagMask;
bool m_StoreCommands;
const char *m_paStrokeStr[2];
CCommand *m_pFirstCommand;
class CExecFile
{
public:
const char *m_pFilename;
struct CExecFile *m_pPrev;
};
CExecFile *m_pFirstExec;
class IStorage *m_pStorage;
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);
//void ExecuteFileRecurse(const char *pFilename);
//void ExecuteLineStroked(int Stroke, const char *pStr);
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];
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;
for(unsigned i = 0; i < Other.m_NumArgs; ++i)
m_apArgs[i] = Other.m_apArgs[i] + Offset;
}
return *this;
}
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);
// DDRace
enum
{
VICTIM_NONE=-3,
VICTIM_ME=-2,
VICTIM_ALL=-1,
};
int m_Victim;
void ResetVictim();
bool HasVictim();
void SetVictim(int Victim);
void SetVictim(const char *pVictim);
virtual int GetVictim();
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; }
};
int ParseStart(CResult *pResult, const char *pString, int Length);
int ParseArgs(CResult *pResult, const char *pFormat);
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;
if(!m_pFirst)
m_pFirst = pEntry;
if(m_pLast)
m_pLast->m_pNext = pEntry;
m_pLast = pEntry;
(void)new(&(pEntry->m_Result)) CResult;
}
void Reset()
{
m_Queue.Reset();
m_pFirst = m_pLast = 0;
}
} m_ExecutionQueue;
CCommand *FindCommand(const char *pName, int FlagMask);
public:
CConsole(int FlagMask);
virtual CCommandInfo *GetCommandInfo(const char *pName, int FlagMask);
virtual void PossibleCommands(const char *pStr, int FlagMask, FPossibleCallback pfnCallback, void *pUser) ;
virtual void ParseArguments(int NumArgs, const char **ppArguments);
virtual void Register(const char *pName, const char *pParams, int Flags, FCommandCallback pfnFunc, void *pUser, const char *pHelp, const int Level);
virtual void Chain(const char *pName, FChainCommandCallback pfnChainFunc, void *pUser);
virtual void StoreCommands(bool Store, int ClientID);
virtual bool LineIsValid(const char *pStr);
//virtual void ExecuteLine(const char *pStr);
//virtual void ExecuteFile(const char *pFilename);
virtual void RegisterPrintCallback(FPrintCallback pfnPrintCallback, void *pUserData);
virtual void Print(int Level, const char *pFrom, const char *pStr);
// DDRace
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);
virtual void ExecuteFile(const char *pFilename, FPrintCallback pfnAlternativePrintCallback = 0, void *pUserData = 0, FPrintCallback pfnAlternativePrintResponseCallback = 0, void *pResponseUserData = 0, int Level = 3);
virtual void RegisterAlternativePrintCallback(FPrintCallback pfnAlternativePrintCallback, void *pAlternativeUserData);
virtual void ReleaseAlternativePrintCallback();
virtual void RegisterPrintResponseCallback(FPrintCallback pfnPrintResponseCallback, void *pUserData);
virtual void RegisterAlternativePrintResponseCallback(FPrintCallback pfnAlternativePrintCallback, void *pAlternativeUserData);
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);
virtual void RegisterCompareClientsCallback(FCompareClientsCallback pfnCallback, void *pUserData);
virtual void RegisterClientOnlineCallback(FClientOnlineCallback pfnCallback, void *pUserData);
virtual bool CompareClients(int ClientLevel, int Victim);
virtual bool ClientOnline(int ClientID);
bool m_Cheated;
private:
/*void ExecuteFileRecurse(const char *pFilename, FPrintCallback pfnAlternativePrintCallback = 0, void *pUserData = 0, FPrintCallback pfnAlternativePrintResponseCallback = 0, void *pResponseUserData = 0, int Level = 3);
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;
int m_PrintResponseUsed; */
FCompareClientsCallback m_pfnCompareClientsCallback;
void *m_pCompareClientsUserdata;
FClientOnlineCallback m_pfnClientOnlineCallback;
void *m_pClientOnlineUserdata;
int m_aCommandCount[5];
};
#endif