2022-02-04 09:45:38 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
2022-02-14 19:45:58 +00:00
|
|
|
|
using System.Text;
|
2022-02-04 09:45:38 +00:00
|
|
|
|
|
2022-02-10 01:44:50 +00:00
|
|
|
|
namespace Shared.Packet.Packets;
|
2022-02-04 09:45:38 +00:00
|
|
|
|
|
|
|
|
|
[Packet(PacketType.Connect)]
|
|
|
|
|
public struct ConnectPacket : IPacket {
|
2022-02-22 03:39:12 +00:00
|
|
|
|
public ConnectionTypes ConnectionType = ConnectionTypes.FirstConnection;
|
2022-02-14 22:09:55 +00:00
|
|
|
|
public string ClientName = "?????";
|
2022-02-10 01:44:50 +00:00
|
|
|
|
|
2022-02-22 03:39:12 +00:00
|
|
|
|
public ConnectPacket() { }
|
|
|
|
|
|
2022-03-11 05:59:02 +00:00
|
|
|
|
public short Size => 4 + Constants.CostumeNameSize;
|
|
|
|
|
|
2022-02-04 09:45:38 +00:00
|
|
|
|
public void Serialize(Span<byte> data) {
|
|
|
|
|
MemoryMarshal.Write(data, ref ConnectionType);
|
2022-02-14 19:45:58 +00:00
|
|
|
|
Encoding.UTF8.GetBytes(ClientName).CopyTo(data[4..(4 + Constants.CostumeNameSize)]);
|
2022-02-04 09:45:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Deserialize(Span<byte> data) {
|
|
|
|
|
ConnectionType = MemoryMarshal.Read<ConnectionTypes>(data);
|
2022-02-14 19:45:58 +00:00
|
|
|
|
ClientName = Encoding.UTF8.GetString(data[4..(4 + Constants.CostumeNameSize)]).TrimNullTerm();
|
2022-02-04 09:45:38 +00:00
|
|
|
|
}
|
2022-03-13 11:14:01 +00:00
|
|
|
|
|
|
|
|
|
public enum ConnectionTypes {
|
|
|
|
|
FirstConnection,
|
|
|
|
|
Reconnecting
|
|
|
|
|
}
|
2021-11-29 04:04:34 +00:00
|
|
|
|
}
|