mirror of
https://github.com/Sanae6/SmoOnlineServer.git
synced 2024-11-21 18:55:17 +00:00
Add attributes to new packets
This commit is contained in:
parent
aa119c0b2f
commit
f8955b630d
9 changed files with 23 additions and 25 deletions
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -10,5 +10,6 @@ public enum PacketType {
|
|||
Disconnect,
|
||||
Costume,
|
||||
Shine,
|
||||
Capture,
|
||||
Command
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
namespace Shared.Packet.Packets;
|
||||
|
||||
[Flags]
|
||||
public enum MovementFlags : byte {
|
||||
IsFlat,
|
||||
IsCapThrown,
|
||||
IsSeeker
|
||||
}
|
|
@ -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);
|
||||
|
|
14
Shared/Packet/Packets/UnhandledPacket.cs
Normal file
14
Shared/Packet/Packets/UnhandledPacket.cs
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue