mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge pull request #1404 from ddnet/decompress
Don't decompress packets from unknown IPs
This commit is contained in:
commit
ff36974bed
|
@ -175,7 +175,7 @@ void CNetBase::SendPacket(NETSOCKET Socket, NETADDR *pAddr, CNetPacketConstruct
|
|||
}
|
||||
|
||||
// TODO: rename this function
|
||||
int CNetBase::UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct *pPacket)
|
||||
int CNetBase::UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct *pPacket, bool Decompress)
|
||||
{
|
||||
// check the size
|
||||
if(Size < NET_PACKETHEADERSIZE || Size > NET_MAX_PACKETSIZE)
|
||||
|
@ -225,6 +225,10 @@ int CNetBase::UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct
|
|||
{
|
||||
if(pPacket->m_Flags&NET_PACKETFLAG_COMPRESSION)
|
||||
{
|
||||
if(!Decompress)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
// Don't allow compressed control packets.
|
||||
if(pPacket->m_Flags&NET_PACKETFLAG_CONTROL)
|
||||
{
|
||||
|
|
|
@ -469,7 +469,7 @@ public:
|
|||
static void SendPacketConnless(NETSOCKET Socket, NETADDR *pAddr, const void *pData, int DataSize, bool Extended, unsigned char aExtra[4]);
|
||||
static void SendPacket(NETSOCKET Socket, NETADDR *pAddr, CNetPacketConstruct *pPacket, SECURITY_TOKEN SecurityToken);
|
||||
|
||||
static int UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct *pPacket);
|
||||
static int UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct *pPacket, bool Decompress);
|
||||
|
||||
// The backroom is ack-NET_MAX_SEQUENCE/2. Used for knowing if we acked a packet or not
|
||||
static int IsSeqInBackroom(int Seq, int Ack);
|
||||
|
|
|
@ -70,7 +70,7 @@ int CNetClient::Recv(CNetChunk *pChunk)
|
|||
if(Bytes <= 0)
|
||||
break;
|
||||
|
||||
if(CNetBase::UnpackPacket(m_RecvUnpacker.m_aBuffer, Bytes, &m_RecvUnpacker.m_Data) == 0)
|
||||
if(CNetBase::UnpackPacket(m_RecvUnpacker.m_aBuffer, Bytes, &m_RecvUnpacker.m_Data, /* decompress = */ true) == 0)
|
||||
{
|
||||
if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONNLESS)
|
||||
{
|
||||
|
|
|
@ -615,9 +615,9 @@ int CNetServer::Recv(CNetChunk *pChunk)
|
|||
continue;
|
||||
}
|
||||
|
||||
if(CNetBase::UnpackPacket(m_RecvUnpacker.m_aBuffer, Bytes, &m_RecvUnpacker.m_Data) == 0)
|
||||
{
|
||||
if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONNLESS)
|
||||
{
|
||||
if(CNetBase::UnpackPacket(m_RecvUnpacker.m_aBuffer, Bytes, &m_RecvUnpacker.m_Data, /* decompress = */ false) == 0)
|
||||
{
|
||||
pChunk->m_Flags = NETSENDFLAG_CONNLESS;
|
||||
pChunk->m_ClientID = -1;
|
||||
|
@ -631,6 +631,7 @@ int CNetServer::Recv(CNetChunk *pChunk)
|
|||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// drop invalid ctrl packets
|
||||
|
@ -646,6 +647,8 @@ int CNetServer::Recv(CNetChunk *pChunk)
|
|||
// found
|
||||
|
||||
// control
|
||||
if(CNetBase::UnpackPacket(m_RecvUnpacker.m_aBuffer, Bytes, &m_RecvUnpacker.m_Data, /* decompress = */ true) == 0)
|
||||
{
|
||||
if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONTROL)
|
||||
OnConnCtrlMsg(Addr, Slot, m_RecvUnpacker.m_Data.m_aChunkData[0], m_RecvUnpacker.m_Data);
|
||||
|
||||
|
@ -655,10 +658,12 @@ int CNetServer::Recv(CNetChunk *pChunk)
|
|||
m_RecvUnpacker.Start(&Addr, &m_aSlots[Slot].m_Connection, Slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// not found, client that wants to connect
|
||||
|
||||
if(CNetBase::UnpackPacket(m_RecvUnpacker.m_aBuffer, Bytes, &m_RecvUnpacker.m_Data, /* decompress = */ false) == 0)
|
||||
{
|
||||
if(IsDDNetControlMsg(&m_RecvUnpacker.m_Data))
|
||||
// got ddnet control msg
|
||||
OnTokenCtrlMsg(Addr, m_RecvUnpacker.m_Data.m_aChunkData[0], m_RecvUnpacker.m_Data);
|
||||
|
|
Loading…
Reference in a new issue