mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge #5636
5636: Minor refactoring of `CNetBase` r=def- a=Robyt3 <!-- What is the motivation for the changes of this pull request --> ## Checklist - [X] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test (especially base/) or added coverage to integration test - [ ] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: Robert Müller <robytemueller@gmail.com>
This commit is contained in:
commit
989dda7e98
|
@ -130,8 +130,8 @@ void CNetBase::SendPacket(NETSOCKET Socket, NETADDR *pAddr, CNetPacketConstruct
|
|||
int HeaderSize = NET_PACKETHEADERSIZE;
|
||||
if(Sixup)
|
||||
{
|
||||
HeaderSize += 4;
|
||||
mem_copy(&aBuffer[3], &SecurityToken, 4);
|
||||
HeaderSize += sizeof(SecurityToken);
|
||||
mem_copy(&aBuffer[3], &SecurityToken, sizeof(SecurityToken));
|
||||
}
|
||||
else if(SecurityToken != NET_SECURITY_TOKEN_UNSUPPORTED)
|
||||
{
|
||||
|
@ -197,10 +197,7 @@ int CNetBase::UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct
|
|||
{
|
||||
// check the size
|
||||
if(Size < NET_PACKETHEADERSIZE || Size > NET_MAX_PACKETSIZE)
|
||||
{
|
||||
//dbg_msg("", "packet too small, %d", Size);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// log the data
|
||||
if(ms_DataLogRecv)
|
||||
|
@ -217,9 +214,6 @@ int CNetBase::UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct
|
|||
|
||||
if(pPacket->m_Flags & NET_PACKETFLAG_CONNLESS)
|
||||
{
|
||||
if(Size < 1)
|
||||
return -1;
|
||||
|
||||
Sixup = (pBuffer[0] & 0x3) == 1;
|
||||
int Offset = Sixup ? 9 : 6;
|
||||
if(Size < Offset)
|
||||
|
@ -227,8 +221,8 @@ int CNetBase::UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct
|
|||
|
||||
if(Sixup)
|
||||
{
|
||||
mem_copy(pSecurityToken, &pBuffer[1], 4);
|
||||
mem_copy(pResponseToken, &pBuffer[5], 4);
|
||||
mem_copy(pSecurityToken, &pBuffer[1], sizeof(*pSecurityToken));
|
||||
mem_copy(pResponseToken, &pBuffer[5], sizeof(*pResponseToken));
|
||||
}
|
||||
|
||||
pPacket->m_Flags = NET_PACKETFLAG_CONNLESS;
|
||||
|
@ -266,7 +260,7 @@ int CNetBase::UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct
|
|||
Flags |= NET_PACKETFLAG_COMPRESSION;
|
||||
pPacket->m_Flags = Flags;
|
||||
|
||||
mem_copy(pSecurityToken, &pBuffer[3], 4);
|
||||
mem_copy(pSecurityToken, &pBuffer[3], sizeof(*pSecurityToken));
|
||||
}
|
||||
|
||||
if(pPacket->m_Flags & NET_PACKETFLAG_COMPRESSION)
|
||||
|
@ -345,23 +339,23 @@ unsigned char *CNetChunkHeader::Unpack(unsigned char *pData, int Split)
|
|||
return pData + 2;
|
||||
}
|
||||
|
||||
int CNetBase::IsSeqInBackroom(int Seq, int Ack)
|
||||
bool CNetBase::IsSeqInBackroom(int Seq, int Ack)
|
||||
{
|
||||
int Bottom = (Ack - NET_MAX_SEQUENCE / 2);
|
||||
if(Bottom < 0)
|
||||
{
|
||||
if(Seq <= Ack)
|
||||
return 1;
|
||||
return true;
|
||||
if(Seq >= (Bottom + NET_MAX_SEQUENCE))
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Seq <= Ack && Seq >= Bottom)
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
IOHANDLE CNetBase::ms_DataLogSent = 0;
|
||||
|
|
|
@ -544,7 +544,7 @@ public:
|
|||
static int UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct *pPacket, bool &Sixup, SECURITY_TOKEN *pSecurityToken = nullptr, SECURITY_TOKEN *pResponseToken = nullptr);
|
||||
|
||||
// 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);
|
||||
static bool IsSeqInBackroom(int Seq, int Ack);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue