-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathPacketHeader.cs
More file actions
68 lines (54 loc) · 2.31 KB
/
Copy pathPacketHeader.cs
File metadata and controls
68 lines (54 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ReliableNetcode.Utils;
namespace ReliableNetcode
{
internal class SentPacketData
{
public double time;
public bool acked;
public uint packetBytes;
}
internal class ReceivedPacketData
{
public double time;
public uint packetBytes;
}
internal class FragmentReassemblyData
{
public ushort Sequence;
public ushort Ack;
public uint AckBits;
public int NumFragmentsReceived;
public int NumFragmentsTotal;
public ByteBuffer PacketDataBuffer = new ByteBuffer();
public int PacketBytes;
public int HeaderOffset;
public bool[] FragmentReceived = new bool[256];
public void StoreFragmentData(byte channelID, ushort sequence, ushort ack, uint ackBits, int fragmentID, int fragmentSize, byte[] fragmentData, int fragmentBytes)
{
int copyOffset = 0;
if (fragmentID == 0) {
byte[] packetHeader = BufferPool.GetBuffer(Defines.MAX_PACKET_HEADER_BYTES);
int headerBytes = PacketIO.WritePacketHeader(packetHeader, channelID, sequence, ack, ackBits);
this.HeaderOffset = Defines.MAX_PACKET_HEADER_BYTES - headerBytes;
if (this.PacketDataBuffer.Length < (Defines.MAX_PACKET_HEADER_BYTES + fragmentSize))
this.PacketDataBuffer.SetSize(Defines.MAX_PACKET_HEADER_BYTES + fragmentSize);
this.PacketDataBuffer.BufferCopy(packetHeader, 0, this.HeaderOffset, headerBytes);
copyOffset = headerBytes;
fragmentBytes -= headerBytes;
BufferPool.ReturnBuffer(packetHeader);
}
int writePos = Defines.MAX_PACKET_HEADER_BYTES + fragmentID * fragmentSize;
int end = writePos + fragmentBytes;
if (this.PacketDataBuffer.Length < end)
this.PacketDataBuffer.SetSize(end);
if (fragmentID == NumFragmentsTotal - 1) {
this.PacketBytes = (this.NumFragmentsTotal - 1) * fragmentSize + fragmentBytes;
}
this.PacketDataBuffer.BufferCopy(fragmentData, copyOffset, Defines.MAX_PACKET_HEADER_BYTES + fragmentID * fragmentSize, fragmentBytes);
}
}
}