-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPacketData.cs
91 lines (81 loc) · 3.61 KB
/
PacketData.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using Hkmp.Networking.Packet;
namespace ExampleAddon {
/// <summary>
/// Example class implementing the IPacketData interface, which represents data that is sent to the client.
/// </summary>
public class ClientPacketData : IPacketData {
/// <summary>
/// Denote whether this packet data should be handled as reliable data. This means that it will try to
/// resend the data if the packet it was in is not acknowledged by the receiving end.
/// </summary>
public bool IsReliable => true;
/// <summary>
/// Denote whether this data can be disregarded if a newer version of the data is also included in the packet.
/// This is useful for cases where the data contains a state that completely overwrites earlier entries.
/// </summary>
public bool DropReliableDataIfNewerExists => true;
/// <summary>
/// This is the actual unsigned short we are transmitting.
/// </summary>
public ushort SomeUShort { get; set; }
/// <summary>
/// The method that handles writing the data from this class into the given packet.
/// </summary>
/// <param name="packet">The packet interface for writing data.</param>
public void WriteData(IPacket packet) {
packet.Write(SomeUShort);
}
/// <summary>
/// The method that handles reading the data from the given packet into this class.
/// </summary>
/// <param name="packet">The packet interface for reading data.</param>
public void ReadData(IPacket packet) {
SomeUShort = packet.ReadUShort();
}
}
/// <summary>
/// Example class implementing the IPacketData interface, which represents data that is sent to the server.
/// </summary>
public class ServerPacketData : IPacketData {
/// <summary>
/// Denote whether this packet data should be handled as reliable data. This means that it will try to
/// resend the data if the packet it was in is not acknowledged by the receiving end.
/// </summary>
public bool IsReliable => true;
/// <summary>
/// Denote whether this data can be disregarded if a newer version of the data is also included in the packet.
/// This is useful for cases where the data contains a state that completely overwrites earlier entries.
/// </summary>
public bool DropReliableDataIfNewerExists => true;
/// <summary>
/// This is the actual float we are transmitting.
/// </summary>
public float SomeFloat { get; set; }
/// <summary>
/// The method that handles writing the data from this class into the given packet.
/// </summary>
/// <param name="packet">The packet interface for writing data.</param>
public void WriteData(IPacket packet) {
packet.Write(SomeFloat);
}
/// <summary>
/// The method that handles reading the data from the given packet into this class.
/// </summary>
/// <param name="packet">The packet interface for reading data.</param>
public void ReadData(IPacket packet) {
SomeFloat = packet.ReadFloat();
}
}
/// <summary>
/// The enum class representing packet IDs for server to client communication.
/// </summary>
public enum ClientPacketId {
PacketId1
}
/// <summary>
/// The enum class representing packet IDs for client to server communication.
/// </summary>
public enum ServerPacketId {
PacketId1
}
}