-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleJSONMessage.cs
59 lines (51 loc) · 1.8 KB
/
SimpleJSONMessage.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
using System.Threading;
using Newtonsoft.Json;
namespace ConnectorLib.JSON;
public abstract class SimpleJSONMessage
{
/// <summary>
/// The JSON serializer settings required by the Crowd Control SimpleJSON protocol.
/// </summary>
public static readonly JsonSerializerSettings JSON_SERIALIZER_SETTINGS = new()
{
NullValueHandling = NullValueHandling.Ignore,
MissingMemberHandling = MissingMemberHandling.Ignore,
Formatting = Formatting.None
};
/// <summary>
/// The JSON serializer settings required by the Crowd Control SimpleJSON protocol.
/// </summary>
public static readonly JsonSerializer JSON_SERIALIZER = new()
{
NullValueHandling = JSON_SERIALIZER_SETTINGS.NullValueHandling,
MissingMemberHandling = JSON_SERIALIZER_SETTINGS.MissingMemberHandling,
Formatting = JSON_SERIALIZER_SETTINGS.Formatting
};
private static int _next_id = 0;
/// <summary>
/// Gets the next block ID.
/// </summary>
/// <remarks>
/// This field is intended for use by the Crowd Control client.
/// It is not intended for use by game plugin developers.
/// </remarks>
public static uint NextID
{
get
{
uint id;
// ReSharper disable once EmptyEmbeddedStatement
while ((id = unchecked((uint)Interlocked.Increment(ref _next_id))) == 0) ;
return id;
}
}
/// <summary>
/// The message ID of the message to which this is a response.
/// </summary>
public abstract uint ID { get; }
/// <summary>
/// True if this message is a keepalive/heartbeat, otherwise false.
/// </summary>
public abstract bool IsKeepAlive { get; }
public string Serialize() => JsonConvert.SerializeObject(this, JSON_SERIALIZER_SETTINGS);
}