Enhance school creation and map management features by updating the API to support mod packs and map layouts. Introduce a new map snapshot protocol for efficient data handling during school sessions. Revise documentation to reflect these changes, including updates to the protocol and architecture documents. Improve UI components for mod selection and map editing, ensuring a better user experience. Update tests to validate new functionalities and ensure robustness.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Buffers.Binary;
|
||||
using System.Text;
|
||||
|
||||
namespace HSchool.Protocol;
|
||||
|
||||
@@ -22,6 +23,13 @@ public ref struct PacketWriter(Span<byte> buffer)
|
||||
|
||||
public void WriteMessageType(MessageType value) => WriteByte((byte)value);
|
||||
|
||||
public void WriteUInt16(ushort value)
|
||||
{
|
||||
EnsureRoom(sizeof(ushort));
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(_buffer[_position..], value);
|
||||
_position += sizeof(ushort);
|
||||
}
|
||||
|
||||
public void WriteUInt32(uint value)
|
||||
{
|
||||
EnsureRoom(sizeof(uint));
|
||||
@@ -29,6 +37,21 @@ public ref struct PacketWriter(Span<byte> buffer)
|
||||
_position += sizeof(uint);
|
||||
}
|
||||
|
||||
/// <summary><c>u16</c> byte length, then UTF-8. Empty string is a zero length.</summary>
|
||||
public void WriteString(string value)
|
||||
{
|
||||
var byteCount = Encoding.UTF8.GetByteCount(value);
|
||||
if (byteCount > ushort.MaxValue)
|
||||
{
|
||||
throw new ProtocolException($"String is {byteCount} bytes; u16 length cannot hold it.");
|
||||
}
|
||||
|
||||
WriteUInt16((ushort)byteCount);
|
||||
EnsureRoom(byteCount);
|
||||
Encoding.UTF8.GetBytes(value, _buffer[_position..]);
|
||||
_position += byteCount;
|
||||
}
|
||||
|
||||
public void WriteInt32(int value)
|
||||
{
|
||||
EnsureRoom(sizeof(int));
|
||||
|
||||
Reference in New Issue
Block a user