MCPcopy Create free account
hub / github.com/ddnet/ddnet / UnpackNextChunk

Method UnpackNextChunk

src/engine/shared/network.cpp:39–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37}
38
39bool CPacketChunkUnpacker::UnpackNextChunk(CNetChunk *pChunk)
40{
41 if(!m_Valid)
42 {
43 return false;
44 }
45
46 const unsigned char *const pEnd = m_Data.m_aChunkData + m_Data.m_DataSize;
47
48 while(true)
49 {
50 if(m_CurrentChunk >= m_Data.m_NumChunks)
51 {
52 m_Valid = false;
53 return false;
54 }
55
56 unsigned char *pData = m_Data.m_aChunkData;
57
58 // TODO: add checking here so we don't read too far
59 const int HeaderSplit = m_pConnection->m_Sixup ? 6 : 4;
60 for(int i = 0; i < m_CurrentChunk; i++)
61 {
62 CNetChunkHeader SkippedHeader;
63 pData = SkippedHeader.Unpack(pData, HeaderSplit);
64 pData += SkippedHeader.m_Size;
65 }
66
67 // unpack the header
68 CNetChunkHeader Header;
69 pData = Header.Unpack(pData, HeaderSplit);
70 m_CurrentChunk++;
71
72 if(pData + Header.m_Size > pEnd)
73 {
74 m_Valid = false;
75 return false;
76 }
77
78 // handle sequence stuff
79 if((Header.m_Flags & NET_CHUNKFLAG_VITAL) != 0)
80 {
81 // anti spoof: ignore unknown sequence
82 if(Header.m_Sequence == (m_pConnection->m_Ack + 1) % NET_MAX_SEQUENCE || m_pConnection->m_UnknownSeq)
83 {
84 m_pConnection->m_UnknownSeq = false;
85
86 // in sequence
87 m_pConnection->m_Ack = Header.m_Sequence;
88 }
89 else
90 {
91 // old packet that we already got
92 if(CNetBase::IsSeqInBackroom(Header.m_Sequence, m_pConnection->m_Ack))
93 continue;
94
95 // out of sequence, request resend
96 if(g_Config.m_Debug)

Callers 2

RecvMethod · 0.80
RecvMethod · 0.80

Calls 3

dbg_msgFunction · 0.85
SignalResendMethod · 0.80
UnpackMethod · 0.45

Tested by

no test coverage detected