From 28b00892f68af6ae6bfbb470e0799519ea6aa8e7 Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Sun, 19 Nov 2023 04:41:56 +0100 Subject: [PATCH] Allow more complex interaction with the antibot via the console Allows the antibot to receive arbitrary console commands. --- src/antibot/antibot_data.h | 2 +- src/antibot/antibot_interface.h | 2 +- src/antibot/antibot_null.cpp | 13 +++++++++++-- src/engine/antibot.h | 2 +- src/engine/server/antibot.cpp | 16 +++++++++++++--- src/engine/server/antibot.h | 2 +- src/game/server/ddracecommands.cpp | 8 +++++++- src/game/server/gamecontext.cpp | 1 + src/game/server/gamecontext.h | 1 + 9 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/antibot/antibot_data.h b/src/antibot/antibot_data.h index cfc6d40b2..15493bd1f 100644 --- a/src/antibot/antibot_data.h +++ b/src/antibot/antibot_data.h @@ -6,7 +6,7 @@ enum { - ANTIBOT_ABI_VERSION = 7, + ANTIBOT_ABI_VERSION = 8, ANTIBOT_MSGFLAG_NONVITAL = 1, ANTIBOT_MSGFLAG_FLUSH = 2, diff --git a/src/antibot/antibot_interface.h b/src/antibot/antibot_interface.h index b89220a08..a982802c9 100644 --- a/src/antibot/antibot_interface.h +++ b/src/antibot/antibot_interface.h @@ -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); diff --git a/src/antibot/antibot_null.cpp b/src/antibot/antibot_null.cpp index f343937c7..6a70c0387 100644 --- a/src/antibot/antibot_null.cpp +++ b/src/antibot/antibot_null.cpp @@ -2,6 +2,8 @@ #include "antibot_interface.h" +#include + 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) { - g_pData->m_pfnLog("null antibot", g_pData->m_pUser); + 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*/) {} diff --git a/src/engine/antibot.h b/src/engine/antibot.h index 34827e53c..bf8e208c4 100644 --- a/src/engine/antibot.h +++ b/src/engine/antibot.h @@ -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(){}; }; diff --git a/src/engine/server/antibot.cpp b/src/engine/server/antibot.cpp index 1ec699b2e..ead44840a 100644 --- a/src/engine/server/antibot.cpp +++ b/src/engine/server/antibot.cpp @@ -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) { - Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "antibot", "antibot support not compiled in"); + 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() { diff --git a/src/engine/server/antibot.h b/src/engine/server/antibot.h index 0569c2d8d..245982eb4 100644 --- a/src/engine/server/antibot.h +++ b/src/engine/server/antibot.h @@ -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(); diff --git a/src/game/server/ddracecommands.cpp b/src/game/server/ddracecommands.cpp index 0630ad24e..3b9ce551a 100644 --- a/src/game/server/ddracecommands.cpp +++ b/src/game/server/ddracecommands.cpp @@ -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) diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 7515fec28..bd661e5bf 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -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); diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index 70b787838..02c53a352 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -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);