Test Commands check and feedback on command not executed

This commit is contained in:
GreYFoX 2011-08-26 23:24:46 +02:00
parent 94c0088c1b
commit 9fe96f6b04
4 changed files with 31 additions and 15 deletions

View file

@ -79,8 +79,8 @@ public:
virtual void StoreCommands(bool Store) = 0;
virtual bool LineIsValid(const char *pStr) = 0;
virtual void ExecuteLine(const char *Sptr, int ClientID = -1) = 0;
virtual void ExecuteLineStroked(int Stroke, const char *pStr, int ClientID = -1) = 0;
virtual bool ExecuteLine(const char *Sptr, int ClientID = -1) = 0;
virtual bool ExecuteLineStroked(int Stroke, const char *pStr, int ClientID = -1) = 0;
virtual void ExecuteFile(const char *pFilename, int ClientID = -1) = 0;
virtual int RegisterPrintCallback(int OutputLevel, FPrintCallback pfnPrintCallback, void *pUserData) = 0;
@ -88,6 +88,10 @@ public:
virtual void Print(int Level, const char *pFrom, const char *pStr) = 0;
virtual void SetAccessLevel(int AccessLevel) = 0;
// DDRace
bool m_Cheated;
};
extern IConsole *CreateConsole(int FlagMask);

View file

@ -253,7 +253,7 @@ bool CConsole::LineIsValid(const char *pStr)
return true;
}
void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, int ClientID)
bool CConsole::ExecuteLineStroked(int Stroke, const char *pStr, int ClientID)
{
while(pStr && *pStr)
{
@ -287,10 +287,10 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, int ClientID)
}
if(ParseStart(&Result, pStr, (pEnd-pStr) + 1) != 0)
return;
return false;
if(!*Result.m_pCommand)
return;
return false;
CCommand *pCommand = FindCommand(Result.m_pCommand, m_FlagMask);
@ -322,7 +322,15 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, int ClientID)
m_ExecutionQueue.m_pLast->m_Result = Result;
}
else
{
if(pCommand->m_Flags&CMDFLAG_TEST && !g_Config.m_SvTestingCommands)
return false;
pCommand->m_pfnCallback(&Result, pCommand->m_pUserData);
if (pCommand->m_Flags&CMDFLAG_TEST) {
m_Cheated = true;
}
return true;
}
}
}
else if(Stroke)
@ -341,6 +349,7 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, int ClientID)
pStr = pNextPart;
}
return false;
}
void CConsole::PossibleCommands(const char *pStr, int FlagMask, bool Temp, FPossibleCallback pfnCallback, void *pUser)
@ -369,10 +378,12 @@ CConsole::CCommand *CConsole::FindCommand(const char *pName, int FlagMask)
return 0x0;
}
void CConsole::ExecuteLine(const char *pStr, int ClientID)
bool CConsole::ExecuteLine(const char *pStr, int ClientID)
{
CConsole::ExecuteLineStroked(1, pStr, ClientID); // press it
CConsole::ExecuteLineStroked(0, pStr, ClientID); // then release it
bool Press = false, Release = false;
Press = CConsole::ExecuteLineStroked(1, pStr, ClientID); // press it
Release = CConsole::ExecuteLineStroked(0, pStr, ClientID); // then release it
return Press || Release;
}

View file

@ -58,7 +58,7 @@ class CConsole : public IConsole
static void ConModCommandStatus(IConsole::IResult *pResult, void *pUser);
void ExecuteFileRecurse(const char *pFilename);
void ExecuteLineStroked(int Stroke, const char *pStr, int ClientID = -1);
bool ExecuteLineStroked(int Stroke, const char *pStr, int ClientID = -1);
struct
{
@ -169,7 +169,7 @@ public:
virtual void StoreCommands(bool Store);
virtual bool LineIsValid(const char *pStr);
virtual void ExecuteLine(const char *pStr, int ClientID = -1);
virtual bool ExecuteLine(const char *pStr, int ClientID = -1);
virtual void ExecuteFile(const char *pFilename, int ClientID = -1);
virtual int RegisterPrintCallback(int OutputLevel, FPrintCallback pfnPrintCallback, void *pUserData);
@ -177,10 +177,6 @@ public:
virtual void Print(int Level, const char *pFrom, const char *pStr);
void SetAccessLevel(int AccessLevel) { m_AccessLevel = clamp(AccessLevel, (int)(ACCESS_LEVEL_ADMIN), (int)(ACCESS_LEVEL_USER)); }
// DDRace
bool m_Cheated;
};
#endif

View file

@ -754,7 +754,12 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
else
Console()->SetAccessLevel(IConsole::ACCESS_LEVEL_USER);
// Todo(Shereef Marzouk): Follow up on the RCON/Chat redirection
Console()->ExecuteLine(pMsg->m_pMessage + 1, ClientID);
if(!Console()->ExecuteLine(pMsg->m_pMessage + 1, ClientID))
{
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "The execution of the line '%s' has been denied (maybe the admin didn't allow the command for users).", pMsg->m_pMessage + 1);
SendChatTarget(ClientID, aBuf);
}
Console()->SetAccessLevel(IConsole::ACCESS_LEVEL_ADMIN);
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "chat",
pMsg->m_pMessage);