Add attributes to new packets

This commit is contained in:
Sanae 2022-02-08 10:22:09 -06:00
parent aa119c0b2f
commit f8955b630d
9 changed files with 23 additions and 25 deletions

View File

@ -9,6 +9,7 @@ public static class Constants {
public const int MaxPacketSize = 256;
public const int MaxClients = 4;
public static int HeaderSize { get; } = Marshal.SizeOf<PacketHeader>();
public static int PacketDataSize { get; } = MaxPacketSize - HeaderSize;
public const int CostumeNameSize = 0x20;
// dictionary of packet types to packet

View File

@ -1,6 +1,6 @@
namespace Shared.Packet;
[AttributeUsage(AttributeTargets.Struct)]
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = true)]
public class PacketAttribute : Attribute {
public PacketType Type { get; }
public PacketAttribute(PacketType type) {

View File

@ -10,5 +10,6 @@ public enum PacketType {
Disconnect,
Costume,
Shine,
Capture,
Command
}

View File

@ -4,7 +4,8 @@ using System.Text;
namespace Shared.Packet.Packets;
public class CapPacket : IPacket {
[Packet(PacketType.Cap)]
public struct CapPacket : IPacket {
public const int NameSize = 0x30;
public Vector3 Position;
public Quaternion Rotation;

View File

@ -3,7 +3,8 @@ using System.Text;
namespace Shared.Packet.Packets;
public class CapturePacket : IPacket {
[Packet(PacketType.Capture)]
public struct CapturePacket : IPacket {
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = Constants.CostumeNameSize)]
public string ModelName;
public bool IsCaptured;

View File

@ -1,13 +0,0 @@
namespace Shared.Packet.Packets;
[Packet(PacketType.Command)]
public struct CommandPacket : IPacket {
//todo: implement something for this
public void Serialize(Span<byte> data) {
}
public void Deserialize(Span<byte> data) {
}
}

View File

@ -1,8 +0,0 @@
namespace Shared.Packet.Packets;
[Flags]
public enum MovementFlags : byte {
IsFlat,
IsCapThrown,
IsSeeker
}

View File

@ -2,7 +2,8 @@
namespace Shared.Packet.Packets;
public class TagPacket : IPacket {
[Packet(PacketType.Tag)]
public struct TagPacket : IPacket {
public bool IsIt = false;
public void Serialize(Span<byte> data) {
MemoryMarshal.Write(data, ref IsIt);

View File

@ -0,0 +1,14 @@
namespace Shared.Packet.Packets;
[Packet(PacketType.Unknown)] // empty like boss
[Packet(PacketType.Command)]
public struct UnhandledPacket : IPacket {
public byte[] Data = new byte[Constants.PacketDataSize];
public void Serialize(Span<byte> data) {
Data.CopyTo(data);
}
public void Deserialize(Span<byte> data) {
data.CopyTo(Data);
}
}