0
0
Fork 0
mirror of https://github.com/Sanae6/SmoOnlineServer.git synced 2024-11-25 04:35:18 +00:00

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 MaxPacketSize = 256;
public const int MaxClients = 4; public const int MaxClients = 4;
public static int HeaderSize { get; } = Marshal.SizeOf<PacketHeader>(); public static int HeaderSize { get; } = Marshal.SizeOf<PacketHeader>();
public static int PacketDataSize { get; } = MaxPacketSize - HeaderSize;
public const int CostumeNameSize = 0x20; public const int CostumeNameSize = 0x20;
// dictionary of packet types to packet // dictionary of packet types to packet

View file

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

View file

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

View file

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

View file

@ -3,7 +3,8 @@ using System.Text;
namespace Shared.Packet.Packets; namespace Shared.Packet.Packets;
public class CapturePacket : IPacket { [Packet(PacketType.Capture)]
public struct CapturePacket : IPacket {
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = Constants.CostumeNameSize)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst = Constants.CostumeNameSize)]
public string ModelName; public string ModelName;
public bool IsCaptured; 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; namespace Shared.Packet.Packets;
public class TagPacket : IPacket { [Packet(PacketType.Tag)]
public struct TagPacket : IPacket {
public bool IsIt = false; public bool IsIt = false;
public void Serialize(Span<byte> data) { public void Serialize(Span<byte> data) {
MemoryMarshal.Write(data, ref IsIt); 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);
}
}