initial commit
This commit is contained in:
21
Assets/Network/Packets/ConnectionPackets.cs
Normal file
21
Assets/Network/Packets/ConnectionPackets.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
using UnityEngine;
|
||||
|
||||
namespace FastArena
|
||||
{
|
||||
internal struct Hash256
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal readonly struct ConnectionRequestTCP
|
||||
{
|
||||
internal readonly PacketHeader header;
|
||||
private SHA256 _sha256;
|
||||
|
||||
public ConnectionRequestTCP()
|
||||
{
|
||||
header = new PacketHeader(PacketType.ConnectionRequestTCP);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Network/Packets/ConnectionPackets.cs.meta
Normal file
3
Assets/Network/Packets/ConnectionPackets.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 973e6f96c4a74c8299406cfe25e29414
|
||||
timeCreated: 1752080764
|
||||
18
Assets/Network/Packets/CreateObjectPacket.cs
Normal file
18
Assets/Network/Packets/CreateObjectPacket.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace FastArena;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal readonly struct CreateObjectPacket
|
||||
{
|
||||
internal readonly PacketHeader header;
|
||||
internal readonly int gameObjectId;
|
||||
internal readonly string prefabPath;
|
||||
|
||||
internal CreateObjectPacket(int _gameObjectId, string _prefabPath)
|
||||
{
|
||||
header = new PacketHeader(PacketType.CreateObject);
|
||||
gameObjectId = _gameObjectId;
|
||||
prefabPath = _prefabPath;
|
||||
}
|
||||
}
|
||||
3
Assets/Network/Packets/CreateObjectPacket.cs.meta
Normal file
3
Assets/Network/Packets/CreateObjectPacket.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0bc94f4527d493d88a018b32d36ae4f
|
||||
timeCreated: 1752080638
|
||||
32
Assets/Network/Packets/PacketHeader.cs
Normal file
32
Assets/Network/Packets/PacketHeader.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace FastArena
|
||||
{
|
||||
internal enum PacketType : ushort
|
||||
{
|
||||
Invalid = 0, // not packet
|
||||
|
||||
ConnectionRequestTCP,
|
||||
ConnectionRequestUDP,
|
||||
ConnectionResponseTCP,
|
||||
ConnectionResponseUDP,
|
||||
|
||||
TransformUpdate,
|
||||
CreateObject
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 4)]
|
||||
internal readonly struct PacketHeader
|
||||
{
|
||||
internal const ushort MAGIC_CONST = 0x6313;
|
||||
|
||||
internal readonly ushort magic;
|
||||
internal readonly PacketType type;
|
||||
|
||||
internal PacketHeader(PacketType t)
|
||||
{
|
||||
magic = MAGIC_CONST;
|
||||
type = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Network/Packets/PacketHeader.cs.meta
Normal file
3
Assets/Network/Packets/PacketHeader.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c5d47bd361a840ab95f8411ad0d2458a
|
||||
timeCreated: 1719857658
|
||||
15
Assets/Network/Packets/PacketParser.cs
Normal file
15
Assets/Network/Packets/PacketParser.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace FastArena;
|
||||
|
||||
internal static class PacketParser
|
||||
{
|
||||
internal static PacketType ReadHeader(byte[] data)
|
||||
{
|
||||
var h = StructBinaryConverter.ReadStruct<PacketHeader>(data);
|
||||
return h.magic == PacketHeader.MAGIC_CONST ? h.type : PacketType.Invalid;
|
||||
}
|
||||
|
||||
internal static T ReadPacket<T>(byte[] data) where T : unmanaged
|
||||
{
|
||||
return StructBinaryConverter.ReadStruct<T>(data);
|
||||
}
|
||||
}
|
||||
3
Assets/Network/Packets/PacketParser.cs.meta
Normal file
3
Assets/Network/Packets/PacketParser.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f0a0f3489a547308cf0e57b45bed6c6
|
||||
timeCreated: 1752080621
|
||||
21
Assets/Network/Packets/TransformUpdatePacket.cs
Normal file
21
Assets/Network/Packets/TransformUpdatePacket.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace FastArena;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal readonly struct TransformUpdatePacket
|
||||
{
|
||||
internal readonly PacketHeader header;
|
||||
internal readonly int gameObjectId;
|
||||
internal readonly Vector3 position;
|
||||
internal readonly Quaternion rotation;
|
||||
|
||||
internal TransformUpdatePacket(int _gameObjectId, Transform transform)
|
||||
{
|
||||
header = new PacketHeader(PacketType.TransformUpdate);
|
||||
gameObjectId = _gameObjectId;
|
||||
position = transform.position;
|
||||
rotation = transform.rotation;
|
||||
}
|
||||
}
|
||||
3
Assets/Network/Packets/TransformUpdatePacket.cs.meta
Normal file
3
Assets/Network/Packets/TransformUpdatePacket.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b57b439f5bd74ca1a4fdbe3621fae51d
|
||||
timeCreated: 1752080633
|
||||
Reference in New Issue
Block a user