mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-26 18:35:34 +00:00
commit
68249823c8
Binary file not shown.
@ -1,12 +1,12 @@
|
||||
ManifestFileVersion: 0
|
||||
CRC: 551896829
|
||||
CRC: 2906651145
|
||||
Hashes:
|
||||
AssetFileHash:
|
||||
serializedVersion: 2
|
||||
Hash: 0fa5758f55c8803c7ba77a52ab2c9488
|
||||
TypeTreeHash:
|
||||
serializedVersion: 2
|
||||
Hash: 927887737c4cf3ead147733f47326ca9
|
||||
Hash: 87b5c87f221cc0cbe8c4eefab7d02419
|
||||
HashAppended: 0
|
||||
ClassTypes:
|
||||
- Class: 1
|
||||
|
@ -63,10 +63,6 @@ copy /y "$(OwmlDir)\OWML.Abstractions.dll" "$(UnityAssetsDir)"
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="UnityEngine.Networking, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\QSB\lib\UnityEngine.Networking.dll</HintPath>
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
</Reference>
|
||||
<PackageReference Include="OuterWildsGameLibs" Version="*" IncludeAssets="compile" />
|
||||
<ProjectReference Include="..\QuantumUNET\QuantumUNET.csproj" />
|
||||
<PackageReference Include="HarmonyX" Version="2.*" IncludeAssets="compile" />
|
||||
|
@ -73,7 +73,7 @@ namespace QSB.Syncs
|
||||
public PlayerInfo Player => QSBPlayerManager.GetPlayer(PlayerId);
|
||||
private bool _baseIsReady => QSBPlayerManager.PlayerExists(PlayerId)
|
||||
&& Player != null
|
||||
&& Player.IsReady
|
||||
// && Player.IsReady
|
||||
&& NetId.Value != uint.MaxValue
|
||||
&& NetId.Value != 0U
|
||||
&& WorldObjectManager.AllAdded;
|
||||
|
@ -3,7 +3,6 @@ using QuantumUNET.Messages;
|
||||
using QuantumUNET.Transport;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.Utility.VariableSync
|
||||
{
|
||||
@ -89,7 +88,6 @@ namespace QSB.Utility.VariableSync
|
||||
}
|
||||
}
|
||||
|
||||
[Client]
|
||||
private void SendVariable()
|
||||
{
|
||||
// TODO - this sends a message, even when the value hasnt changed! this is really bad!
|
||||
|
Binary file not shown.
@ -5,7 +5,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Components
|
||||
{
|
||||
@ -14,8 +13,8 @@ namespace QuantumUNET.Components
|
||||
public bool IsClient { get; private set; }
|
||||
public bool IsServer => m_IsServer && QNetworkServer.active && m_IsServer;
|
||||
public bool HasAuthority { get; private set; }
|
||||
public NetworkInstanceId NetId { get; private set; }
|
||||
public NetworkSceneId SceneId => m_SceneId;
|
||||
public QNetworkInstanceId NetId { get; private set; }
|
||||
public QNetworkSceneId SceneId => m_SceneId;
|
||||
public QNetworkConnection ClientAuthorityOwner { get; private set; }
|
||||
public int AssetId => m_AssetId;
|
||||
public bool IsLocalPlayer { get; private set; }
|
||||
@ -101,11 +100,11 @@ namespace QuantumUNET.Components
|
||||
public ReadOnlyCollection<QNetworkConnection> Observers
|
||||
=> m_Observers == null ? null : new ReadOnlyCollection<QNetworkConnection>(m_Observers);
|
||||
|
||||
internal static NetworkInstanceId GetNextNetworkId()
|
||||
internal static QNetworkInstanceId GetNextNetworkId()
|
||||
{
|
||||
var value = s_NextNetworkId;
|
||||
s_NextNetworkId += 1U;
|
||||
return new NetworkInstanceId(value);
|
||||
return new QNetworkInstanceId(value);
|
||||
}
|
||||
|
||||
private void CacheBehaviours()
|
||||
@ -124,7 +123,7 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
internal void SetNetworkInstanceId(NetworkInstanceId newNetId)
|
||||
internal void SetNetworkInstanceId(QNetworkInstanceId newNetId)
|
||||
{
|
||||
NetId = newNetId;
|
||||
if (newNetId.Value == 0U)
|
||||
@ -133,7 +132,7 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
public void ForceSceneId(int newSceneId) => m_SceneId = new NetworkSceneId((uint)newSceneId);
|
||||
public void ForceSceneId(int newSceneId) => m_SceneId = new QNetworkSceneId((uint)newSceneId);
|
||||
|
||||
internal void UpdateClientServer(bool isClientFlag, bool isServerFlag)
|
||||
{
|
||||
@ -778,7 +777,7 @@ namespace QuantumUNET.Components
|
||||
m_IsServer = false;
|
||||
IsClient = false;
|
||||
HasAuthority = false;
|
||||
NetId = (NetworkInstanceId)typeof(NetworkInstanceId).GetField("Zero", System.Reflection.BindingFlags.Static).GetValue(null);
|
||||
NetId = (QNetworkInstanceId)typeof(QNetworkInstanceId).GetField("Zero", System.Reflection.BindingFlags.Static).GetValue(null);
|
||||
IsLocalPlayer = false;
|
||||
ConnectionToServer = null;
|
||||
ConnectionToClient = null;
|
||||
@ -796,7 +795,7 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private NetworkSceneId m_SceneId;
|
||||
private QNetworkSceneId m_SceneId;
|
||||
|
||||
[SerializeField]
|
||||
private int m_AssetId;
|
||||
@ -825,4 +824,4 @@ namespace QuantumUNET.Components
|
||||
|
||||
public delegate void ClientAuthorityCallback(QNetworkConnection conn, QNetworkIdentity uv, bool authorityState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using QuantumUNET.Logging;
|
||||
using QuantumUNET.Messages;
|
||||
using QuantumUNET.Transport;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@ -386,7 +387,7 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
for (var i = 0; i < QNetworkServer.numChannels; i++)
|
||||
{
|
||||
netMsg.Connection.SetChannelOption(i, ChannelOption.MaxPendingBuffers, m_MaxBufferedPackets);
|
||||
netMsg.Connection.SetChannelOption(i, QChannelOption.MaxPendingBuffers, m_MaxBufferedPackets);
|
||||
}
|
||||
}
|
||||
|
||||
@ -394,7 +395,7 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
for (var j = 0; j < QNetworkServer.numChannels; j++)
|
||||
{
|
||||
netMsg.Connection.SetChannelOption(j, ChannelOption.AllowFragmentation, 0);
|
||||
netMsg.Connection.SetChannelOption(j, QChannelOption.AllowFragmentation, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -419,7 +420,7 @@ namespace QuantumUNET.Components
|
||||
netMsg.ReadMessage(s_AddPlayerMessage);
|
||||
if (s_AddPlayerMessage.msgSize != 0)
|
||||
{
|
||||
var extraMessageReader = new NetworkReader(s_AddPlayerMessage.msgData);
|
||||
var extraMessageReader = new QNetworkReader(s_AddPlayerMessage.msgData);
|
||||
OnServerAddPlayer(netMsg.Connection, s_AddPlayerMessage.playerControllerId, extraMessageReader);
|
||||
}
|
||||
else
|
||||
@ -496,7 +497,7 @@ namespace QuantumUNET.Components
|
||||
QNetworkServer.SetClientReady(conn);
|
||||
}
|
||||
|
||||
public virtual void OnServerAddPlayer(QNetworkConnection conn, short playerControllerId, NetworkReader extraMessageReader) => OnServerAddPlayerInternal(conn, playerControllerId);
|
||||
public virtual void OnServerAddPlayer(QNetworkConnection conn, short playerControllerId, QNetworkReader extraMessageReader) => OnServerAddPlayerInternal(conn, playerControllerId);
|
||||
|
||||
public virtual void OnServerAddPlayer(QNetworkConnection conn, short playerControllerId) => OnServerAddPlayerInternal(conn, playerControllerId);
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
using QuantumUNET.Messages;
|
||||
using QuantumUNET.Transport;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Components
|
||||
{
|
||||
@ -128,7 +127,6 @@ namespace QuantumUNET.Components
|
||||
|| Quaternion.Angle(transform.rotation, _prevRotation) > 1E-05f;
|
||||
}
|
||||
|
||||
[Client]
|
||||
private void SendTransform()
|
||||
{
|
||||
if (HasMoved() && QClientScene.readyConnection != null)
|
||||
|
@ -2,7 +2,6 @@
|
||||
using QuantumUNET.Transport;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Components
|
||||
{
|
||||
@ -234,7 +233,6 @@ namespace QuantumUNET.Components
|
||||
return result;
|
||||
}
|
||||
|
||||
[Client]
|
||||
private void SendTransform()
|
||||
{
|
||||
if (HasMoved() && QClientScene.readyConnection != null)
|
||||
|
@ -1,11 +1,10 @@
|
||||
using QuantumUNET.Transport;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QAnimationMessage : QMessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public QNetworkInstanceId netId;
|
||||
public int stateHash;
|
||||
public float normalizedTime;
|
||||
public byte[] parameters;
|
||||
|
@ -1,11 +1,10 @@
|
||||
using QuantumUNET.Transport;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QAnimationParametersMessage : QMessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public QNetworkInstanceId netId;
|
||||
public byte[] parameters;
|
||||
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
|
@ -1,11 +1,10 @@
|
||||
using QuantumUNET.Transport;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QAnimationTriggerMessage : QMessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public QNetworkInstanceId netId;
|
||||
public int hash;
|
||||
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
|
@ -1,11 +1,10 @@
|
||||
using QuantumUNET.Transport;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QClientAuthorityMessage : QMessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public QNetworkInstanceId netId;
|
||||
public bool authority;
|
||||
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
|
@ -1,11 +1,10 @@
|
||||
using QuantumUNET.Transport;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QObjectDestroyMessage : QMessageBase
|
||||
{
|
||||
public NetworkInstanceId NetId;
|
||||
public QNetworkInstanceId NetId;
|
||||
|
||||
public override void Serialize(QNetworkWriter writer) => writer.Write(NetId);
|
||||
|
||||
|
@ -1,12 +1,11 @@
|
||||
using QuantumUNET.Transport;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QObjectSpawnMessage : QMessageBase
|
||||
{
|
||||
public NetworkInstanceId NetId;
|
||||
public QNetworkInstanceId NetId;
|
||||
public int assetId;
|
||||
public Vector3 Position;
|
||||
public byte[] Payload;
|
||||
|
@ -1,13 +1,12 @@
|
||||
using QuantumUNET.Transport;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QObjectSpawnSceneMessage : QMessageBase
|
||||
{
|
||||
public NetworkInstanceId NetId;
|
||||
public NetworkSceneId SceneId;
|
||||
public QNetworkInstanceId NetId;
|
||||
public QNetworkSceneId SceneId;
|
||||
public Vector3 Position;
|
||||
public byte[] Payload;
|
||||
|
||||
|
@ -1,11 +1,10 @@
|
||||
using QuantumUNET.Transport;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QOwnerMessage : QMessageBase
|
||||
{
|
||||
public NetworkInstanceId NetId;
|
||||
public QNetworkInstanceId NetId;
|
||||
public short PlayerControllerId;
|
||||
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
|
@ -1,6 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace QuantumUNET
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
public delegate GameObject QSpawnDelegate(Vector3 position, int assetId);
|
||||
}
|
||||
|
6
QuantumUNET/Messages/QUnSpawnDelegate.cs
Normal file
6
QuantumUNET/Messages/QUnSpawnDelegate.cs
Normal file
@ -0,0 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
public delegate void QUnSpawnDelegate(GameObject spawned);
|
||||
}
|
@ -19,11 +19,11 @@ namespace QuantumUNET
|
||||
|
||||
public static int reconnectId { get; private set; } = -1;
|
||||
|
||||
public static Dictionary<NetworkInstanceId, QNetworkIdentity> Objects => s_NetworkScene.localObjects;
|
||||
public static Dictionary<QNetworkInstanceId, QNetworkIdentity> Objects => s_NetworkScene.localObjects;
|
||||
|
||||
public static Dictionary<int, GameObject> Prefabs => QNetworkScene.guidToPrefab;
|
||||
|
||||
public static Dictionary<NetworkSceneId, QNetworkIdentity> SpawnableObjects { get; private set; }
|
||||
public static Dictionary<QNetworkSceneId, QNetworkIdentity> SpawnableObjects { get; private set; }
|
||||
|
||||
internal static void Shutdown()
|
||||
{
|
||||
@ -241,7 +241,7 @@ namespace QuantumUNET
|
||||
|
||||
internal static void PrepareToSpawnSceneObjects()
|
||||
{
|
||||
SpawnableObjects = new Dictionary<NetworkSceneId, QNetworkIdentity>();
|
||||
SpawnableObjects = new Dictionary<QNetworkSceneId, QNetworkIdentity>();
|
||||
foreach (var networkIdentity in Resources.FindObjectsOfTypeAll<QNetworkIdentity>())
|
||||
{
|
||||
if (!networkIdentity.gameObject.activeSelf)
|
||||
@ -258,7 +258,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
internal static QNetworkIdentity SpawnSceneObject(NetworkSceneId sceneId)
|
||||
internal static QNetworkIdentity SpawnSceneObject(QNetworkSceneId sceneId)
|
||||
{
|
||||
QNetworkIdentity result;
|
||||
if (SpawnableObjects.ContainsKey(sceneId))
|
||||
@ -321,11 +321,11 @@ namespace QuantumUNET
|
||||
|
||||
public static void RegisterPrefab(GameObject prefab) => QNetworkScene.RegisterPrefab(prefab);
|
||||
|
||||
public static void RegisterPrefab(GameObject prefab, QSpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler) => QNetworkScene.RegisterPrefab(prefab, spawnHandler, unspawnHandler);
|
||||
public static void RegisterPrefab(GameObject prefab, QSpawnDelegate spawnHandler, QUnSpawnDelegate unspawnHandler) => QNetworkScene.RegisterPrefab(prefab, spawnHandler, unspawnHandler);
|
||||
|
||||
public static void UnregisterPrefab(GameObject prefab) => QNetworkScene.UnregisterPrefab(prefab);
|
||||
|
||||
public static void RegisterSpawnHandler(int assetId, QSpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler) => QNetworkScene.RegisterSpawnHandler(assetId, spawnHandler, unspawnHandler);
|
||||
public static void RegisterSpawnHandler(int assetId, QSpawnDelegate spawnHandler, QUnSpawnDelegate unspawnHandler) => QNetworkScene.RegisterSpawnHandler(assetId, spawnHandler, unspawnHandler);
|
||||
|
||||
public static void UnregisterSpawnHandler(int assetId) => QNetworkScene.UnregisterSpawnHandler(assetId);
|
||||
|
||||
@ -333,11 +333,11 @@ namespace QuantumUNET
|
||||
|
||||
public static void DestroyAllClientObjects() => s_NetworkScene.DestroyAllClientObjects();
|
||||
|
||||
public static void SetLocalObject(NetworkInstanceId netId, GameObject obj) => s_NetworkScene.SetLocalObject(netId, obj, s_IsSpawnFinished, false);
|
||||
public static void SetLocalObject(QNetworkInstanceId netId, GameObject obj) => s_NetworkScene.SetLocalObject(netId, obj, s_IsSpawnFinished, false);
|
||||
|
||||
public static GameObject FindLocalObject(NetworkInstanceId netId) => s_NetworkScene.FindLocalObject(netId);
|
||||
public static GameObject FindLocalObject(QNetworkInstanceId netId) => s_NetworkScene.FindLocalObject(netId);
|
||||
|
||||
private static void ApplySpawnPayload(QNetworkIdentity uv, Vector3 position, byte[] payload, NetworkInstanceId netId, GameObject newGameObject)
|
||||
private static void ApplySpawnPayload(QNetworkIdentity uv, Vector3 position, byte[] payload, QNetworkInstanceId netId, GameObject newGameObject)
|
||||
{
|
||||
if (!uv.gameObject.activeSelf)
|
||||
{
|
||||
@ -678,7 +678,7 @@ namespace QuantumUNET
|
||||
|
||||
private struct PendingOwner
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public QNetworkInstanceId netId;
|
||||
|
||||
public short playerControllerId;
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Sockets;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
@ -17,7 +16,7 @@ namespace QuantumUNET
|
||||
public bool IsClient => MyView.IsClient;
|
||||
public bool IsLocalPlayer => MyView.IsLocalPlayer;
|
||||
public bool HasAuthority => MyView.HasAuthority;
|
||||
public NetworkInstanceId NetId => MyView.NetId;
|
||||
public QNetworkInstanceId NetId => MyView.NetId;
|
||||
public QNetworkConnection ConnectionToServer => MyView.ConnectionToServer;
|
||||
public QNetworkConnection ConnectionToClient => MyView.ConnectionToClient;
|
||||
public short PlayerControllerId => MyView.PlayerControllerId;
|
||||
@ -429,11 +428,11 @@ namespace QuantumUNET
|
||||
internal static string GetCmdHashListName(int cmdHash)
|
||||
=> GetCmdHashPrefixName(cmdHash, "InvokeSyncList");
|
||||
|
||||
protected void SetSyncVarGameObject(GameObject newGameObject, ref GameObject gameObjectField, uint dirtyBit, ref NetworkInstanceId netIdField)
|
||||
protected void SetSyncVarGameObject(GameObject newGameObject, ref GameObject gameObjectField, uint dirtyBit, ref QNetworkInstanceId netIdField)
|
||||
{
|
||||
if (!SyncVarHookGuard)
|
||||
{
|
||||
NetworkInstanceId networkInstanceId = default;
|
||||
QNetworkInstanceId networkInstanceId = default;
|
||||
if (newGameObject != null)
|
||||
{
|
||||
var component = newGameObject.GetComponent<QNetworkIdentity>();
|
||||
@ -448,7 +447,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
NetworkInstanceId networkInstanceId2 = default;
|
||||
QNetworkInstanceId networkInstanceId2 = default;
|
||||
if (gameObjectField != null)
|
||||
{
|
||||
networkInstanceId2 = gameObjectField.GetComponent<QNetworkIdentity>().NetId;
|
||||
|
@ -16,14 +16,14 @@ namespace QuantumUNET
|
||||
public QNetworkClient()
|
||||
{
|
||||
m_MsgBuffer = new byte[65535];
|
||||
m_MsgReader = new NetworkReader(m_MsgBuffer);
|
||||
m_MsgReader = new QNetworkReader(m_MsgBuffer);
|
||||
AddClient(this);
|
||||
}
|
||||
|
||||
public QNetworkClient(QNetworkConnection conn)
|
||||
{
|
||||
m_MsgBuffer = new byte[65535];
|
||||
m_MsgReader = new NetworkReader(m_MsgBuffer);
|
||||
m_MsgReader = new QNetworkReader(m_MsgBuffer);
|
||||
AddClient(this);
|
||||
SetActive(true);
|
||||
m_Connection = conn;
|
||||
@ -60,7 +60,7 @@ namespace QuantumUNET
|
||||
private readonly QNetworkMessageHandlers m_MessageHandlers = new();
|
||||
protected QNetworkConnection m_Connection;
|
||||
private readonly byte[] m_MsgBuffer;
|
||||
private readonly NetworkReader m_MsgReader;
|
||||
private readonly QNetworkReader m_MsgReader;
|
||||
protected ConnectState m_AsyncConnect = ConnectState.None;
|
||||
private string m_RequestedServerHost = "";
|
||||
|
||||
|
@ -18,7 +18,7 @@ namespace QuantumUNET
|
||||
|
||||
public List<QPlayerController> PlayerControllers { get; } = new List<QPlayerController>();
|
||||
|
||||
public HashSet<NetworkInstanceId> ClientOwnedObjects { get; private set; }
|
||||
public HashSet<QNetworkInstanceId> ClientOwnedObjects { get; private set; }
|
||||
|
||||
public bool isConnected => hostId != -1;
|
||||
|
||||
@ -95,7 +95,7 @@ namespace QuantumUNET
|
||||
|
||||
private static bool IsReliableQoS(QosType qos) => qos is QosType.Reliable or QosType.ReliableFragmented or QosType.ReliableSequenced or QosType.ReliableStateUpdate;
|
||||
|
||||
public bool SetChannelOption(int channelId, ChannelOption option, int value) => m_Channels != null && channelId >= 0 && channelId < m_Channels.Length && m_Channels[channelId].SetOption(option, value);
|
||||
public bool SetChannelOption(int channelId, QChannelOption option, int value) => m_Channels != null && channelId >= 0 && channelId < m_Channels.Length && m_Channels[channelId].SetOption(option, value);
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
@ -386,7 +386,7 @@ namespace QuantumUNET
|
||||
{
|
||||
if (ClientOwnedObjects == null)
|
||||
{
|
||||
ClientOwnedObjects = new HashSet<NetworkInstanceId>();
|
||||
ClientOwnedObjects = new HashSet<QNetworkInstanceId>();
|
||||
}
|
||||
|
||||
ClientOwnedObjects.Add(obj.NetId);
|
||||
|
32
QuantumUNET/QNetworkInstanceId.cs
Normal file
32
QuantumUNET/QNetworkInstanceId.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
[Serializable]
|
||||
public struct QNetworkInstanceId
|
||||
{
|
||||
[SerializeField]
|
||||
private readonly uint m_Value;
|
||||
|
||||
public static QNetworkInstanceId Invalid = new QNetworkInstanceId(uint.MaxValue);
|
||||
|
||||
internal static QNetworkInstanceId Zero = new QNetworkInstanceId(0U);
|
||||
|
||||
public QNetworkInstanceId(uint value) => m_Value = value;
|
||||
|
||||
public bool IsEmpty() => m_Value == 0U;
|
||||
|
||||
public override int GetHashCode() => (int)m_Value;
|
||||
|
||||
public override bool Equals(object obj) => obj is QNetworkInstanceId id && this == id;
|
||||
|
||||
public static bool operator ==(QNetworkInstanceId c1, QNetworkInstanceId c2) => c1.m_Value == c2.m_Value;
|
||||
|
||||
public static bool operator !=(QNetworkInstanceId c1, QNetworkInstanceId c2) => c1.m_Value != c2.m_Value;
|
||||
|
||||
public override string ToString() => m_Value.ToString();
|
||||
|
||||
public uint Value => m_Value;
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using QuantumUNET.Components;
|
||||
using System.Collections.Generic;
|
||||
using QuantumUNET.Messages;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
@ -9,8 +9,8 @@ namespace QuantumUNET
|
||||
{
|
||||
internal static Dictionary<int, GameObject> guidToPrefab { get; } = new Dictionary<int, GameObject>();
|
||||
internal static Dictionary<int, QSpawnDelegate> spawnHandlers { get; } = new Dictionary<int, QSpawnDelegate>();
|
||||
internal static Dictionary<int, UnSpawnDelegate> unspawnHandlers { get; } = new Dictionary<int, UnSpawnDelegate>();
|
||||
internal Dictionary<NetworkInstanceId, QNetworkIdentity> localObjects { get; } = new Dictionary<NetworkInstanceId, QNetworkIdentity>();
|
||||
internal static Dictionary<int, QUnSpawnDelegate> unspawnHandlers { get; } = new Dictionary<int, QUnSpawnDelegate>();
|
||||
internal Dictionary<QNetworkInstanceId, QNetworkIdentity> localObjects { get; } = new Dictionary<QNetworkInstanceId, QNetworkIdentity>();
|
||||
|
||||
internal void Shutdown()
|
||||
{
|
||||
@ -18,7 +18,7 @@ namespace QuantumUNET
|
||||
ClearSpawners();
|
||||
}
|
||||
|
||||
internal void SetLocalObject(NetworkInstanceId netId, GameObject obj, bool isClient, bool isServer)
|
||||
internal void SetLocalObject(QNetworkInstanceId netId, GameObject obj, bool isClient, bool isServer)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
@ -42,7 +42,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
internal GameObject FindLocalObject(NetworkInstanceId netId)
|
||||
internal GameObject FindLocalObject(QNetworkInstanceId netId)
|
||||
{
|
||||
if (localObjects.ContainsKey(netId))
|
||||
{
|
||||
@ -56,7 +56,7 @@ namespace QuantumUNET
|
||||
return null;
|
||||
}
|
||||
|
||||
internal bool GetNetworkIdentity(NetworkInstanceId netId, out QNetworkIdentity uv)
|
||||
internal bool GetNetworkIdentity(QNetworkInstanceId netId, out QNetworkIdentity uv)
|
||||
{
|
||||
bool result;
|
||||
if (localObjects.ContainsKey(netId) && localObjects[netId] != null)
|
||||
@ -73,10 +73,10 @@ namespace QuantumUNET
|
||||
return result;
|
||||
}
|
||||
|
||||
internal bool RemoveLocalObject(NetworkInstanceId netId)
|
||||
internal bool RemoveLocalObject(QNetworkInstanceId netId)
|
||||
=> localObjects.Remove(netId);
|
||||
|
||||
internal bool RemoveLocalObjectAndDestroy(NetworkInstanceId netId)
|
||||
internal bool RemoveLocalObjectAndDestroy(QNetworkInstanceId netId)
|
||||
{
|
||||
bool result;
|
||||
if (localObjects.ContainsKey(netId))
|
||||
@ -116,7 +116,7 @@ namespace QuantumUNET
|
||||
if (component)
|
||||
{
|
||||
guidToPrefab[component.AssetId] = prefab;
|
||||
var componentsInChildren = prefab.GetComponentsInChildren<NetworkIdentity>();
|
||||
var componentsInChildren = prefab.GetComponentsInChildren<QNetworkIdentity>();
|
||||
if (componentsInChildren.Length > 1)
|
||||
{
|
||||
Debug.LogWarning(
|
||||
@ -164,7 +164,7 @@ namespace QuantumUNET
|
||||
unspawnHandlers.Remove(assetId);
|
||||
}
|
||||
|
||||
internal static void RegisterSpawnHandler(int assetId, QSpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
|
||||
internal static void RegisterSpawnHandler(int assetId, QSpawnDelegate spawnHandler, QUnSpawnDelegate unspawnHandler)
|
||||
{
|
||||
if (spawnHandler == null || unspawnHandler == null)
|
||||
{
|
||||
@ -191,7 +191,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
internal static void RegisterPrefab(GameObject prefab, QSpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
|
||||
internal static void RegisterPrefab(GameObject prefab, QSpawnDelegate spawnHandler, QUnSpawnDelegate unspawnHandler)
|
||||
{
|
||||
var component = prefab.GetComponent<QNetworkIdentity>();
|
||||
if (component == null)
|
||||
|
28
QuantumUNET/QNetworkSceneId.cs
Normal file
28
QuantumUNET/QNetworkSceneId.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
[Serializable]
|
||||
public struct QNetworkSceneId
|
||||
{
|
||||
[SerializeField]
|
||||
private uint m_Value;
|
||||
|
||||
public QNetworkSceneId(uint value) => m_Value = value;
|
||||
|
||||
public bool IsEmpty() => m_Value == 0U;
|
||||
|
||||
public override int GetHashCode() => (int)m_Value;
|
||||
|
||||
public override bool Equals(object obj) => obj is QNetworkSceneId id && this == id;
|
||||
|
||||
public static bool operator ==(QNetworkSceneId c1, QNetworkSceneId c2) => c1.m_Value == c2.m_Value;
|
||||
|
||||
public static bool operator !=(QNetworkSceneId c1, QNetworkSceneId c2) => c1.m_Value != c2.m_Value;
|
||||
|
||||
public override string ToString() => m_Value.ToString();
|
||||
|
||||
public uint Value => m_Value;
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@ namespace QuantumUNET
|
||||
private QNetworkServer()
|
||||
{
|
||||
NetworkTransport.Init();
|
||||
m_RemoveList = new HashSet<NetworkInstanceId>();
|
||||
m_RemoveList = new HashSet<QNetworkInstanceId>();
|
||||
m_ExternalConnections = new HashSet<int>();
|
||||
m_NetworkScene = new QNetworkScene();
|
||||
m_SimpleServerSimple = new ServerSimpleWrapper(this);
|
||||
@ -34,7 +34,7 @@ namespace QuantumUNET
|
||||
|
||||
public static HostTopology hostTopology => instance.m_SimpleServerSimple.hostTopology;
|
||||
|
||||
public static Dictionary<NetworkInstanceId, QNetworkIdentity> objects => instance.m_NetworkScene.localObjects;
|
||||
public static Dictionary<QNetworkInstanceId, QNetworkIdentity> objects => instance.m_NetworkScene.localObjects;
|
||||
|
||||
public static bool dontListen { get; set; }
|
||||
|
||||
@ -193,7 +193,7 @@ namespace QuantumUNET
|
||||
m_SimpleServerSimple.RemoveConnectionAtIndex(0);
|
||||
}
|
||||
|
||||
internal void SetLocalObjectOnServer(NetworkInstanceId netId, GameObject obj)
|
||||
internal void SetLocalObjectOnServer(QNetworkInstanceId netId, GameObject obj)
|
||||
{
|
||||
QLog.Debug($"SetLocalObjectOnServer {netId} {obj}");
|
||||
m_NetworkScene.SetLocalObject(netId, obj, false, true);
|
||||
@ -1061,7 +1061,7 @@ namespace QuantumUNET
|
||||
{
|
||||
if (conn.ClientOwnedObjects != null)
|
||||
{
|
||||
var hashSet = new HashSet<NetworkInstanceId>(conn.ClientOwnedObjects);
|
||||
var hashSet = new HashSet<QNetworkInstanceId>(conn.ClientOwnedObjects);
|
||||
foreach (var gameObject in hashSet.Select(FindLocalObject).Where(gameObject => gameObject != null))
|
||||
{
|
||||
DestroyObject(gameObject);
|
||||
@ -1271,7 +1271,7 @@ namespace QuantumUNET
|
||||
return result;
|
||||
}
|
||||
|
||||
public static GameObject FindLocalObject(NetworkInstanceId netId) => instance.m_NetworkScene.FindLocalObject(netId);
|
||||
public static GameObject FindLocalObject(QNetworkInstanceId netId) => instance.m_NetworkScene.FindLocalObject(netId);
|
||||
|
||||
private static bool ValidateSceneObject(QNetworkIdentity netId) => netId.gameObject.hideFlags != HideFlags.NotEditable && netId.gameObject.hideFlags != HideFlags.HideAndDontSave && !netId.SceneId.IsEmpty();
|
||||
|
||||
@ -1352,7 +1352,7 @@ namespace QuantumUNET
|
||||
|
||||
private float m_MaxDelay = 0.1f;
|
||||
|
||||
private readonly HashSet<NetworkInstanceId> m_RemoveList;
|
||||
private readonly HashSet<QNetworkInstanceId> m_RemoveList;
|
||||
|
||||
private int m_RemoveListCount;
|
||||
|
||||
|
@ -18,7 +18,7 @@ namespace QuantumUNET
|
||||
public ReadOnlyCollection<QNetworkConnection> connections { get; }
|
||||
public Dictionary<short, QNetworkMessageDelegate> handlers => m_MessageHandlers.GetHandlers();
|
||||
public byte[] messageBuffer { get; private set; }
|
||||
public NetworkReader messageReader { get; private set; }
|
||||
public QNetworkReader messageReader { get; private set; }
|
||||
public Type networkConnectionClass { get; private set; } = typeof(QNetworkConnection);
|
||||
|
||||
public void SetNetworkConnectionClass<T>()
|
||||
@ -32,7 +32,7 @@ namespace QuantumUNET
|
||||
m_Initialized = true;
|
||||
NetworkTransport.Init();
|
||||
messageBuffer = new byte[65535];
|
||||
messageReader = new NetworkReader(messageBuffer);
|
||||
messageReader = new QNetworkReader(messageBuffer);
|
||||
if (hostTopology == null)
|
||||
{
|
||||
var connectionConfig = new ConnectionConfig();
|
||||
|
@ -15,9 +15,5 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="OuterWildsGameLibs" Version="*" IncludeAssets="compile" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="UnityEngine.Networking, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\QSB\lib\UnityEngine.Networking.dll</HintPath>
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -2,7 +2,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Transport
|
||||
{
|
||||
@ -88,14 +87,14 @@ namespace QuantumUNET.Transport
|
||||
_disposed = true;
|
||||
}
|
||||
|
||||
public bool SetOption(ChannelOption option, int value)
|
||||
public bool SetOption(QChannelOption option, int value)
|
||||
{
|
||||
bool result;
|
||||
if (option != ChannelOption.MaxPendingBuffers)
|
||||
if (option != QChannelOption.MaxPendingBuffers)
|
||||
{
|
||||
if (option != ChannelOption.AllowFragmentation)
|
||||
if (option != QChannelOption.AllowFragmentation)
|
||||
{
|
||||
if (option != ChannelOption.MaxPacketSize)
|
||||
if (option != QChannelOption.MaxPacketSize)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
9
QuantumUNET/Transport/QChannelOption.cs
Normal file
9
QuantumUNET/Transport/QChannelOption.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace QuantumUNET.Transport
|
||||
{
|
||||
public enum QChannelOption
|
||||
{
|
||||
MaxPendingBuffers = 1,
|
||||
AllowFragmentation,
|
||||
MaxPacketSize
|
||||
}
|
||||
}
|
108
QuantumUNET/Transport/QNetworkHash128.cs
Normal file
108
QuantumUNET/Transport/QNetworkHash128.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using System;
|
||||
|
||||
namespace QuantumUNET.Transport
|
||||
{
|
||||
[Serializable]
|
||||
public struct QNetworkHash128
|
||||
{
|
||||
public byte i0;
|
||||
public byte i1;
|
||||
public byte i2;
|
||||
public byte i3;
|
||||
public byte i4;
|
||||
public byte i5;
|
||||
public byte i6;
|
||||
public byte i7;
|
||||
public byte i8;
|
||||
public byte i9;
|
||||
public byte i10;
|
||||
public byte i11;
|
||||
public byte i12;
|
||||
public byte i13;
|
||||
public byte i14;
|
||||
public byte i15;
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
i0 = 0;
|
||||
i1 = 0;
|
||||
i2 = 0;
|
||||
i3 = 0;
|
||||
i4 = 0;
|
||||
i5 = 0;
|
||||
i6 = 0;
|
||||
i7 = 0;
|
||||
i8 = 0;
|
||||
i9 = 0;
|
||||
i10 = 0;
|
||||
i11 = 0;
|
||||
i12 = 0;
|
||||
i13 = 0;
|
||||
i14 = 0;
|
||||
i15 = 0;
|
||||
}
|
||||
|
||||
public bool IsValid()
|
||||
{
|
||||
return (i0 | i1 | i2 | i3 | i4 | i5 | i6 | i7 | i8 | i9 | i10 | i11 | i12 | i13 | i14 | i15) != 0;
|
||||
}
|
||||
|
||||
private static int HexToNumber(char c)
|
||||
{
|
||||
int result;
|
||||
if (c is >= '0' and <= '9')
|
||||
{
|
||||
result = c - '0';
|
||||
}
|
||||
else if (c is >= 'a' and <= 'f')
|
||||
{
|
||||
result = c - 'a' + '\n';
|
||||
}
|
||||
else if (c is >= 'A' and <= 'F')
|
||||
{
|
||||
result = c - 'A' + '\n';
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static QNetworkHash128 Parse(string text)
|
||||
{
|
||||
var length = text.Length;
|
||||
if (length < 32)
|
||||
{
|
||||
var str = "";
|
||||
for (var i = 0; i < 32 - length; i++)
|
||||
{
|
||||
str += "0";
|
||||
}
|
||||
text = str + text;
|
||||
}
|
||||
QNetworkHash128 result;
|
||||
result.i0 = (byte)(HexToNumber(text[0]) * 16 + HexToNumber(text[1]));
|
||||
result.i1 = (byte)(HexToNumber(text[2]) * 16 + HexToNumber(text[3]));
|
||||
result.i2 = (byte)(HexToNumber(text[4]) * 16 + HexToNumber(text[5]));
|
||||
result.i3 = (byte)(HexToNumber(text[6]) * 16 + HexToNumber(text[7]));
|
||||
result.i4 = (byte)(HexToNumber(text[8]) * 16 + HexToNumber(text[9]));
|
||||
result.i5 = (byte)(HexToNumber(text[10]) * 16 + HexToNumber(text[11]));
|
||||
result.i6 = (byte)(HexToNumber(text[12]) * 16 + HexToNumber(text[13]));
|
||||
result.i7 = (byte)(HexToNumber(text[14]) * 16 + HexToNumber(text[15]));
|
||||
result.i8 = (byte)(HexToNumber(text[16]) * 16 + HexToNumber(text[17]));
|
||||
result.i9 = (byte)(HexToNumber(text[18]) * 16 + HexToNumber(text[19]));
|
||||
result.i10 = (byte)(HexToNumber(text[20]) * 16 + HexToNumber(text[21]));
|
||||
result.i11 = (byte)(HexToNumber(text[22]) * 16 + HexToNumber(text[23]));
|
||||
result.i12 = (byte)(HexToNumber(text[24]) * 16 + HexToNumber(text[25]));
|
||||
result.i13 = (byte)(HexToNumber(text[26]) * 16 + HexToNumber(text[27]));
|
||||
result.i14 = (byte)(HexToNumber(text[28]) * 16 + HexToNumber(text[29]));
|
||||
result.i15 = (byte)(HexToNumber(text[30]) * 16 + HexToNumber(text[31]));
|
||||
return result;
|
||||
}
|
||||
|
||||
public override string ToString() =>
|
||||
$"{i0:x2}{i1:x2}{i2:x2}{i3:x2}{i4:x2}{i5:x2}{i6:x2}{i7:x2}"
|
||||
+ $"{i8:x2}{i9:x2}{i10:x2}{i11:x2}{i12:x2}{i13:x2}{i14:x2}{i15:x2}";
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@ using QuantumUNET.Messages;
|
||||
using System;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Transport
|
||||
{
|
||||
@ -166,9 +165,9 @@ namespace QuantumUNET.Transport
|
||||
return result;
|
||||
}
|
||||
|
||||
public NetworkInstanceId ReadNetworkId() => new(ReadPackedUInt32());
|
||||
public QNetworkInstanceId ReadNetworkId() => new(ReadPackedUInt32());
|
||||
|
||||
public NetworkSceneId ReadSceneId() => new(ReadPackedUInt32());
|
||||
public QNetworkSceneId ReadSceneId() => new(ReadPackedUInt32());
|
||||
|
||||
public byte ReadByte() => m_buf.ReadByte();
|
||||
|
||||
@ -357,9 +356,9 @@ namespace QuantumUNET.Transport
|
||||
m33 = ReadSingle()
|
||||
};
|
||||
|
||||
public NetworkHash128 ReadNetworkHash128()
|
||||
public QNetworkHash128 ReadNetworkHash128()
|
||||
{
|
||||
NetworkHash128 result;
|
||||
QNetworkHash128 result;
|
||||
result.i0 = ReadByte();
|
||||
result.i1 = ReadByte();
|
||||
result.i2 = ReadByte();
|
||||
|
@ -3,7 +3,6 @@ using QuantumUNET.Messages;
|
||||
using System;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Transport
|
||||
{
|
||||
@ -152,9 +151,9 @@ namespace QuantumUNET.Transport
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(NetworkInstanceId value) => WritePackedUInt32(value.Value);
|
||||
public void Write(QNetworkInstanceId value) => WritePackedUInt32(value.Value);
|
||||
|
||||
public void Write(NetworkSceneId value) => WritePackedUInt32(value.Value);
|
||||
public void Write(QNetworkSceneId value) => WritePackedUInt32(value.Value);
|
||||
|
||||
public void Write(char value) => m_Buffer.WriteByte((byte)value);
|
||||
|
||||
@ -361,7 +360,7 @@ namespace QuantumUNET.Transport
|
||||
Write(value.m33);
|
||||
}
|
||||
|
||||
public void Write(NetworkHash128 value)
|
||||
public void Write(QNetworkHash128 value)
|
||||
{
|
||||
Write(value.i0);
|
||||
Write(value.i1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user