facebookarchive / RakNet

RakNet is a cross platform, open source, C++ networking engine for game programmers.
Other
3.32k stars 1.03k forks source link

重建分包的时候,没有考虑来包顺序混乱的问题导致 包的数据会出错。 #122

Open qtx0213 opened 7 years ago

qtx0213 commented 7 years ago

把 ReliabilityLayer 的 BuildPacketFromSplitPacketList 改成下面这样就可以了。` InternalPacket ReliabilityLayer::BuildPacketFromSplitPacketList( SplitPacketChannel splitPacketChannel, CCTimeType time ) {

if PREALLOCATE_LARGE_MESSAGES==1

InternalPacket *returnedPacket=splitPacketChannel->returnedPacket;
RakNet::OP_DELETE(splitPacketChannel, __FILE__, __LINE__);
(void) time;
return returnedPacket;

else

unsigned int j;
InternalPacket * internalPacket, *splitPacket;
// int splitPacketPartLength;

// Reconstruct
internalPacket = CreateInternalPacketCopy( splitPacketChannel->splitPacketList[0], 0, 0, time );
internalPacket->dataBitLength=0;
for (j=0; j < splitPacketChannel->splitPacketList.Size(); j++)
    internalPacket->dataBitLength+=splitPacketChannel->splitPacketList[j]->dataBitLength;
// splitPacketPartLength=BITS_TO_BYTES(splitPacketChannel->firstPacket->dataBitLength);

internalPacket->data = (unsigned char*) rakMalloc_Ex( (size_t) BITS_TO_BYTES( internalPacket->dataBitLength ), _FILE_AND_LINE_ );
internalPacket->allocationScheme=InternalPacket::NORMAL;

BitSize_t offset = 0; 

int itt = 0;
while (itt < splitPacketChannel->splitPacketList.Size())
{
    for (j = 0; j < splitPacketChannel->splitPacketList.Size(); j++)
    {
        splitPacket = splitPacketChannel->splitPacketList[j];
        if (itt == splitPacket->splitPacketIndex)
        {
            memcpy(internalPacket->data + BITS_TO_BYTES(offset), splitPacket->data, (size_t)BITS_TO_BYTES(splitPacketChannel->splitPacketList[j]->dataBitLength));
            offset += splitPacketChannel->splitPacketList[j]->dataBitLength;
            break;
        }
    }

    itt++;
}

for (j=0; j < splitPacketChannel->splitPacketList.Size(); j++)
{
    FreeInternalPacketData(splitPacketChannel->splitPacketList[j], _FILE_AND_LINE_ );
    ReleaseToInternalPacketPool(splitPacketChannel->splitPacketList[j]);
}
RakNet::OP_DELETE(splitPacketChannel, __FILE__, __LINE__);

return internalPacket;

endif

}``

wwqly12 commented 6 years ago

you are right

cgoxopx commented 5 years ago

发pr吧