From 5e02bb5a2370504cbbdb568c66921863a4cec8ad Mon Sep 17 00:00:00 2001 From: Learath Date: Wed, 13 May 2020 23:27:49 +0300 Subject: [PATCH] Extend antibot interface Co-authored-by: heinrich5991 --- CMakeLists.txt | 5 +- src/antibot/antibot_data.h | 15 ++- src/antibot/antibot_interface.h | 7 +- src/antibot/antibot_null.cpp | 25 +++-- src/engine/antibot.h | 44 ++++++++ src/engine/server.h | 6 + src/engine/server/antibot.cpp | 149 +++++++++++++++++++++++++ src/engine/server/antibot.h | 54 +++++++++ src/engine/server/server.cpp | 34 ++++++ src/engine/server/server.h | 5 + src/game/server/antibot.cpp | 94 ---------------- src/game/server/antibot.h | 27 ----- src/game/server/entities/character.cpp | 2 +- src/game/server/entities/character.h | 3 +- src/game/server/gamecontext.cpp | 7 +- src/game/server/gamecontext.h | 9 +- 16 files changed, 339 insertions(+), 147 deletions(-) create mode 100644 src/engine/antibot.h create mode 100644 src/engine/server/antibot.cpp create mode 100644 src/engine/server/antibot.h delete mode 100644 src/game/server/antibot.cpp delete mode 100644 src/game/server/antibot.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 73912392c..897ab9794 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -653,6 +653,7 @@ set_src(BASE GLOB_RECURSE src/base vmath.h ) set_src(ENGINE_INTERFACE GLOB src/engine + antibot.h client.h config.h console.h @@ -1064,6 +1065,8 @@ set_src(ANTIBOT_SRC GLOB src/antibot ) set_src(ENGINE_SERVER GLOB src/engine/server + antibot.cpp + antibot.h authmanager.cpp authmanager.h name_ban.cpp @@ -1080,8 +1083,6 @@ set_src(ENGINE_SERVER GLOB src/engine/server sql_string_helpers.h ) set_src(GAME_SERVER GLOB_RECURSE src/game/server - antibot.cpp - antibot.h ddracechat.cpp ddracechat.h ddracecommands.cpp diff --git a/src/antibot/antibot_data.h b/src/antibot/antibot_data.h index aa52f2255..11a82f35d 100644 --- a/src/antibot/antibot_data.h +++ b/src/antibot/antibot_data.h @@ -5,6 +5,9 @@ enum { + ANTIBOT_MSGFLAG_NONVITAL=1, + ANTIBOT_MSGFLAG_FLUSH=2, + ANTIBOT_MAX_CLIENTS=64, }; @@ -46,14 +49,18 @@ struct CAntibotCharacterData int m_WeaponChangeTick; }; -struct CAntibotData +struct CAntibotCallbackData +{ + void (*m_pfnLog)(const char *pMessage, void *pUser); + void (*m_pfnReport)(int ClientID, const char *pMessage, void *pUser); + void (*m_pfnSend)(int ClientID, const void *pData, int DataSize, int Flags, void *pUser); + void *m_pUser; +}; +struct CAntibotRoundData { int m_Tick; CAntibotCharacterData m_aCharacters[ANTIBOT_MAX_CLIENTS]; CAntibotMapData m_Map; - void (*m_pfnLog)(const char *pMessage, void *pUser); - void (*m_pfnReport)(int ClientID, const char *pMessage, void *pUser); - void *m_pUser; }; #endif // ANTIBOT_ANTIBOT_DATA_H diff --git a/src/antibot/antibot_interface.h b/src/antibot/antibot_interface.h index eb3f9bd95..b638b4407 100644 --- a/src/antibot/antibot_interface.h +++ b/src/antibot/antibot_interface.h @@ -5,7 +5,9 @@ extern "C" { -void AntibotInit(CAntibotData *pData); +void AntibotInit(CAntibotCallbackData *pCallbackData); +void AntibotRoundStart(CAntibotRoundData *pRoundData); +void AntibotRoundEnd(void); void AntibotUpdateData(void); void AntibotDestroy(void); void AntibotDump(void); @@ -18,6 +20,9 @@ void AntibotOnHammerHit(int ClientID); void AntibotOnDirectInput(int ClientID); void AntibotOnTick(int ClientID); void AntibotOnHookAttach(int ClientID, bool Player); +void AntibotOnEngineClientJoin(int ClientID); +void AntibotOnEngineClientDrop(int ClientID, const char *pReason); +void AntibotOnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags); } diff --git a/src/antibot/antibot_null.cpp b/src/antibot/antibot_null.cpp index 59f57702c..98ce85db3 100644 --- a/src/antibot/antibot_null.cpp +++ b/src/antibot/antibot_null.cpp @@ -1,25 +1,27 @@ #include "antibot_data.h" -static CAntibotData *g_pAntibot; +static CAntibotCallbackData *g_pCallbacks; extern "C" { -void AntibotInit(CAntibotData *pData) +void AntibotInit(CAntibotCallbackData *pData) { - g_pAntibot = pData; - if(g_pAntibot->m_pfnLog) + g_pCallbacks = pData; + if(g_pCallbacks->m_pfnLog) { - g_pAntibot->m_pfnLog("null antibot initialized", g_pAntibot->m_pUser); + g_pCallbacks->m_pfnLog("null antibot initialized", g_pCallbacks->m_pUser); } } -void AntibotUpdateData() { } -void AntibotDestroy() { g_pAntibot = 0; } -void AntibotDump() +void AntibotRoundStart(CAntibotRoundData *pRoundData) { }; +void AntibotRoundEnd(void) { }; +void AntibotUpdateData(void) { } +void AntibotDestroy(void) { g_pCallbacks = 0; } +void AntibotDump(void) { - if(g_pAntibot->m_pfnLog) + if(g_pCallbacks->m_pfnLog) { - g_pAntibot->m_pfnLog("null antibot", g_pAntibot->m_pUser); + g_pCallbacks->m_pfnLog("null antibot", g_pCallbacks->m_pUser); } } void AntibotOnPlayerInit(int ClientID) { (void)ClientID; } @@ -31,5 +33,8 @@ void AntibotOnHammerHit(int ClientID) { (void)ClientID; } void AntibotOnDirectInput(int ClientID) { (void)ClientID; } void AntibotOnTick(int ClientID) { (void)ClientID; } void AntibotOnHookAttach(int ClientID, bool Player) { (void)ClientID; (void)Player; } +void AntibotOnEngineClientJoin(int ClientID) { (void)ClientID; } +void AntibotOnEngineClientDrop(int ClientID, const char *pReason) { (void)ClientID; (void)pReason; } +void AntibotOnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags) { (void)ClientID; (void)pData; (void)Size; (void)Flags; } } diff --git a/src/engine/antibot.h b/src/engine/antibot.h new file mode 100644 index 000000000..d02285151 --- /dev/null +++ b/src/engine/antibot.h @@ -0,0 +1,44 @@ +#ifndef ENGINE_ANTIBOT_H +#define ENGINE_ANTIBOT_H + +#include "kernel.h" + +class IAntibot : public IInterface +{ + MACRO_INTERFACE("antibot", 0) +public: + virtual void RoundStart(class IGameServer *pGameServer) = 0; + virtual void RoundEnd() = 0; + + // Hooks + virtual void OnPlayerInit(int ClientID) = 0; + virtual void OnPlayerDestroy(int ClientID) = 0; + virtual void OnSpawn(int ClientID) = 0; + virtual void OnHammerFireReloading(int ClientID) = 0; + virtual void OnHammerFire(int ClientID) = 0; + virtual void OnHammerHit(int ClientID) = 0; + virtual void OnDirectInput(int ClientID) = 0; + virtual void OnTick(int ClientID) = 0; + virtual void OnHookAttach(int ClientID, bool Player) = 0; + + // Commands + virtual void Dump() = 0; + + virtual ~IAntibot() { }; +}; + +class IEngineAntibot : public IAntibot +{ + MACRO_INTERFACE("engineantibot", 0) +public: + virtual void Init() = 0; + + // Hooks + virtual void OnEngineClientJoin(int ClientID) = 0; + virtual void OnEngineClientDrop(int ClientID, const char *pReason) = 0; + virtual void OnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags) = 0; + + virtual ~IEngineAntibot() { }; +}; + +#endif //ENGINE_ANTIBOT_H diff --git a/src/engine/server.h b/src/engine/server.h index 394feee3c..63dba0f0e 100644 --- a/src/engine/server.h +++ b/src/engine/server.h @@ -11,6 +11,8 @@ #include #include +struct CAntibotRoundData; + class IServer : public IInterface { MACRO_INTERFACE("server", 0) @@ -190,6 +192,8 @@ public: virtual void SetErrorShutdown(const char *pReason) = 0; virtual void ExpireServerInfo() = 0; + virtual void SendMsgRaw(int ClientID, const void *pData, int Size, int Flags) = 0; + virtual char *GetMapName() = 0; }; @@ -236,6 +240,8 @@ public: virtual void OnClientEngineJoin(int ClientID) = 0; virtual void OnClientEngineDrop(int ClientID, const char *pReason) = 0; + + virtual void FillAntibot(CAntibotRoundData *pData) = 0; }; extern IGameServer *CreateGameServer(); diff --git a/src/engine/server/antibot.cpp b/src/engine/server/antibot.cpp new file mode 100644 index 000000000..fabe3b50c --- /dev/null +++ b/src/engine/server/antibot.cpp @@ -0,0 +1,149 @@ +#include "antibot.h" +#include + +#include +#include +#include + +#ifdef CONF_ANTIBOT +CAntibot::CAntibot() + : m_pGameServer(0) +{ +} +CAntibot::~CAntibot() +{ + if(m_pGameServer && m_RoundData.m_Map.m_pTiles) + free(m_RoundData.m_Map.m_pTiles); + + AntibotDestroy(); +} +void CAntibot::Send(int ClientID, const void *pData, int Size, int Flags, void *pUser) +{ + CAntibot *pAntibot = (CAntibot *)pUser; + + int RealFlags = MSGFLAG_VITAL; + if(Flags&ANTIBOT_MSGFLAG_NONVITAL) + { + RealFlags &= ~MSGFLAG_VITAL; + } + if(Flags&ANTIBOT_MSGFLAG_FLUSH) + { + RealFlags |= MSGFLAG_FLUSH; + } + pAntibot->Server()->SendMsgRaw(ClientID, pData, Size, RealFlags); +} +void CAntibot::Log(const char *pMessage, void *pUser) +{ + CAntibot *pAntibot = (CAntibot *)pUser; + pAntibot->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "antibot", pMessage); +} +void CAntibot::Report(int ClientID, const char *pMessage, void *pUser) +{ + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "%d: %s", ClientID, pMessage); + Log(aBuf, pUser); +} +void CAntibot::Init() +{ + m_pServer = Kernel()->RequestInterface(); + m_pConsole = Kernel()->RequestInterface(); + dbg_assert(m_pServer && m_pConsole, "antibot requires server and console"); + + mem_zero(&m_CallbackData, sizeof(m_CallbackData)); + m_CallbackData.m_pfnLog = Log; + m_CallbackData.m_pfnReport = Report; + m_CallbackData.m_pfnSend = Send; + m_CallbackData.m_pUser = this; + AntibotInit(&m_CallbackData); +} +void CAntibot::RoundStart(IGameServer *pGameServer) +{ + m_pGameServer = pGameServer; + mem_zero(&m_RoundData, sizeof(m_RoundData)); + m_RoundData.m_Map.m_pTiles = 0; + AntibotRoundStart(&m_RoundData); + Update(); +} +void CAntibot::RoundEnd() +{ + // Let the external module clean up first + AntibotRoundEnd(); + + m_pGameServer = 0; + if(m_RoundData.m_Map.m_pTiles) + free(m_RoundData.m_Map.m_pTiles); +} +void CAntibot::Dump() { AntibotDump(); } +void CAntibot::Update() +{ + GameServer()->FillAntibot(&m_RoundData); + AntibotUpdateData(); +} + +void CAntibot::OnPlayerInit(int ClientID) { Update(); AntibotOnPlayerInit(ClientID); } +void CAntibot::OnPlayerDestroy(int ClientID) { Update(); AntibotOnPlayerDestroy(ClientID); } +void CAntibot::OnSpawn(int ClientID) { Update(); AntibotOnSpawn(ClientID); } +void CAntibot::OnHammerFireReloading(int ClientID) { Update(); AntibotOnHammerFireReloading(ClientID); } +void CAntibot::OnHammerFire(int ClientID) { Update(); AntibotOnHammerFire(ClientID); } +void CAntibot::OnHammerHit(int ClientID) { Update(); AntibotOnHammerHit(ClientID); } +void CAntibot::OnDirectInput(int ClientID) { Update(); AntibotOnDirectInput(ClientID); } +void CAntibot::OnTick(int ClientID) { Update(); AntibotOnTick(ClientID); } +void CAntibot::OnHookAttach(int ClientID, bool Player) { Update(); AntibotOnHookAttach(ClientID, Player); } + +void CAntibot::OnEngineClientJoin(int ClientID) { AntibotOnEngineClientJoin(ClientID); } +void CAntibot::OnEngineClientDrop(int ClientID, const char *pReason) { AntibotOnEngineClientDrop(ClientID, pReason); } +void CAntibot::OnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags) +{ + int AntibotFlags = 0; + if((Flags&MSGFLAG_VITAL) == 0) + { + AntibotFlags |= ANTIBOT_MSGFLAG_NONVITAL; + } + AntibotOnEngineClientMessage(ClientID, pData, Size, Flags); +} +#else +CAntibot::CAntibot() : + m_pGameServer(0) +{ +} +CAntibot::~CAntibot() +{ +} +void CAntibot::Init() +{ + m_pServer = Kernel()->RequestInterface(); + m_pConsole = Kernel()->RequestInterface(); + dbg_assert(m_pServer && m_pConsole, "antibot requires server and console"); +} +void CAntibot::RoundStart(IGameServer *pGameServer) +{ + m_pGameServer = pGameServer; +} +void CAntibot::RoundEnd() +{ + m_pGameServer = 0; +} +void CAntibot::Dump() +{ + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "antibot", "antibot support not compiled in"); +} +void CAntibot::Update() +{ +} + +void CAntibot::OnPlayerInit(int ClientID) { } +void CAntibot::OnPlayerDestroy(int ClientID) { } +void CAntibot::OnSpawn(int ClientID) { } +void CAntibot::OnHammerFireReloading(int ClientID) { } +void CAntibot::OnHammerFire(int ClientID) { } +void CAntibot::OnHammerHit(int ClientID) { } +void CAntibot::OnDirectInput(int ClientID) { } +void CAntibot::OnTick(int ClientID) { } +void CAntibot::OnHookAttach(int ClientID, bool Player) { } + +void CAntibot::OnEngineClientJoin(int ClientID) { } +void CAntibot::OnEngineClientDrop(int ClientID, const char *pReason) { } +void CAntibot::OnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags) { } +#endif + +IEngineAntibot *CreateEngineAntibot() { return new CAntibot; } diff --git a/src/engine/server/antibot.h b/src/engine/server/antibot.h new file mode 100644 index 000000000..27fc98311 --- /dev/null +++ b/src/engine/server/antibot.h @@ -0,0 +1,54 @@ +#ifndef ENGINE_SERVER_ANTIBOT_H +#define ENGINE_SERVER_ANTIBOT_H + +#include +#include + +class CAntibot : public IEngineAntibot +{ + class IServer *m_pServer; + class IConsole *m_pConsole; + class IGameServer *m_pGameServer; + + class IServer *Server() const { return m_pServer; } + class IConsole *Console() const { return m_pConsole; } + class IGameServer *GameServer() const { return m_pGameServer; } + + CAntibotCallbackData m_CallbackData; + CAntibotRoundData m_RoundData; + + void Update(); + static void Send(int ClientID, const void *pData, int Size, int Flags, void *pUser); + static void Log(const char *pMessage, void *pUser); + static void Report(int ClientID, const char *pMessage, void *pUser); +public: + CAntibot(); + virtual ~CAntibot(); + + // Engine + virtual void Init(); + + virtual void OnEngineClientJoin(int ClientID); + virtual void OnEngineClientDrop(int ClientID, const char *pReason); + virtual void OnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags); + + // Game + virtual void RoundStart(class IGameServer *pGameServer); + virtual void RoundEnd(); + + virtual void OnPlayerInit(int ClientID); + virtual void OnPlayerDestroy(int ClientID); + virtual void OnSpawn(int ClientID); + virtual void OnHammerFireReloading(int ClientID); + virtual void OnHammerFire(int ClientID); + virtual void OnHammerHit(int ClientID); + virtual void OnDirectInput(int ClientID); + virtual void OnTick(int ClientID); + virtual void OnHookAttach(int ClientID, bool Player); + + virtual void Dump(); +}; + +extern IEngineAntibot *CreateEngineAntibot(); + +#endif // ENGINE_SERVER_ANTIBOT_H diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 0a0edfe05..0b6a0bdad 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -663,6 +663,25 @@ int CServer::SendMsg(CMsgPacker *pMsg, int Flags, int ClientID) return 0; } +void CServer::SendMsgRaw(int ClientID, const void *pData, int Size, int Flags) +{ + CNetChunk Packet; + mem_zero(&Packet, sizeof(CNetChunk)); + Packet.m_ClientID = ClientID; + Packet.m_pData = pData; + Packet.m_DataSize = Size; + Packet.m_Flags = 0; + if(Flags&MSGFLAG_VITAL) + { + Packet.m_Flags |= NETSENDFLAG_VITAL; + } + if(Flags&MSGFLAG_FLUSH) + { + Packet.m_Flags |= NETSENDFLAG_FLUSH; + } + m_NetServer.Send(&Packet); +} + void CServer::DoSnapshot() { GameServer()->OnPreSnap(); @@ -869,7 +888,9 @@ int CServer::NewClientCallback(int ClientID, void *pUser) pThis->m_aClients[ClientID].m_ShowIps = false; memset(&pThis->m_aClients[ClientID].m_Addr, 0, sizeof(NETADDR)); pThis->m_aClients[ClientID].Reset(); + pThis->GameServer()->OnClientEngineJoin(ClientID); + pThis->Antibot()->OnEngineClientJoin(ClientID); #if defined(CONF_FAMILY_UNIX) pThis->SendConnLoggingCommand(OPEN_SESSION, pThis->m_NetServer.ClientAddr(ClientID)); @@ -951,6 +972,7 @@ int CServer::DelClientCallback(int ClientID, const char *pReason, void *pUser) pThis->m_aClients[ClientID].m_Snapshots.PurgeAll(); pThis->GameServer()->OnClientEngineDrop(ClientID, pReason); + pThis->Antibot()->OnEngineClientDrop(ClientID, pReason); #if defined(CONF_FAMILY_UNIX) pThis->SendConnLoggingCommand(CLOSE_SESSION, pThis->m_NetServer.ClientAddr(ClientID)); #endif @@ -1128,6 +1150,13 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket) Unpacker.Reset(pPacket->m_pData, pPacket->m_DataSize); CMsgPacker Packer(NETMSG_EX, true); + int GameFlags = 0; + if(pPacket->m_Flags&NET_CHUNKFLAG_VITAL) + { + GameFlags |= MSGFLAG_VITAL; + } + Antibot()->OnEngineClientMessage(ClientID, pPacket->m_pData, pPacket->m_DataSize, GameFlags); + // unpack msgid and system flag int Msg; bool Sys; @@ -1980,6 +2009,7 @@ int CServer::Run() str_format(aBuf, sizeof(aBuf), "server name is '%s'", g_Config.m_SvName); Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); + Antibot()->Init(); GameServer()->OnInit(); if(ErrorShutdown()) { @@ -2965,6 +2995,7 @@ void CServer::RegisterCommands() m_pGameServer = Kernel()->RequestInterface(); m_pMap = Kernel()->RequestInterface(); m_pStorage = Kernel()->RequestInterface(); + m_pAntibot = Kernel()->RequestInterface(); // register console commands Console()->Register("kick", "i[id] ?r[reason]", CFGFLAG_SERVER, ConKick, this, "Kick player with specified id for any reason"); @@ -3076,6 +3107,7 @@ int main(int argc, const char **argv) // ignore_convention IEngineMasterServer *pEngineMasterServer = CreateEngineMasterServer(); IStorage *pStorage = CreateStorage("Teeworlds", IStorage::STORAGETYPE_SERVER, argc, argv); // ignore_convention IConfig *pConfig = CreateConfig(); + IEngineAntibot *pEngineAntibot = CreateEngineAntibot(); pServer->InitRegister(&pServer->m_NetServer, pEngineMasterServer, pConsole); @@ -3092,6 +3124,8 @@ int main(int argc, const char **argv) // ignore_convention RegisterFail = RegisterFail || !pKernel->RegisterInterface(pConfig); RegisterFail = RegisterFail || !pKernel->RegisterInterface(pEngineMasterServer); // register as both RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast(pEngineMasterServer), false); + RegisterFail = RegisterFail || !pKernel->RegisterInterface(pEngineAntibot); + RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast(pEngineAntibot), false); if(RegisterFail) { diff --git a/src/engine/server/server.h b/src/engine/server/server.h index cee0009ef..03e785191 100644 --- a/src/engine/server/server.h +++ b/src/engine/server/server.h @@ -25,6 +25,7 @@ #include +#include "antibot.h" #include "authmanager.h" #include "name_ban.h" @@ -91,6 +92,7 @@ class CServer : public IServer class IGameServer *m_pGameServer; class IConsole *m_pConsole; class IStorage *m_pStorage; + class IEngineAntibot *m_pAntibot; #if defined(CONF_SQL) lock m_GlobalSqlLock; @@ -109,6 +111,7 @@ public: class IGameServer *GameServer() { return m_pGameServer; } class IConsole *Console() { return m_pConsole; } class IStorage *Storage() { return m_pStorage; } + class IEngineAntibot *Antibot() { return m_pAntibot; } enum { @@ -412,6 +415,8 @@ public: bool SetTimedOut(int ClientID, int OrigID); void SetTimeoutProtected(int ClientID) { m_NetServer.SetTimeoutProtected(ClientID); }; + void SendMsgRaw(int ClientID, const void *pData, int Size, int Flags); + bool ErrorShutdown() const { return m_aErrorShutdownReason[0] != 0; } void SetErrorShutdown(const char *pReason); diff --git a/src/game/server/antibot.cpp b/src/game/server/antibot.cpp deleted file mode 100644 index 199dfc070..000000000 --- a/src/game/server/antibot.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "antibot.h" -#include -#include - -#include - -#ifdef CONF_ANTIBOT -static CAntibotData g_Data; - -static void Log(const char *pMessage, void *pUser) -{ - CGameContext *pGameContext = (CGameContext *)pUser; - pGameContext->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "antibot", pMessage); -} -static void Report(int ClientID, const char *pMessage, void *pUser) -{ - char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "%d: %s", ClientID, pMessage); - Log(aBuf, pUser); -} - -CAntibot::CAntibot() - : m_pGameContext(0) -{ -} -CAntibot::~CAntibot() -{ - // Check if `Init` was called. There is no easy way to prevent two - // destructors running without an `Init` call in between. - if(m_pGameContext) - { - AntibotDestroy(); - free(g_Data.m_Map.m_pTiles); - g_Data.m_Map.m_pTiles = 0; - m_pGameContext = 0; - } -} -void CAntibot::Init(CGameContext *pGameContext) -{ - m_pGameContext = pGameContext; - mem_zero(&g_Data, sizeof(g_Data)); - g_Data.m_Map.m_pTiles = 0; - g_Data.m_pfnLog = Log; - g_Data.m_pfnReport = Report; - g_Data.m_pUser = m_pGameContext; - AntibotInit(&g_Data); - Update(); -} -void CAntibot::Dump() { AntibotDump(); } -void CAntibot::Update() -{ - m_pGameContext->FillAntibot(&g_Data); - AntibotUpdateData(); -} - -void CAntibot::OnPlayerInit(int ClientID) { Update(); AntibotOnPlayerInit(ClientID); } -void CAntibot::OnPlayerDestroy(int ClientID) { Update(); AntibotOnPlayerDestroy(ClientID); } -void CAntibot::OnSpawn(int ClientID) { Update(); AntibotOnSpawn(ClientID); } -void CAntibot::OnHammerFireReloading(int ClientID) { Update(); AntibotOnHammerFireReloading(ClientID); } -void CAntibot::OnHammerFire(int ClientID) { Update(); AntibotOnHammerFire(ClientID); } -void CAntibot::OnHammerHit(int ClientID) { Update(); AntibotOnHammerHit(ClientID); } -void CAntibot::OnDirectInput(int ClientID) { Update(); AntibotOnDirectInput(ClientID); } -void CAntibot::OnTick(int ClientID) { Update(); AntibotOnTick(ClientID); } -void CAntibot::OnHookAttach(int ClientID, bool Player) { Update(); AntibotOnHookAttach(ClientID, Player); } -#else -CAntibot::CAntibot() : - m_pGameContext(0) -{ -} -CAntibot::~CAntibot() -{ -} -void CAntibot::Init(CGameContext *pGameContext) -{ - m_pGameContext = pGameContext; -} -void CAntibot::Dump() -{ - m_pGameContext->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "antibot", "antibot support not compiled in"); -} -void CAntibot::Update() -{ -} - -void CAntibot::OnPlayerInit(int ClientID) { } -void CAntibot::OnPlayerDestroy(int ClientID) { } -void CAntibot::OnSpawn(int ClientID) { } -void CAntibot::OnHammerFireReloading(int ClientID) { } -void CAntibot::OnHammerFire(int ClientID) { } -void CAntibot::OnHammerHit(int ClientID) { } -void CAntibot::OnDirectInput(int ClientID) { } -void CAntibot::OnTick(int ClientID) { } -void CAntibot::OnHookAttach(int ClientID, bool Player) { } -#endif diff --git a/src/game/server/antibot.h b/src/game/server/antibot.h deleted file mode 100644 index 4dca085ee..000000000 --- a/src/game/server/antibot.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef GAME_SERVER_ANTIBOT_H -#define GAME_SERVER_ANTIBOT_H - -class CGameContext; - -class CAntibot -{ - CGameContext *m_pGameContext; - void Update(); -public: - CAntibot(); - ~CAntibot(); - void Init(CGameContext *pGameContext); - void Dump(); - - void OnPlayerInit(int ClientID); - void OnPlayerDestroy(int ClientID); - void OnSpawn(int ClientID); - void OnHammerFireReloading(int ClientID); - void OnHammerFire(int ClientID); - void OnHammerHit(int ClientID); - void OnDirectInput(int ClientID); - void OnTick(int ClientID); - void OnHookAttach(int ClientID, bool Player); -}; - -#endif // GAME_SERVER_ANTIBOT_H diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 6c35b5918..4af87d674 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -2108,7 +2108,7 @@ void CCharacter::SendZoneMsgs() } } -CAntibot *CCharacter::Antibot() +IAntibot *CCharacter::Antibot() { return GameServer()->Antibot(); } diff --git a/src/game/server/entities/character.h b/src/game/server/entities/character.h index 8cbdbe9e7..96cf94128 100644 --- a/src/game/server/entities/character.h +++ b/src/game/server/entities/character.h @@ -3,6 +3,7 @@ #ifndef GAME_SERVER_ENTITIES_CHARACTER_H #define GAME_SERVER_ENTITIES_CHARACTER_H +#include #include #include #include @@ -173,7 +174,7 @@ private: void HandleBroadcast(); void HandleTuneLayer(); void SendZoneMsgs(); - CAntibot *Antibot(); + IAntibot *Antibot(); bool m_SetSavePos; vec2 m_PrevSavePos; diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 7405b25a8..2830b3647 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -131,7 +131,7 @@ bool CGameContext::EmulateBug(int Bug) return m_MapBugs.Contains(Bug); } -void CGameContext::FillAntibot(CAntibotData *pData) +void CGameContext::FillAntibot(CAntibotRoundData *pData) { if(!pData->m_Map.m_pTiles) { @@ -2617,7 +2617,8 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/) m_pConsole = Kernel()->RequestInterface(); m_pEngine = Kernel()->RequestInterface(); m_pStorage = Kernel()->RequestInterface(); - m_Antibot.Init(this); + m_pAntibot = Kernel()->RequestInterface(); + m_pAntibot->RoundStart(this); m_World.SetGameServer(this); m_Events.SetGameServer(this); @@ -3044,6 +3045,8 @@ void CGameContext::OnShutdown(bool FullShutdown) if (FullShutdown) Score()->OnShutdown(); + Antibot()->RoundEnd(); + if(m_TeeHistorianActive) { m_TeeHistorian.Finish(); diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index d95d97a40..ebf5855ff 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -3,6 +3,7 @@ #ifndef GAME_SERVER_GAMECONTEXT_H #define GAME_SERVER_GAMECONTEXT_H +#include #include #include #include @@ -11,7 +12,6 @@ #include #include -#include "antibot.h" #include "eventhandler.h" #include "gamecontroller.h" #include "gameworld.h" @@ -67,6 +67,7 @@ class CGameContext : public IGameServer IConsole *m_pConsole; IEngine *m_pEngine; IStorage *m_pStorage; + IAntibot *m_pAntibot; CLayers m_Layers; CCollision m_Collision; CNetObjHandler m_NetObjHandler; @@ -78,7 +79,6 @@ class CGameContext : public IGameServer ASYNCIO *m_pTeeHistorianFile; CUuid m_GameUuid; CMapBugs m_MapBugs; - CAntibot m_Antibot; std::shared_ptr m_pRandomMapResult; std::shared_ptr m_pMapVoteResult; @@ -130,7 +130,7 @@ public: CCollision *Collision() { return &m_Collision; } CTuningParams *Tuning() { return &m_Tuning; } CTuningParams *TuningList() { return &m_aTuningList[0]; } - CAntibot *Antibot() { return &m_Antibot; } + IAntibot *Antibot() { return m_pAntibot; } CGameContext(); ~CGameContext(); @@ -146,7 +146,6 @@ public: // helper functions class CCharacter *GetPlayerChar(int ClientID); bool EmulateBug(int Bug); - void FillAntibot(CAntibotData *pData); // voting void StartVote(const char *pDesc, const char *pCommand, const char *pReason); @@ -253,7 +252,7 @@ public: virtual const char *NetVersion(); // DDRace - + virtual void FillAntibot(CAntibotRoundData *pData); int ProcessSpamProtection(int ClientID); int GetDDRaceTeam(int ClientID); // Describes the time when the first player joined the server.