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-04-27 05:24:40 +00:00
|
|
|
|
public ushort MaxPlayers = 0;
|
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-04-27 05:24:40 +00:00
|
|
|
|
public short Size => 6 + Constants.CostumeNameSize;
|
2022-03-11 05:59:02 +00:00
|
|
|
|
|
2022-02-04 09:45:38 +00:00
|
|
|
|
public void Serialize(Span<byte> data) {
|
|
|
|
|
MemoryMarshal.Write(data, ref ConnectionType);
|
2022-04-27 05:24:40 +00:00
|
|
|
|
MemoryMarshal.Write(data[4..], ref MaxPlayers);
|
|
|
|
|
Encoding.UTF8.GetBytes(ClientName).CopyTo(data[6..(6 + Constants.CostumeNameSize)]);
|
2022-02-04 09:45:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 04:29:34 +00:00
|
|
|
|
public void Deserialize(ReadOnlySpan<byte> data) {
|
2022-02-04 09:45:38 +00:00
|
|
|
|
ConnectionType = MemoryMarshal.Read<ConnectionTypes>(data);
|
2022-04-27 05:24:40 +00:00
|
|
|
|
ConnectionType = MemoryMarshal.Read<ConnectionTypes>(data[4..]);
|
|
|
|
|
ClientName = Encoding.UTF8.GetString(data[6..(6 + 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
|
|
|
|
}
|