-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCharacterInfo.cs
More file actions
57 lines (50 loc) · 1.65 KB
/
Copy pathCharacterInfo.cs
File metadata and controls
57 lines (50 loc) · 1.65 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
using ScrapServer.Networking.Data;
using ScrapServer.Utility.Serialization;
using System.Text;
namespace ScrapServer.Networking;
/// <summary>
/// The packet sent by the client during the join sequence that contains
/// the player's name and their character customization options.
/// </summary>
/// <seealso href="https://docs.scrapmods.io/docs/networking/packets/character-info"/>
public struct CharacterInfo : IPacket
{
/// <inheritdoc/>
public static PacketId PacketId => PacketId.CharacterInfo;
/// <inheritdoc/>
public static bool IsCompressable => true;
/// <summary>
/// The players's name displayed in chat and above the character model.
/// </summary>
public string? Name;
/// <summary>
/// The players's character customization options.
/// </summary>
public CharacterCustomization Customization;
/// <inheritdoc/>
public readonly void Serialize(ref BitWriter writer)
{
if (Name != null)
{
var byteLen = Encoding.UTF8.GetByteCount(Name);
if (byteLen > UInt16.MaxValue)
{
throw new ArgumentException($"Character name too long: {byteLen} bytes (max is {UInt16.MaxValue}).");
}
writer.WriteUInt16((UInt16)byteLen);
writer.WriteString(Name);
}
else
{
writer.WriteUInt16(0);
}
writer.WriteObject(Customization);
}
/// <inheritdoc/>
public void Deserialize(ref BitReader reader)
{
var byteLen = reader.ReadUInt16();
Name = reader.ReadString(byteLen);
Customization = reader.ReadObject<CharacterCustomization>();
}
}