mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Allow the antibot to get more insight into the network
E.g. allow it to see the messages the server sends.
This commit is contained in:
parent
0393ac0f88
commit
fe082b9a6a
|
@ -6,7 +6,7 @@
|
|||
|
||||
enum
|
||||
{
|
||||
ANTIBOT_ABI_VERSION = 3,
|
||||
ANTIBOT_ABI_VERSION = 4,
|
||||
|
||||
ANTIBOT_MSGFLAG_NONVITAL = 1,
|
||||
ANTIBOT_MSGFLAG_FLUSH = 2,
|
||||
|
|
|
@ -29,7 +29,11 @@ ANTIBOTAPI void AntibotOnHookAttach(int ClientID, bool Player);
|
|||
ANTIBOTAPI void AntibotOnEngineTick(void);
|
||||
ANTIBOTAPI void AntibotOnEngineClientJoin(int ClientID, bool Sixup);
|
||||
ANTIBOTAPI void AntibotOnEngineClientDrop(int ClientID, const char *pReason);
|
||||
ANTIBOTAPI void AntibotOnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags);
|
||||
// Returns true if the message shouldn't be processed by the server.
|
||||
ANTIBOTAPI bool AntibotOnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags);
|
||||
ANTIBOTAPI bool AntibotOnEngineServerMessage(int ClientID, const void *pData, int Size, int Flags);
|
||||
// Returns true if the server should simulate receiving a client message.
|
||||
ANTIBOTAPI bool AntibotOnEngineSimulateClientMessage(int *pClientID, void *pBuffer, int BufferSize, int *pOutSize, int *pFlags);
|
||||
}
|
||||
|
||||
#endif // ANTIBOT_ANTIBOT_INTERFACE_H
|
||||
|
|
|
@ -35,5 +35,7 @@ void AntibotOnHookAttach(int /*ClientID*/, bool /*Player*/) {}
|
|||
void AntibotOnEngineTick(void) {}
|
||||
void AntibotOnEngineClientJoin(int /*ClientID*/, bool /*Sixup*/) {}
|
||||
void AntibotOnEngineClientDrop(int /*ClientID*/, const char * /*pReason*/) {}
|
||||
void AntibotOnEngineClientMessage(int /*ClientID*/, const void * /*pData*/, int /*Size*/, int /*Flags*/) {}
|
||||
bool AntibotOnEngineClientMessage(int /*ClientID*/, const void * /*pData*/, int /*Size*/, int /*Flags*/) { return false; }
|
||||
bool AntibotOnEngineServerMessage(int /*ClientID*/, const void * /*pData*/, int /*Size*/, int /*Flags*/) { return false; }
|
||||
bool AntibotOnEngineSimulateClientMessage(int * /*pClientID*/, void * /*pBuffer*/, int /*BufferSize*/, int * /*pOutSize*/, int * /*pFlags*/) { return false; }
|
||||
}
|
||||
|
|
|
@ -37,7 +37,9 @@ public:
|
|||
virtual void OnEngineTick() = 0;
|
||||
virtual void OnEngineClientJoin(int ClientID, bool Sixup) = 0;
|
||||
virtual void OnEngineClientDrop(int ClientID, const char *pReason) = 0;
|
||||
virtual void OnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags) = 0;
|
||||
virtual bool OnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags) = 0;
|
||||
virtual bool OnEngineServerMessage(int ClientID, const void *pData, int Size, int Flags) = 0;
|
||||
virtual bool OnEngineSimulateClientMessage(int *pClientID, void *pBuffer, int BufferSize, int *pOutSize, int *pFlags) = 0;
|
||||
|
||||
virtual ~IEngineAntibot(){};
|
||||
};
|
||||
|
|
|
@ -156,7 +156,7 @@ void CAntibot::OnEngineClientDrop(int ClientID, const char *pReason)
|
|||
Update();
|
||||
AntibotOnEngineClientDrop(ClientID, pReason);
|
||||
}
|
||||
void CAntibot::OnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags)
|
||||
bool CAntibot::OnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags)
|
||||
{
|
||||
Update();
|
||||
int AntibotFlags = 0;
|
||||
|
@ -164,7 +164,31 @@ void CAntibot::OnEngineClientMessage(int ClientID, const void *pData, int Size,
|
|||
{
|
||||
AntibotFlags |= ANTIBOT_MSGFLAG_NONVITAL;
|
||||
}
|
||||
AntibotOnEngineClientMessage(ClientID, pData, Size, Flags);
|
||||
return AntibotOnEngineClientMessage(ClientID, pData, Size, Flags);
|
||||
}
|
||||
bool CAntibot::OnEngineServerMessage(int ClientID, const void *pData, int Size, int Flags)
|
||||
{
|
||||
Update();
|
||||
int AntibotFlags = 0;
|
||||
if((Flags & MSGFLAG_VITAL) == 0)
|
||||
{
|
||||
AntibotFlags |= ANTIBOT_MSGFLAG_NONVITAL;
|
||||
}
|
||||
return AntibotOnEngineServerMessage(ClientID, pData, Size, Flags);
|
||||
}
|
||||
bool CAntibot::OnEngineSimulateClientMessage(int *pClientID, void *pBuffer, int BufferSize, int *pOutSize, int *pFlags)
|
||||
{
|
||||
int AntibotFlags = 0;
|
||||
bool Result = AntibotOnEngineSimulateClientMessage(pClientID, pBuffer, BufferSize, pOutSize, &AntibotFlags);
|
||||
if(Result)
|
||||
{
|
||||
*pFlags = 0;
|
||||
if((AntibotFlags & ANTIBOT_MSGFLAG_NONVITAL) == 0)
|
||||
{
|
||||
*pFlags |= MSGFLAG_VITAL;
|
||||
}
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
#else
|
||||
CAntibot::CAntibot() :
|
||||
|
@ -209,7 +233,9 @@ void CAntibot::OnHookAttach(int ClientID, bool Player) {}
|
|||
void CAntibot::OnEngineTick() {}
|
||||
void CAntibot::OnEngineClientJoin(int ClientID, bool Sixup) {}
|
||||
void CAntibot::OnEngineClientDrop(int ClientID, const char *pReason) {}
|
||||
void CAntibot::OnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags) {}
|
||||
bool CAntibot::OnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags) { return false; }
|
||||
bool CAntibot::OnEngineServerMessage(int ClientID, const void *pData, int Size, int Flags) { return false; }
|
||||
bool CAntibot::OnEngineSimulateClientMessage(int *pClientID, void *pBuffer, int BufferSize, int *pOutSize, int *pFlags) { return false; }
|
||||
#endif
|
||||
|
||||
IEngineAntibot *CreateEngineAntibot()
|
||||
|
|
|
@ -33,7 +33,9 @@ public:
|
|||
virtual void OnEngineTick();
|
||||
virtual void OnEngineClientJoin(int ClientID, bool Sixup);
|
||||
virtual void OnEngineClientDrop(int ClientID, const char *pReason);
|
||||
virtual void OnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags);
|
||||
virtual bool OnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags);
|
||||
virtual bool OnEngineServerMessage(int ClientID, const void *pData, int Size, int Flags);
|
||||
virtual bool OnEngineSimulateClientMessage(int *pClientID, void *pBuffer, int BufferSize, int *pOutSize, int *pFlags);
|
||||
|
||||
// Game
|
||||
virtual void RoundStart(class IGameServer *pGameServer);
|
||||
|
|
|
@ -778,6 +778,10 @@ int CServer::SendMsg(CMsgPacker *pMsg, int Flags, int ClientID)
|
|||
Packet.m_pData = pPack->Data();
|
||||
Packet.m_DataSize = pPack->Size();
|
||||
Packet.m_ClientID = i;
|
||||
if(Antibot()->OnEngineServerMessage(i, Packet.m_pData, Packet.m_DataSize, Flags))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
m_NetServer.Send(&Packet);
|
||||
}
|
||||
}
|
||||
|
@ -793,6 +797,11 @@ int CServer::SendMsg(CMsgPacker *pMsg, int Flags, int ClientID)
|
|||
Packet.m_pData = Pack.Data();
|
||||
Packet.m_DataSize = Pack.Size();
|
||||
|
||||
if(Antibot()->OnEngineServerMessage(ClientID, Packet.m_pData, Packet.m_DataSize, Flags))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!(Flags & MSGFLAG_NORECORD))
|
||||
{
|
||||
m_aDemoRecorder[ClientID].RecordMessage(Pack.Data(), Pack.Size());
|
||||
|
@ -1319,13 +1328,6 @@ 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;
|
||||
|
@ -2244,10 +2246,36 @@ void CServer::PumpNetwork(bool PacketWaiting)
|
|||
}
|
||||
else
|
||||
{
|
||||
int GameFlags = 0;
|
||||
if(Packet.m_Flags & NET_CHUNKFLAG_VITAL)
|
||||
{
|
||||
GameFlags |= MSGFLAG_VITAL;
|
||||
}
|
||||
if(Antibot()->OnEngineClientMessage(Packet.m_ClientID, Packet.m_pData, Packet.m_DataSize, GameFlags))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ProcessClientPacket(&Packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
unsigned char aBuffer[NET_MAX_PAYLOAD];
|
||||
int Flags;
|
||||
CNetChunk Packet;
|
||||
mem_zero(&Packet, sizeof(Packet));
|
||||
Packet.m_pData = aBuffer;
|
||||
while(Antibot()->OnEngineSimulateClientMessage(&Packet.m_ClientID, aBuffer, sizeof(aBuffer), &Packet.m_DataSize, &Flags))
|
||||
{
|
||||
Packet.m_Flags = 0;
|
||||
if(Flags & MSGFLAG_VITAL)
|
||||
{
|
||||
Packet.m_Flags |= NET_CHUNKFLAG_VITAL;
|
||||
}
|
||||
ProcessClientPacket(&Packet);
|
||||
}
|
||||
}
|
||||
|
||||
m_ServerBan.Update();
|
||||
m_Econ.Update();
|
||||
|
|
Loading…
Reference in a new issue