-
Notifications
You must be signed in to change notification settings - Fork 0
/
GuaranteedPacket.cs
54 lines (44 loc) · 1.12 KB
/
GuaranteedPacket.cs
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
using System;
namespace Terralite
{
/// <summary>
/// Class to hold data about a guaranteed packet
/// </summary>
public class GuaranteedPacket
{
public byte PacketID { get; private set; }
public byte[] Header { get; private set; }
public byte[] ByteArray { get; private set; }
private byte[] data;
public GuaranteedPacket(byte packetID, byte[] packet)
{
PacketID = packetID;
data = packet;
Header = CreateHeader();
ByteArray = ToByteArray();
}
/// <summary>
/// Creates a byte array containing the header information.
/// </summary>
/// <returns>Byte array with type 2 + packet id</returns>
private byte[] CreateHeader()
{
byte[] header = new byte[2];
header[0] = Packet.RELIABLE;
header[1] = PacketID;
return header;
}
/// <summary>
/// Creates a byte array containing the MD5 and packet data.
/// </summary>
/// <returns>Byte array with MD5 + packet data</returns>
private byte[] ToByteArray()
{
byte[] packet = new byte[data.Length];
int index = 0;
Array.Copy(data, 0, packet, index, data.Length);
index += data.Length;
return packet;
}
}
}