Merge pull request #7495 from heinrich5991/pr_ddnet_antibot_command

Allow more complex interaction with the antibot via the console
This commit is contained in:
Dennis Felsing 2023-11-19 08:45:34 +00:00 committed by GitHub
commit d369238636
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 37 additions and 10 deletions

View file

@ -6,7 +6,7 @@
enum
{
ANTIBOT_ABI_VERSION = 7,
ANTIBOT_ABI_VERSION = 8,
ANTIBOT_MSGFLAG_NONVITAL = 1,
ANTIBOT_MSGFLAG_FLUSH = 2,

View file

@ -16,7 +16,7 @@ ANTIBOTAPI void AntibotRoundStart(CAntibotRoundData *pRoundData);
ANTIBOTAPI void AntibotRoundEnd(void);
ANTIBOTAPI void AntibotUpdateData(void);
ANTIBOTAPI void AntibotDestroy(void);
ANTIBOTAPI void AntibotDump(void);
ANTIBOTAPI void AntibotConsoleCommand(const char *pCommand);
ANTIBOTAPI void AntibotOnPlayerInit(int ClientID);
ANTIBOTAPI void AntibotOnPlayerDestroy(int ClientID);
ANTIBOTAPI void AntibotOnSpawn(int ClientID);

View file

@ -2,6 +2,8 @@
#include "antibot_interface.h"
#include <cstring>
static CAntibotData *g_pData;
extern "C" {
@ -19,9 +21,16 @@ void AntibotRoundStart(CAntibotRoundData *pRoundData){};
void AntibotRoundEnd(void){};
void AntibotUpdateData(void) {}
void AntibotDestroy(void) { g_pData = 0; }
void AntibotDump(void)
void AntibotConsoleCommand(const char *pCommand)
{
if(strcmp(pCommand, "dump") == 0)
{
g_pData->m_pfnLog("null antibot", g_pData->m_pUser);
}
else
{
g_pData->m_pfnLog("unknown command", g_pData->m_pUser);
}
}
void AntibotOnPlayerInit(int /*ClientID*/) {}
void AntibotOnPlayerDestroy(int /*ClientID*/) {}

View file

@ -22,7 +22,7 @@ public:
virtual void OnHookAttach(int ClientID, bool Player) = 0;
// Commands
virtual void Dump() = 0;
virtual void ConsoleCommand(const char *pCommand) = 0;
virtual ~IAntibot(){};
};

View file

@ -92,7 +92,10 @@ void CAntibot::RoundEnd()
m_pGameServer = 0;
free(m_RoundData.m_Map.m_pTiles);
}
void CAntibot::Dump() { AntibotDump(); }
void CAntibot::ConsoleCommand(const char *pCommand)
{
AntibotConsoleCommand(pCommand);
}
void CAntibot::Update()
{
m_Data.m_Now = time_get();
@ -221,9 +224,16 @@ void CAntibot::RoundEnd()
{
m_pGameServer = 0;
}
void CAntibot::Dump()
void CAntibot::ConsoleCommand(const char *pCommand)
{
if(str_comp(pCommand, "dump") == 0)
{
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "antibot", "antibot support not compiled in");
}
else
{
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "antibot", "unknown command");
}
}
void CAntibot::Update()
{

View file

@ -52,7 +52,7 @@ public:
void OnCharacterTick(int ClientID) override;
void OnHookAttach(int ClientID, bool Player) override;
void Dump() override;
void ConsoleCommand(const char *pCommand) override;
};
extern IEngineAntibot *CreateEngineAntibot();

View file

@ -878,7 +878,13 @@ void CGameContext::ConDrySave(IConsole::IResult *pResult, void *pUserData)
void CGameContext::ConDumpAntibot(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->Antibot()->Dump();
pSelf->Antibot()->ConsoleCommand("dump");
}
void CGameContext::ConAntibot(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->Antibot()->ConsoleCommand(pResult->GetString(0));
}
void CGameContext::ConDumpLog(IConsole::IResult *pResult, void *pUserData)

View file

@ -3472,6 +3472,7 @@ void CGameContext::OnConsoleInit()
Console()->Register("vote", "r['yes'|'no']", CFGFLAG_SERVER, ConVote, this, "Force a vote to yes/no");
Console()->Register("votes", "?i[page]", CFGFLAG_SERVER, ConVotes, this, "Show all votes (page 0 by default, 20 entries per page)");
Console()->Register("dump_antibot", "", CFGFLAG_SERVER, ConDumpAntibot, this, "Dumps the antibot status");
Console()->Register("antibot", "r[command]", CFGFLAG_SERVER, ConAntibot, this, "Sends a command to the antibot");
Console()->Chain("sv_motd", ConchainSpecialMotdupdate, this);

View file

@ -132,6 +132,7 @@ class CGameContext : public IGameServer
static void ConVoteNo(IConsole::IResult *pResult, void *pUserData);
static void ConDrySave(IConsole::IResult *pResult, void *pUserData);
static void ConDumpAntibot(IConsole::IResult *pResult, void *pUserData);
static void ConAntibot(IConsole::IResult *pResult, void *pUserData);
static void ConchainSpecialMotdupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainSettingUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConDumpLog(IConsole::IResult *pResult, void *pUserData);