mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-05 23:58:19 +00:00
Extend antibot interface
Co-authored-by: heinrich5991 <heinrich5991@gmail.com>
This commit is contained in:
parent
aeeee5a643
commit
5e02bb5a23
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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; }
|
||||
|
||||
}
|
||||
|
|
44
src/engine/antibot.h
Normal file
44
src/engine/antibot.h
Normal file
|
@ -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
|
|
@ -11,6 +11,8 @@
|
|||
#include <game/generated/protocol.h>
|
||||
#include <engine/shared/protocol.h>
|
||||
|
||||
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();
|
||||
|
|
149
src/engine/server/antibot.cpp
Normal file
149
src/engine/server/antibot.cpp
Normal file
|
@ -0,0 +1,149 @@
|
|||
#include "antibot.h"
|
||||
#include <antibot/antibot_interface.h>
|
||||
|
||||
#include <engine/kernel.h>
|
||||
#include <engine/console.h>
|
||||
#include <engine/server.h>
|
||||
|
||||
#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<IServer>();
|
||||
m_pConsole = Kernel()->RequestInterface<IConsole>();
|
||||
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<IServer>();
|
||||
m_pConsole = Kernel()->RequestInterface<IConsole>();
|
||||
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; }
|
54
src/engine/server/antibot.h
Normal file
54
src/engine/server/antibot.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
#ifndef ENGINE_SERVER_ANTIBOT_H
|
||||
#define ENGINE_SERVER_ANTIBOT_H
|
||||
|
||||
#include <antibot/antibot_data.h>
|
||||
#include <engine/antibot.h>
|
||||
|
||||
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
|
|
@ -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<IGameServer>();
|
||||
m_pMap = Kernel()->RequestInterface<IEngineMap>();
|
||||
m_pStorage = Kernel()->RequestInterface<IStorage>();
|
||||
m_pAntibot = Kernel()->RequestInterface<IEngineAntibot>();
|
||||
|
||||
// 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<IMasterServer*>(pEngineMasterServer), false);
|
||||
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pEngineAntibot);
|
||||
RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast<IAntibot*>(pEngineAntibot), false);
|
||||
|
||||
if(RegisterFail)
|
||||
{
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include <list>
|
||||
|
||||
#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);
|
||||
|
||||
|
|
|
@ -1,94 +0,0 @@
|
|||
#include "antibot.h"
|
||||
#include <antibot/antibot_data.h>
|
||||
#include <antibot/antibot_interface.h>
|
||||
|
||||
#include <game/server/gamecontext.h>
|
||||
|
||||
#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
|
|
@ -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
|
|
@ -2108,7 +2108,7 @@ void CCharacter::SendZoneMsgs()
|
|||
}
|
||||
}
|
||||
|
||||
CAntibot *CCharacter::Antibot()
|
||||
IAntibot *CCharacter::Antibot()
|
||||
{
|
||||
return GameServer()->Antibot();
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#ifndef GAME_SERVER_ENTITIES_CHARACTER_H
|
||||
#define GAME_SERVER_ENTITIES_CHARACTER_H
|
||||
|
||||
#include <engine/antibot.h>
|
||||
#include <game/server/entity.h>
|
||||
#include <game/generated/server_data.h>
|
||||
#include <game/generated/protocol.h>
|
||||
|
@ -173,7 +174,7 @@ private:
|
|||
void HandleBroadcast();
|
||||
void HandleTuneLayer();
|
||||
void SendZoneMsgs();
|
||||
CAntibot *Antibot();
|
||||
IAntibot *Antibot();
|
||||
|
||||
bool m_SetSavePos;
|
||||
vec2 m_PrevSavePos;
|
||||
|
|
|
@ -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<IConsole>();
|
||||
m_pEngine = Kernel()->RequestInterface<IEngine>();
|
||||
m_pStorage = Kernel()->RequestInterface<IStorage>();
|
||||
m_Antibot.Init(this);
|
||||
m_pAntibot = Kernel()->RequestInterface<IAntibot>();
|
||||
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();
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#ifndef GAME_SERVER_GAMECONTEXT_H
|
||||
#define GAME_SERVER_GAMECONTEXT_H
|
||||
|
||||
#include <engine/antibot.h>
|
||||
#include <engine/server.h>
|
||||
#include <engine/console.h>
|
||||
#include <engine/shared/memheap.h>
|
||||
|
@ -11,7 +12,6 @@
|
|||
#include <game/mapbugs.h>
|
||||
#include <game/voting.h>
|
||||
|
||||
#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<CRandomMapResult> m_pRandomMapResult;
|
||||
std::shared_ptr<CMapVoteResult> 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.
|
||||
|
|
Loading…
Reference in a new issue