Compare commits
1 Commits
1fa8516ebe
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d3f9f8afb |
@@ -31,7 +31,7 @@ namespace BoneSync
|
|||||||
|
|
||||||
|
|
||||||
public static LobbyManager lobby;
|
public static LobbyManager lobby;
|
||||||
public static TransportBase transport;
|
public static ITransportBase transport;
|
||||||
public override void OnApplicationStart()
|
public override void OnApplicationStart()
|
||||||
{
|
{
|
||||||
SteamClient.Init(823500, true);
|
SteamClient.Init(823500, true);
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
using BoneSync.Data;
|
using System;
|
||||||
using BoneSync.Networking.Transport;
|
|
||||||
using BoneSync.Sync;
|
|
||||||
using MelonLoader;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using BoneSync.Data;
|
||||||
|
using BoneSync.Networking.Transport;
|
||||||
|
using BoneSync.Sync;
|
||||||
|
using MelonLoader;
|
||||||
|
using Oculus.Platform;
|
||||||
#if TEST
|
#if TEST
|
||||||
using Xunit;
|
using Xunit;
|
||||||
#endif
|
#endif
|
||||||
@@ -137,11 +138,14 @@ namespace BoneSync.Networking
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static NetworkMessage ParsePacket(Packet packet)
|
|
||||||
|
private static readonly Dictionary<PacketType, ConstructorInfo> ConstructorCache = new Dictionary<PacketType, ConstructorInfo>();
|
||||||
|
public static ConstructorInfo GetConstructor(Packet packet)
|
||||||
{
|
{
|
||||||
//SyncLogger.Msg("Received packet of type " + packet.Info.packetType + " from " + packet.Info.senderId + " Length: " + packet.Data.Length);
|
if (ConstructorCache.ContainsKey(packet.Info.packetType))
|
||||||
// find a class that can parse this packet using Reflection
|
{
|
||||||
// and return it
|
return ConstructorCache[packet.Info.packetType];
|
||||||
|
}
|
||||||
if (!PacketTypeMap.ContainsKey(packet.Info.packetType))
|
if (!PacketTypeMap.ContainsKey(packet.Info.packetType))
|
||||||
{
|
{
|
||||||
throw new Exception("No class found for packet type '" + packet.Info.packetType + "'");
|
throw new Exception("No class found for packet type '" + packet.Info.packetType + "'");
|
||||||
@@ -150,6 +154,18 @@ namespace BoneSync.Networking
|
|||||||
Type type = PacketTypeMap[packet.Info.packetType];
|
Type type = PacketTypeMap[packet.Info.packetType];
|
||||||
// get the constructor that takes a Packet
|
// get the constructor that takes a Packet
|
||||||
ConstructorInfo constructor = type.GetConstructor(new Type[] { typeof(Packet) }) ?? throw new Exception("No constructor found for type " + type.Name);
|
ConstructorInfo constructor = type.GetConstructor(new Type[] { typeof(Packet) }) ?? throw new Exception("No constructor found for type " + type.Name);
|
||||||
|
ConstructorCache[packet.Info.packetType] = constructor;
|
||||||
|
return constructor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static NetworkMessage ParsePacket(Packet packet)
|
||||||
|
{
|
||||||
|
//SyncLogger.Msg("Received packet of type " + packet.Info.packetType + " from " + packet.Info.senderId + " Length: " + packet.Data.Length);
|
||||||
|
// find a class that can parse this packet using Reflection
|
||||||
|
// and return it
|
||||||
|
|
||||||
|
ConstructorInfo constructor = GetConstructor(packet);
|
||||||
NetworkMessage networkMessage = (NetworkMessage)constructor.Invoke(new object[] { packet });
|
NetworkMessage networkMessage = (NetworkMessage)constructor.Invoke(new object[] { packet });
|
||||||
networkMessage.senderId = packet.Info.senderId;
|
networkMessage.senderId = packet.Info.senderId;
|
||||||
return networkMessage;
|
return networkMessage;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ using Oculus.Platform;
|
|||||||
|
|
||||||
namespace BoneSync.Networking.Transport
|
namespace BoneSync.Networking.Transport
|
||||||
{
|
{
|
||||||
internal class SteamTransport : TransportBase
|
internal class SteamTransport : ITransportBase
|
||||||
{
|
{
|
||||||
|
|
||||||
public SteamTransport()
|
public SteamTransport()
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace BoneSync.Networking.Transport
|
namespace BoneSync.Networking.Transport
|
||||||
{
|
{
|
||||||
public interface TransportBase
|
public interface ITransportBase
|
||||||
{
|
{
|
||||||
ulong BROADCAST_ID { get; }
|
ulong BROADCAST_ID { get; }
|
||||||
void Send(Packet packet);
|
void Send(Packet packet);
|
||||||
|
|||||||
Reference in New Issue
Block a user