0
0
Fork 0
mirror of https://github.com/Sanae6/SmoOnlineServer.git synced 2024-11-16 00:25:07 +00:00
SmoOnlineServer/Shared/Packet/Packets/ConnectPacket.cs

29 lines
911 B
C#
Raw Normal View History

2022-02-04 09:45:38 +00:00
using System.Runtime.InteropServices;
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 {
public ConnectionTypes ConnectionType = ConnectionTypes.FirstConnection;
2022-02-14 22:09:55 +00:00
public string ClientName = "?????";
2022-02-10 01:44:50 +00:00
public ConnectPacket() { }
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);
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);
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
}