mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-26 18:35:34 +00:00
Merge pull request #236 from misternebula/qnet-rename-and-logging
Qnet rename and logging
This commit is contained in:
commit
3887dd962e
@ -13,7 +13,7 @@ namespace QSB.Animation
|
||||
{
|
||||
private Animator _anim;
|
||||
private Animator _bodyAnim;
|
||||
private QSBNetworkAnimator _netAnim;
|
||||
private QNetworkAnimator _netAnim;
|
||||
|
||||
private RuntimeAnimatorController _suitedAnimController;
|
||||
private AnimatorOverrideController _unsuitedAnimController;
|
||||
@ -34,7 +34,7 @@ namespace QSB.Animation
|
||||
protected void Awake()
|
||||
{
|
||||
_anim = gameObject.AddComponent<Animator>();
|
||||
_netAnim = gameObject.AddComponent<QSBNetworkAnimator>();
|
||||
_netAnim = gameObject.AddComponent<QNetworkAnimator>();
|
||||
_netAnim.enabled = false;
|
||||
_netAnim.animator = _anim;
|
||||
|
||||
|
@ -4,7 +4,7 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.Animation
|
||||
{
|
||||
public class CrouchSync : QSBNetworkBehaviour
|
||||
public class CrouchSync : QNetworkBehaviour
|
||||
{
|
||||
public AnimFloatParam CrouchParam { get; } = new AnimFloatParam();
|
||||
|
||||
|
@ -9,7 +9,7 @@ namespace QSB.ConversationSync.Events
|
||||
public int ObjectId { get; set; }
|
||||
public string Message { get; set; }
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
ObjectId = reader.ReadInt32();
|
||||
@ -17,7 +17,7 @@ namespace QSB.ConversationSync.Events
|
||||
Message = reader.ReadString();
|
||||
}
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(ObjectId);
|
||||
|
@ -9,7 +9,7 @@ namespace QSB.ConversationSync.Events
|
||||
public uint PlayerId { get; set; }
|
||||
public bool State { get; set; }
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
CharacterId = reader.ReadInt32();
|
||||
@ -17,7 +17,7 @@ namespace QSB.ConversationSync.Events
|
||||
State = reader.ReadBoolean();
|
||||
}
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(CharacterId);
|
||||
|
@ -8,14 +8,14 @@ namespace QSB.ConversationSync.Events
|
||||
public string ConditionName { get; set; }
|
||||
public bool ConditionState { get; set; }
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
ConditionName = reader.ReadString();
|
||||
ConditionState = reader.ReadBoolean();
|
||||
}
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(ConditionName);
|
||||
|
@ -51,12 +51,12 @@ namespace QSB.Events
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.OnlySendToServer && !QSBNetworkServer.active)
|
||||
if (message.OnlySendToServer && !QNetworkServer.active)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (PlayerTransformSync.LocalInstance == null || PlayerTransformSync.LocalInstance.GetComponent<QSBNetworkIdentity>() == null)
|
||||
if (PlayerTransformSync.LocalInstance == null || PlayerTransformSync.LocalInstance.GetComponent<QNetworkIdentity>() == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - Tried to handle message of type <{message.GetType().Name}> before localplayer was established.", MessageType.Warning);
|
||||
return;
|
||||
@ -65,11 +65,11 @@ namespace QSB.Events
|
||||
if (message.FromId == QSBPlayerManager.LocalPlayerId ||
|
||||
QSBPlayerManager.IsBelongingToLocalPlayer(message.AboutId))
|
||||
{
|
||||
OnReceiveLocal(QSBNetworkServer.active, message);
|
||||
OnReceiveLocal(QNetworkServer.active, message);
|
||||
return;
|
||||
}
|
||||
|
||||
OnReceiveRemote(QSBNetworkServer.active, message);
|
||||
OnReceiveRemote(QNetworkServer.active, message);
|
||||
}
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ namespace QSB.GeyserSync
|
||||
|
||||
private void HandleEvent(bool state)
|
||||
{
|
||||
if (QSBNetworkServer.active)
|
||||
if (QNetworkServer.active)
|
||||
{
|
||||
GlobalMessenger<int, bool>.FireEvent(EventNames.QSBGeyserState, ObjectId, state);
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ namespace QSB.Instruments.QSBCamera
|
||||
{
|
||||
_cameraBase = new GameObject();
|
||||
_cameraBase.SetActive(false);
|
||||
_cameraBase.AddComponent<Transform>();
|
||||
_cameraBase.transform.parent = Locator.GetPlayerTransform();
|
||||
_cameraBase.transform.localPosition = Vector3.zero;
|
||||
_cameraBase.transform.localRotation = Quaternion.Euler(0, 0, 0);
|
||||
|
@ -9,7 +9,7 @@ namespace QSB.LogSync.Events
|
||||
public bool SaveGame { get; set; }
|
||||
public bool ShowNotification { get; set; }
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
FactId = reader.ReadString();
|
||||
@ -17,7 +17,7 @@ namespace QSB.LogSync.Events
|
||||
ShowNotification = reader.ReadBoolean();
|
||||
}
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(FactId);
|
||||
|
@ -6,13 +6,13 @@ namespace QSB.Messaging
|
||||
{
|
||||
public T Value;
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
Value = (T)(object)reader.ReadInt32();
|
||||
}
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write((int)(object)Value);
|
||||
|
@ -6,13 +6,13 @@ namespace QSB.Messaging
|
||||
{
|
||||
public float Value;
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
Value = reader.ReadSingle();
|
||||
}
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(Value);
|
||||
|
@ -7,7 +7,7 @@ using System.Linq;
|
||||
|
||||
namespace QSB.Messaging
|
||||
{
|
||||
public class MessageHandler<T> where T : QSBMessageBase, new()
|
||||
public class MessageHandler<T> where T : QMessageBase, new()
|
||||
{
|
||||
public event Action<T> OnClientReceiveMessage;
|
||||
public event Action<T> OnServerReceiveMessage;
|
||||
@ -16,7 +16,7 @@ namespace QSB.Messaging
|
||||
|
||||
public MessageHandler(EventType eventType)
|
||||
{
|
||||
_eventType = (short)(eventType + QSBMsgType.Highest + 1);
|
||||
_eventType = (short)(eventType + QMsgType.Highest + 1);
|
||||
if (QSBNetworkManager.Instance.IsReady)
|
||||
{
|
||||
Init();
|
||||
@ -29,13 +29,13 @@ namespace QSB.Messaging
|
||||
|
||||
private void Init()
|
||||
{
|
||||
if (QSBNetworkServer.handlers.Keys.Contains(_eventType))
|
||||
if (QNetworkServer.handlers.Keys.Contains(_eventType))
|
||||
{
|
||||
QSBNetworkServer.handlers.Remove(_eventType);
|
||||
QSBNetworkManagerUNET.singleton.client.handlers.Remove(_eventType);
|
||||
QNetworkServer.handlers.Remove(_eventType);
|
||||
QNetworkManager.singleton.client.handlers.Remove(_eventType);
|
||||
}
|
||||
QSBNetworkServer.RegisterHandler(_eventType, OnServerReceiveMessageHandler);
|
||||
QSBNetworkManagerUNET.singleton.client.RegisterHandler(_eventType, OnClientReceiveMessageHandler);
|
||||
QNetworkServer.RegisterHandler(_eventType, OnServerReceiveMessageHandler);
|
||||
QNetworkManager.singleton.client.RegisterHandler(_eventType, OnClientReceiveMessageHandler);
|
||||
}
|
||||
|
||||
public void SendToAll(T message)
|
||||
@ -44,7 +44,7 @@ namespace QSB.Messaging
|
||||
{
|
||||
return;
|
||||
}
|
||||
QSBNetworkServer.SendToAll(_eventType, message);
|
||||
QNetworkServer.SendToAll(_eventType, message);
|
||||
}
|
||||
|
||||
public void SendToServer(T message)
|
||||
@ -53,16 +53,16 @@ namespace QSB.Messaging
|
||||
{
|
||||
return;
|
||||
}
|
||||
QSBNetworkManagerUNET.singleton.client.Send(_eventType, message);
|
||||
QNetworkManager.singleton.client.Send(_eventType, message);
|
||||
}
|
||||
|
||||
private void OnClientReceiveMessageHandler(QSBNetworkMessage netMsg)
|
||||
private void OnClientReceiveMessageHandler(QNetworkMessage netMsg)
|
||||
{
|
||||
var message = netMsg.ReadMessage<T>();
|
||||
OnClientReceiveMessage?.Invoke(message);
|
||||
}
|
||||
|
||||
private void OnServerReceiveMessageHandler(QSBNetworkMessage netMsg)
|
||||
private void OnServerReceiveMessageHandler(QNetworkMessage netMsg)
|
||||
{
|
||||
var message = netMsg.ReadMessage<T>();
|
||||
OnServerReceiveMessage?.Invoke(message);
|
||||
|
@ -3,20 +3,20 @@ using QuantumUNET.Transport;
|
||||
|
||||
namespace QSB.Messaging
|
||||
{
|
||||
public class PlayerMessage : QSBMessageBase
|
||||
public class PlayerMessage : QMessageBase
|
||||
{
|
||||
public uint FromId { get; set; }
|
||||
public uint AboutId { get; set; }
|
||||
public bool OnlySendToServer { get; set; }
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
FromId = reader.ReadUInt32();
|
||||
AboutId = reader.ReadUInt32();
|
||||
OnlySendToServer = reader.ReadBoolean();
|
||||
}
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
writer.Write(FromId);
|
||||
writer.Write(AboutId);
|
||||
|
@ -6,13 +6,13 @@ namespace QSB.Messaging
|
||||
{
|
||||
public bool ToggleValue { get; set; }
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
ToggleValue = reader.ReadBoolean();
|
||||
}
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(ToggleValue);
|
||||
|
@ -9,7 +9,7 @@ namespace QSB.OrbSync.Events
|
||||
public int OrbId { get; set; }
|
||||
public bool SlotState { get; set; }
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
SlotId = reader.ReadInt32();
|
||||
@ -17,7 +17,7 @@ namespace QSB.OrbSync.Events
|
||||
SlotState = reader.ReadBoolean();
|
||||
}
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(SlotId);
|
||||
|
@ -50,7 +50,7 @@ namespace QSB.OrbSync.Events
|
||||
|
||||
private static void HandleServer(WorldObjectMessage message)
|
||||
{
|
||||
var fromPlayer = QSBNetworkServer.connections.First(x => x.GetPlayer().PlayerId == message.FromId);
|
||||
var fromPlayer = QNetworkServer.connections.First(x => x.GetPlayer().PlayerId == message.FromId);
|
||||
if (QSBWorldSync.OrbSyncList.Count == 0)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - OrbSyncList is empty. (ID {message.ObjectId})", MessageType.Error);
|
||||
@ -67,7 +67,7 @@ namespace QSB.OrbSync.Events
|
||||
DebugLog.ToConsole($"Error - No orb found for user event. (ID {message.ObjectId})", MessageType.Error);
|
||||
return;
|
||||
}
|
||||
var orbIdentity = orbSync.GetComponent<QSBNetworkIdentity>();
|
||||
var orbIdentity = orbSync.GetComponent<QNetworkIdentity>();
|
||||
if (orbIdentity == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - Orb identity is null. (ID {message.ObjectId})", MessageType.Error);
|
||||
|
@ -30,16 +30,16 @@ namespace QSB.OrbSync
|
||||
{
|
||||
QSBWorldSync.OldOrbList.Clear();
|
||||
QSBWorldSync.OldOrbList = Resources.FindObjectsOfTypeAll<NomaiInterfaceOrb>().ToList();
|
||||
if (QSBNetworkServer.active)
|
||||
if (QNetworkServer.active)
|
||||
{
|
||||
QSBWorldSync.OrbSyncList.ForEach(x => QSBNetworkServer.Destroy(x.gameObject));
|
||||
QSBWorldSync.OrbSyncList.ForEach(x => QNetworkServer.Destroy(x.gameObject));
|
||||
QSBWorldSync.OrbSyncList.Clear();
|
||||
QSBWorldSync.OldOrbList.ForEach(x => QSBNetworkServer.Spawn(Instantiate(QSBNetworkManager.Instance.OrbPrefab)));
|
||||
QSBWorldSync.OldOrbList.ForEach(x => QNetworkServer.Spawn(Instantiate(QSBNetworkManager.Instance.OrbPrefab)));
|
||||
}
|
||||
DebugLog.DebugWrite($"Finished orb build with {QSBWorldSync.OldOrbList.Count} orbs.", MessageType.Success);
|
||||
}
|
||||
|
||||
public void QueueBuildSlots() => QSBCore.Helper.Events.Unity.RunWhen(() => QSBCore.HasWokenUp, BuildOrbSlots);
|
||||
public void QueueBuildOrbs() => QSBCore.Helper.Events.Unity.RunWhen(() => QSBNetworkServer.active, BuildOrbs);
|
||||
public void QueueBuildOrbs() => QSBCore.Helper.Events.Unity.RunWhen(() => QNetworkServer.active, BuildOrbs);
|
||||
}
|
||||
}
|
@ -7,13 +7,13 @@ namespace QSB.Player.Events
|
||||
{
|
||||
public string PlayerName { get; set; }
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
PlayerName = reader.ReadString();
|
||||
}
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(PlayerName);
|
||||
|
@ -9,7 +9,7 @@ namespace QSB.Player.Events
|
||||
public bool PlayerReady { get; set; }
|
||||
public State PlayerState { get; set; }
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
PlayerName = reader.ReadString();
|
||||
@ -17,7 +17,7 @@ namespace QSB.Player.Events
|
||||
PlayerState = (State)reader.ReadInt32();
|
||||
}
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(PlayerName);
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace QSB.Player
|
||||
{
|
||||
public abstract class PlayerSyncObject : QSBNetworkBehaviour
|
||||
public abstract class PlayerSyncObject : QNetworkBehaviour
|
||||
{
|
||||
public uint AttachedNetId => NetIdentity?.NetId.Value ?? uint.MaxValue;
|
||||
public uint PlayerId => NetIdentity.RootIdentity?.NetId.Value ?? NetIdentity.NetId.Value;
|
||||
|
@ -43,7 +43,7 @@ namespace QSB
|
||||
public static AssetBundle NetworkAssetBundle { get; private set; }
|
||||
public static AssetBundle InstrumentAssetBundle { get; private set; }
|
||||
public static bool HasWokenUp { get; set; }
|
||||
public static bool IsServer => QSBNetworkServer.active;
|
||||
public static bool IsServer => QNetworkServer.active;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
@ -66,7 +66,7 @@ namespace QSB
|
||||
QSBPatchManager.DoPatchType(QSBPatchTypes.OnModStart);
|
||||
|
||||
gameObject.AddComponent<QSBNetworkManager>();
|
||||
gameObject.AddComponent<QSBNetworkManagerHUD>();
|
||||
gameObject.AddComponent<QNetworkManagerHUD>();
|
||||
gameObject.AddComponent<DebugActions>();
|
||||
gameObject.AddComponent<ElevatorManager>();
|
||||
gameObject.AddComponent<GeyserManager>();
|
||||
@ -82,7 +82,7 @@ namespace QSB
|
||||
}
|
||||
|
||||
public void Update() =>
|
||||
QSBNetworkIdentity.UNetStaticUpdate();
|
||||
QNetworkIdentity.UNetStaticUpdate();
|
||||
|
||||
public override void Configure(IModConfig config)
|
||||
{
|
||||
|
@ -23,7 +23,7 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QSB
|
||||
{
|
||||
public class QSBNetworkManager : QSBNetworkManagerUNET
|
||||
public class QSBNetworkManager : QNetworkManager
|
||||
{
|
||||
public static QSBNetworkManager Instance { get; private set; }
|
||||
|
||||
@ -87,7 +87,7 @@ namespace QSB
|
||||
|
||||
private void SetupNetworkId(GameObject go)
|
||||
{
|
||||
var ident = go.AddComponent<QSBNetworkIdentity>();
|
||||
var ident = go.AddComponent<QNetworkIdentity>();
|
||||
ident.LocalPlayerAuthority = true;
|
||||
ident.SetValue("m_AssetId", go.GetComponent<NetworkIdentity>().assetId);
|
||||
ident.SetValue("m_SceneId", go.GetComponent<NetworkIdentity>().sceneId);
|
||||
@ -95,9 +95,9 @@ namespace QSB
|
||||
|
||||
private void SetupNetworkTransform(GameObject go)
|
||||
{
|
||||
var trans = go.AddComponent<QSBNetworkTransform>();
|
||||
trans.SyncRotationAxis = QSBNetworkTransform.AxisSyncMode.AxisXYZ;
|
||||
Destroy(go.GetComponent<NetworkTransform>());
|
||||
var trans = go.AddComponent<QuantumUNET.Components.QNetworkTransform>();
|
||||
trans.SyncRotationAxis = QuantumUNET.Components.QNetworkTransform.AxisSyncMode.AxisXYZ;
|
||||
Destroy(go.GetComponent<UnityEngine.Networking.NetworkTransform>());
|
||||
Destroy(go.GetComponent<NetworkIdentity>());
|
||||
}
|
||||
|
||||
@ -140,17 +140,17 @@ namespace QSB
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnServerAddPlayer(QSBNetworkConnection connection, short playerControllerId) // Called on the server when a client joins
|
||||
public override void OnServerAddPlayer(QNetworkConnection connection, short playerControllerId) // Called on the server when a client joins
|
||||
{
|
||||
DebugLog.DebugWrite($"OnServerAddPlayer {playerControllerId}", MessageType.Info);
|
||||
base.OnServerAddPlayer(connection, playerControllerId);
|
||||
|
||||
QSBNetworkServer.SpawnWithClientAuthority(Instantiate(_shipPrefab), connection);
|
||||
QSBNetworkServer.SpawnWithClientAuthority(Instantiate(_cameraPrefab), connection);
|
||||
QSBNetworkServer.SpawnWithClientAuthority(Instantiate(_probePrefab), connection);
|
||||
QNetworkServer.SpawnWithClientAuthority(Instantiate(_shipPrefab), connection);
|
||||
QNetworkServer.SpawnWithClientAuthority(Instantiate(_cameraPrefab), connection);
|
||||
QNetworkServer.SpawnWithClientAuthority(Instantiate(_probePrefab), connection);
|
||||
}
|
||||
|
||||
public override void OnStartClient(QSBNetworkClient _)
|
||||
public override void OnStartClient(QNetworkClient _)
|
||||
{
|
||||
DebugLog.DebugWrite($"Setting defaultServerIP to {networkAddress}");
|
||||
var config = QSBCore.Helper.Config;
|
||||
@ -158,7 +158,7 @@ namespace QSB
|
||||
QSBCore.Helper.Storage.Save(config, Constants.ModConfigFileName);
|
||||
}
|
||||
|
||||
public override void OnClientConnect(QSBNetworkConnection connection) // Called on the client when connecting to a server
|
||||
public override void OnClientConnect(QNetworkConnection connection) // Called on the client when connecting to a server
|
||||
{
|
||||
DebugLog.DebugWrite("OnClientConnect", MessageType.Info);
|
||||
base.OnClientConnect(connection);
|
||||
@ -175,7 +175,7 @@ namespace QSB
|
||||
OrbManager.Instance.QueueBuildSlots();
|
||||
}
|
||||
|
||||
var specificType = QSBNetworkServer.active ? QSBPatchTypes.OnServerClientConnect : QSBPatchTypes.OnNonServerClientConnect;
|
||||
var specificType = QNetworkServer.active ? QSBPatchTypes.OnServerClientConnect : QSBPatchTypes.OnNonServerClientConnect;
|
||||
QSBPatchManager.DoPatchType(specificType);
|
||||
QSBPatchManager.DoPatchType(QSBPatchTypes.OnClientConnect);
|
||||
|
||||
@ -216,14 +216,14 @@ namespace QSB
|
||||
_lobby.CanEditName = true;
|
||||
}
|
||||
|
||||
public override void OnServerDisconnect(QSBNetworkConnection connection) // Called on the server when any client disconnects
|
||||
public override void OnServerDisconnect(QNetworkConnection connection) // Called on the server when any client disconnects
|
||||
{
|
||||
base.OnServerDisconnect(connection);
|
||||
DebugLog.DebugWrite("OnServerDisconnect", MessageType.Info);
|
||||
|
||||
foreach (var item in QSBWorldSync.OrbSyncList)
|
||||
{
|
||||
var identity = item.GetComponent<QSBNetworkIdentity>();
|
||||
var identity = item.GetComponent<QNetworkIdentity>();
|
||||
if (identity.ClientAuthorityOwner == connection)
|
||||
{
|
||||
identity.RemoveClientAuthority(connection);
|
||||
|
@ -1,8 +1,4 @@
|
||||
using QSB.Events;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace QSB.QuantumSync.Events
|
||||
{
|
||||
|
@ -7,13 +7,13 @@ namespace QSB.QuantumSync.Events
|
||||
{
|
||||
public int StateIndex { get; set; }
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
StateIndex = reader.ReadInt32();
|
||||
}
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(StateIndex);
|
||||
|
@ -9,14 +9,14 @@ namespace QSB.QuantumSync.Events
|
||||
public int SocketId { get; set; }
|
||||
public Quaternion LocalRotation { get; set; }
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
SocketId = reader.ReadInt32();
|
||||
LocalRotation = reader.ReadQuaternion();
|
||||
}
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(SocketId);
|
||||
|
@ -1,11 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace QSB.QuantumSync
|
||||
namespace QSB.QuantumSync
|
||||
{
|
||||
class QSBMultiStateQuantumObject
|
||||
internal class QSBMultiStateQuantumObject
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -8,14 +8,14 @@ namespace QSB.TimeSync.Events
|
||||
public float ServerTime { get; set; }
|
||||
public int LoopCount { get; set; }
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
ServerTime = reader.ReadSingle();
|
||||
LoopCount = reader.ReadInt16();
|
||||
}
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(ServerTime);
|
||||
|
@ -3,7 +3,7 @@ using QuantumUNET;
|
||||
|
||||
namespace QSB.TimeSync
|
||||
{
|
||||
public class PreserveTimeScale : QSBNetworkBehaviour
|
||||
public class PreserveTimeScale : QNetworkBehaviour
|
||||
{
|
||||
public void Start()
|
||||
{
|
||||
|
@ -6,7 +6,7 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.TimeSync
|
||||
{
|
||||
public class WakeUpSync : QSBNetworkBehaviour
|
||||
public class WakeUpSync : QNetworkBehaviour
|
||||
{
|
||||
public static WakeUpSync LocalInstance { get; private set; }
|
||||
|
||||
@ -48,7 +48,7 @@ namespace QSB.TimeSync
|
||||
|
||||
private void OnWakeUp()
|
||||
{
|
||||
if (QSBNetworkServer.active)
|
||||
if (QNetworkServer.active)
|
||||
{
|
||||
QSBCore.HasWokenUp = true;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.TransformSync
|
||||
{
|
||||
public class NomaiOrbTransformSync : QSBNetworkBehaviour
|
||||
public class NomaiOrbTransformSync : QNetworkBehaviour
|
||||
{
|
||||
public NomaiInterfaceOrb AttachedOrb { get; private set; }
|
||||
public Transform OrbTransform { get; private set; }
|
||||
|
@ -6,7 +6,7 @@ namespace QSB.Utility
|
||||
{
|
||||
public static class UnetExtensions
|
||||
{
|
||||
public static PlayerInfo GetPlayer(this QSBNetworkConnection connection)
|
||||
public static PlayerInfo GetPlayer(this QNetworkConnection connection)
|
||||
{
|
||||
var go = connection.PlayerControllers[0].Gameobject;
|
||||
var controller = go.GetComponent<PlayerTransformSync>();
|
||||
|
@ -6,13 +6,13 @@ namespace QSB.WorldSync.Events
|
||||
{
|
||||
public bool State { get; set; }
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
State = reader.ReadBoolean();
|
||||
}
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(State);
|
||||
|
@ -7,13 +7,13 @@ namespace QSB.WorldSync.Events
|
||||
{
|
||||
public int ObjectId { get; set; }
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
ObjectId = reader.ReadInt32();
|
||||
}
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(ObjectId);
|
||||
|
@ -4,17 +4,17 @@ using UnityEngine;
|
||||
|
||||
namespace QuantumUNET.Components
|
||||
{
|
||||
public class QSBNetworkAnimator : QSBNetworkBehaviour
|
||||
public class QNetworkAnimator : QNetworkBehaviour
|
||||
{
|
||||
private static readonly QSBAnimationMessage AnimationMessage = new QSBAnimationMessage();
|
||||
private static readonly QSBAnimationParametersMessage ParametersMessage = new QSBAnimationParametersMessage();
|
||||
private static readonly QSBAnimationTriggerMessage TriggersMessage = new QSBAnimationTriggerMessage();
|
||||
private static readonly QAnimationMessage AnimationMessage = new QAnimationMessage();
|
||||
private static readonly QAnimationParametersMessage ParametersMessage = new QAnimationParametersMessage();
|
||||
private static readonly QAnimationTriggerMessage TriggersMessage = new QAnimationTriggerMessage();
|
||||
|
||||
private Animator m_Animator;
|
||||
private uint m_ParameterSendBits;
|
||||
private int m_AnimationHash;
|
||||
private int m_TransitionHash;
|
||||
private QSBNetworkWriter m_ParameterWriter;
|
||||
private QNetworkWriter m_ParameterWriter;
|
||||
private float m_SendTimer;
|
||||
|
||||
public Animator animator
|
||||
@ -43,7 +43,7 @@ namespace QuantumUNET.Components
|
||||
((int)m_ParameterSendBits & (1 << index)) != 0;
|
||||
|
||||
public override void OnStartAuthority() =>
|
||||
m_ParameterWriter = new QSBNetworkWriter();
|
||||
m_ParameterWriter = new QNetworkWriter();
|
||||
|
||||
public void FixedUpdate()
|
||||
{
|
||||
@ -56,7 +56,7 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
return;
|
||||
}
|
||||
var animationMessage = new QSBAnimationMessage
|
||||
var animationMessage = new QAnimationMessage
|
||||
{
|
||||
netId = NetId,
|
||||
stateHash = stateHash,
|
||||
@ -67,9 +67,9 @@ namespace QuantumUNET.Components
|
||||
WriteParameters(m_ParameterWriter, false);
|
||||
animationMessage.parameters = m_ParameterWriter.ToArray();
|
||||
|
||||
if (HasAuthority || QSBClientScene.readyConnection != null)
|
||||
if (HasAuthority || QClientScene.readyConnection != null)
|
||||
{
|
||||
QSBClientScene.readyConnection.Send(40, animationMessage);
|
||||
QClientScene.readyConnection.Send(40, animationMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -77,7 +77,7 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
return;
|
||||
}
|
||||
QSBNetworkServer.SendToReady(gameObject, 40, animationMessage);
|
||||
QNetworkServer.SendToReady(gameObject, 40, animationMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,16 +118,16 @@ namespace QuantumUNET.Components
|
||||
return;
|
||||
}
|
||||
m_SendTimer = Time.time + GetNetworkSendInterval();
|
||||
var parametersMessage = new QSBAnimationParametersMessage
|
||||
var parametersMessage = new QAnimationParametersMessage
|
||||
{
|
||||
netId = NetId
|
||||
};
|
||||
m_ParameterWriter.SeekZero();
|
||||
WriteParameters(m_ParameterWriter, true);
|
||||
parametersMessage.parameters = m_ParameterWriter.ToArray();
|
||||
if (HasAuthority && QSBClientScene.readyConnection != null)
|
||||
if (HasAuthority && QClientScene.readyConnection != null)
|
||||
{
|
||||
QSBClientScene.readyConnection.Send(41, parametersMessage);
|
||||
QClientScene.readyConnection.Send(41, parametersMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -136,11 +136,11 @@ namespace QuantumUNET.Components
|
||||
return;
|
||||
}
|
||||
|
||||
QSBNetworkServer.SendToReady(gameObject, 41, parametersMessage);
|
||||
QNetworkServer.SendToReady(gameObject, 41, parametersMessage);
|
||||
}
|
||||
}
|
||||
|
||||
internal void HandleAnimMsg(QSBAnimationMessage msg, QSBNetworkReader reader)
|
||||
internal void HandleAnimMsg(QAnimationMessage msg, QNetworkReader reader)
|
||||
{
|
||||
if (HasAuthority)
|
||||
{
|
||||
@ -153,7 +153,7 @@ namespace QuantumUNET.Components
|
||||
ReadParameters(reader, false);
|
||||
}
|
||||
|
||||
internal void HandleAnimParamsMsg(QSBAnimationParametersMessage msg, QSBNetworkReader reader)
|
||||
internal void HandleAnimParamsMsg(QAnimationParametersMessage msg, QNetworkReader reader)
|
||||
{
|
||||
if (HasAuthority)
|
||||
{
|
||||
@ -164,7 +164,7 @@ namespace QuantumUNET.Components
|
||||
|
||||
internal void HandleAnimTriggerMsg(int hash) => m_Animator.SetTrigger(hash);
|
||||
|
||||
private void WriteParameters(QSBNetworkWriter writer, bool autoSend)
|
||||
private void WriteParameters(QNetworkWriter writer, bool autoSend)
|
||||
{
|
||||
for (var index = 0; index < m_Animator.parameters.Length; ++index)
|
||||
{
|
||||
@ -189,7 +189,7 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
private void ReadParameters(QSBNetworkReader reader, bool autoSend)
|
||||
private void ReadParameters(QNetworkReader reader, bool autoSend)
|
||||
{
|
||||
for (var index = 0; index < m_Animator.parameters.Length; ++index)
|
||||
{
|
||||
@ -221,7 +221,7 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnSerialize(QSBNetworkWriter writer, bool forceAll)
|
||||
public override bool OnSerialize(QNetworkWriter writer, bool forceAll)
|
||||
{
|
||||
if (!forceAll)
|
||||
{
|
||||
@ -243,7 +243,7 @@ namespace QuantumUNET.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void OnDeserialize(QSBNetworkReader reader, bool initialState)
|
||||
public override void OnDeserialize(QNetworkReader reader, bool initialState)
|
||||
{
|
||||
if (!initialState)
|
||||
{
|
||||
@ -259,18 +259,18 @@ namespace QuantumUNET.Components
|
||||
|
||||
public void SetTrigger(int hash)
|
||||
{
|
||||
var animationTriggerMessage = new QSBAnimationTriggerMessage
|
||||
var animationTriggerMessage = new QAnimationTriggerMessage
|
||||
{
|
||||
netId = NetId,
|
||||
hash = hash
|
||||
};
|
||||
if (HasAuthority && LocalPlayerAuthority)
|
||||
{
|
||||
if (QSBNetworkClient.allClients.Count <= 0)
|
||||
if (QNetworkClient.allClients.Count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var readyConnection = QSBClientScene.readyConnection;
|
||||
var readyConnection = QClientScene.readyConnection;
|
||||
if (readyConnection == null)
|
||||
{
|
||||
return;
|
||||
@ -283,99 +283,99 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
return;
|
||||
}
|
||||
QSBNetworkServer.SendToReady(gameObject, 42, animationTriggerMessage);
|
||||
QNetworkServer.SendToReady(gameObject, 42, animationTriggerMessage);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void OnAnimationServerMessage(QSBNetworkMessage netMsg)
|
||||
internal static void OnAnimationServerMessage(QNetworkMessage netMsg)
|
||||
{
|
||||
netMsg.ReadMessage(AnimationMessage);
|
||||
var localObject = QSBNetworkServer.FindLocalObject(AnimationMessage.netId);
|
||||
var localObject = QNetworkServer.FindLocalObject(AnimationMessage.netId);
|
||||
if (localObject == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var component = localObject.GetComponent<QSBNetworkAnimator>();
|
||||
var reader = new QSBNetworkReader(AnimationMessage.parameters);
|
||||
var component = localObject.GetComponent<QNetworkAnimator>();
|
||||
var reader = new QNetworkReader(AnimationMessage.parameters);
|
||||
component?.HandleAnimMsg(AnimationMessage, reader);
|
||||
QSBNetworkServer.SendToReady(localObject, 40, AnimationMessage);
|
||||
QNetworkServer.SendToReady(localObject, 40, AnimationMessage);
|
||||
}
|
||||
|
||||
internal static void OnAnimationParametersServerMessage(QSBNetworkMessage netMsg)
|
||||
internal static void OnAnimationParametersServerMessage(QNetworkMessage netMsg)
|
||||
{
|
||||
netMsg.ReadMessage(ParametersMessage);
|
||||
var localObject = QSBNetworkServer.FindLocalObject(ParametersMessage.netId);
|
||||
var localObject = QNetworkServer.FindLocalObject(ParametersMessage.netId);
|
||||
if (localObject == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var component = localObject.GetComponent<QSBNetworkAnimator>();
|
||||
var reader = new QSBNetworkReader(ParametersMessage.parameters);
|
||||
var component = localObject.GetComponent<QNetworkAnimator>();
|
||||
var reader = new QNetworkReader(ParametersMessage.parameters);
|
||||
component?.HandleAnimParamsMsg(ParametersMessage, reader);
|
||||
QSBNetworkServer.SendToReady(localObject, 41, ParametersMessage);
|
||||
QNetworkServer.SendToReady(localObject, 41, ParametersMessage);
|
||||
}
|
||||
|
||||
internal static void OnAnimationTriggerServerMessage(QSBNetworkMessage netMsg)
|
||||
internal static void OnAnimationTriggerServerMessage(QNetworkMessage netMsg)
|
||||
{
|
||||
netMsg.ReadMessage(TriggersMessage);
|
||||
var localObject = QSBNetworkServer.FindLocalObject(TriggersMessage.netId);
|
||||
var localObject = QNetworkServer.FindLocalObject(TriggersMessage.netId);
|
||||
if (localObject == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var component = localObject.GetComponent<QSBNetworkAnimator>();
|
||||
var component = localObject.GetComponent<QNetworkAnimator>();
|
||||
component?.HandleAnimTriggerMsg(TriggersMessage.hash);
|
||||
QSBNetworkServer.SendToReady(localObject, 42, TriggersMessage);
|
||||
QNetworkServer.SendToReady(localObject, 42, TriggersMessage);
|
||||
}
|
||||
|
||||
internal static void OnAnimationClientMessage(QSBNetworkMessage netMsg)
|
||||
internal static void OnAnimationClientMessage(QNetworkMessage netMsg)
|
||||
{
|
||||
netMsg.ReadMessage(AnimationMessage);
|
||||
var localObject = QSBClientScene.FindLocalObject(AnimationMessage.netId);
|
||||
var localObject = QClientScene.FindLocalObject(AnimationMessage.netId);
|
||||
if (localObject == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var component = localObject.GetComponent<QSBNetworkAnimator>();
|
||||
var component = localObject.GetComponent<QNetworkAnimator>();
|
||||
if (component == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var reader = new QSBNetworkReader(AnimationMessage.parameters);
|
||||
var reader = new QNetworkReader(AnimationMessage.parameters);
|
||||
component.HandleAnimMsg(AnimationMessage, reader);
|
||||
}
|
||||
|
||||
internal static void OnAnimationParametersClientMessage(QSBNetworkMessage netMsg)
|
||||
internal static void OnAnimationParametersClientMessage(QNetworkMessage netMsg)
|
||||
{
|
||||
netMsg.ReadMessage(ParametersMessage);
|
||||
var localObject = QSBClientScene.FindLocalObject(ParametersMessage.netId);
|
||||
var localObject = QClientScene.FindLocalObject(ParametersMessage.netId);
|
||||
if (localObject == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var component = localObject.GetComponent<QSBNetworkAnimator>();
|
||||
var component = localObject.GetComponent<QNetworkAnimator>();
|
||||
if (component == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var reader = new QSBNetworkReader(ParametersMessage.parameters);
|
||||
var reader = new QNetworkReader(ParametersMessage.parameters);
|
||||
component.HandleAnimParamsMsg(ParametersMessage, reader);
|
||||
}
|
||||
|
||||
internal static void OnAnimationTriggerClientMessage(QSBNetworkMessage netMsg)
|
||||
internal static void OnAnimationTriggerClientMessage(QNetworkMessage netMsg)
|
||||
{
|
||||
netMsg.ReadMessage(TriggersMessage);
|
||||
var localObject = QSBClientScene.FindLocalObject(TriggersMessage.netId);
|
||||
var localObject = QClientScene.FindLocalObject(TriggersMessage.netId);
|
||||
if (localObject == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var component = localObject.GetComponent<QSBNetworkAnimator>();
|
||||
var component = localObject.GetComponent<QNetworkAnimator>();
|
||||
if (component == null)
|
||||
{
|
||||
return;
|
@ -1,4 +1,4 @@
|
||||
using OWML.Logging;
|
||||
using QuantumUNET.Logging;
|
||||
using QuantumUNET.Messages;
|
||||
using QuantumUNET.Transport;
|
||||
using System;
|
||||
@ -9,21 +9,21 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Components
|
||||
{
|
||||
public sealed class QSBNetworkIdentity : MonoBehaviour
|
||||
public sealed class QNetworkIdentity : MonoBehaviour
|
||||
{
|
||||
public bool IsClient { get; private set; }
|
||||
public bool IsServer => m_IsServer && QSBNetworkServer.active && m_IsServer;
|
||||
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 QSBNetworkConnection ClientAuthorityOwner { get; private set; }
|
||||
public QNetworkConnection ClientAuthorityOwner { get; private set; }
|
||||
public NetworkHash128 AssetId => m_AssetId;
|
||||
public bool IsLocalPlayer { get; private set; }
|
||||
public short PlayerControllerId { get; private set; } = -1;
|
||||
public QSBNetworkConnection ConnectionToServer { get; private set; }
|
||||
public QSBNetworkConnection ConnectionToClient { get; private set; }
|
||||
public QSBNetworkIdentity RootIdentity { get; private set; }
|
||||
public List<QSBNetworkIdentity> SubIdentities { get; private set; } = new List<QSBNetworkIdentity>();
|
||||
public QNetworkConnection ConnectionToServer { get; private set; }
|
||||
public QNetworkConnection ConnectionToClient { get; private set; }
|
||||
public QNetworkIdentity RootIdentity { get; private set; }
|
||||
public List<QNetworkIdentity> SubIdentities { get; private set; } = new List<QNetworkIdentity>();
|
||||
|
||||
public bool ServerOnly
|
||||
{
|
||||
@ -37,7 +37,7 @@ namespace QuantumUNET.Components
|
||||
set => m_LocalPlayerAuthority = value;
|
||||
}
|
||||
|
||||
public void SetRootIdentity(QSBNetworkIdentity newRoot)
|
||||
public void SetRootIdentity(QNetworkIdentity newRoot)
|
||||
{
|
||||
if (RootIdentity != null)
|
||||
{
|
||||
@ -47,10 +47,10 @@ namespace QuantumUNET.Components
|
||||
RootIdentity.AddSubIndentity(this);
|
||||
}
|
||||
|
||||
internal void AddSubIndentity(QSBNetworkIdentity identityToAdd)
|
||||
internal void AddSubIndentity(QNetworkIdentity identityToAdd)
|
||||
=> SubIdentities.Add(identityToAdd);
|
||||
|
||||
internal void RemoveSubIdentity(QSBNetworkIdentity identityToRemove)
|
||||
internal void RemoveSubIdentity(QNetworkIdentity identityToRemove)
|
||||
=> SubIdentities.Remove(identityToRemove);
|
||||
|
||||
internal void SetDynamicAssetId(NetworkHash128 newAssetId)
|
||||
@ -61,15 +61,15 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"SetDynamicAssetId object already has an assetId <{m_AssetId}>");
|
||||
QLog.LogWarning($"SetDynamicAssetId object already has an assetId <{m_AssetId}>");
|
||||
}
|
||||
}
|
||||
|
||||
internal void SetClientOwner(QSBNetworkConnection conn)
|
||||
internal void SetClientOwner(QNetworkConnection conn)
|
||||
{
|
||||
if (ClientAuthorityOwner != null)
|
||||
{
|
||||
Debug.LogError("SetClientOwner m_ClientAuthorityOwner already set!");
|
||||
QLog.LogError("SetClientOwner m_ClientAuthorityOwner already set!");
|
||||
}
|
||||
ClientAuthorityOwner = conn;
|
||||
ClientAuthorityOwner.AddOwnedObject(this);
|
||||
@ -93,18 +93,18 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<QSBNetworkConnection> Observers
|
||||
public ReadOnlyCollection<QNetworkConnection> Observers
|
||||
{
|
||||
get
|
||||
{
|
||||
ReadOnlyCollection<QSBNetworkConnection> result;
|
||||
ReadOnlyCollection<QNetworkConnection> result;
|
||||
if (m_Observers == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = new ReadOnlyCollection<QSBNetworkConnection>(m_Observers);
|
||||
result = new ReadOnlyCollection<QNetworkConnection>(m_Observers);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -121,7 +121,7 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
if (m_NetworkBehaviours == null)
|
||||
{
|
||||
m_NetworkBehaviours = GetComponents<QSBNetworkBehaviour>();
|
||||
m_NetworkBehaviours = GetComponents<QNetworkBehaviour>();
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,13 +153,13 @@ namespace QuantumUNET.Components
|
||||
internal void SetNotLocalPlayer()
|
||||
{
|
||||
IsLocalPlayer = false;
|
||||
if (!QSBNetworkServer.active || !QSBNetworkServer.localClientActive)
|
||||
if (!QNetworkServer.active || !QNetworkServer.localClientActive)
|
||||
{
|
||||
HasAuthority = false;
|
||||
}
|
||||
}
|
||||
|
||||
internal void RemoveObserverInternal(QSBNetworkConnection conn)
|
||||
internal void RemoveObserverInternal(QNetworkConnection conn)
|
||||
{
|
||||
if (m_Observers != null)
|
||||
{
|
||||
@ -170,9 +170,9 @@ namespace QuantumUNET.Components
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
if (m_IsServer && QSBNetworkServer.active)
|
||||
if (m_IsServer && QNetworkServer.active)
|
||||
{
|
||||
QSBNetworkServer.Destroy(gameObject);
|
||||
QNetworkServer.Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
@ -189,7 +189,7 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
HasAuthority = true;
|
||||
}
|
||||
m_Observers = new List<QSBNetworkConnection>();
|
||||
m_Observers = new List<QNetworkConnection>();
|
||||
m_ObserverConnections = new HashSet<int>();
|
||||
CacheBehaviours();
|
||||
if (NetId.IsEmpty())
|
||||
@ -198,10 +198,10 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
else if (!allowNonZeroNetId)
|
||||
{
|
||||
ModConsole.OwmlConsole.WriteLine($"Object has non-zero netId {NetId} for {gameObject}");
|
||||
QLog.LogWarning($"Object has non-zero netId {NetId} for {gameObject}");
|
||||
return;
|
||||
}
|
||||
QSBNetworkServer.instance.SetLocalObjectOnServer(NetId, gameObject);
|
||||
QNetworkServer.instance.SetLocalObjectOnServer(NetId, gameObject);
|
||||
foreach (var networkBehaviour in m_NetworkBehaviours)
|
||||
{
|
||||
try
|
||||
@ -210,12 +210,12 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"Exception in OnStartServer:{ex.Message} {ex.StackTrace}");
|
||||
QLog.LogFatalError($"Exception in OnStartServer:{ex.Message} {ex.StackTrace}");
|
||||
}
|
||||
}
|
||||
if (QSBNetworkClient.active && QSBNetworkServer.localClientActive)
|
||||
if (QNetworkClient.active && QNetworkServer.localClientActive)
|
||||
{
|
||||
QSBClientScene.SetLocalObject(NetId, gameObject);
|
||||
QClientScene.SetLocalObject(NetId, gameObject);
|
||||
OnStartClient();
|
||||
}
|
||||
if (HasAuthority)
|
||||
@ -232,7 +232,7 @@ namespace QuantumUNET.Components
|
||||
IsClient = true;
|
||||
}
|
||||
CacheBehaviours();
|
||||
Debug.Log($"OnStartClient {gameObject} GUID:{NetId} localPlayerAuthority:{LocalPlayerAuthority}");
|
||||
QLog.LogDebug($"OnStartClient {gameObject} GUID:{NetId} localPlayerAuthority:{LocalPlayerAuthority}");
|
||||
foreach (var networkBehaviour in m_NetworkBehaviours)
|
||||
{
|
||||
try
|
||||
@ -242,7 +242,7 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"Exception in OnStartClient:{ex.Message} {ex.StackTrace}");
|
||||
QLog.LogFatalError($"Exception in OnStartClient:{ex.Message} {ex.StackTrace}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -272,7 +272,7 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"Exception in OnStopAuthority:{ex.Message} {ex.StackTrace}");
|
||||
QLog.LogFatalError($"Exception in OnStopAuthority:{ex.Message} {ex.StackTrace}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -287,12 +287,12 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"Exception in OnSetLocalVisibility:{ex.Message} {ex.StackTrace}");
|
||||
QLog.LogFatalError($"Exception in OnSetLocalVisibility:{ex.Message} {ex.StackTrace}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal bool OnCheckObserver(QSBNetworkConnection conn)
|
||||
internal bool OnCheckObserver(QNetworkConnection conn)
|
||||
{
|
||||
foreach (var networkBehaviour in m_NetworkBehaviours)
|
||||
{
|
||||
@ -305,14 +305,14 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"Exception in OnCheckObserver:{ex.Message} {ex.StackTrace}");
|
||||
QLog.LogFatalError($"Exception in OnCheckObserver:{ex.Message} {ex.StackTrace}");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
internal void UNetSerializeAllVars(QSBNetworkWriter writer)
|
||||
internal void UNetSerializeAllVars(QNetworkWriter writer)
|
||||
{
|
||||
foreach (var networkBehaviour in m_NetworkBehaviours)
|
||||
{
|
||||
@ -324,7 +324,7 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
if (!LocalPlayerAuthority)
|
||||
{
|
||||
Debug.LogError($"HandleClientAuthority {gameObject} does not have localPlayerAuthority");
|
||||
QLog.LogError($"HandleClientAuthority {gameObject} does not have localPlayerAuthority");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -332,9 +332,9 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
private bool GetInvokeComponent(int cmdHash, Type invokeClass, out QSBNetworkBehaviour invokeComponent)
|
||||
private bool GetInvokeComponent(int cmdHash, Type invokeClass, out QNetworkBehaviour invokeComponent)
|
||||
{
|
||||
QSBNetworkBehaviour networkBehaviour = null;
|
||||
QNetworkBehaviour networkBehaviour = null;
|
||||
foreach (var networkBehaviour2 in m_NetworkBehaviours)
|
||||
{
|
||||
if (networkBehaviour2.GetType() == invokeClass || networkBehaviour2.GetType().IsSubclassOf(invokeClass))
|
||||
@ -346,8 +346,8 @@ namespace QuantumUNET.Components
|
||||
bool result;
|
||||
if (networkBehaviour == null)
|
||||
{
|
||||
var cmdHashHandlerName = QSBNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
Debug.LogError(
|
||||
var cmdHashHandlerName = QNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
QLog.LogFatalError(
|
||||
$"Found no behaviour for incoming [{cmdHashHandlerName}] on {gameObject}, the server and client should have the same NetworkBehaviour instances [netId={NetId}].");
|
||||
invokeComponent = null;
|
||||
result = false;
|
||||
@ -360,23 +360,23 @@ namespace QuantumUNET.Components
|
||||
return result;
|
||||
}
|
||||
|
||||
internal void HandleSyncEvent(int cmdHash, QSBNetworkReader reader)
|
||||
internal void HandleSyncEvent(int cmdHash, QNetworkReader reader)
|
||||
{
|
||||
if (gameObject == null)
|
||||
{
|
||||
var cmdHashHandlerName = QSBNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
Debug.LogWarning($"SyncEvent [{cmdHashHandlerName}] received for deleted object [netId={NetId}]");
|
||||
var cmdHashHandlerName = QNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
QLog.LogWarning($"SyncEvent [{cmdHashHandlerName}] received for deleted object [netId={NetId}]");
|
||||
}
|
||||
else if (!QSBNetworkBehaviour.GetInvokerForHashSyncEvent(cmdHash, out var invokeClass, out var cmdDelegate))
|
||||
else if (!QNetworkBehaviour.GetInvokerForHashSyncEvent(cmdHash, out var invokeClass, out var cmdDelegate))
|
||||
{
|
||||
var cmdHashHandlerName2 = QSBNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
Debug.LogError(
|
||||
var cmdHashHandlerName2 = QNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
QLog.LogFatalError(
|
||||
$"Found no receiver for incoming [{cmdHashHandlerName2}] on {gameObject}, the server and client should have the same NetworkBehaviour instances [netId={NetId}].");
|
||||
}
|
||||
else if (!GetInvokeComponent(cmdHash, invokeClass, out var obj))
|
||||
{
|
||||
var cmdHashHandlerName3 = QSBNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
Debug.LogWarning($"SyncEvent [{cmdHashHandlerName3}] handler not found [netId={NetId}]");
|
||||
var cmdHashHandlerName3 = QNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
QLog.LogWarning($"SyncEvent [{cmdHashHandlerName3}] handler not found [netId={NetId}]");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -384,23 +384,23 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
internal void HandleSyncList(int cmdHash, QSBNetworkReader reader)
|
||||
internal void HandleSyncList(int cmdHash, QNetworkReader reader)
|
||||
{
|
||||
if (gameObject == null)
|
||||
{
|
||||
var cmdHashHandlerName = QSBNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
Debug.LogWarning($"SyncList [{cmdHashHandlerName}] received for deleted object [netId={NetId}]");
|
||||
var cmdHashHandlerName = QNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
QLog.LogWarning($"SyncList [{cmdHashHandlerName}] received for deleted object [netId={NetId}]");
|
||||
}
|
||||
else if (!QSBNetworkBehaviour.GetInvokerForHashSyncList(cmdHash, out var invokeClass, out var cmdDelegate))
|
||||
else if (!QNetworkBehaviour.GetInvokerForHashSyncList(cmdHash, out var invokeClass, out var cmdDelegate))
|
||||
{
|
||||
var cmdHashHandlerName2 = QSBNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
Debug.LogError(
|
||||
var cmdHashHandlerName2 = QNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
QLog.LogFatalError(
|
||||
$"Found no receiver for incoming [{cmdHashHandlerName2}] on {gameObject}, the server and client should have the same NetworkBehaviour instances [netId={NetId}].");
|
||||
}
|
||||
else if (!GetInvokeComponent(cmdHash, invokeClass, out var obj))
|
||||
{
|
||||
var cmdHashHandlerName3 = QSBNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
Debug.LogWarning($"SyncList [{cmdHashHandlerName3}] handler not found [netId={NetId}]");
|
||||
var cmdHashHandlerName3 = QNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
QLog.LogWarning($"SyncList [{cmdHashHandlerName3}] handler not found [netId={NetId}]");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -408,23 +408,23 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
internal void HandleCommand(int cmdHash, QSBNetworkReader reader)
|
||||
internal void HandleCommand(int cmdHash, QNetworkReader reader)
|
||||
{
|
||||
if (gameObject == null)
|
||||
{
|
||||
var cmdHashHandlerName = QSBNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
Debug.LogWarning($"Command [{cmdHashHandlerName}] received for deleted object [netId={NetId}]");
|
||||
var cmdHashHandlerName = QNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
QLog.LogWarning($"Command [{cmdHashHandlerName}] received for deleted object [netId={NetId}]");
|
||||
}
|
||||
else if (!QSBNetworkBehaviour.GetInvokerForHashCommand(cmdHash, out var invokeClass, out var cmdDelegate))
|
||||
else if (!QNetworkBehaviour.GetInvokerForHashCommand(cmdHash, out var invokeClass, out var cmdDelegate))
|
||||
{
|
||||
var cmdHashHandlerName2 = QSBNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
Debug.LogError(
|
||||
var cmdHashHandlerName2 = QNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
QLog.LogFatalError(
|
||||
$"Found no receiver for incoming [{cmdHashHandlerName2}] on {gameObject}, the server and client should have the same NetworkBehaviour instances [netId={NetId}].");
|
||||
}
|
||||
else if (!GetInvokeComponent(cmdHash, invokeClass, out var obj))
|
||||
{
|
||||
var cmdHashHandlerName3 = QSBNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
Debug.LogWarning($"Command [{cmdHashHandlerName3}] handler not found [netId={NetId}]");
|
||||
var cmdHashHandlerName3 = QNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
QLog.LogWarning($"Command [{cmdHashHandlerName3}] handler not found [netId={NetId}]");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -432,23 +432,23 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
internal void HandleRPC(int cmdHash, QSBNetworkReader reader)
|
||||
internal void HandleRPC(int cmdHash, QNetworkReader reader)
|
||||
{
|
||||
if (gameObject == null)
|
||||
{
|
||||
var cmdHashHandlerName = QSBNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
Debug.LogWarning($"ClientRpc [{cmdHashHandlerName}] received for deleted object [netId={NetId}]");
|
||||
var cmdHashHandlerName = QNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
QLog.LogWarning($"ClientRpc [{cmdHashHandlerName}] received for deleted object [netId={NetId}]");
|
||||
}
|
||||
else if (!QSBNetworkBehaviour.GetInvokerForHashClientRpc(cmdHash, out var invokeClass, out var cmdDelegate))
|
||||
else if (!QNetworkBehaviour.GetInvokerForHashClientRpc(cmdHash, out var invokeClass, out var cmdDelegate))
|
||||
{
|
||||
var cmdHashHandlerName2 = QSBNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
Debug.LogError(
|
||||
var cmdHashHandlerName2 = QNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
QLog.LogFatalError(
|
||||
$"Found no receiver for incoming [{cmdHashHandlerName2}] on {gameObject}, the server and client should have the same NetworkBehaviour instances [netId={NetId}].");
|
||||
}
|
||||
else if (!GetInvokeComponent(cmdHash, invokeClass, out var obj))
|
||||
{
|
||||
var cmdHashHandlerName3 = QSBNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
Debug.LogWarning($"ClientRpc [{cmdHashHandlerName3}] handler not found [netId={NetId}]");
|
||||
var cmdHashHandlerName3 = QNetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
QLog.LogWarning($"ClientRpc [{cmdHashHandlerName3}] handler not found [netId={NetId}]");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -470,7 +470,7 @@ namespace QuantumUNET.Components
|
||||
if (num != 0U)
|
||||
{
|
||||
var j = 0;
|
||||
while (j < QSBNetworkServer.numChannels)
|
||||
while (j < QNetworkServer.numChannels)
|
||||
{
|
||||
if ((num & (1U << j)) != 0U)
|
||||
{
|
||||
@ -491,10 +491,10 @@ namespace QuantumUNET.Components
|
||||
networkBehaviour.ClearAllDirtyBits();
|
||||
flag = true;
|
||||
}
|
||||
var maxPacketSize = QSBNetworkServer.maxPacketSize;
|
||||
var maxPacketSize = QNetworkServer.maxPacketSize;
|
||||
if (s_UpdateWriter.Position - position > maxPacketSize)
|
||||
{
|
||||
Debug.LogWarning(
|
||||
QLog.LogWarning(
|
||||
$"Large state update of {s_UpdateWriter.Position - position} bytes for netId:{NetId} from script:{networkBehaviour}");
|
||||
}
|
||||
}
|
||||
@ -502,7 +502,7 @@ namespace QuantumUNET.Components
|
||||
if (flag)
|
||||
{
|
||||
s_UpdateWriter.FinishMessage();
|
||||
QSBNetworkServer.SendWriterToReady(gameObject, s_UpdateWriter, j);
|
||||
QNetworkServer.SendWriterToReady(gameObject, s_UpdateWriter, j);
|
||||
}
|
||||
}
|
||||
j++;
|
||||
@ -510,11 +510,11 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
internal void OnUpdateVars(QSBNetworkReader reader, bool initialState)
|
||||
internal void OnUpdateVars(QNetworkReader reader, bool initialState)
|
||||
{
|
||||
if (initialState && m_NetworkBehaviours == null)
|
||||
{
|
||||
m_NetworkBehaviours = GetComponents<QSBNetworkBehaviour>();
|
||||
m_NetworkBehaviours = GetComponents<QNetworkBehaviour>();
|
||||
}
|
||||
|
||||
foreach (var networkBehaviour in m_NetworkBehaviours)
|
||||
@ -542,9 +542,9 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
internal void SetConnectionToServer(QSBNetworkConnection conn) => ConnectionToServer = conn;
|
||||
internal void SetConnectionToServer(QNetworkConnection conn) => ConnectionToServer = conn;
|
||||
|
||||
internal void SetConnectionToClient(QSBNetworkConnection conn, short newPlayerControllerId)
|
||||
internal void SetConnectionToClient(QNetworkConnection conn, short newPlayerControllerId)
|
||||
{
|
||||
PlayerControllerId = newPlayerControllerId;
|
||||
ConnectionToClient = conn;
|
||||
@ -577,26 +577,26 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
internal void AddObserver(QSBNetworkConnection conn)
|
||||
internal void AddObserver(QNetworkConnection conn)
|
||||
{
|
||||
if (m_Observers == null)
|
||||
{
|
||||
Debug.LogError($"AddObserver for {gameObject} observer list is null");
|
||||
QLog.LogError($"AddObserver for {gameObject} observer list is null");
|
||||
}
|
||||
else if (m_ObserverConnections.Contains(conn.connectionId))
|
||||
{
|
||||
Debug.Log($"Duplicate observer {conn.address} added for {gameObject}");
|
||||
QLog.LogWarning($"Duplicate observer {conn.address} added for {gameObject}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"Added observer {conn.address} added for {gameObject}");
|
||||
QLog.LogDebug($"Added observer {conn.address} added for {gameObject}");
|
||||
m_Observers.Add(conn);
|
||||
m_ObserverConnections.Add(conn.connectionId);
|
||||
conn.AddToVisList(this);
|
||||
}
|
||||
}
|
||||
|
||||
internal void RemoveObserver(QSBNetworkConnection conn)
|
||||
internal void RemoveObserver(QNetworkConnection conn)
|
||||
{
|
||||
if (m_Observers != null)
|
||||
{
|
||||
@ -612,8 +612,8 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
var flag = false;
|
||||
var flag2 = false;
|
||||
var hashSet = new HashSet<QSBNetworkConnection>();
|
||||
var hashSet2 = new HashSet<QSBNetworkConnection>(m_Observers);
|
||||
var hashSet = new HashSet<QNetworkConnection>();
|
||||
var hashSet2 = new HashSet<QNetworkConnection>(m_Observers);
|
||||
foreach (var networkBehaviour in m_NetworkBehaviours)
|
||||
{
|
||||
flag2 |= networkBehaviour.OnRebuildObservers(hashSet, initialize);
|
||||
@ -622,7 +622,7 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
if (initialize)
|
||||
{
|
||||
foreach (var networkConnection in QSBNetworkServer.connections)
|
||||
foreach (var networkConnection in QNetworkServer.connections)
|
||||
{
|
||||
if (networkConnection != null)
|
||||
{
|
||||
@ -633,7 +633,7 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var networkConnection2 in QSBNetworkServer.localConnections)
|
||||
foreach (var networkConnection2 in QNetworkServer.localConnections)
|
||||
{
|
||||
if (networkConnection2 != null)
|
||||
{
|
||||
@ -653,12 +653,12 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
if (!networkConnection3.isReady)
|
||||
{
|
||||
Debug.LogWarning($"Observer is not ready for {gameObject} {networkConnection3}");
|
||||
QLog.LogWarning($"Observer is not ready for {gameObject} {networkConnection3}");
|
||||
}
|
||||
else if (initialize || !hashSet2.Contains(networkConnection3))
|
||||
{
|
||||
networkConnection3.AddToVisList(this);
|
||||
Debug.Log($"New Observer for {gameObject} {networkConnection3}");
|
||||
QLog.Log($"New Observer for {gameObject} {networkConnection3}");
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
@ -668,13 +668,13 @@ namespace QuantumUNET.Components
|
||||
if (!hashSet.Contains(networkConnection4))
|
||||
{
|
||||
networkConnection4.RemoveFromVisList(this, true);
|
||||
Debug.Log($"Removed Observer for {gameObject} {networkConnection4}");
|
||||
QLog.Log($"Removed Observer for {gameObject} {networkConnection4}");
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
if (initialize)
|
||||
{
|
||||
foreach (var connection in QSBNetworkServer.localConnections)
|
||||
foreach (var connection in QNetworkServer.localConnections)
|
||||
{
|
||||
if (!hashSet.Contains(connection))
|
||||
{
|
||||
@ -684,7 +684,7 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
m_Observers = new List<QSBNetworkConnection>(hashSet);
|
||||
m_Observers = new List<QNetworkConnection>(hashSet);
|
||||
m_ObserverConnections.Clear();
|
||||
foreach (var observer in m_Observers)
|
||||
{
|
||||
@ -695,32 +695,32 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
public bool RemoveClientAuthority(QSBNetworkConnection conn)
|
||||
public bool RemoveClientAuthority(QNetworkConnection conn)
|
||||
{
|
||||
if (!IsServer)
|
||||
{
|
||||
ModConsole.OwmlConsole.WriteLine($"Warning - Cannot remove authority on client-side. (NetId:{NetId}, Gameobject:{gameObject.name})");
|
||||
QLog.LogWarning($"Cannot remove authority on client-side. (NetId:{NetId}, Gameobject:{gameObject.name})");
|
||||
return false;
|
||||
}
|
||||
else if (ConnectionToClient != null)
|
||||
{
|
||||
Debug.LogError("RemoveClientAuthority cannot remove authority for a player object");
|
||||
QLog.LogWarning("RemoveClientAuthority cannot remove authority for a player object");
|
||||
return false;
|
||||
}
|
||||
else if (ClientAuthorityOwner == null)
|
||||
{
|
||||
Debug.LogError($"RemoveClientAuthority for {gameObject} has no clientAuthority owner.");
|
||||
QLog.LogWarning($"RemoveClientAuthority for {gameObject} has no clientAuthority owner.");
|
||||
return false;
|
||||
}
|
||||
else if (ClientAuthorityOwner != conn)
|
||||
{
|
||||
Debug.LogError($"RemoveClientAuthority for {gameObject} has different owner.");
|
||||
QLog.LogWarning($"RemoveClientAuthority for {gameObject} has different owner.");
|
||||
return false;
|
||||
}
|
||||
ClientAuthorityOwner.RemoveOwnedObject(this);
|
||||
ClientAuthorityOwner = null;
|
||||
ForceAuthority(true);
|
||||
conn.Send(15, new QSBClientAuthorityMessage
|
||||
conn.Send(15, new QClientAuthorityMessage
|
||||
{
|
||||
netId = NetId,
|
||||
authority = false
|
||||
@ -729,35 +729,33 @@ namespace QuantumUNET.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool AssignClientAuthority(QSBNetworkConnection conn)
|
||||
public bool AssignClientAuthority(QNetworkConnection conn)
|
||||
{
|
||||
if (!IsServer)
|
||||
{
|
||||
ModConsole.OwmlConsole.WriteLine($"Warning - Cannot assign authority on client-side. (NetId:{NetId}, Gameobject:{gameObject.name})");
|
||||
QLog.LogWarning($"Cannot assign authority on client-side. (NetId:{NetId}, Gameobject:{gameObject.name})");
|
||||
return false;
|
||||
}
|
||||
else if (!LocalPlayerAuthority)
|
||||
{
|
||||
ModConsole.OwmlConsole.WriteLine($"Warning - Cannot assign authority on object without LocalPlayerAuthority. (NetId:{NetId}, Gameobject:{gameObject.name})");
|
||||
QLog.LogWarning($"Cannot assign authority on object without LocalPlayerAuthority. (NetId:{NetId}, Gameobject:{gameObject.name})");
|
||||
return false;
|
||||
}
|
||||
else if (ClientAuthorityOwner != null && conn != ClientAuthorityOwner)
|
||||
{
|
||||
ModConsole.OwmlConsole.WriteLine(
|
||||
$"AssignClientAuthority for {gameObject} already has an owner. Use RemoveClientAuthority() first.");
|
||||
QLog.LogWarning($"AssignClientAuthority for {gameObject} already has an owner. Use RemoveClientAuthority() first.");
|
||||
return false;
|
||||
}
|
||||
else if (conn == null)
|
||||
{
|
||||
ModConsole.OwmlConsole.WriteLine(
|
||||
$"AssignClientAuthority for {gameObject} owner cannot be null. Use RemoveClientAuthority() instead.");
|
||||
QLog.LogWarning($"AssignClientAuthority for {gameObject} owner cannot be null. Use RemoveClientAuthority() instead.");
|
||||
return false;
|
||||
}
|
||||
ClientAuthorityOwner = conn;
|
||||
ClientAuthorityOwner.AddOwnedObject(this);
|
||||
|
||||
ForceAuthority(false);
|
||||
conn.Send(15, new QSBClientAuthorityMessage
|
||||
conn.Send(15, new QClientAuthorityMessage
|
||||
{
|
||||
netId = NetId,
|
||||
authority = true
|
||||
@ -789,9 +787,9 @@ namespace QuantumUNET.Components
|
||||
|
||||
public static void UNetStaticUpdate()
|
||||
{
|
||||
QSBNetworkServer.Update();
|
||||
QSBNetworkClient.UpdateClients();
|
||||
QSBNetworkManagerUNET.UpdateScene();
|
||||
QNetworkServer.Update();
|
||||
QNetworkClient.UpdateClients();
|
||||
QNetworkManager.UpdateScene();
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
@ -808,20 +806,20 @@ namespace QuantumUNET.Components
|
||||
|
||||
private bool m_IsServer;
|
||||
|
||||
private QSBNetworkBehaviour[] m_NetworkBehaviours;
|
||||
private QNetworkBehaviour[] m_NetworkBehaviours;
|
||||
|
||||
private HashSet<int> m_ObserverConnections;
|
||||
|
||||
private List<QSBNetworkConnection> m_Observers;
|
||||
private List<QNetworkConnection> m_Observers;
|
||||
|
||||
private bool m_Reset;
|
||||
|
||||
private static uint s_NextNetworkId = 1U;
|
||||
|
||||
private static readonly QSBNetworkWriter s_UpdateWriter = new QSBNetworkWriter();
|
||||
private static readonly QNetworkWriter s_UpdateWriter = new QNetworkWriter();
|
||||
|
||||
public static ClientAuthorityCallback clientAuthorityCallback;
|
||||
|
||||
public delegate void ClientAuthorityCallback(QSBNetworkConnection conn, QSBNetworkIdentity uv, bool authorityState);
|
||||
public delegate void ClientAuthorityCallback(QNetworkConnection conn, QNetworkIdentity uv, bool authorityState);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using OWML.Logging;
|
||||
using QuantumUNET.Logging;
|
||||
using QuantumUNET.Messages;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -8,9 +8,9 @@ using UnityEngine.SceneManagement;
|
||||
|
||||
namespace QuantumUNET.Components
|
||||
{
|
||||
public class QSBNetworkManagerUNET : MonoBehaviour
|
||||
public class QNetworkManager : MonoBehaviour
|
||||
{
|
||||
public static QSBNetworkManagerUNET singleton;
|
||||
public static QNetworkManager singleton;
|
||||
public static string networkSceneName = "";
|
||||
|
||||
public int networkPort { get; set; } = 7777;
|
||||
@ -32,7 +32,7 @@ namespace QuantumUNET.Components
|
||||
public float maxDelay { get; set; } = 0.01f;
|
||||
public GameObject playerPrefab { get; set; }
|
||||
public List<GameObject> spawnPrefabs { get; } = new List<GameObject>();
|
||||
public QSBNetworkClient client;
|
||||
public QNetworkClient client;
|
||||
public int maxConnections { get; set; } = 4;
|
||||
public List<QosType> channels { get; } = new List<QosType>();
|
||||
|
||||
@ -40,11 +40,11 @@ namespace QuantumUNET.Components
|
||||
private GlobalConfig m_GlobalConfig;
|
||||
private readonly int m_MaxBufferedPackets = 16;
|
||||
private readonly bool m_AllowFragmentation = true;
|
||||
private static readonly QSBAddPlayerMessage s_AddPlayerMessage = new QSBAddPlayerMessage();
|
||||
private static readonly QSBRemovePlayerMessage s_RemovePlayerMessage = new QSBRemovePlayerMessage();
|
||||
private static readonly QSBErrorMessage s_ErrorMessage = new QSBErrorMessage();
|
||||
private static readonly QAddPlayerMessage s_AddPlayerMessage = new QAddPlayerMessage();
|
||||
private static readonly QRemovePlayerMessage s_RemovePlayerMessage = new QRemovePlayerMessage();
|
||||
private static readonly QErrorMessage s_ErrorMessage = new QErrorMessage();
|
||||
private static AsyncOperation s_LoadingSceneAsync;
|
||||
private static QSBNetworkConnection s_ClientReadyConnection;
|
||||
private static QNetworkConnection s_ClientReadyConnection;
|
||||
private static string s_Address;
|
||||
|
||||
public bool customConfig { get; set; }
|
||||
@ -78,7 +78,7 @@ namespace QuantumUNET.Components
|
||||
get
|
||||
{
|
||||
var num = 0;
|
||||
foreach (var networkConnection in QSBNetworkServer.connections)
|
||||
foreach (var networkConnection in QNetworkServer.connections)
|
||||
{
|
||||
if (networkConnection != null)
|
||||
{
|
||||
@ -105,11 +105,11 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
if (singleton != null)
|
||||
{
|
||||
Debug.Log("Multiple NetworkManagers detected in the scene. Only one NetworkManager can exist at a time. The duplicate NetworkManager will not be used.");
|
||||
QLog.LogWarning("Multiple NetworkManagers detected in the scene. Only one NetworkManager can exist at a time. The duplicate NetworkManager will not be used.");
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
Debug.Log("NetworkManager created singleton (DontDestroyOnLoad)");
|
||||
QLog.Log("NetworkManager created singleton (DontDestroyOnLoad)");
|
||||
singleton = this;
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
@ -118,7 +118,7 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("NetworkManager created singleton (ForScene)");
|
||||
QLog.Log("NetworkManager created singleton (ForScene)");
|
||||
singleton = this;
|
||||
}
|
||||
if (networkAddress != "")
|
||||
@ -134,12 +134,12 @@ namespace QuantumUNET.Components
|
||||
|
||||
internal void RegisterServerMessages()
|
||||
{
|
||||
QSBNetworkServer.RegisterHandler(QSBMsgType.Connect, OnServerConnectInternal);
|
||||
QSBNetworkServer.RegisterHandler(QSBMsgType.Disconnect, OnServerDisconnectInternal);
|
||||
QSBNetworkServer.RegisterHandler(QSBMsgType.Ready, OnServerReadyMessageInternal);
|
||||
QSBNetworkServer.RegisterHandler(QSBMsgType.AddPlayer, OnServerAddPlayerMessageInternal);
|
||||
QSBNetworkServer.RegisterHandler(QSBMsgType.RemovePlayer, OnServerRemovePlayerMessageInternal);
|
||||
QSBNetworkServer.RegisterHandler(QSBMsgType.Error, OnServerErrorInternal);
|
||||
QNetworkServer.RegisterHandler(QMsgType.Connect, OnServerConnectInternal);
|
||||
QNetworkServer.RegisterHandler(QMsgType.Disconnect, OnServerDisconnectInternal);
|
||||
QNetworkServer.RegisterHandler(QMsgType.Ready, OnServerReadyMessageInternal);
|
||||
QNetworkServer.RegisterHandler(QMsgType.AddPlayer, OnServerAddPlayerMessageInternal);
|
||||
QNetworkServer.RegisterHandler(QMsgType.RemovePlayer, OnServerRemovePlayerMessageInternal);
|
||||
QNetworkServer.RegisterHandler(QMsgType.Error, OnServerErrorInternal);
|
||||
}
|
||||
|
||||
public bool StartServer() => StartServer(null, -1);
|
||||
@ -152,8 +152,8 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
Application.runInBackground = true;
|
||||
}
|
||||
QSBNetworkCRC.scriptCRCCheck = scriptCRCCheck;
|
||||
QSBNetworkServer.useWebSockets = useWebSockets;
|
||||
QNetworkCRC.scriptCRCCheck = scriptCRCCheck;
|
||||
QNetworkServer.useWebSockets = useWebSockets;
|
||||
if (m_GlobalConfig != null)
|
||||
{
|
||||
NetworkTransport.Init(m_GlobalConfig);
|
||||
@ -165,27 +165,27 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
m_ConnectionConfig.AddChannel(channel);
|
||||
}
|
||||
QSBNetworkServer.Configure(m_ConnectionConfig, this.maxConnections);
|
||||
QNetworkServer.Configure(m_ConnectionConfig, this.maxConnections);
|
||||
}
|
||||
if (config != null)
|
||||
{
|
||||
QSBNetworkServer.Configure(config, maxConnections);
|
||||
QNetworkServer.Configure(config, maxConnections);
|
||||
}
|
||||
if (serverBindToIP && !string.IsNullOrEmpty(serverBindAddress))
|
||||
{
|
||||
if (!QSBNetworkServer.Listen(serverBindAddress, networkPort))
|
||||
if (!QNetworkServer.Listen(serverBindAddress, networkPort))
|
||||
{
|
||||
Debug.LogError($"StartServer listen on {serverBindAddress} failed.");
|
||||
QLog.LogFatalError($"StartServer listen on {serverBindAddress} failed.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!QSBNetworkServer.Listen(networkPort))
|
||||
else if (!QNetworkServer.Listen(networkPort))
|
||||
{
|
||||
Debug.LogError("StartServer listen failed.");
|
||||
QLog.LogFatalError("StartServer listen failed.");
|
||||
return false;
|
||||
}
|
||||
RegisterServerMessages();
|
||||
Debug.Log($"NetworkManager StartServer port:{networkPort}");
|
||||
QLog.Log($"NetworkManager StartServer port:{networkPort}");
|
||||
isNetworkActive = true;
|
||||
var name = SceneManager.GetSceneAt(0).name;
|
||||
if (!string.IsNullOrEmpty(onlineScene) && onlineScene != name && onlineScene != offlineScene)
|
||||
@ -194,32 +194,32 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
else
|
||||
{
|
||||
QSBNetworkServer.SpawnObjects();
|
||||
QNetworkServer.SpawnObjects();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
internal void RegisterClientMessages(QSBNetworkClient client)
|
||||
internal void RegisterClientMessages(QNetworkClient client)
|
||||
{
|
||||
client.RegisterHandler(QSBMsgType.Connect, OnClientConnectInternal);
|
||||
client.RegisterHandler(QSBMsgType.Disconnect, OnClientDisconnectInternal);
|
||||
client.RegisterHandler(QSBMsgType.NotReady, OnClientNotReadyMessageInternal);
|
||||
client.RegisterHandler(QSBMsgType.Error, OnClientErrorInternal);
|
||||
client.RegisterHandler(QSBMsgType.Scene, OnClientSceneInternal);
|
||||
client.RegisterHandler(QMsgType.Connect, OnClientConnectInternal);
|
||||
client.RegisterHandler(QMsgType.Disconnect, OnClientDisconnectInternal);
|
||||
client.RegisterHandler(QMsgType.NotReady, OnClientNotReadyMessageInternal);
|
||||
client.RegisterHandler(QMsgType.Error, OnClientErrorInternal);
|
||||
client.RegisterHandler(QMsgType.Scene, OnClientSceneInternal);
|
||||
if (playerPrefab != null)
|
||||
{
|
||||
QSBClientScene.RegisterPrefab(playerPrefab);
|
||||
QClientScene.RegisterPrefab(playerPrefab);
|
||||
}
|
||||
foreach (var gameObject in spawnPrefabs)
|
||||
{
|
||||
if (gameObject != null)
|
||||
{
|
||||
QSBClientScene.RegisterPrefab(gameObject);
|
||||
QClientScene.RegisterPrefab(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UseExternalClient(QSBNetworkClient externalClient)
|
||||
public void UseExternalClient(QNetworkClient externalClient)
|
||||
{
|
||||
if (runInBackground)
|
||||
{
|
||||
@ -235,8 +235,8 @@ namespace QuantumUNET.Components
|
||||
else
|
||||
{
|
||||
OnStopClient();
|
||||
QSBClientScene.DestroyAllClientObjects();
|
||||
QSBClientScene.HandleClientDisconnect(client.connection);
|
||||
QClientScene.DestroyAllClientObjects();
|
||||
QClientScene.HandleClientDisconnect(client.connection);
|
||||
client = null;
|
||||
if (!string.IsNullOrEmpty(offlineScene))
|
||||
{
|
||||
@ -246,7 +246,7 @@ namespace QuantumUNET.Components
|
||||
s_Address = networkAddress;
|
||||
}
|
||||
|
||||
public QSBNetworkClient StartClient(ConnectionConfig config, int hostPort)
|
||||
public QNetworkClient StartClient(ConnectionConfig config, int hostPort)
|
||||
{
|
||||
InitializeSingleton();
|
||||
if (runInBackground)
|
||||
@ -258,7 +258,7 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
NetworkTransport.Init(m_GlobalConfig);
|
||||
}
|
||||
client = new QSBNetworkClient
|
||||
client = new QNetworkClient
|
||||
{
|
||||
hostPort = hostPort
|
||||
};
|
||||
@ -286,7 +286,7 @@ namespace QuantumUNET.Components
|
||||
RegisterClientMessages(client);
|
||||
if (string.IsNullOrEmpty(networkAddress))
|
||||
{
|
||||
ModConsole.OwmlConsole.WriteLine("Must set the Network Address field in the manager");
|
||||
QLog.LogError("Must set the Network Address field in the manager");
|
||||
return null;
|
||||
}
|
||||
if (useSimulator)
|
||||
@ -302,14 +302,14 @@ namespace QuantumUNET.Components
|
||||
return client;
|
||||
}
|
||||
|
||||
public QSBNetworkClient StartClient() => StartClient(null);
|
||||
public QNetworkClient StartClient() => StartClient(null);
|
||||
|
||||
public QSBNetworkClient StartClient(ConnectionConfig config) => StartClient(config, 0);
|
||||
public QNetworkClient StartClient(ConnectionConfig config) => StartClient(config, 0);
|
||||
|
||||
public virtual QSBNetworkClient StartHost(ConnectionConfig config, int maxConnections)
|
||||
public virtual QNetworkClient StartHost(ConnectionConfig config, int maxConnections)
|
||||
{
|
||||
OnStartHost();
|
||||
QSBNetworkClient result;
|
||||
QNetworkClient result;
|
||||
if (StartServer(config, maxConnections))
|
||||
{
|
||||
var networkClient = ConnectLocalClient();
|
||||
@ -324,10 +324,10 @@ namespace QuantumUNET.Components
|
||||
return result;
|
||||
}
|
||||
|
||||
public virtual QSBNetworkClient StartHost()
|
||||
public virtual QNetworkClient StartHost()
|
||||
{
|
||||
OnStartHost();
|
||||
QSBNetworkClient result;
|
||||
QNetworkClient result;
|
||||
if (StartServer())
|
||||
{
|
||||
var networkClient = ConnectLocalClient();
|
||||
@ -341,11 +341,11 @@ namespace QuantumUNET.Components
|
||||
return result;
|
||||
}
|
||||
|
||||
private QSBNetworkClient ConnectLocalClient()
|
||||
private QNetworkClient ConnectLocalClient()
|
||||
{
|
||||
Debug.Log($"NetworkManager StartHost port:{networkPort}");
|
||||
QLog.Log($"NetworkManager StartHost port:{networkPort}");
|
||||
networkAddress = "localhost";
|
||||
client = QSBClientScene.ConnectLocalServer();
|
||||
client = QClientScene.ConnectLocalServer();
|
||||
RegisterClientMessages(client);
|
||||
return client;
|
||||
}
|
||||
@ -359,12 +359,12 @@ namespace QuantumUNET.Components
|
||||
|
||||
public void StopServer()
|
||||
{
|
||||
if (QSBNetworkServer.active)
|
||||
if (QNetworkServer.active)
|
||||
{
|
||||
OnStopServer();
|
||||
Debug.Log("NetworkManager StopServer");
|
||||
QLog.Log("NetworkManager StopServer");
|
||||
isNetworkActive = false;
|
||||
QSBNetworkServer.Shutdown();
|
||||
QNetworkServer.Shutdown();
|
||||
if (!string.IsNullOrEmpty(offlineScene))
|
||||
{
|
||||
ServerChangeScene(offlineScene);
|
||||
@ -376,7 +376,7 @@ namespace QuantumUNET.Components
|
||||
public void StopClient()
|
||||
{
|
||||
OnStopClient();
|
||||
Debug.Log("NetworkManager StopClient");
|
||||
QLog.Log("NetworkManager StopClient");
|
||||
isNetworkActive = false;
|
||||
if (client != null)
|
||||
{
|
||||
@ -384,7 +384,7 @@ namespace QuantumUNET.Components
|
||||
client.Shutdown();
|
||||
client = null;
|
||||
}
|
||||
QSBClientScene.DestroyAllClientObjects();
|
||||
QClientScene.DestroyAllClientObjects();
|
||||
if (!string.IsNullOrEmpty(offlineScene))
|
||||
{
|
||||
ClientChangeScene(offlineScene, false);
|
||||
@ -396,22 +396,22 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
if (string.IsNullOrEmpty(newSceneName))
|
||||
{
|
||||
Debug.LogError("ServerChangeScene empty scene name");
|
||||
QLog.LogError("ServerChangeScene empty scene name");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"ServerChangeScene {newSceneName}");
|
||||
QSBNetworkServer.SetAllClientsNotReady();
|
||||
QLog.Log($"ServerChangeScene {newSceneName}");
|
||||
QNetworkServer.SetAllClientsNotReady();
|
||||
networkSceneName = newSceneName;
|
||||
s_LoadingSceneAsync = SceneManager.LoadSceneAsync(newSceneName);
|
||||
var msg = new QSBStringMessage(networkSceneName);
|
||||
QSBNetworkServer.SendToAll(39, msg);
|
||||
var msg = new QStringMessage(networkSceneName);
|
||||
QNetworkServer.SendToAll(39, msg);
|
||||
}
|
||||
}
|
||||
|
||||
private void CleanupNetworkIdentities()
|
||||
{
|
||||
foreach (var networkIdentity in Resources.FindObjectsOfTypeAll<QSBNetworkIdentity>())
|
||||
foreach (var networkIdentity in Resources.FindObjectsOfTypeAll<QNetworkIdentity>())
|
||||
{
|
||||
networkIdentity.MarkForReset();
|
||||
}
|
||||
@ -421,11 +421,11 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
if (string.IsNullOrEmpty(newSceneName))
|
||||
{
|
||||
Debug.LogError("ClientChangeScene empty scene name");
|
||||
QLog.LogError("ClientChangeScene empty scene name");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"ClientChangeScene newSceneName:{newSceneName} networkSceneName:{networkSceneName}");
|
||||
QLog.Log($"ClientChangeScene newSceneName:{newSceneName} networkSceneName:{networkSceneName}");
|
||||
if (newSceneName == networkSceneName)
|
||||
{
|
||||
if (!forceReload)
|
||||
@ -452,11 +452,11 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("FinishLoadScene client is null");
|
||||
QLog.LogError("FinishLoadScene client is null");
|
||||
}
|
||||
if (QSBNetworkServer.active)
|
||||
if (QNetworkServer.active)
|
||||
{
|
||||
QSBNetworkServer.SpawnObjects();
|
||||
QNetworkServer.SpawnObjects();
|
||||
OnServerSceneChanged(networkSceneName);
|
||||
}
|
||||
if (IsClientConnected() && client != null)
|
||||
@ -474,7 +474,7 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
if (s_LoadingSceneAsync.isDone)
|
||||
{
|
||||
ModConsole.OwmlConsole.WriteLine($"ClientChangeScene done readyCon:{s_ClientReadyConnection}");
|
||||
QLog.Log($"ClientChangeScene done readyCon:{s_ClientReadyConnection}");
|
||||
singleton.FinishLoadScene();
|
||||
s_LoadingSceneAsync.allowSceneActivation = true;
|
||||
s_LoadingSceneAsync = null;
|
||||
@ -495,47 +495,47 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
internal void OnServerConnectInternal(QSBNetworkMessage netMsg)
|
||||
internal void OnServerConnectInternal(QNetworkMessage netMsg)
|
||||
{
|
||||
Debug.Log("NetworkManager:OnServerConnectInternal");
|
||||
QLog.Log("NetworkManager:OnServerConnectInternal");
|
||||
netMsg.Connection.SetMaxDelay(maxDelay);
|
||||
if (m_MaxBufferedPackets != 512)
|
||||
{
|
||||
for (var i = 0; i < QSBNetworkServer.numChannels; i++)
|
||||
for (var i = 0; i < QNetworkServer.numChannels; i++)
|
||||
{
|
||||
netMsg.Connection.SetChannelOption(i, ChannelOption.MaxPendingBuffers, m_MaxBufferedPackets);
|
||||
}
|
||||
}
|
||||
if (!m_AllowFragmentation)
|
||||
{
|
||||
for (var j = 0; j < QSBNetworkServer.numChannels; j++)
|
||||
for (var j = 0; j < QNetworkServer.numChannels; j++)
|
||||
{
|
||||
netMsg.Connection.SetChannelOption(j, ChannelOption.AllowFragmentation, 0);
|
||||
}
|
||||
}
|
||||
if (networkSceneName != "" && networkSceneName != offlineScene)
|
||||
{
|
||||
var msg = new QSBStringMessage(networkSceneName);
|
||||
var msg = new QStringMessage(networkSceneName);
|
||||
netMsg.Connection.Send(39, msg);
|
||||
}
|
||||
OnServerConnect(netMsg.Connection);
|
||||
}
|
||||
|
||||
internal void OnServerDisconnectInternal(QSBNetworkMessage netMsg)
|
||||
internal void OnServerDisconnectInternal(QNetworkMessage netMsg)
|
||||
{
|
||||
Debug.Log("NetworkManager:OnServerDisconnectInternal");
|
||||
QLog.Log("NetworkManager:OnServerDisconnectInternal");
|
||||
OnServerDisconnect(netMsg.Connection);
|
||||
}
|
||||
|
||||
internal void OnServerReadyMessageInternal(QSBNetworkMessage netMsg)
|
||||
internal void OnServerReadyMessageInternal(QNetworkMessage netMsg)
|
||||
{
|
||||
Debug.Log("NetworkManager:OnServerReadyMessageInternal");
|
||||
QLog.Log("NetworkManager:OnServerReadyMessageInternal");
|
||||
OnServerReady(netMsg.Connection);
|
||||
}
|
||||
|
||||
internal void OnServerAddPlayerMessageInternal(QSBNetworkMessage netMsg)
|
||||
internal void OnServerAddPlayerMessageInternal(QNetworkMessage netMsg)
|
||||
{
|
||||
Debug.Log("NetworkManager:OnServerAddPlayerMessageInternal");
|
||||
QLog.Log("NetworkManager:OnServerAddPlayerMessageInternal");
|
||||
netMsg.ReadMessage(s_AddPlayerMessage);
|
||||
if (s_AddPlayerMessage.msgSize != 0)
|
||||
{
|
||||
@ -548,25 +548,25 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
internal void OnServerRemovePlayerMessageInternal(QSBNetworkMessage netMsg)
|
||||
internal void OnServerRemovePlayerMessageInternal(QNetworkMessage netMsg)
|
||||
{
|
||||
Debug.Log("NetworkManager:OnServerRemovePlayerMessageInternal");
|
||||
QLog.Log("NetworkManager:OnServerRemovePlayerMessageInternal");
|
||||
netMsg.ReadMessage(s_RemovePlayerMessage);
|
||||
netMsg.Connection.GetPlayerController(s_RemovePlayerMessage.PlayerControllerId, out var player);
|
||||
OnServerRemovePlayer(netMsg.Connection, player);
|
||||
netMsg.Connection.RemovePlayerController(s_RemovePlayerMessage.PlayerControllerId);
|
||||
}
|
||||
|
||||
internal void OnServerErrorInternal(QSBNetworkMessage netMsg)
|
||||
internal void OnServerErrorInternal(QNetworkMessage netMsg)
|
||||
{
|
||||
Debug.Log("NetworkManager:OnServerErrorInternal");
|
||||
QLog.Log("NetworkManager:OnServerErrorInternal");
|
||||
netMsg.ReadMessage(s_ErrorMessage);
|
||||
OnServerError(netMsg.Connection, s_ErrorMessage.errorCode);
|
||||
}
|
||||
|
||||
internal void OnClientConnectInternal(QSBNetworkMessage netMsg)
|
||||
internal void OnClientConnectInternal(QNetworkMessage netMsg)
|
||||
{
|
||||
Debug.Log("NetworkManager:OnClientConnectInternal");
|
||||
QLog.Log("NetworkManager:OnClientConnectInternal");
|
||||
netMsg.Connection.SetMaxDelay(maxDelay);
|
||||
var name = SceneManager.GetSceneAt(0).name;
|
||||
if (string.IsNullOrEmpty(onlineScene) || onlineScene == offlineScene || name == onlineScene)
|
||||
@ -580,9 +580,9 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
internal void OnClientDisconnectInternal(QSBNetworkMessage netMsg)
|
||||
internal void OnClientDisconnectInternal(QNetworkMessage netMsg)
|
||||
{
|
||||
Debug.Log("NetworkManager:OnClientDisconnectInternal");
|
||||
QLog.Log("NetworkManager:OnClientDisconnectInternal");
|
||||
if (!string.IsNullOrEmpty(offlineScene))
|
||||
{
|
||||
ClientChangeScene(offlineScene, false);
|
||||
@ -590,86 +590,86 @@ namespace QuantumUNET.Components
|
||||
OnClientDisconnect(netMsg.Connection);
|
||||
}
|
||||
|
||||
internal void OnClientNotReadyMessageInternal(QSBNetworkMessage netMsg)
|
||||
internal void OnClientNotReadyMessageInternal(QNetworkMessage netMsg)
|
||||
{
|
||||
Debug.Log("NetworkManager:OnClientNotReadyMessageInternal");
|
||||
QSBClientScene.SetNotReady();
|
||||
QLog.Log("NetworkManager:OnClientNotReadyMessageInternal");
|
||||
QClientScene.SetNotReady();
|
||||
OnClientNotReady(netMsg.Connection);
|
||||
}
|
||||
|
||||
internal void OnClientErrorInternal(QSBNetworkMessage netMsg)
|
||||
internal void OnClientErrorInternal(QNetworkMessage netMsg)
|
||||
{
|
||||
Debug.Log("NetworkManager:OnClientErrorInternal");
|
||||
QLog.Log("NetworkManager:OnClientErrorInternal");
|
||||
netMsg.ReadMessage(s_ErrorMessage);
|
||||
OnClientError(netMsg.Connection, s_ErrorMessage.errorCode);
|
||||
}
|
||||
|
||||
internal void OnClientSceneInternal(QSBNetworkMessage netMsg)
|
||||
internal void OnClientSceneInternal(QNetworkMessage netMsg)
|
||||
{
|
||||
Debug.Log("NetworkManager:OnClientSceneInternal");
|
||||
QLog.Log("NetworkManager:OnClientSceneInternal");
|
||||
var newSceneName = netMsg.Reader.ReadString();
|
||||
if (IsClientConnected() && !QSBNetworkServer.active)
|
||||
if (IsClientConnected() && !QNetworkServer.active)
|
||||
{
|
||||
ClientChangeScene(newSceneName, true);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnServerConnect(QSBNetworkConnection conn)
|
||||
public virtual void OnServerConnect(QNetworkConnection conn)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnServerDisconnect(QSBNetworkConnection conn)
|
||||
public virtual void OnServerDisconnect(QNetworkConnection conn)
|
||||
{
|
||||
QSBNetworkServer.DestroyPlayersForConnection(conn);
|
||||
QNetworkServer.DestroyPlayersForConnection(conn);
|
||||
if (conn.LastError != NetworkError.Ok)
|
||||
{
|
||||
Debug.LogError($"ServerDisconnected due to error: {conn.LastError}");
|
||||
QLog.LogError($"ServerDisconnected due to error: {conn.LastError}");
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnServerReady(QSBNetworkConnection conn)
|
||||
public virtual void OnServerReady(QNetworkConnection conn)
|
||||
{
|
||||
if (conn.PlayerControllers.Count == 0)
|
||||
{
|
||||
Debug.Log("Ready with no player object");
|
||||
QLog.LogWarning("Ready with no player object");
|
||||
}
|
||||
QSBNetworkServer.SetClientReady(conn);
|
||||
QNetworkServer.SetClientReady(conn);
|
||||
}
|
||||
|
||||
public virtual void OnServerAddPlayer(QSBNetworkConnection conn, short playerControllerId, NetworkReader extraMessageReader) => OnServerAddPlayerInternal(conn, playerControllerId);
|
||||
public virtual void OnServerAddPlayer(QNetworkConnection conn, short playerControllerId, NetworkReader extraMessageReader) => OnServerAddPlayerInternal(conn, playerControllerId);
|
||||
|
||||
public virtual void OnServerAddPlayer(QSBNetworkConnection conn, short playerControllerId) => OnServerAddPlayerInternal(conn, playerControllerId);
|
||||
public virtual void OnServerAddPlayer(QNetworkConnection conn, short playerControllerId) => OnServerAddPlayerInternal(conn, playerControllerId);
|
||||
|
||||
private void OnServerAddPlayerInternal(QSBNetworkConnection conn, short playerControllerId)
|
||||
private void OnServerAddPlayerInternal(QNetworkConnection conn, short playerControllerId)
|
||||
{
|
||||
if (playerPrefab == null)
|
||||
{
|
||||
ModConsole.OwmlConsole.WriteLine("Error - The PlayerPrefab is empty on the QSBNetworkManager. Please setup a PlayerPrefab object.");
|
||||
QLog.LogFatalError("The PlayerPrefab is empty on the QSBNetworkManager. Please setup a PlayerPrefab object.");
|
||||
}
|
||||
else if (playerPrefab.GetComponent<QSBNetworkIdentity>() == null)
|
||||
else if (playerPrefab.GetComponent<QNetworkIdentity>() == null)
|
||||
{
|
||||
ModConsole.OwmlConsole.WriteLine("Error - The PlayerPrefab does not have a QSBNetworkIdentity. Please add a QSBNetworkIdentity to the player prefab.");
|
||||
QLog.LogFatalError("The PlayerPrefab does not have a QSBNetworkIdentity. Please add a QSBNetworkIdentity to the player prefab.");
|
||||
}
|
||||
else if (playerControllerId < conn.PlayerControllers.Count && conn.PlayerControllers[playerControllerId].IsValid && conn.PlayerControllers[playerControllerId].Gameobject != null)
|
||||
{
|
||||
ModConsole.OwmlConsole.WriteLine("Warning - There is already a player at that playerControllerId for this connections.");
|
||||
QLog.LogWarning("There is already a player at that playerControllerId for this connections.");
|
||||
}
|
||||
else
|
||||
{
|
||||
var player = Instantiate(playerPrefab, Vector3.zero, Quaternion.identity);
|
||||
QSBNetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
|
||||
QNetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnServerRemovePlayer(QSBNetworkConnection conn, QSBPlayerController player)
|
||||
public virtual void OnServerRemovePlayer(QNetworkConnection conn, QPlayerController player)
|
||||
{
|
||||
if (player.Gameobject != null)
|
||||
{
|
||||
QSBNetworkServer.Destroy(player.Gameobject);
|
||||
QNetworkServer.Destroy(player.Gameobject);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnServerError(QSBNetworkConnection conn, int errorCode)
|
||||
public virtual void OnServerError(QNetworkConnection conn, int errorCode)
|
||||
{
|
||||
}
|
||||
|
||||
@ -677,43 +677,43 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnClientConnect(QSBNetworkConnection conn)
|
||||
public virtual void OnClientConnect(QNetworkConnection conn)
|
||||
{
|
||||
if (!clientLoadedScene)
|
||||
{
|
||||
QSBClientScene.Ready(conn);
|
||||
QClientScene.Ready(conn);
|
||||
if (autoCreatePlayer)
|
||||
{
|
||||
QSBClientScene.AddPlayer(0);
|
||||
QClientScene.AddPlayer(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnClientDisconnect(QSBNetworkConnection conn)
|
||||
public virtual void OnClientDisconnect(QNetworkConnection conn)
|
||||
{
|
||||
StopClient();
|
||||
if (conn.LastError != NetworkError.Ok)
|
||||
{
|
||||
Debug.LogError($"ClientDisconnected due to error: {conn.LastError}");
|
||||
QLog.LogError($"ClientDisconnected due to error: {conn.LastError}");
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnClientError(QSBNetworkConnection conn, int errorCode)
|
||||
public virtual void OnClientError(QNetworkConnection conn, int errorCode)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnClientNotReady(QSBNetworkConnection conn)
|
||||
public virtual void OnClientNotReady(QNetworkConnection conn)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnClientSceneChanged(QSBNetworkConnection conn)
|
||||
public virtual void OnClientSceneChanged(QNetworkConnection conn)
|
||||
{
|
||||
QSBClientScene.Ready(conn);
|
||||
QClientScene.Ready(conn);
|
||||
if (autoCreatePlayer)
|
||||
{
|
||||
var flag = QSBClientScene.localPlayers.Count == 0;
|
||||
var flag = QClientScene.localPlayers.Count == 0;
|
||||
var flag2 = false;
|
||||
foreach (var player in QSBClientScene.localPlayers)
|
||||
foreach (var player in QClientScene.localPlayers)
|
||||
{
|
||||
if (player.Gameobject != null)
|
||||
{
|
||||
@ -727,7 +727,7 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
QSBClientScene.AddPlayer(0);
|
||||
QClientScene.AddPlayer(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -740,7 +740,7 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnStartClient(QSBNetworkClient client)
|
||||
public virtual void OnStartClient(QNetworkClient client)
|
||||
{
|
||||
}
|
||||
|
@ -2,14 +2,14 @@
|
||||
|
||||
namespace QuantumUNET.Components
|
||||
{
|
||||
public class QSBNetworkManagerHUD : MonoBehaviour
|
||||
public class QNetworkManagerHUD : MonoBehaviour
|
||||
{
|
||||
public QSBNetworkManagerUNET manager;
|
||||
public QNetworkManager manager;
|
||||
public bool showGUI = true;
|
||||
public int offsetX;
|
||||
public int offsetY;
|
||||
|
||||
private void Awake() => manager = GetComponent<QSBNetworkManagerUNET>();
|
||||
private void Awake() => manager = GetComponent<QNetworkManager>();
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
@ -18,7 +18,7 @@ namespace QuantumUNET.Components
|
||||
var num = 10 + offsetX;
|
||||
var num2 = 40 + offsetY;
|
||||
var flag = manager.client == null || manager.client.connection == null || manager.client.connection.connectionId == -1;
|
||||
if (!manager.IsClientConnected() && !QSBNetworkServer.active)
|
||||
if (!manager.IsClientConnected() && !QNetworkServer.active)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
@ -50,7 +50,7 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
else
|
||||
{
|
||||
if (QSBNetworkServer.active)
|
||||
if (QNetworkServer.active)
|
||||
{
|
||||
var text = $"Hosting on port {manager.networkPort}";
|
||||
if (manager.useWebSockets)
|
||||
@ -66,19 +66,19 @@ namespace QuantumUNET.Components
|
||||
num2 += 24;
|
||||
}
|
||||
}
|
||||
if (manager.IsClientConnected() && !QSBClientScene.ready)
|
||||
if (manager.IsClientConnected() && !QClientScene.ready)
|
||||
{
|
||||
if (GUI.Button(new Rect(num, num2, 200f, 20f), "Client Ready"))
|
||||
{
|
||||
QSBClientScene.Ready(manager.client.connection);
|
||||
if (QSBClientScene.localPlayers.Count == 0)
|
||||
QClientScene.Ready(manager.client.connection);
|
||||
if (QClientScene.localPlayers.Count == 0)
|
||||
{
|
||||
QSBClientScene.AddPlayer(0);
|
||||
QClientScene.AddPlayer(0);
|
||||
}
|
||||
}
|
||||
num2 += 24;
|
||||
}
|
||||
if (QSBNetworkServer.active || manager.IsClientConnected())
|
||||
if (QNetworkServer.active || manager.IsClientConnected())
|
||||
{
|
||||
if (GUI.Button(new Rect(num, num2, 200f, 20f), "Stop"))
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
using OWML.Logging;
|
||||
using QuantumUNET.Logging;
|
||||
using QuantumUNET.Messages;
|
||||
using QuantumUNET.Transport;
|
||||
using UnityEngine;
|
||||
@ -6,7 +6,7 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Components
|
||||
{
|
||||
public class QSBNetworkTransform : QSBNetworkBehaviour
|
||||
public class QNetworkTransform : QNetworkBehaviour
|
||||
{
|
||||
public float SendInterval { get; set; } = 0.1f;
|
||||
public AxisSyncMode SyncRotationAxis { get; set; } = AxisSyncMode.AxisXYZ;
|
||||
@ -20,13 +20,13 @@ namespace QuantumUNET.Components
|
||||
m_PrevRotation = transform.rotation;
|
||||
if (LocalPlayerAuthority)
|
||||
{
|
||||
m_LocalTransformWriter = new QSBNetworkWriter();
|
||||
m_LocalTransformWriter = new QNetworkWriter();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnStartServer() => LastSyncTime = 0f;
|
||||
|
||||
public override bool OnSerialize(QSBNetworkWriter writer, bool initialState)
|
||||
public override bool OnSerialize(QNetworkWriter writer, bool initialState)
|
||||
{
|
||||
if (!initialState)
|
||||
{
|
||||
@ -41,7 +41,7 @@ namespace QuantumUNET.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
private void SerializeModeTransform(QSBNetworkWriter writer)
|
||||
private void SerializeModeTransform(QNetworkWriter writer)
|
||||
{
|
||||
writer.Write(transform.position);
|
||||
if (SyncRotationAxis != AxisSyncMode.None)
|
||||
@ -52,9 +52,9 @@ namespace QuantumUNET.Components
|
||||
m_PrevRotation = transform.rotation;
|
||||
}
|
||||
|
||||
public override void OnDeserialize(QSBNetworkReader reader, bool initialState)
|
||||
public override void OnDeserialize(QNetworkReader reader, bool initialState)
|
||||
{
|
||||
if (!IsServer || !QSBNetworkServer.localClientActive)
|
||||
if (!IsServer || !QNetworkServer.localClientActive)
|
||||
{
|
||||
if (!initialState)
|
||||
{
|
||||
@ -68,7 +68,7 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
private void UnserializeModeTransform(QSBNetworkReader reader, bool initialState)
|
||||
private void UnserializeModeTransform(QNetworkReader reader, bool initialState)
|
||||
{
|
||||
if (HasAuthority)
|
||||
{
|
||||
@ -118,7 +118,7 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
if (SyncVarDirtyBits == 0U)
|
||||
{
|
||||
if (QSBNetworkServer.active)
|
||||
if (QNetworkServer.active)
|
||||
{
|
||||
if (IsServer)
|
||||
{
|
||||
@ -140,7 +140,7 @@ namespace QuantumUNET.Components
|
||||
{
|
||||
if (LocalPlayerAuthority)
|
||||
{
|
||||
if (!QSBNetworkServer.active)
|
||||
if (!QNetworkServer.active)
|
||||
{
|
||||
if (Time.time - m_LastClientSendTime > GetNetworkSendInterval())
|
||||
{
|
||||
@ -178,7 +178,7 @@ namespace QuantumUNET.Components
|
||||
[Client]
|
||||
private void SendTransform()
|
||||
{
|
||||
if (HasMoved() && QSBClientScene.readyConnection != null)
|
||||
if (HasMoved() && QClientScene.readyConnection != null)
|
||||
{
|
||||
m_LocalTransformWriter.StartMessage(6);
|
||||
m_LocalTransformWriter.Write(NetId);
|
||||
@ -186,32 +186,32 @@ namespace QuantumUNET.Components
|
||||
m_PrevPosition = transform.position;
|
||||
m_PrevRotation = transform.rotation;
|
||||
m_LocalTransformWriter.FinishMessage();
|
||||
QSBClientScene.readyConnection.SendWriter(m_LocalTransformWriter, GetNetworkChannel());
|
||||
QClientScene.readyConnection.SendWriter(m_LocalTransformWriter, GetNetworkChannel());
|
||||
}
|
||||
}
|
||||
|
||||
public static void HandleTransform(QSBNetworkMessage netMsg)
|
||||
public static void HandleTransform(QNetworkMessage netMsg)
|
||||
{
|
||||
var networkInstanceId = netMsg.Reader.ReadNetworkId();
|
||||
var gameObject = QSBNetworkServer.FindLocalObject(networkInstanceId);
|
||||
var gameObject = QNetworkServer.FindLocalObject(networkInstanceId);
|
||||
if (gameObject == null)
|
||||
{
|
||||
ModConsole.OwmlConsole.WriteLine("Warning - Received NetworkTransform data for GameObject that doesn't exist");
|
||||
QLog.LogWarning("Received NetworkTransform data for GameObject that doesn't exist");
|
||||
}
|
||||
else
|
||||
{
|
||||
var component = gameObject.GetComponent<QSBNetworkTransform>();
|
||||
var component = gameObject.GetComponent<QNetworkTransform>();
|
||||
if (component == null)
|
||||
{
|
||||
ModConsole.OwmlConsole.WriteLine("Warning - HandleTransform null target");
|
||||
QLog.LogWarning("HandleTransform null target");
|
||||
}
|
||||
else if (!component.LocalPlayerAuthority)
|
||||
{
|
||||
ModConsole.OwmlConsole.WriteLine("Warning - HandleTransform no localPlayerAuthority");
|
||||
QLog.LogWarning("HandleTransform no localPlayerAuthority");
|
||||
}
|
||||
else if (netMsg.Connection.ClientOwnedObjects == null)
|
||||
{
|
||||
ModConsole.OwmlConsole.WriteLine("Warning - HandleTransform object not owned by connection");
|
||||
QLog.LogWarning("HandleTransform object not owned by connection");
|
||||
}
|
||||
else if (netMsg.Connection.ClientOwnedObjects.Contains(networkInstanceId))
|
||||
{
|
||||
@ -220,13 +220,13 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
else
|
||||
{
|
||||
ModConsole.OwmlConsole.WriteLine(
|
||||
$"Warning - HandleTransform netId:{networkInstanceId} is not for a valid player");
|
||||
QLog.LogWarning(
|
||||
$"HandleTransform netId:{networkInstanceId} is not for a valid player");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteAngle(QSBNetworkWriter writer, float angle, CompressionSyncMode compression)
|
||||
private static void WriteAngle(QNetworkWriter writer, float angle, CompressionSyncMode compression)
|
||||
{
|
||||
if (compression != CompressionSyncMode.None)
|
||||
{
|
||||
@ -248,7 +248,7 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
private static float ReadAngle(QSBNetworkReader reader, CompressionSyncMode compression)
|
||||
private static float ReadAngle(QNetworkReader reader, CompressionSyncMode compression)
|
||||
{
|
||||
float result;
|
||||
if (compression != CompressionSyncMode.None)
|
||||
@ -276,10 +276,10 @@ namespace QuantumUNET.Components
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void SerializeVelocity3D(QSBNetworkWriter writer, Vector3 velocity, CompressionSyncMode compression) =>
|
||||
public static void SerializeVelocity3D(QNetworkWriter writer, Vector3 velocity, CompressionSyncMode compression) =>
|
||||
writer.Write(velocity);
|
||||
|
||||
public static void SerializeRotation3D(QSBNetworkWriter writer, Quaternion rot, AxisSyncMode mode, CompressionSyncMode compression)
|
||||
public static void SerializeRotation3D(QNetworkWriter writer, Quaternion rot, AxisSyncMode mode, CompressionSyncMode compression)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
@ -318,7 +318,7 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
public static void SerializeSpin3D(QSBNetworkWriter writer, Vector3 angularVelocity, AxisSyncMode mode, CompressionSyncMode compression)
|
||||
public static void SerializeSpin3D(QNetworkWriter writer, Vector3 angularVelocity, AxisSyncMode mode, CompressionSyncMode compression)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
@ -357,9 +357,9 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector3 UnserializeVelocity3D(QSBNetworkReader reader, CompressionSyncMode compression) => reader.ReadVector3();
|
||||
public static Vector3 UnserializeVelocity3D(QNetworkReader reader, CompressionSyncMode compression) => reader.ReadVector3();
|
||||
|
||||
public static Quaternion UnserializeRotation3D(QSBNetworkReader reader, AxisSyncMode mode, CompressionSyncMode compression)
|
||||
public static Quaternion UnserializeRotation3D(QNetworkReader reader, AxisSyncMode mode, CompressionSyncMode compression)
|
||||
{
|
||||
var identity = Quaternion.identity;
|
||||
var zero = Vector3.zero;
|
||||
@ -403,7 +403,7 @@ namespace QuantumUNET.Components
|
||||
return identity;
|
||||
}
|
||||
|
||||
public static Vector3 UnserializeSpin3D(QSBNetworkReader reader, AxisSyncMode mode, CompressionSyncMode compression)
|
||||
public static Vector3 UnserializeSpin3D(QNetworkReader reader, AxisSyncMode mode, CompressionSyncMode compression)
|
||||
{
|
||||
var zero = Vector3.zero;
|
||||
switch (mode)
|
||||
@ -451,7 +451,7 @@ namespace QuantumUNET.Components
|
||||
|
||||
private Quaternion m_PrevRotation;
|
||||
|
||||
private QSBNetworkWriter m_LocalTransformWriter;
|
||||
private QNetworkWriter m_LocalTransformWriter;
|
||||
|
||||
public enum AxisSyncMode
|
||||
{
|
31
QuantumUNET/Logging/FlagsHelper.cs
Normal file
31
QuantumUNET/Logging/FlagsHelper.cs
Normal file
@ -0,0 +1,31 @@
|
||||
namespace QuantumUNET.Logging
|
||||
{
|
||||
// Stolen from here : https://stackoverflow.com/questions/3261451/using-a-bitmask-in-c-sharp
|
||||
|
||||
public static class FlagsHelper
|
||||
{
|
||||
public static bool IsSet<T>(T flags, T flag) where T : struct
|
||||
{
|
||||
var flagsValue = (int)(object)flags;
|
||||
var flagValue = (int)(object)flag;
|
||||
|
||||
return (flagsValue & flagValue) != 0;
|
||||
}
|
||||
|
||||
public static void Set<T>(ref T flags, T flag) where T : struct
|
||||
{
|
||||
var flagsValue = (int)(object)flags;
|
||||
var flagValue = (int)(object)flag;
|
||||
|
||||
flags = (T)(object)(flagsValue | flagValue);
|
||||
}
|
||||
|
||||
public static void Unset<T>(ref T flags, T flag) where T : struct
|
||||
{
|
||||
var flagsValue = (int)(object)flags;
|
||||
var flagValue = (int)(object)flag;
|
||||
|
||||
flags = (T)(object)(flagsValue & ~flagValue);
|
||||
}
|
||||
}
|
||||
}
|
67
QuantumUNET/Logging/QLog.cs
Normal file
67
QuantumUNET/Logging/QLog.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace QuantumUNET.Logging
|
||||
{
|
||||
public static class QLog
|
||||
{
|
||||
private static QLogType LogType = QLogType.Warning | QLogType.Error | QLogType.FatalError;
|
||||
|
||||
public static void SetLogType(QLogType flags)
|
||||
=> LogType = flags;
|
||||
|
||||
public static void SetSpecifcLogType(QLogType flag, bool state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
FlagsHelper.Set(ref LogType, flag);
|
||||
return;
|
||||
}
|
||||
FlagsHelper.Unset(ref LogType, flag);
|
||||
}
|
||||
|
||||
public static void LogDebug(string message)
|
||||
{
|
||||
if (!FlagsHelper.IsSet(LogType, QLogType.Debug))
|
||||
{
|
||||
return;
|
||||
}
|
||||
Debug.Log($"DEBUG : {message}");
|
||||
}
|
||||
|
||||
public static void Log(string message)
|
||||
{
|
||||
if (!FlagsHelper.IsSet(LogType, QLogType.Log))
|
||||
{
|
||||
return;
|
||||
}
|
||||
Debug.Log($"LOG : {message}");
|
||||
}
|
||||
|
||||
public static void LogWarning(string message)
|
||||
{
|
||||
if (!FlagsHelper.IsSet(LogType, QLogType.Warning))
|
||||
{
|
||||
return;
|
||||
}
|
||||
Debug.LogWarning($"WARN : {message}");
|
||||
}
|
||||
|
||||
public static void LogError(string message)
|
||||
{
|
||||
if (!FlagsHelper.IsSet(LogType, QLogType.Error))
|
||||
{
|
||||
return;
|
||||
}
|
||||
Debug.LogError($"ERROR : {message}");
|
||||
}
|
||||
|
||||
public static void LogFatalError(string message)
|
||||
{
|
||||
if (!FlagsHelper.IsSet(LogType, QLogType.FatalError))
|
||||
{
|
||||
return;
|
||||
}
|
||||
Debug.LogError($"FATAL : {message}");
|
||||
}
|
||||
}
|
||||
}
|
14
QuantumUNET/Logging/QLogType.cs
Normal file
14
QuantumUNET/Logging/QLogType.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace QuantumUNET.Logging
|
||||
{
|
||||
[Flags]
|
||||
public enum QLogType
|
||||
{
|
||||
Debug,
|
||||
Log,
|
||||
Warning,
|
||||
Error,
|
||||
FatalError
|
||||
}
|
||||
}
|
@ -2,19 +2,19 @@
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QSBAddPlayerMessage : QSBMessageBase
|
||||
internal class QAddPlayerMessage : QMessageBase
|
||||
{
|
||||
public short playerControllerId;
|
||||
public int msgSize;
|
||||
public byte[] msgData;
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
writer.Write(playerControllerId);
|
||||
writer.WriteBytesAndSize(msgData, msgSize);
|
||||
}
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
playerControllerId = reader.ReadInt16();
|
||||
msgData = reader.ReadBytesAndSize();
|
@ -3,14 +3,14 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QSBAnimationMessage : QSBMessageBase
|
||||
internal class QAnimationMessage : QMessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public int stateHash;
|
||||
public float normalizedTime;
|
||||
public byte[] parameters;
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
writer.Write(netId);
|
||||
writer.WritePackedUInt32((uint)stateHash);
|
||||
@ -18,7 +18,7 @@ namespace QuantumUNET.Messages
|
||||
writer.WriteBytesAndSize(parameters, parameters?.Length ?? 0);
|
||||
}
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
netId = reader.ReadNetworkId();
|
||||
stateHash = (int)reader.ReadPackedUInt32();
|
@ -3,18 +3,18 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QSBAnimationParametersMessage : QSBMessageBase
|
||||
internal class QAnimationParametersMessage : QMessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public byte[] parameters;
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
netId = reader.ReadNetworkId();
|
||||
parameters = reader.ReadBytesAndSize();
|
||||
}
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
writer.Write(netId);
|
||||
writer.WriteBytesAndSize(parameters, parameters?.Length ?? 0);
|
@ -3,18 +3,18 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QSBAnimationTriggerMessage : QSBMessageBase
|
||||
internal class QAnimationTriggerMessage : QMessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public int hash;
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
netId = reader.ReadNetworkId();
|
||||
hash = (int)reader.ReadPackedUInt32();
|
||||
}
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
writer.Write(netId);
|
||||
writer.WritePackedUInt32((uint)hash);
|
@ -2,24 +2,24 @@
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QSBCRCMessage : QSBMessageBase
|
||||
internal class QCRCMessage : QMessageBase
|
||||
{
|
||||
public QSBCRCMessageEntry[] scripts;
|
||||
public QCRCMessageEntry[] scripts;
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
var num = (int)reader.ReadUInt16();
|
||||
scripts = new QSBCRCMessageEntry[num];
|
||||
scripts = new QCRCMessageEntry[num];
|
||||
for (var i = 0; i < scripts.Length; i++)
|
||||
{
|
||||
var crcmessageEntry = default(QSBCRCMessageEntry);
|
||||
var crcmessageEntry = default(QCRCMessageEntry);
|
||||
crcmessageEntry.name = reader.ReadString();
|
||||
crcmessageEntry.channel = reader.ReadByte();
|
||||
scripts[i] = crcmessageEntry;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
writer.Write((ushort)scripts.Length);
|
||||
for (var i = 0; i < scripts.Length; i++)
|
@ -3,18 +3,18 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QSBClientAuthorityMessage : QSBMessageBase
|
||||
internal class QClientAuthorityMessage : QMessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public bool authority;
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
netId = reader.ReadNetworkId();
|
||||
authority = reader.ReadBoolean();
|
||||
}
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
writer.Write(netId);
|
||||
writer.Write(authority);
|
10
QuantumUNET/Messages/QEmptyMessage.cs
Normal file
10
QuantumUNET/Messages/QEmptyMessage.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using QuantumUNET.Transport;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
public class QEmptyMessage : QMessageBase
|
||||
{
|
||||
public override void Serialize(QNetworkWriter writer) { }
|
||||
public override void Deserialize(QNetworkReader reader) { }
|
||||
}
|
||||
}
|
13
QuantumUNET/Messages/QErrorMessage.cs
Normal file
13
QuantumUNET/Messages/QErrorMessage.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using QuantumUNET.Transport;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
public class QErrorMessage : QMessageBase
|
||||
{
|
||||
public int errorCode;
|
||||
|
||||
public override void Serialize(QNetworkWriter writer) => writer.Write((ushort)errorCode);
|
||||
|
||||
public override void Deserialize(QNetworkReader reader) => errorCode = reader.ReadUInt16();
|
||||
}
|
||||
}
|
11
QuantumUNET/Messages/QMessageBase.cs
Normal file
11
QuantumUNET/Messages/QMessageBase.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using QuantumUNET.Transport;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
public abstract class QMessageBase
|
||||
{
|
||||
public virtual void Serialize(QNetworkWriter writer) { }
|
||||
|
||||
public virtual void Deserialize(QNetworkReader reader) { }
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
public class QSBMsgType
|
||||
public class QMsgType
|
||||
{
|
||||
public static string MsgTypeToString(short value)
|
||||
{
|
@ -3,21 +3,21 @@ using System;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
public class QSBNetworkMessage
|
||||
public class QNetworkMessage
|
||||
{
|
||||
public short MsgType;
|
||||
public QSBNetworkConnection Connection;
|
||||
public QSBNetworkReader Reader;
|
||||
public QNetworkConnection Connection;
|
||||
public QNetworkReader Reader;
|
||||
public int ChannelId;
|
||||
|
||||
public TMsg ReadMessage<TMsg>() where TMsg : QSBMessageBase, new()
|
||||
public TMsg ReadMessage<TMsg>() where TMsg : QMessageBase, new()
|
||||
{
|
||||
var result = Activator.CreateInstance<TMsg>();
|
||||
result.Deserialize(Reader);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void ReadMessage<TMsg>(TMsg msg) where TMsg : QSBMessageBase =>
|
||||
public void ReadMessage<TMsg>(TMsg msg) where TMsg : QMessageBase =>
|
||||
msg.Deserialize(Reader);
|
||||
}
|
||||
}
|
4
QuantumUNET/Messages/QNetworkMessageDelegate.cs
Normal file
4
QuantumUNET/Messages/QNetworkMessageDelegate.cs
Normal file
@ -0,0 +1,4 @@
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
public delegate void QNetworkMessageDelegate(QNetworkMessage netMsg);
|
||||
}
|
6
QuantumUNET/Messages/QNotReadyMessage.cs
Normal file
6
QuantumUNET/Messages/QNotReadyMessage.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
public class QNotReadyMessage : QEmptyMessage
|
||||
{
|
||||
}
|
||||
}
|
14
QuantumUNET/Messages/QObjectDestroyMessage.cs
Normal file
14
QuantumUNET/Messages/QObjectDestroyMessage.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using QuantumUNET.Transport;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QObjectDestroyMessage : QMessageBase
|
||||
{
|
||||
public NetworkInstanceId NetId;
|
||||
|
||||
public override void Serialize(QNetworkWriter writer) => writer.Write(NetId);
|
||||
|
||||
public override void Deserialize(QNetworkReader reader) => NetId = reader.ReadNetworkId();
|
||||
}
|
||||
}
|
13
QuantumUNET/Messages/QObjectSpawnFinishedMessage.cs
Normal file
13
QuantumUNET/Messages/QObjectSpawnFinishedMessage.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using QuantumUNET.Transport;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QObjectSpawnFinishedMessage : QMessageBase
|
||||
{
|
||||
public uint State;
|
||||
|
||||
public override void Serialize(QNetworkWriter writer) => writer.WritePackedUInt32(State);
|
||||
|
||||
public override void Deserialize(QNetworkReader reader) => State = reader.ReadPackedUInt32();
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QSBObjectSpawnMessage : QSBMessageBase
|
||||
internal class QObjectSpawnMessage : QMessageBase
|
||||
{
|
||||
public NetworkInstanceId NetId;
|
||||
public NetworkHash128 assetId;
|
||||
@ -12,7 +12,7 @@ namespace QuantumUNET.Messages
|
||||
public byte[] Payload;
|
||||
public Quaternion Rotation;
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
writer.Write(NetId);
|
||||
writer.Write(assetId);
|
||||
@ -21,7 +21,7 @@ namespace QuantumUNET.Messages
|
||||
writer.Write(Rotation);
|
||||
}
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
NetId = reader.ReadNetworkId();
|
||||
assetId = reader.ReadNetworkHash128();
|
@ -4,14 +4,14 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QSBObjectSpawnSceneMessage : QSBMessageBase
|
||||
internal class QObjectSpawnSceneMessage : QMessageBase
|
||||
{
|
||||
public NetworkInstanceId NetId;
|
||||
public NetworkSceneId SceneId;
|
||||
public Vector3 Position;
|
||||
public byte[] Payload;
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
writer.Write(NetId);
|
||||
writer.Write(SceneId);
|
||||
@ -19,7 +19,7 @@ namespace QuantumUNET.Messages
|
||||
writer.WriteBytesFull(Payload);
|
||||
}
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
NetId = reader.ReadNetworkId();
|
||||
SceneId = reader.ReadSceneId();
|
@ -3,18 +3,18 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QSBOwnerMessage : QSBMessageBase
|
||||
internal class QOwnerMessage : QMessageBase
|
||||
{
|
||||
public NetworkInstanceId NetId;
|
||||
public short PlayerControllerId;
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer)
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
writer.Write(NetId);
|
||||
writer.WritePackedUInt32((uint)PlayerControllerId);
|
||||
}
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader)
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
NetId = reader.ReadNetworkId();
|
||||
PlayerControllerId = (short)reader.ReadPackedUInt32();
|
6
QuantumUNET/Messages/QReadyMessage.cs
Normal file
6
QuantumUNET/Messages/QReadyMessage.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
public class QReadyMessage : QEmptyMessage
|
||||
{
|
||||
}
|
||||
}
|
13
QuantumUNET/Messages/QRemovePlayerMessage.cs
Normal file
13
QuantumUNET/Messages/QRemovePlayerMessage.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using QuantumUNET.Transport;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
public class QRemovePlayerMessage : QMessageBase
|
||||
{
|
||||
public short PlayerControllerId;
|
||||
|
||||
public override void Serialize(QNetworkWriter writer) => writer.Write((ushort)PlayerControllerId);
|
||||
|
||||
public override void Deserialize(QNetworkReader reader) => PlayerControllerId = (short)reader.ReadUInt16();
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
using QuantumUNET.Transport;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
public class QSBEmptyMessage : QSBMessageBase
|
||||
{
|
||||
public override void Serialize(QSBNetworkWriter writer) { }
|
||||
public override void Deserialize(QSBNetworkReader reader) { }
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
using QuantumUNET.Transport;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
public class QSBErrorMessage : QSBMessageBase
|
||||
{
|
||||
public int errorCode;
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer) => writer.Write((ushort)errorCode);
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader) => errorCode = reader.ReadUInt16();
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
using QuantumUNET.Transport;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
public abstract class QSBMessageBase
|
||||
{
|
||||
public virtual void Serialize(QSBNetworkWriter writer) { }
|
||||
|
||||
public virtual void Deserialize(QSBNetworkReader reader) { }
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
public delegate void QSBNetworkMessageDelegate(QSBNetworkMessage netMsg);
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
public class QSBNotReadyMessage : QSBEmptyMessage
|
||||
{
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
using QuantumUNET.Transport;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QSBObjectDestroyMessage : QSBMessageBase
|
||||
{
|
||||
public NetworkInstanceId NetId;
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer) => writer.Write(NetId);
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader) => NetId = reader.ReadNetworkId();
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
using QuantumUNET.Transport;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QSBObjectSpawnFinishedMessage : QSBMessageBase
|
||||
{
|
||||
public uint State;
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer) => writer.WritePackedUInt32(State);
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader) => State = reader.ReadPackedUInt32();
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
public class QSBReadyMessage : QSBEmptyMessage
|
||||
{
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
using QuantumUNET.Transport;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
public class QSBRemovePlayerMessage : QSBMessageBase
|
||||
{
|
||||
public short PlayerControllerId;
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer) => writer.Write((ushort)PlayerControllerId);
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader) => PlayerControllerId = (short)reader.ReadUInt16();
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
public delegate GameObject QSBSpawnDelegate(Vector3 position, NetworkHash128 assetId);
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
using QuantumUNET.Transport;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
public class QSBStringMessage : QSBMessageBase
|
||||
{
|
||||
public string value;
|
||||
|
||||
public QSBStringMessage(string v)
|
||||
{
|
||||
value = v;
|
||||
}
|
||||
|
||||
public override void Serialize(QSBNetworkWriter writer) => writer.Write(value);
|
||||
|
||||
public override void Deserialize(QSBNetworkReader reader) => value = reader.ReadString();
|
||||
}
|
||||
}
|
7
QuantumUNET/Messages/QSpawnDelegate.cs
Normal file
7
QuantumUNET/Messages/QSpawnDelegate.cs
Normal file
@ -0,0 +1,7 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
public delegate GameObject QSpawnDelegate(Vector3 position, NetworkHash128 assetId);
|
||||
}
|
18
QuantumUNET/Messages/QStringMessage.cs
Normal file
18
QuantumUNET/Messages/QStringMessage.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using QuantumUNET.Transport;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
public class QStringMessage : QMessageBase
|
||||
{
|
||||
public string value;
|
||||
|
||||
public QStringMessage(string v)
|
||||
{
|
||||
value = v;
|
||||
}
|
||||
|
||||
public override void Serialize(QNetworkWriter writer) => writer.Write(value);
|
||||
|
||||
public override void Deserialize(QNetworkReader reader) => value = reader.ReadString();
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
namespace QuantumUNET
|
||||
{
|
||||
internal struct QSBCRCMessageEntry
|
||||
internal struct QCRCMessageEntry
|
||||
{
|
||||
public string name;
|
||||
public byte channel;
|
@ -7,28 +7,28 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
public class QSBClientScene
|
||||
public class QClientScene
|
||||
{
|
||||
internal static void SetNotReady() => ready = false;
|
||||
|
||||
public static List<QSBPlayerController> localPlayers { get; private set; } = new List<QSBPlayerController>();
|
||||
public static List<QPlayerController> localPlayers { get; private set; } = new List<QPlayerController>();
|
||||
|
||||
public static bool ready { get; private set; }
|
||||
|
||||
public static QSBNetworkConnection readyConnection { get; private set; }
|
||||
public static QNetworkConnection readyConnection { get; private set; }
|
||||
|
||||
public static int reconnectId { get; private set; } = -1;
|
||||
|
||||
public static Dictionary<NetworkInstanceId, QSBNetworkIdentity> Objects => s_NetworkScene.localObjects;
|
||||
public static Dictionary<NetworkInstanceId, QNetworkIdentity> Objects => s_NetworkScene.localObjects;
|
||||
|
||||
public static Dictionary<NetworkHash128, GameObject> Prefabs => QSBNetworkScene.guidToPrefab;
|
||||
public static Dictionary<NetworkHash128, GameObject> Prefabs => QNetworkScene.guidToPrefab;
|
||||
|
||||
public static Dictionary<NetworkSceneId, QSBNetworkIdentity> SpawnableObjects { get; private set; }
|
||||
public static Dictionary<NetworkSceneId, QNetworkIdentity> SpawnableObjects { get; private set; }
|
||||
|
||||
internal static void Shutdown()
|
||||
{
|
||||
s_NetworkScene.Shutdown();
|
||||
localPlayers = new List<QSBPlayerController>();
|
||||
localPlayers = new List<QPlayerController>();
|
||||
s_PendingOwnerIds = new List<PendingOwner>();
|
||||
SpawnableObjects = null;
|
||||
readyConnection = null;
|
||||
@ -39,7 +39,7 @@ namespace QuantumUNET
|
||||
NetworkTransport.Init();
|
||||
}
|
||||
|
||||
internal static bool GetPlayerController(short playerControllerId, out QSBPlayerController player)
|
||||
internal static bool GetPlayerController(short playerControllerId, out QPlayerController player)
|
||||
{
|
||||
player = null;
|
||||
bool result;
|
||||
@ -61,7 +61,7 @@ namespace QuantumUNET
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static void InternalAddPlayer(QSBNetworkIdentity view, short playerControllerId)
|
||||
internal static void InternalAddPlayer(QNetworkIdentity view, short playerControllerId)
|
||||
{
|
||||
Debug.LogWarning($"ClientScene::InternalAddPlayer: playerControllerId : {playerControllerId}");
|
||||
if (playerControllerId >= localPlayers.Count)
|
||||
@ -70,10 +70,10 @@ namespace QuantumUNET
|
||||
$"ClientScene::InternalAddPlayer: playerControllerId higher than expected: {playerControllerId}");
|
||||
while (playerControllerId >= localPlayers.Count)
|
||||
{
|
||||
localPlayers.Add(new QSBPlayerController());
|
||||
localPlayers.Add(new QPlayerController());
|
||||
}
|
||||
}
|
||||
var playerController = new QSBPlayerController
|
||||
var playerController = new QPlayerController
|
||||
{
|
||||
Gameobject = view.gameObject,
|
||||
PlayerControllerId = playerControllerId,
|
||||
@ -85,9 +85,9 @@ namespace QuantumUNET
|
||||
|
||||
public static bool AddPlayer(short playerControllerId) => AddPlayer(null, playerControllerId);
|
||||
|
||||
public static bool AddPlayer(QSBNetworkConnection readyConn, short playerControllerId) => AddPlayer(readyConn, playerControllerId, null);
|
||||
public static bool AddPlayer(QNetworkConnection readyConn, short playerControllerId) => AddPlayer(readyConn, playerControllerId, null);
|
||||
|
||||
public static bool AddPlayer(QSBNetworkConnection readyConn, short playerControllerId, QSBMessageBase extraMessage)
|
||||
public static bool AddPlayer(QNetworkConnection readyConn, short playerControllerId, QMessageBase extraMessage)
|
||||
{
|
||||
bool result;
|
||||
if (playerControllerId < 0)
|
||||
@ -108,7 +108,7 @@ namespace QuantumUNET
|
||||
}
|
||||
while (playerControllerId >= localPlayers.Count)
|
||||
{
|
||||
localPlayers.Add(new QSBPlayerController());
|
||||
localPlayers.Add(new QPlayerController());
|
||||
}
|
||||
if (readyConn == null)
|
||||
{
|
||||
@ -132,13 +132,13 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
Debug.Log($"ClientScene::AddPlayer() for ID {playerControllerId} called with connection [{readyConnection}]");
|
||||
var addPlayerMessage = new QSBAddPlayerMessage
|
||||
var addPlayerMessage = new QAddPlayerMessage
|
||||
{
|
||||
playerControllerId = playerControllerId
|
||||
};
|
||||
if (extraMessage != null)
|
||||
{
|
||||
var networkWriter = new QSBNetworkWriter();
|
||||
var networkWriter = new QNetworkWriter();
|
||||
extraMessage.Serialize(networkWriter);
|
||||
addPlayerMessage.msgData = networkWriter.ToArray();
|
||||
addPlayerMessage.msgSize = networkWriter.Position;
|
||||
@ -155,13 +155,13 @@ namespace QuantumUNET
|
||||
bool result;
|
||||
if (readyConnection.GetPlayerController(playerControllerId, out var playerController))
|
||||
{
|
||||
var removePlayerMessage = new QSBRemovePlayerMessage
|
||||
var removePlayerMessage = new QRemovePlayerMessage
|
||||
{
|
||||
PlayerControllerId = playerControllerId
|
||||
};
|
||||
readyConnection.Send(38, removePlayerMessage);
|
||||
readyConnection.RemovePlayerController(playerControllerId);
|
||||
localPlayers[playerControllerId] = new QSBPlayerController();
|
||||
localPlayers[playerControllerId] = new QPlayerController();
|
||||
Object.Destroy(playerController.Gameobject);
|
||||
result = true;
|
||||
}
|
||||
@ -173,7 +173,7 @@ namespace QuantumUNET
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool Ready(QSBNetworkConnection conn)
|
||||
public static bool Ready(QNetworkConnection conn)
|
||||
{
|
||||
bool result;
|
||||
if (ready)
|
||||
@ -186,7 +186,7 @@ namespace QuantumUNET
|
||||
Debug.Log($"ClientScene::Ready() called with connection [{conn}]");
|
||||
if (conn != null)
|
||||
{
|
||||
var msg = new QSBReadyMessage();
|
||||
var msg = new QReadyMessage();
|
||||
conn.Send(35, msg);
|
||||
ready = true;
|
||||
readyConnection = conn;
|
||||
@ -202,25 +202,25 @@ namespace QuantumUNET
|
||||
return result;
|
||||
}
|
||||
|
||||
public static QSBNetworkClient ConnectLocalServer()
|
||||
public static QNetworkClient ConnectLocalServer()
|
||||
{
|
||||
var localClient = new QSBLocalClient();
|
||||
QSBNetworkServer.instance.ActivateLocalClientScene();
|
||||
var localClient = new QLocalClient();
|
||||
QNetworkServer.instance.ActivateLocalClientScene();
|
||||
localClient.InternalConnectLocalServer(true);
|
||||
return localClient;
|
||||
}
|
||||
|
||||
internal static QSBNetworkClient ReconnectLocalServer()
|
||||
internal static QNetworkClient ReconnectLocalServer()
|
||||
{
|
||||
var localClient = new QSBLocalClient();
|
||||
QSBNetworkServer.instance.ActivateLocalClientScene();
|
||||
var localClient = new QLocalClient();
|
||||
QNetworkServer.instance.ActivateLocalClientScene();
|
||||
localClient.InternalConnectLocalServer(false);
|
||||
return localClient;
|
||||
}
|
||||
|
||||
internal static void ClearLocalPlayers() => localPlayers.Clear();
|
||||
|
||||
internal static void HandleClientDisconnect(QSBNetworkConnection conn)
|
||||
internal static void HandleClientDisconnect(QNetworkConnection conn)
|
||||
{
|
||||
if (readyConnection == conn && ready)
|
||||
{
|
||||
@ -231,8 +231,8 @@ namespace QuantumUNET
|
||||
|
||||
internal static void PrepareToSpawnSceneObjects()
|
||||
{
|
||||
SpawnableObjects = new Dictionary<NetworkSceneId, QSBNetworkIdentity>();
|
||||
foreach (var networkIdentity in Resources.FindObjectsOfTypeAll<QSBNetworkIdentity>())
|
||||
SpawnableObjects = new Dictionary<NetworkSceneId, QNetworkIdentity>();
|
||||
foreach (var networkIdentity in Resources.FindObjectsOfTypeAll<QNetworkIdentity>())
|
||||
{
|
||||
if (!networkIdentity.gameObject.activeSelf)
|
||||
{
|
||||
@ -248,9 +248,9 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
internal static QSBNetworkIdentity SpawnSceneObject(NetworkSceneId sceneId)
|
||||
internal static QNetworkIdentity SpawnSceneObject(NetworkSceneId sceneId)
|
||||
{
|
||||
QSBNetworkIdentity result;
|
||||
QNetworkIdentity result;
|
||||
if (SpawnableObjects.ContainsKey(sceneId))
|
||||
{
|
||||
var networkIdentity = SpawnableObjects[sceneId];
|
||||
@ -264,7 +264,7 @@ namespace QuantumUNET
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static void RegisterSystemHandlers(QSBNetworkClient client, bool localClient)
|
||||
internal static void RegisterSystemHandlers(QNetworkClient client, bool localClient)
|
||||
{
|
||||
if (localClient)
|
||||
{
|
||||
@ -284,40 +284,40 @@ namespace QuantumUNET
|
||||
client.RegisterHandlerSafe(8, OnUpdateVarsMessage);
|
||||
client.RegisterHandlerSafe(4, OnOwnerMessage);
|
||||
client.RegisterHandlerSafe(9, OnSyncListMessage);
|
||||
client.RegisterHandlerSafe(40, QSBNetworkAnimator.OnAnimationClientMessage);
|
||||
client.RegisterHandlerSafe(41, QSBNetworkAnimator.OnAnimationParametersClientMessage);
|
||||
client.RegisterHandlerSafe(40, QNetworkAnimator.OnAnimationClientMessage);
|
||||
client.RegisterHandlerSafe(41, QNetworkAnimator.OnAnimationParametersClientMessage);
|
||||
client.RegisterHandlerSafe(15, OnClientAuthority);
|
||||
}
|
||||
client.RegisterHandlerSafe(2, OnRPCMessage);
|
||||
client.RegisterHandlerSafe(7, OnSyncEventMessage);
|
||||
client.RegisterHandlerSafe(42, QSBNetworkAnimator.OnAnimationTriggerClientMessage);
|
||||
client.RegisterHandlerSafe(42, QNetworkAnimator.OnAnimationTriggerClientMessage);
|
||||
}
|
||||
|
||||
internal static string GetStringForAssetId(NetworkHash128 assetId)
|
||||
{
|
||||
if (QSBNetworkScene.GetPrefab(assetId, out var gameObject))
|
||||
if (QNetworkScene.GetPrefab(assetId, out var gameObject))
|
||||
{
|
||||
return gameObject.name;
|
||||
}
|
||||
|
||||
return QSBNetworkScene.GetSpawnHandler(assetId, out var func)
|
||||
return QNetworkScene.GetSpawnHandler(assetId, out var func)
|
||||
? func.GetMethodName()
|
||||
: "unknown";
|
||||
}
|
||||
|
||||
public static void RegisterPrefab(GameObject prefab, NetworkHash128 newAssetId) => QSBNetworkScene.RegisterPrefab(prefab, newAssetId);
|
||||
public static void RegisterPrefab(GameObject prefab, NetworkHash128 newAssetId) => QNetworkScene.RegisterPrefab(prefab, newAssetId);
|
||||
|
||||
public static void RegisterPrefab(GameObject prefab) => QSBNetworkScene.RegisterPrefab(prefab);
|
||||
public static void RegisterPrefab(GameObject prefab) => QNetworkScene.RegisterPrefab(prefab);
|
||||
|
||||
public static void RegisterPrefab(GameObject prefab, QSBSpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler) => QSBNetworkScene.RegisterPrefab(prefab, spawnHandler, unspawnHandler);
|
||||
public static void RegisterPrefab(GameObject prefab, QSpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler) => QNetworkScene.RegisterPrefab(prefab, spawnHandler, unspawnHandler);
|
||||
|
||||
public static void UnregisterPrefab(GameObject prefab) => QSBNetworkScene.UnregisterPrefab(prefab);
|
||||
public static void UnregisterPrefab(GameObject prefab) => QNetworkScene.UnregisterPrefab(prefab);
|
||||
|
||||
public static void RegisterSpawnHandler(NetworkHash128 assetId, QSBSpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler) => QSBNetworkScene.RegisterSpawnHandler(assetId, spawnHandler, unspawnHandler);
|
||||
public static void RegisterSpawnHandler(NetworkHash128 assetId, QSpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler) => QNetworkScene.RegisterSpawnHandler(assetId, spawnHandler, unspawnHandler);
|
||||
|
||||
public static void UnregisterSpawnHandler(NetworkHash128 assetId) => QSBNetworkScene.UnregisterSpawnHandler(assetId);
|
||||
public static void UnregisterSpawnHandler(NetworkHash128 assetId) => QNetworkScene.UnregisterSpawnHandler(assetId);
|
||||
|
||||
public static void ClearSpawners() => QSBNetworkScene.ClearSpawners();
|
||||
public static void ClearSpawners() => QNetworkScene.ClearSpawners();
|
||||
|
||||
public static void DestroyAllClientObjects() => s_NetworkScene.DestroyAllClientObjects();
|
||||
|
||||
@ -325,7 +325,7 @@ namespace QuantumUNET
|
||||
|
||||
public static GameObject FindLocalObject(NetworkInstanceId netId) => s_NetworkScene.FindLocalObject(netId);
|
||||
|
||||
private static void ApplySpawnPayload(QSBNetworkIdentity uv, Vector3 position, byte[] payload, NetworkInstanceId netId, GameObject newGameObject)
|
||||
private static void ApplySpawnPayload(QNetworkIdentity uv, Vector3 position, byte[] payload, NetworkInstanceId netId, GameObject newGameObject)
|
||||
{
|
||||
if (!uv.gameObject.activeSelf)
|
||||
{
|
||||
@ -334,7 +334,7 @@ namespace QuantumUNET
|
||||
uv.transform.position = position;
|
||||
if (payload != null && payload.Length > 0)
|
||||
{
|
||||
var reader = new QSBNetworkReader(payload);
|
||||
var reader = new QNetworkReader(payload);
|
||||
uv.OnUpdateVars(reader, true);
|
||||
}
|
||||
if (newGameObject != null)
|
||||
@ -350,7 +350,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnObjectSpawn(QSBNetworkMessage netMsg)
|
||||
private static void OnObjectSpawn(QNetworkMessage netMsg)
|
||||
{
|
||||
netMsg.ReadMessage(s_ObjectSpawnMessage);
|
||||
if (!s_ObjectSpawnMessage.assetId.IsValid())
|
||||
@ -363,10 +363,10 @@ namespace QuantumUNET
|
||||
{
|
||||
ApplySpawnPayload(component, s_ObjectSpawnMessage.Position, s_ObjectSpawnMessage.Payload, s_ObjectSpawnMessage.NetId, null);
|
||||
}
|
||||
else if (QSBNetworkScene.GetPrefab(s_ObjectSpawnMessage.assetId, out var original))
|
||||
else if (QNetworkScene.GetPrefab(s_ObjectSpawnMessage.assetId, out var original))
|
||||
{
|
||||
var gameObject = Object.Instantiate(original, s_ObjectSpawnMessage.Position, s_ObjectSpawnMessage.Rotation);
|
||||
component = gameObject.GetComponent<QSBNetworkIdentity>();
|
||||
component = gameObject.GetComponent<QNetworkIdentity>();
|
||||
if (component == null)
|
||||
{
|
||||
Debug.LogError($"Client object spawned for {s_ObjectSpawnMessage.assetId} does not have a NetworkIdentity");
|
||||
@ -377,7 +377,7 @@ namespace QuantumUNET
|
||||
ApplySpawnPayload(component, s_ObjectSpawnMessage.Position, s_ObjectSpawnMessage.Payload, s_ObjectSpawnMessage.NetId, gameObject);
|
||||
}
|
||||
}
|
||||
else if (QSBNetworkScene.GetSpawnHandler(s_ObjectSpawnMessage.assetId, out var spawnDelegate))
|
||||
else if (QNetworkScene.GetSpawnHandler(s_ObjectSpawnMessage.assetId, out var spawnDelegate))
|
||||
{
|
||||
var gameObject2 = spawnDelegate(s_ObjectSpawnMessage.Position, s_ObjectSpawnMessage.assetId);
|
||||
if (gameObject2 == null)
|
||||
@ -386,7 +386,7 @@ namespace QuantumUNET
|
||||
}
|
||||
else
|
||||
{
|
||||
component = gameObject2.GetComponent<QSBNetworkIdentity>();
|
||||
component = gameObject2.GetComponent<QNetworkIdentity>();
|
||||
if (component == null)
|
||||
{
|
||||
Debug.LogError($"Client object spawned for {s_ObjectSpawnMessage.assetId} does not have a network identity");
|
||||
@ -406,7 +406,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnObjectSpawnScene(QSBNetworkMessage netMsg)
|
||||
private static void OnObjectSpawnScene(QNetworkMessage netMsg)
|
||||
{
|
||||
netMsg.ReadMessage(s_ObjectSpawnSceneMessage);
|
||||
if (s_NetworkScene.GetNetworkIdentity(s_ObjectSpawnSceneMessage.NetId, out var networkIdentity))
|
||||
@ -429,7 +429,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnObjectSpawnFinished(QSBNetworkMessage netMsg)
|
||||
private static void OnObjectSpawnFinished(QNetworkMessage netMsg)
|
||||
{
|
||||
netMsg.ReadMessage(s_ObjectSpawnFinishedMessage);
|
||||
Debug.Log($"SpawnFinished:{s_ObjectSpawnFinishedMessage.State}");
|
||||
@ -452,14 +452,14 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnObjectDestroy(QSBNetworkMessage netMsg)
|
||||
private static void OnObjectDestroy(QNetworkMessage netMsg)
|
||||
{
|
||||
netMsg.ReadMessage(s_ObjectDestroyMessage);
|
||||
Debug.Log($"ClientScene::OnObjDestroy netId:{s_ObjectDestroyMessage.NetId}");
|
||||
if (s_NetworkScene.GetNetworkIdentity(s_ObjectDestroyMessage.NetId, out var networkIdentity))
|
||||
{
|
||||
networkIdentity.OnNetworkDestroy();
|
||||
if (!QSBNetworkScene.InvokeUnSpawnHandler(networkIdentity.AssetId, networkIdentity.gameObject))
|
||||
if (!QNetworkScene.InvokeUnSpawnHandler(networkIdentity.AssetId, networkIdentity.gameObject))
|
||||
{
|
||||
if (networkIdentity.SceneId.IsEmpty())
|
||||
{
|
||||
@ -480,14 +480,14 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnLocalClientObjectDestroy(QSBNetworkMessage netMsg)
|
||||
private static void OnLocalClientObjectDestroy(QNetworkMessage netMsg)
|
||||
{
|
||||
netMsg.ReadMessage(s_ObjectDestroyMessage);
|
||||
Debug.Log($"ClientScene::OnLocalObjectObjDestroy netId:{s_ObjectDestroyMessage.NetId}");
|
||||
s_NetworkScene.RemoveLocalObject(s_ObjectDestroyMessage.NetId);
|
||||
}
|
||||
|
||||
private static void OnLocalClientObjectHide(QSBNetworkMessage netMsg)
|
||||
private static void OnLocalClientObjectHide(QNetworkMessage netMsg)
|
||||
{
|
||||
netMsg.ReadMessage(s_ObjectDestroyMessage);
|
||||
Debug.Log($"ClientScene::OnLocalObjectObjHide netId:{s_ObjectDestroyMessage.NetId}");
|
||||
@ -497,7 +497,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnLocalClientObjectSpawn(QSBNetworkMessage netMsg)
|
||||
private static void OnLocalClientObjectSpawn(QNetworkMessage netMsg)
|
||||
{
|
||||
netMsg.ReadMessage(s_ObjectSpawnMessage);
|
||||
if (s_NetworkScene.GetNetworkIdentity(s_ObjectSpawnMessage.NetId, out var networkIdentity))
|
||||
@ -506,7 +506,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnLocalClientObjectSpawnScene(QSBNetworkMessage netMsg)
|
||||
private static void OnLocalClientObjectSpawnScene(QNetworkMessage netMsg)
|
||||
{
|
||||
netMsg.ReadMessage(s_ObjectSpawnSceneMessage);
|
||||
if (s_NetworkScene.GetNetworkIdentity(s_ObjectSpawnSceneMessage.NetId, out var networkIdentity))
|
||||
@ -515,7 +515,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnUpdateVarsMessage(QSBNetworkMessage netMsg)
|
||||
private static void OnUpdateVarsMessage(QNetworkMessage netMsg)
|
||||
{
|
||||
var networkInstanceId = netMsg.Reader.ReadNetworkId();
|
||||
if (s_NetworkScene.GetNetworkIdentity(networkInstanceId, out var networkIdentity))
|
||||
@ -528,7 +528,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnRPCMessage(QSBNetworkMessage netMsg)
|
||||
private static void OnRPCMessage(QNetworkMessage netMsg)
|
||||
{
|
||||
var num = (int)netMsg.Reader.ReadPackedUInt32();
|
||||
var networkInstanceId = netMsg.Reader.ReadNetworkId();
|
||||
@ -539,12 +539,12 @@ namespace QuantumUNET
|
||||
}
|
||||
else
|
||||
{
|
||||
var cmdHashHandlerName = QSBNetworkBehaviour.GetCmdHashHandlerName(num);
|
||||
var cmdHashHandlerName = QNetworkBehaviour.GetCmdHashHandlerName(num);
|
||||
Debug.LogWarningFormat("Could not find target object with netId:{0} for RPC call {1}", networkInstanceId, cmdHashHandlerName);
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnSyncEventMessage(QSBNetworkMessage netMsg)
|
||||
private static void OnSyncEventMessage(QNetworkMessage netMsg)
|
||||
{
|
||||
var cmdHash = (int)netMsg.Reader.ReadPackedUInt32();
|
||||
var networkInstanceId = netMsg.Reader.ReadNetworkId();
|
||||
@ -559,7 +559,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnSyncListMessage(QSBNetworkMessage netMsg)
|
||||
private static void OnSyncListMessage(QNetworkMessage netMsg)
|
||||
{
|
||||
var networkInstanceId = netMsg.Reader.ReadNetworkId();
|
||||
var cmdHash = (int)netMsg.Reader.ReadPackedUInt32();
|
||||
@ -574,7 +574,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnClientAuthority(QSBNetworkMessage netMsg)
|
||||
private static void OnClientAuthority(QNetworkMessage netMsg)
|
||||
{
|
||||
netMsg.ReadMessage(s_ClientAuthorityMessage);
|
||||
Debug.Log(
|
||||
@ -585,7 +585,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnOwnerMessage(QSBNetworkMessage netMsg)
|
||||
private static void OnOwnerMessage(QNetworkMessage netMsg)
|
||||
{
|
||||
netMsg.ReadMessage(s_OwnerMessage);
|
||||
Debug.Log(
|
||||
@ -611,7 +611,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckForOwner(QSBNetworkIdentity uv)
|
||||
private static void CheckForOwner(QNetworkIdentity uv)
|
||||
{
|
||||
var i = 0;
|
||||
while (i < s_PendingOwnerIds.Count)
|
||||
@ -638,19 +638,19 @@ namespace QuantumUNET
|
||||
|
||||
private static bool s_IsSpawnFinished;
|
||||
|
||||
private static readonly QSBNetworkScene s_NetworkScene = new QSBNetworkScene();
|
||||
private static readonly QNetworkScene s_NetworkScene = new QNetworkScene();
|
||||
|
||||
private static readonly QSBObjectSpawnSceneMessage s_ObjectSpawnSceneMessage = new QSBObjectSpawnSceneMessage();
|
||||
private static readonly QObjectSpawnSceneMessage s_ObjectSpawnSceneMessage = new QObjectSpawnSceneMessage();
|
||||
|
||||
private static readonly QSBObjectSpawnFinishedMessage s_ObjectSpawnFinishedMessage = new QSBObjectSpawnFinishedMessage();
|
||||
private static readonly QObjectSpawnFinishedMessage s_ObjectSpawnFinishedMessage = new QObjectSpawnFinishedMessage();
|
||||
|
||||
private static readonly QSBObjectDestroyMessage s_ObjectDestroyMessage = new QSBObjectDestroyMessage();
|
||||
private static readonly QObjectDestroyMessage s_ObjectDestroyMessage = new QObjectDestroyMessage();
|
||||
|
||||
private static readonly QSBObjectSpawnMessage s_ObjectSpawnMessage = new QSBObjectSpawnMessage();
|
||||
private static readonly QObjectSpawnMessage s_ObjectSpawnMessage = new QObjectSpawnMessage();
|
||||
|
||||
private static readonly QSBOwnerMessage s_OwnerMessage = new QSBOwnerMessage();
|
||||
private static readonly QOwnerMessage s_OwnerMessage = new QOwnerMessage();
|
||||
|
||||
private static readonly QSBClientAuthorityMessage s_ClientAuthorityMessage = new QSBClientAuthorityMessage();
|
||||
private static readonly QClientAuthorityMessage s_ClientAuthorityMessage = new QClientAuthorityMessage();
|
||||
|
||||
public const int ReconnectIdInvalid = -1;
|
||||
|
@ -5,11 +5,11 @@ using UnityEngine;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
internal class QSBLocalClient : QSBNetworkClient
|
||||
internal class QLocalClient : QNetworkClient
|
||||
{
|
||||
public override void Disconnect()
|
||||
{
|
||||
QSBClientScene.HandleClientDisconnect(m_Connection);
|
||||
QClientScene.HandleClientDisconnect(m_Connection);
|
||||
if (m_Connected)
|
||||
{
|
||||
PostInternalMessage(33);
|
||||
@ -30,8 +30,8 @@ namespace QuantumUNET
|
||||
m_FreeMessages.Push(t);
|
||||
}
|
||||
}
|
||||
m_LocalServer = QSBNetworkServer.instance;
|
||||
m_Connection = new QSBULocalConnectionToServer(m_LocalServer);
|
||||
m_LocalServer = QNetworkServer.instance;
|
||||
m_Connection = new QULocalConnectionToServer(m_LocalServer);
|
||||
SetHandlers(m_Connection);
|
||||
m_Connection.connectionId = m_LocalServer.AddLocalClient(this);
|
||||
m_AsyncConnect = ConnectState.Connected;
|
||||
@ -46,7 +46,7 @@ namespace QuantumUNET
|
||||
|
||||
internal override void Update() => ProcessInternalMessages();
|
||||
|
||||
internal void AddLocalPlayer(QSBPlayerController localPlayer)
|
||||
internal void AddLocalPlayer(QPlayerController localPlayer)
|
||||
{
|
||||
Debug.Log($"Local client AddLocalPlayer {localPlayer.Gameobject.name} conn={m_Connection.connectionId}");
|
||||
m_Connection.isReady = true;
|
||||
@ -54,10 +54,10 @@ namespace QuantumUNET
|
||||
var unetView = localPlayer.UnetView;
|
||||
if (unetView != null)
|
||||
{
|
||||
QSBClientScene.SetLocalObject(unetView.NetId, localPlayer.Gameobject);
|
||||
QClientScene.SetLocalObject(unetView.NetId, localPlayer.Gameobject);
|
||||
unetView.SetConnectionToServer(m_Connection);
|
||||
}
|
||||
QSBClientScene.InternalAddPlayer(unetView, localPlayer.PlayerControllerId);
|
||||
QClientScene.InternalAddPlayer(unetView, localPlayer.PlayerControllerId);
|
||||
}
|
||||
|
||||
private void PostInternalMessage(byte[] buffer, int channelId)
|
||||
@ -70,7 +70,7 @@ namespace QuantumUNET
|
||||
|
||||
private void PostInternalMessage(short msgType)
|
||||
{
|
||||
var networkWriter = new QSBNetworkWriter();
|
||||
var networkWriter = new QNetworkWriter();
|
||||
networkWriter.StartMessage(msgType);
|
||||
networkWriter.FinishMessage();
|
||||
PostInternalMessage(networkWriter.AsArray(), 0);
|
||||
@ -86,7 +86,7 @@ namespace QuantumUNET
|
||||
{
|
||||
if (s_InternalMessage.Reader == null)
|
||||
{
|
||||
s_InternalMessage.Reader = new QSBNetworkReader(msg.buffer);
|
||||
s_InternalMessage.Reader = new QNetworkReader(msg.buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -110,9 +110,9 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
internal void InvokeHandlerOnClient(short msgType, QSBMessageBase msg, int channelId)
|
||||
internal void InvokeHandlerOnClient(short msgType, QMessageBase msg, int channelId)
|
||||
{
|
||||
var networkWriter = new QSBNetworkWriter();
|
||||
var networkWriter = new QNetworkWriter();
|
||||
networkWriter.StartMessage(msgType);
|
||||
msg.Serialize(networkWriter);
|
||||
networkWriter.FinishMessage();
|
||||
@ -129,11 +129,11 @@ namespace QuantumUNET
|
||||
|
||||
private Stack<InternalMsg> m_FreeMessages;
|
||||
|
||||
private QSBNetworkServer m_LocalServer;
|
||||
private QNetworkServer m_LocalServer;
|
||||
|
||||
private bool m_Connected;
|
||||
|
||||
private readonly QSBNetworkMessage s_InternalMessage = new QSBNetworkMessage();
|
||||
private readonly QNetworkMessage s_InternalMessage = new QNetworkMessage();
|
||||
|
||||
private struct InternalMsg
|
||||
{
|
@ -1,5 +1,5 @@
|
||||
using OWML.Logging;
|
||||
using QuantumUNET.Components;
|
||||
using QuantumUNET.Components;
|
||||
using QuantumUNET.Logging;
|
||||
using QuantumUNET.Transport;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -9,7 +9,7 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
public class QSBNetworkBehaviour : MonoBehaviour
|
||||
public class QNetworkBehaviour : MonoBehaviour
|
||||
{
|
||||
public bool LocalPlayerAuthority => MyView.LocalPlayerAuthority;
|
||||
public bool IsServer => MyView.IsServer;
|
||||
@ -17,26 +17,26 @@ namespace QuantumUNET
|
||||
public bool IsLocalPlayer => MyView.IsLocalPlayer;
|
||||
public bool HasAuthority => MyView.HasAuthority;
|
||||
public NetworkInstanceId NetId => MyView.NetId;
|
||||
public QSBNetworkConnection ConnectionToServer => MyView.ConnectionToServer;
|
||||
public QSBNetworkConnection ConnectionToClient => MyView.ConnectionToClient;
|
||||
public QNetworkConnection ConnectionToServer => MyView.ConnectionToServer;
|
||||
public QNetworkConnection ConnectionToClient => MyView.ConnectionToClient;
|
||||
public short PlayerControllerId => MyView.PlayerControllerId;
|
||||
|
||||
protected uint SyncVarDirtyBits { get; private set; }
|
||||
protected bool SyncVarHookGuard { get; set; }
|
||||
|
||||
public QSBNetworkIdentity NetIdentity => MyView;
|
||||
public QNetworkIdentity NetIdentity => MyView;
|
||||
|
||||
private QSBNetworkIdentity MyView
|
||||
private QNetworkIdentity MyView
|
||||
{
|
||||
get
|
||||
{
|
||||
QSBNetworkIdentity myView;
|
||||
QNetworkIdentity myView;
|
||||
if (m_MyView == null)
|
||||
{
|
||||
m_MyView = GetComponent<QSBNetworkIdentity>();
|
||||
m_MyView = GetComponent<QNetworkIdentity>();
|
||||
if (m_MyView == null)
|
||||
{
|
||||
Debug.LogError("There is no NetworkIdentity on this object. Please add one.");
|
||||
QLog.LogFatalError($"There is no QNetworkIdentity on this object (name={name}). Please add one.");
|
||||
}
|
||||
myView = m_MyView;
|
||||
}
|
||||
@ -48,63 +48,63 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
protected void SendCommandInternal(QSBNetworkWriter writer, int channelId, string cmdName)
|
||||
protected void SendCommandInternal(QNetworkWriter writer, int channelId, string cmdName)
|
||||
{
|
||||
if (!IsLocalPlayer && !HasAuthority)
|
||||
{
|
||||
Debug.LogWarning("Trying to send command for object without authority.");
|
||||
QLog.LogWarning("Trying to send command for object without authority.");
|
||||
}
|
||||
else if (QSBClientScene.readyConnection == null)
|
||||
else if (QClientScene.readyConnection == null)
|
||||
{
|
||||
Debug.LogError($"Send command attempted with no client running [client={ConnectionToServer}].");
|
||||
QLog.LogError($"Send command attempted with no client running [client={ConnectionToServer}].");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.FinishMessage();
|
||||
QSBClientScene.readyConnection.SendWriter(writer, channelId);
|
||||
QClientScene.readyConnection.SendWriter(writer, channelId);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool InvokeCommand(int cmdHash, QSBNetworkReader reader) => InvokeCommandDelegate(cmdHash, reader);
|
||||
public virtual bool InvokeCommand(int cmdHash, QNetworkReader reader) => InvokeCommandDelegate(cmdHash, reader);
|
||||
|
||||
protected void SendRPCInternal(QSBNetworkWriter writer, int channelId, string rpcName)
|
||||
protected void SendRPCInternal(QNetworkWriter writer, int channelId, string rpcName)
|
||||
{
|
||||
if (!IsServer)
|
||||
{
|
||||
Debug.LogWarning("ClientRpc call on un-spawned object");
|
||||
QLog.LogWarning("ClientRpc call on un-spawned object");
|
||||
return;
|
||||
}
|
||||
writer.FinishMessage();
|
||||
QSBNetworkServer.SendWriterToReady(gameObject, writer, channelId);
|
||||
QNetworkServer.SendWriterToReady(gameObject, writer, channelId);
|
||||
}
|
||||
|
||||
protected void SendTargetRPCInternal(QSBNetworkConnection conn, QSBNetworkWriter writer, int channelId, string rpcName)
|
||||
protected void SendTargetRPCInternal(QNetworkConnection conn, QNetworkWriter writer, int channelId, string rpcName)
|
||||
{
|
||||
if (!IsServer)
|
||||
{
|
||||
Debug.LogWarning("TargetRpc call on un-spawned object");
|
||||
QLog.LogWarning("TargetRpc call on un-spawned object");
|
||||
return;
|
||||
}
|
||||
writer.FinishMessage();
|
||||
conn.SendWriter(writer, channelId);
|
||||
}
|
||||
|
||||
public virtual bool InvokeRPC(int cmdHash, QSBNetworkReader reader) => InvokeRpcDelegate(cmdHash, reader);
|
||||
public virtual bool InvokeRPC(int cmdHash, QNetworkReader reader) => InvokeRpcDelegate(cmdHash, reader);
|
||||
|
||||
protected void SendEventInternal(QSBNetworkWriter writer, int channelId, string eventName)
|
||||
protected void SendEventInternal(QNetworkWriter writer, int channelId, string eventName)
|
||||
{
|
||||
if (!QSBNetworkServer.active)
|
||||
if (!QNetworkServer.active)
|
||||
{
|
||||
ModConsole.OwmlConsole.WriteLine($"Error - Tried to send event {eventName} on channel {channelId} but QSBNetworkServer isn't active.");
|
||||
QLog.LogError($"Tried to send event {eventName} on channel {channelId} but QSBNetworkServer isn't active.");
|
||||
return;
|
||||
}
|
||||
writer.FinishMessage();
|
||||
QSBNetworkServer.SendWriterToReady(gameObject, writer, channelId);
|
||||
QNetworkServer.SendWriterToReady(gameObject, writer, channelId);
|
||||
}
|
||||
|
||||
public virtual bool InvokeSyncEvent(int cmdHash, QSBNetworkReader reader) => InvokeSyncEventDelegate(cmdHash, reader);
|
||||
public virtual bool InvokeSyncEvent(int cmdHash, QNetworkReader reader) => InvokeSyncEventDelegate(cmdHash, reader);
|
||||
|
||||
public virtual bool InvokeSyncList(int cmdHash, QSBNetworkReader reader) => InvokeSyncListDelegate(cmdHash, reader);
|
||||
public virtual bool InvokeSyncList(int cmdHash, QNetworkReader reader) => InvokeSyncListDelegate(cmdHash, reader);
|
||||
|
||||
protected static void RegisterCommandDelegate(Type invokeClass, int cmdHash, CmdDelegate func)
|
||||
{
|
||||
@ -194,21 +194,21 @@ namespace QuantumUNET
|
||||
bool result;
|
||||
if (!s_CmdHandlerDelegates.TryGetValue(cmdHash, out var invoker))
|
||||
{
|
||||
Debug.Log($"GetInvokerForHash hash:{cmdHash} not found");
|
||||
QLog.LogError($"GetInvokerForHash hash:{cmdHash} not found");
|
||||
invokeClass = null;
|
||||
invokeFunction = null;
|
||||
result = false;
|
||||
}
|
||||
else if (invoker == null)
|
||||
{
|
||||
Debug.Log($"GetInvokerForHash hash:{cmdHash} invoker null");
|
||||
QLog.LogError($"GetInvokerForHash hash:{cmdHash} invoker null");
|
||||
invokeClass = null;
|
||||
invokeFunction = null;
|
||||
result = false;
|
||||
}
|
||||
else if (invoker.invokeType != invokeType)
|
||||
{
|
||||
Debug.LogError($"GetInvokerForHash hash:{cmdHash} mismatched invokeType");
|
||||
QLog.LogError($"GetInvokerForHash hash:{cmdHash} mismatched invokeType");
|
||||
invokeClass = null;
|
||||
invokeFunction = null;
|
||||
result = false;
|
||||
@ -224,17 +224,17 @@ namespace QuantumUNET
|
||||
|
||||
internal static void DumpInvokers()
|
||||
{
|
||||
Debug.Log($"DumpInvokers size:{s_CmdHandlerDelegates.Count}");
|
||||
QLog.Log($"DumpInvokers size:{s_CmdHandlerDelegates.Count}");
|
||||
foreach (var keyValuePair in s_CmdHandlerDelegates)
|
||||
{
|
||||
Debug.Log($" Invoker:{keyValuePair.Value.invokeClass}:{keyValuePair.Value.invokeFunction.GetMethodName()} {keyValuePair.Value.invokeType} {keyValuePair.Key}");
|
||||
QLog.Log($" Invoker:{keyValuePair.Value.invokeClass}:{keyValuePair.Value.invokeFunction.GetMethodName()} {keyValuePair.Value.invokeType} {keyValuePair.Key}");
|
||||
}
|
||||
}
|
||||
|
||||
internal bool ContainsCommandDelegate(int cmdHash)
|
||||
=> s_CmdHandlerDelegates.ContainsKey(cmdHash);
|
||||
|
||||
internal bool InvokeCommandDelegate(int cmdHash, QSBNetworkReader reader)
|
||||
internal bool InvokeCommandDelegate(int cmdHash, QNetworkReader reader)
|
||||
{
|
||||
bool result;
|
||||
if (!s_CmdHandlerDelegates.ContainsKey(cmdHash))
|
||||
@ -264,7 +264,7 @@ namespace QuantumUNET
|
||||
return result;
|
||||
}
|
||||
|
||||
internal bool InvokeRpcDelegate(int cmdHash, QSBNetworkReader reader)
|
||||
internal bool InvokeRpcDelegate(int cmdHash, QNetworkReader reader)
|
||||
{
|
||||
bool result;
|
||||
if (!s_CmdHandlerDelegates.ContainsKey(cmdHash))
|
||||
@ -294,7 +294,7 @@ namespace QuantumUNET
|
||||
return result;
|
||||
}
|
||||
|
||||
internal bool InvokeSyncEventDelegate(int cmdHash, QSBNetworkReader reader)
|
||||
internal bool InvokeSyncEventDelegate(int cmdHash, QNetworkReader reader)
|
||||
{
|
||||
bool result;
|
||||
if (!s_CmdHandlerDelegates.ContainsKey(cmdHash))
|
||||
@ -317,7 +317,7 @@ namespace QuantumUNET
|
||||
return result;
|
||||
}
|
||||
|
||||
internal bool InvokeSyncListDelegate(int cmdHash, QSBNetworkReader reader)
|
||||
internal bool InvokeSyncListDelegate(int cmdHash, QNetworkReader reader)
|
||||
{
|
||||
bool result;
|
||||
if (!s_CmdHandlerDelegates.ContainsKey(cmdHash))
|
||||
@ -399,13 +399,13 @@ namespace QuantumUNET
|
||||
NetworkInstanceId networkInstanceId = default;
|
||||
if (newGameObject != null)
|
||||
{
|
||||
var component = newGameObject.GetComponent<QSBNetworkIdentity>();
|
||||
var component = newGameObject.GetComponent<QNetworkIdentity>();
|
||||
if (component != null)
|
||||
{
|
||||
networkInstanceId = component.NetId;
|
||||
if (networkInstanceId.IsEmpty())
|
||||
{
|
||||
Debug.LogWarning(
|
||||
QLog.LogWarning(
|
||||
$"SetSyncVarGameObject GameObject {newGameObject} has a zero netId. Maybe it is not spawned yet?");
|
||||
}
|
||||
}
|
||||
@ -413,11 +413,11 @@ namespace QuantumUNET
|
||||
NetworkInstanceId networkInstanceId2 = default;
|
||||
if (gameObjectField != null)
|
||||
{
|
||||
networkInstanceId2 = gameObjectField.GetComponent<QSBNetworkIdentity>().NetId;
|
||||
networkInstanceId2 = gameObjectField.GetComponent<QNetworkIdentity>().NetId;
|
||||
}
|
||||
if (networkInstanceId != networkInstanceId2)
|
||||
{
|
||||
Debug.Log(
|
||||
QLog.Log(
|
||||
$"SetSyncVar GameObject {GetType().Name} bit [{dirtyBit}] netfieldId:{networkInstanceId2}->{networkInstanceId}");
|
||||
SetDirtyBit(dirtyBit);
|
||||
gameObjectField = newGameObject;
|
||||
@ -443,7 +443,7 @@ namespace QuantumUNET
|
||||
|
||||
if (flag)
|
||||
{
|
||||
Debug.Log($"SetSyncVar {GetType().Name} bit [{dirtyBit}] {fieldValue}->{value}");
|
||||
QLog.Log($"SetSyncVar {GetType().Name} bit [{dirtyBit}] {fieldValue}->{value}");
|
||||
|
||||
SetDirtyBit(dirtyBit);
|
||||
fieldValue = value;
|
||||
@ -470,7 +470,7 @@ namespace QuantumUNET
|
||||
return -1;
|
||||
}
|
||||
|
||||
public virtual bool OnSerialize(QSBNetworkWriter writer, bool initialState)
|
||||
public virtual bool OnSerialize(QNetworkWriter writer, bool initialState)
|
||||
{
|
||||
if (!initialState)
|
||||
{
|
||||
@ -479,7 +479,7 @@ namespace QuantumUNET
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual void OnDeserialize(QSBNetworkReader reader, bool initialState)
|
||||
public virtual void OnDeserialize(QNetworkReader reader, bool initialState)
|
||||
{
|
||||
if (!initialState)
|
||||
{
|
||||
@ -515,26 +515,26 @@ namespace QuantumUNET
|
||||
{
|
||||
}
|
||||
|
||||
public virtual bool OnRebuildObservers(HashSet<QSBNetworkConnection> observers, bool initialize) => false;
|
||||
public virtual bool OnRebuildObservers(HashSet<QNetworkConnection> observers, bool initialize) => false;
|
||||
|
||||
public virtual void OnSetLocalVisibility(bool vis)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual bool OnCheckObserver(QSBNetworkConnection conn) => true;
|
||||
public virtual bool OnCheckObserver(QNetworkConnection conn) => true;
|
||||
|
||||
public virtual int GetNetworkChannel() => 0;
|
||||
|
||||
public virtual float GetNetworkSendInterval() => 0.1f;
|
||||
|
||||
private float m_LastSendTime;
|
||||
private QSBNetworkIdentity m_MyView;
|
||||
private QNetworkIdentity m_MyView;
|
||||
|
||||
private static readonly Dictionary<int, Invoker> s_CmdHandlerDelegates = new Dictionary<int, Invoker>();
|
||||
|
||||
public delegate void CmdDelegate(QSBNetworkBehaviour obj, QSBNetworkReader reader);
|
||||
public delegate void CmdDelegate(QNetworkBehaviour obj, QNetworkReader reader);
|
||||
|
||||
protected delegate void EventDelegate(List<Delegate> targets, QSBNetworkReader reader);
|
||||
protected delegate void EventDelegate(List<Delegate> targets, QNetworkReader reader);
|
||||
|
||||
protected enum UNetInvokeType
|
||||
{
|
@ -4,15 +4,15 @@ using UnityEngine;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
public class QSBNetworkCRC
|
||||
public class QNetworkCRC
|
||||
{
|
||||
internal static QSBNetworkCRC singleton
|
||||
internal static QNetworkCRC singleton
|
||||
{
|
||||
get
|
||||
{
|
||||
if (s_Singleton == null)
|
||||
{
|
||||
s_Singleton = new QSBNetworkCRC();
|
||||
s_Singleton = new QNetworkCRC();
|
||||
}
|
||||
return s_Singleton;
|
||||
}
|
||||
@ -31,7 +31,7 @@ namespace QuantumUNET
|
||||
singleton.scripts.Clear();
|
||||
foreach (var type in callingAssembly.GetTypes())
|
||||
{
|
||||
if (type.GetBaseType() == typeof(QSBNetworkBehaviour))
|
||||
if (type.GetBaseType() == typeof(QNetworkBehaviour))
|
||||
{
|
||||
var method = type.GetMethod(".cctor", BindingFlags.Static);
|
||||
method?.Invoke(null, new object[0]);
|
||||
@ -41,9 +41,9 @@ namespace QuantumUNET
|
||||
|
||||
public static void RegisterBehaviour(string name, int channel) => singleton.scripts[name] = channel;
|
||||
|
||||
internal static bool Validate(QSBCRCMessageEntry[] scripts, int numChannels) => singleton.ValidateInternal(scripts, numChannels);
|
||||
internal static bool Validate(QCRCMessageEntry[] scripts, int numChannels) => singleton.ValidateInternal(scripts, numChannels);
|
||||
|
||||
private bool ValidateInternal(QSBCRCMessageEntry[] remoteScripts, int numChannels)
|
||||
private bool ValidateInternal(QCRCMessageEntry[] remoteScripts, int numChannels)
|
||||
{
|
||||
bool result;
|
||||
if (scripts.Count != remoteScripts.Length)
|
||||
@ -81,7 +81,7 @@ namespace QuantumUNET
|
||||
return result;
|
||||
}
|
||||
|
||||
private void Dump(QSBCRCMessageEntry[] remoteScripts)
|
||||
private void Dump(QCRCMessageEntry[] remoteScripts)
|
||||
{
|
||||
foreach (var text in scripts.Keys)
|
||||
{
|
||||
@ -93,7 +93,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
internal static QSBNetworkCRC s_Singleton;
|
||||
internal static QNetworkCRC s_Singleton;
|
||||
private bool m_ScriptCRCCheck;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using OWML.Logging;
|
||||
using QuantumUNET.Logging;
|
||||
using QuantumUNET.Messages;
|
||||
using QuantumUNET.Transport;
|
||||
using System;
|
||||
@ -11,16 +11,16 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
public class QSBNetworkClient
|
||||
public class QNetworkClient
|
||||
{
|
||||
public QSBNetworkClient()
|
||||
public QNetworkClient()
|
||||
{
|
||||
m_MsgBuffer = new byte[65535];
|
||||
m_MsgReader = new NetworkReader(m_MsgBuffer);
|
||||
AddClient(this);
|
||||
}
|
||||
|
||||
public QSBNetworkClient(QSBNetworkConnection conn)
|
||||
public QNetworkClient(QNetworkConnection conn)
|
||||
{
|
||||
m_MsgBuffer = new byte[65535];
|
||||
m_MsgReader = new NetworkReader(m_MsgBuffer);
|
||||
@ -32,21 +32,21 @@ namespace QuantumUNET
|
||||
RegisterSystemHandlers(false);
|
||||
}
|
||||
|
||||
public static List<QSBNetworkClient> allClients { get; private set; } = new List<QSBNetworkClient>();
|
||||
public static List<QNetworkClient> allClients { get; private set; } = new List<QNetworkClient>();
|
||||
|
||||
public static bool active { get; private set; }
|
||||
|
||||
internal void SetHandlers(QSBNetworkConnection conn) => conn.SetHandlers(m_MessageHandlers);
|
||||
internal void SetHandlers(QNetworkConnection conn) => conn.SetHandlers(m_MessageHandlers);
|
||||
|
||||
public string serverIp { get; private set; } = "";
|
||||
|
||||
public int serverPort { get; private set; }
|
||||
|
||||
public QSBNetworkConnection connection => m_Connection;
|
||||
public QNetworkConnection connection => m_Connection;
|
||||
|
||||
internal int hostId { get; private set; } = -1;
|
||||
|
||||
public Dictionary<short, QSBNetworkMessageDelegate> handlers => m_MessageHandlers.GetHandlers();
|
||||
public Dictionary<short, QNetworkMessageDelegate> handlers => m_MessageHandlers.GetHandlers();
|
||||
|
||||
public int numChannels => hostTopology.DefaultConfig.ChannelCount;
|
||||
|
||||
@ -71,9 +71,9 @@ namespace QuantumUNET
|
||||
|
||||
public bool isConnected => m_AsyncConnect == ConnectState.Connected;
|
||||
|
||||
public Type networkConnectionClass { get; private set; } = typeof(QSBNetworkConnection);
|
||||
public Type networkConnectionClass { get; private set; } = typeof(QNetworkConnection);
|
||||
|
||||
public void SetNetworkConnectionClass<T>() where T : QSBNetworkConnection => networkConnectionClass = typeof(T);
|
||||
public void SetNetworkConnectionClass<T>() where T : QNetworkConnection => networkConnectionClass = typeof(T);
|
||||
|
||||
public bool Configure(ConnectionConfig config, int maxConnections)
|
||||
{
|
||||
@ -92,19 +92,19 @@ namespace QuantumUNET
|
||||
bool result;
|
||||
if (!active)
|
||||
{
|
||||
Debug.LogError("Reconnect - NetworkClient must be active");
|
||||
QLog.LogError("Reconnect - NetworkClient must be active");
|
||||
result = false;
|
||||
}
|
||||
else if (m_Connection == null)
|
||||
{
|
||||
Debug.LogError("Reconnect - no old connection exists");
|
||||
QLog.LogError("Reconnect - no old connection exists");
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"NetworkClient Reconnect {serverIp}:{serverPort}");
|
||||
QSBClientScene.HandleClientDisconnect(m_Connection);
|
||||
QSBClientScene.ClearLocalPlayers();
|
||||
QLog.Log($"NetworkClient Reconnect {serverIp}:{serverPort}");
|
||||
QClientScene.HandleClientDisconnect(m_Connection);
|
||||
QClientScene.ClearLocalPlayers();
|
||||
m_Connection.Disconnect();
|
||||
m_Connection = null;
|
||||
hostId = NetworkTransport.AddHost(hostTopology, m_HostPort);
|
||||
@ -121,7 +121,7 @@ namespace QuantumUNET
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"Async DNS START:{serverIp}");
|
||||
QLog.Log($"Async DNS START:{serverIp}");
|
||||
m_AsyncConnect = ConnectState.Resolving;
|
||||
Dns.BeginGetHostAddresses(serverIp, GetHostAddressesCallback, this);
|
||||
}
|
||||
@ -135,31 +135,31 @@ namespace QuantumUNET
|
||||
bool result;
|
||||
if (!active)
|
||||
{
|
||||
Debug.LogError("Reconnect - NetworkClient must be active");
|
||||
QLog.LogError("Reconnect - NetworkClient must be active");
|
||||
result = false;
|
||||
}
|
||||
else if (m_Connection == null)
|
||||
{
|
||||
Debug.LogError("Reconnect - no old connection exists");
|
||||
QLog.LogError("Reconnect - no old connection exists");
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("NetworkClient Reconnect to remoteSockAddr");
|
||||
QSBClientScene.HandleClientDisconnect(m_Connection);
|
||||
QSBClientScene.ClearLocalPlayers();
|
||||
QLog.Log("NetworkClient Reconnect to remoteSockAddr");
|
||||
QClientScene.HandleClientDisconnect(m_Connection);
|
||||
QClientScene.ClearLocalPlayers();
|
||||
m_Connection.Disconnect();
|
||||
m_Connection = null;
|
||||
hostId = NetworkTransport.AddHost(hostTopology, m_HostPort);
|
||||
if (secureTunnelEndPoint == null)
|
||||
{
|
||||
Debug.LogError("Reconnect failed: null endpoint passed in");
|
||||
QLog.LogError("Reconnect failed: null endpoint passed in");
|
||||
m_AsyncConnect = ConnectState.Failed;
|
||||
result = false;
|
||||
}
|
||||
else if (secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetwork && secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetworkV6)
|
||||
{
|
||||
Debug.LogError("Reconnect failed: Endpoint AddressFamily must be either InterNetwork or InterNetworkV6");
|
||||
QLog.LogError("Reconnect failed: Endpoint AddressFamily must be either InterNetwork or InterNetworkV6");
|
||||
m_AsyncConnect = ConnectState.Failed;
|
||||
result = false;
|
||||
}
|
||||
@ -174,7 +174,7 @@ namespace QuantumUNET
|
||||
}
|
||||
else if (fullName != "UnityEngine.XboxOne.XboxOneEndPoint" && fullName != "UnityEngine.PS4.SceEndPoint")
|
||||
{
|
||||
Debug.LogError("Reconnect failed: invalid Endpoint (not IPEndPoint or XboxOneEndPoint or SceEndPoint)");
|
||||
QLog.LogError("Reconnect failed: invalid Endpoint (not IPEndPoint or XboxOneEndPoint or SceEndPoint)");
|
||||
m_AsyncConnect = ConnectState.Failed;
|
||||
result = false;
|
||||
}
|
||||
@ -189,19 +189,19 @@ namespace QuantumUNET
|
||||
}
|
||||
catch (Exception arg)
|
||||
{
|
||||
Debug.LogError($"Reconnect failed: Exception when trying to connect to EndPoint: {arg}");
|
||||
QLog.LogError($"Reconnect failed: Exception when trying to connect to EndPoint: {arg}");
|
||||
m_AsyncConnect = ConnectState.Failed;
|
||||
return false;
|
||||
}
|
||||
if (m_ClientConnectionId == 0)
|
||||
{
|
||||
Debug.LogError($"Reconnect failed: Unable to connect to EndPoint ({b})");
|
||||
QLog.LogError($"Reconnect failed: Unable to connect to EndPoint ({b})");
|
||||
m_AsyncConnect = ConnectState.Failed;
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Connection = (QSBNetworkConnection)Activator.CreateInstance(networkConnectionClass);
|
||||
m_Connection = (QNetworkConnection)Activator.CreateInstance(networkConnectionClass);
|
||||
m_Connection.SetHandlers(m_MessageHandlers);
|
||||
m_Connection.Initialize(serverIp, hostId, m_ClientConnectionId, hostTopology);
|
||||
result = true;
|
||||
@ -244,7 +244,7 @@ namespace QuantumUNET
|
||||
}
|
||||
else
|
||||
{
|
||||
ModConsole.OwmlConsole.WriteLine($"Async DNS START:{serverIp}");
|
||||
QLog.Log($"Async DNS START:{serverIp}");
|
||||
m_RequestedServerHost = serverIp;
|
||||
m_AsyncConnect = ConnectState.Resolving;
|
||||
Dns.BeginGetHostAddresses(serverIp, GetHostAddressesCallback, this);
|
||||
@ -253,18 +253,16 @@ namespace QuantumUNET
|
||||
|
||||
public void Connect(EndPoint secureTunnelEndPoint)
|
||||
{
|
||||
//bool usePlatformSpecificProtocols = NetworkTransport.DoesEndPointUsePlatformProtocols(secureTunnelEndPoint);
|
||||
var usePlatformSpecificProtocols = false;
|
||||
PrepareForConnect(usePlatformSpecificProtocols);
|
||||
Debug.Log("Client Connect to remoteSockAddr");
|
||||
PrepareForConnect();
|
||||
QLog.Log("Client Connect to remoteSockAddr");
|
||||
if (secureTunnelEndPoint == null)
|
||||
{
|
||||
Debug.LogError("Connect failed: null endpoint passed in");
|
||||
QLog.LogError("Connect failed: null endpoint passed in");
|
||||
m_AsyncConnect = ConnectState.Failed;
|
||||
}
|
||||
else if (secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetwork && secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetworkV6)
|
||||
{
|
||||
Debug.LogError("Connect failed: Endpoint AddressFamily must be either InterNetwork or InterNetworkV6");
|
||||
QLog.LogError("Connect failed: Endpoint AddressFamily must be either InterNetwork or InterNetworkV6");
|
||||
m_AsyncConnect = ConnectState.Failed;
|
||||
}
|
||||
else
|
||||
@ -277,7 +275,7 @@ namespace QuantumUNET
|
||||
}
|
||||
else if (fullName != "UnityEngine.XboxOne.XboxOneEndPoint" && fullName != "UnityEngine.PS4.SceEndPoint" && fullName != "UnityEngine.PSVita.SceEndPoint")
|
||||
{
|
||||
Debug.LogError("Connect failed: invalid Endpoint (not IPEndPoint or XboxOneEndPoint or SceEndPoint)");
|
||||
QLog.LogError("Connect failed: invalid Endpoint (not IPEndPoint or XboxOneEndPoint or SceEndPoint)");
|
||||
m_AsyncConnect = ConnectState.Failed;
|
||||
}
|
||||
else
|
||||
@ -291,18 +289,18 @@ namespace QuantumUNET
|
||||
}
|
||||
catch (Exception arg)
|
||||
{
|
||||
Debug.LogError($"Connect failed: Exception when trying to connect to EndPoint: {arg}");
|
||||
QLog.LogError($"Connect failed: Exception when trying to connect to EndPoint: {arg}");
|
||||
m_AsyncConnect = ConnectState.Failed;
|
||||
return;
|
||||
}
|
||||
if (m_ClientConnectionId == 0)
|
||||
{
|
||||
Debug.LogError($"Connect failed: Unable to connect to EndPoint ({b})");
|
||||
QLog.LogError($"Connect failed: Unable to connect to EndPoint ({b})");
|
||||
m_AsyncConnect = ConnectState.Failed;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Connection = (QSBNetworkConnection)Activator.CreateInstance(networkConnectionClass);
|
||||
m_Connection = (QNetworkConnection)Activator.CreateInstance(networkConnectionClass);
|
||||
m_Connection.SetHandlers(m_MessageHandlers);
|
||||
m_Connection.Initialize(serverIp, hostId, m_ClientConnectionId, hostTopology);
|
||||
}
|
||||
@ -310,9 +308,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
private void PrepareForConnect() => PrepareForConnect(false);
|
||||
|
||||
private void PrepareForConnect(bool usePlatformSpecificProtocols)
|
||||
private void PrepareForConnect()
|
||||
{
|
||||
SetActive(true);
|
||||
RegisterSystemHandlers(false);
|
||||
@ -321,7 +317,7 @@ namespace QuantumUNET
|
||||
var connectionConfig = new ConnectionConfig();
|
||||
connectionConfig.AddChannel(QosType.ReliableSequenced);
|
||||
connectionConfig.AddChannel(QosType.Unreliable);
|
||||
connectionConfig.UsePlatformSpecificProtocols = usePlatformSpecificProtocols;
|
||||
connectionConfig.UsePlatformSpecificProtocols = false;
|
||||
hostTopology = new HostTopology(connectionConfig, 8);
|
||||
}
|
||||
if (m_UseSimulator)
|
||||
@ -332,7 +328,7 @@ namespace QuantumUNET
|
||||
num = 1;
|
||||
}
|
||||
var num2 = m_SimulatedLatency * 3;
|
||||
ModConsole.OwmlConsole.WriteLine($"AddHost Using Simulator {num}/{num2}");
|
||||
QLog.Log($"AddHost Using Simulator {num}/{num2}");
|
||||
hostId = NetworkTransport.AddHostWithSimulator(hostTopology, num, num2, m_HostPort);
|
||||
}
|
||||
else
|
||||
@ -346,25 +342,25 @@ namespace QuantumUNET
|
||||
try
|
||||
{
|
||||
var array = Dns.EndGetHostAddresses(ar);
|
||||
var networkClient = (QSBNetworkClient)ar.AsyncState;
|
||||
var networkClient = (QNetworkClient)ar.AsyncState;
|
||||
if (array.Length == 0)
|
||||
{
|
||||
Debug.LogError($"DNS lookup failed for:{networkClient.m_RequestedServerHost}");
|
||||
QLog.LogError($"DNS lookup failed for:{networkClient.m_RequestedServerHost}");
|
||||
networkClient.m_AsyncConnect = ConnectState.Failed;
|
||||
}
|
||||
else
|
||||
{
|
||||
networkClient.serverIp = array[0].ToString();
|
||||
networkClient.m_AsyncConnect = ConnectState.Resolved;
|
||||
Debug.Log(
|
||||
QLog.Log(
|
||||
$"Async DNS Result:{networkClient.serverIp} for {networkClient.m_RequestedServerHost}: {networkClient.serverIp}");
|
||||
}
|
||||
}
|
||||
catch (SocketException ex)
|
||||
{
|
||||
var networkClient2 = (QSBNetworkClient)ar.AsyncState;
|
||||
Debug.LogError($"DNS resolution failed: {ex.GetErrorCode()}");
|
||||
Debug.LogError($"Exception:{ex}");
|
||||
var networkClient2 = (QNetworkClient)ar.AsyncState;
|
||||
QLog.LogError($"DNS resolution failed: {ex.GetErrorCode()}");
|
||||
QLog.LogError($"Exception:{ex}");
|
||||
networkClient2.m_AsyncConnect = ConnectState.Failed;
|
||||
}
|
||||
}
|
||||
@ -378,7 +374,7 @@ namespace QuantumUNET
|
||||
{
|
||||
num = 1;
|
||||
}
|
||||
ModConsole.OwmlConsole.WriteLine(
|
||||
QLog.Log(
|
||||
$"Connect Using Simulator {m_SimulatedLatency / 3}/{m_SimulatedLatency}");
|
||||
var conf = new ConnectionSimulatorConfig(num, m_SimulatedLatency, num, m_SimulatedLatency, m_PacketLoss);
|
||||
m_ClientConnectionId = NetworkTransport.ConnectWithSimulator(hostId, serverIp, serverPort, 0, out var b, conf);
|
||||
@ -387,7 +383,7 @@ namespace QuantumUNET
|
||||
{
|
||||
m_ClientConnectionId = NetworkTransport.Connect(hostId, serverIp, serverPort, 0, out var b);
|
||||
}
|
||||
m_Connection = (QSBNetworkConnection)Activator.CreateInstance(networkConnectionClass);
|
||||
m_Connection = (QNetworkConnection)Activator.CreateInstance(networkConnectionClass);
|
||||
m_Connection.SetHandlers(m_MessageHandlers);
|
||||
m_Connection.Initialize(serverIp, hostId, m_ClientConnectionId, hostTopology);
|
||||
}
|
||||
@ -395,7 +391,7 @@ namespace QuantumUNET
|
||||
public virtual void Disconnect()
|
||||
{
|
||||
m_AsyncConnect = ConnectState.Disconnected;
|
||||
QSBClientScene.HandleClientDisconnect(m_Connection);
|
||||
QClientScene.HandleClientDisconnect(m_Connection);
|
||||
if (m_Connection != null)
|
||||
{
|
||||
m_Connection.Disconnect();
|
||||
@ -409,14 +405,14 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
public bool Send(short msgType, QSBMessageBase msg)
|
||||
public bool Send(short msgType, QMessageBase msg)
|
||||
{
|
||||
bool result;
|
||||
if (m_Connection != null)
|
||||
{
|
||||
if (m_AsyncConnect != ConnectState.Connected)
|
||||
{
|
||||
Debug.LogError("NetworkClient Send when not connected to a server");
|
||||
QLog.LogError("NetworkClient Send when not connected to a server");
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
@ -426,20 +422,20 @@ namespace QuantumUNET
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("NetworkClient Send with no connection");
|
||||
QLog.LogError("NetworkClient Send with no connection");
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool SendWriter(QSBNetworkWriter writer, int channelId)
|
||||
public bool SendWriter(QNetworkWriter writer, int channelId)
|
||||
{
|
||||
bool result;
|
||||
if (m_Connection != null)
|
||||
{
|
||||
if (m_AsyncConnect != ConnectState.Connected)
|
||||
{
|
||||
Debug.LogError("NetworkClient SendWriter when not connected to a server");
|
||||
QLog.LogError("NetworkClient SendWriter when not connected to a server");
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
@ -449,7 +445,7 @@ namespace QuantumUNET
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("NetworkClient SendWriter with no connection");
|
||||
QLog.LogError("NetworkClient SendWriter with no connection");
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
@ -462,7 +458,7 @@ namespace QuantumUNET
|
||||
{
|
||||
if (m_AsyncConnect != ConnectState.Connected)
|
||||
{
|
||||
Debug.LogError("NetworkClient SendBytes when not connected to a server");
|
||||
QLog.LogError("NetworkClient SendBytes when not connected to a server");
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
@ -472,20 +468,20 @@ namespace QuantumUNET
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("NetworkClient SendBytes with no connection");
|
||||
QLog.LogError("NetworkClient SendBytes with no connection");
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool SendUnreliable(short msgType, QSBMessageBase msg)
|
||||
public bool SendUnreliable(short msgType, QMessageBase msg)
|
||||
{
|
||||
bool result;
|
||||
if (m_Connection != null)
|
||||
{
|
||||
if (m_AsyncConnect != ConnectState.Connected)
|
||||
{
|
||||
Debug.LogError("NetworkClient SendUnreliable when not connected to a server");
|
||||
QLog.LogError("NetworkClient SendUnreliable when not connected to a server");
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
@ -495,20 +491,20 @@ namespace QuantumUNET
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("NetworkClient SendUnreliable with no connection");
|
||||
QLog.LogError("NetworkClient SendUnreliable with no connection");
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool SendByChannel(short msgType, QSBMessageBase msg, int channelId)
|
||||
public bool SendByChannel(short msgType, QMessageBase msg, int channelId)
|
||||
{
|
||||
bool result;
|
||||
if (m_Connection != null)
|
||||
{
|
||||
if (m_AsyncConnect != ConnectState.Connected)
|
||||
{
|
||||
Debug.LogError("NetworkClient SendByChannel when not connected to a server");
|
||||
QLog.LogError("NetworkClient SendByChannel when not connected to a server");
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
@ -518,7 +514,7 @@ namespace QuantumUNET
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("NetworkClient SendByChannel with no connection");
|
||||
QLog.LogError("NetworkClient SendByChannel with no connection");
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
@ -528,7 +524,7 @@ namespace QuantumUNET
|
||||
{
|
||||
if (m_Connection == null)
|
||||
{
|
||||
Debug.LogWarning("SetMaxDelay failed, not connected.");
|
||||
QLog.LogWarning("SetMaxDelay failed, not connected.");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -538,7 +534,7 @@ namespace QuantumUNET
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
Debug.Log($"Shutting down client {hostId}");
|
||||
QLog.Log($"Shutting down client {hostId}");
|
||||
if (hostId != -1)
|
||||
{
|
||||
NetworkTransport.RemoveHost(hostId);
|
||||
@ -599,7 +595,7 @@ namespace QuantumUNET
|
||||
break;
|
||||
|
||||
case NetworkEventType.ConnectEvent:
|
||||
Debug.Log("Client connected");
|
||||
QLog.Log("Client connected");
|
||||
if (b != 0)
|
||||
{
|
||||
goto Block_10;
|
||||
@ -609,7 +605,7 @@ namespace QuantumUNET
|
||||
break;
|
||||
|
||||
case NetworkEventType.DisconnectEvent:
|
||||
Debug.Log("Client disconnected");
|
||||
QLog.Log("Client disconnected");
|
||||
m_AsyncConnect = ConnectState.Disconnected;
|
||||
if (b != 0)
|
||||
{
|
||||
@ -618,7 +614,7 @@ namespace QuantumUNET
|
||||
GenerateDisconnectError(b);
|
||||
}
|
||||
}
|
||||
QSBClientScene.HandleClientDisconnect(m_Connection);
|
||||
QClientScene.HandleClientDisconnect(m_Connection);
|
||||
m_Connection?.InvokeHandlerNoData(33);
|
||||
break;
|
||||
|
||||
@ -626,7 +622,7 @@ namespace QuantumUNET
|
||||
break;
|
||||
|
||||
default:
|
||||
Debug.LogError($"Unknown network message type received: {networkEventType}");
|
||||
QLog.LogError($"Unknown network message type received: {networkEventType}");
|
||||
break;
|
||||
}
|
||||
if (++num >= 500)
|
||||
@ -649,7 +645,7 @@ namespace QuantumUNET
|
||||
GenerateDataError(b);
|
||||
return;
|
||||
Block_17:
|
||||
Debug.Log($"MaxEventsPerFrame hit ({500})");
|
||||
QLog.Log($"MaxEventsPerFrame hit ({500})");
|
||||
Block_19:
|
||||
IL_2C6:
|
||||
if (m_Connection != null && m_AsyncConnect == ConnectState.Connected)
|
||||
@ -661,19 +657,19 @@ namespace QuantumUNET
|
||||
|
||||
private void GenerateConnectError(int error)
|
||||
{
|
||||
Debug.LogError($"UNet Client Error Connect Error: {error}");
|
||||
QLog.LogError($"UNet Client Error Connect Error: {error}");
|
||||
GenerateError(error);
|
||||
}
|
||||
|
||||
private void GenerateDataError(int error)
|
||||
{
|
||||
Debug.LogError($"UNet Client Data Error: {(NetworkError)error}");
|
||||
QLog.LogError($"UNet Client Data Error: {(NetworkError)error}");
|
||||
GenerateError(error);
|
||||
}
|
||||
|
||||
private void GenerateDisconnectError(int error)
|
||||
{
|
||||
Debug.LogError($"UNet Client Disconnect Error: {(NetworkError)error}");
|
||||
QLog.LogError($"UNet Client Disconnect Error: {(NetworkError)error}");
|
||||
GenerateError(error);
|
||||
}
|
||||
|
||||
@ -683,15 +679,15 @@ namespace QuantumUNET
|
||||
?? m_MessageHandlers.GetHandler(34);
|
||||
if (handler != null)
|
||||
{
|
||||
var errorMessage = new QSBErrorMessage
|
||||
var errorMessage = new QErrorMessage
|
||||
{
|
||||
errorCode = error
|
||||
};
|
||||
var buffer = new byte[200];
|
||||
var writer = new QSBNetworkWriter(buffer);
|
||||
var writer = new QNetworkWriter(buffer);
|
||||
errorMessage.Serialize(writer);
|
||||
var reader = new QSBNetworkReader(buffer);
|
||||
handler(new QSBNetworkMessage
|
||||
var reader = new QNetworkReader(buffer);
|
||||
handler(new QNetworkMessage
|
||||
{
|
||||
MsgType = 34,
|
||||
Reader = reader,
|
||||
@ -723,7 +719,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<short, QSBNetworkConnection.PacketStat> GetConnectionStats() =>
|
||||
public Dictionary<short, QNetworkConnection.PacketStat> GetConnectionStats() =>
|
||||
m_Connection?.PacketStats;
|
||||
|
||||
public void ResetConnectionStats() => m_Connection?.ResetStats();
|
||||
@ -733,25 +729,25 @@ namespace QuantumUNET
|
||||
|
||||
internal void RegisterSystemHandlers(bool localClient)
|
||||
{
|
||||
QSBClientScene.RegisterSystemHandlers(this, localClient);
|
||||
QClientScene.RegisterSystemHandlers(this, localClient);
|
||||
RegisterHandlerSafe(14, OnCRC);
|
||||
}
|
||||
|
||||
private void OnCRC(QSBNetworkMessage netMsg)
|
||||
private void OnCRC(QNetworkMessage netMsg)
|
||||
{
|
||||
netMsg.ReadMessage(s_CRCMessage);
|
||||
QSBNetworkCRC.Validate(s_CRCMessage.scripts, numChannels);
|
||||
QNetworkCRC.Validate(s_CRCMessage.scripts, numChannels);
|
||||
}
|
||||
|
||||
public void RegisterHandler(short msgType, QSBNetworkMessageDelegate handler) => m_MessageHandlers.RegisterHandler(msgType, handler);
|
||||
public void RegisterHandler(short msgType, QNetworkMessageDelegate handler) => m_MessageHandlers.RegisterHandler(msgType, handler);
|
||||
|
||||
public void RegisterHandlerSafe(short msgType, QSBNetworkMessageDelegate handler) => m_MessageHandlers.RegisterHandlerSafe(msgType, handler);
|
||||
public void RegisterHandlerSafe(short msgType, QNetworkMessageDelegate handler) => m_MessageHandlers.RegisterHandlerSafe(msgType, handler);
|
||||
|
||||
public void UnregisterHandler(short msgType) => m_MessageHandlers.UnregisterHandler(msgType);
|
||||
|
||||
public static Dictionary<short, QSBNetworkConnection.PacketStat> GetTotalConnectionStats()
|
||||
public static Dictionary<short, QNetworkConnection.PacketStat> GetTotalConnectionStats()
|
||||
{
|
||||
var dictionary = new Dictionary<short, QSBNetworkConnection.PacketStat>();
|
||||
var dictionary = new Dictionary<short, QNetworkConnection.PacketStat>();
|
||||
foreach (var networkClient in allClients)
|
||||
{
|
||||
var connectionStats = networkClient.GetConnectionStats();
|
||||
@ -766,16 +762,16 @@ namespace QuantumUNET
|
||||
}
|
||||
else
|
||||
{
|
||||
dictionary[key] = new QSBNetworkConnection.PacketStat(connectionStats[key]);
|
||||
dictionary[key] = new QNetworkConnection.PacketStat(connectionStats[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
internal static void AddClient(QSBNetworkClient client) => allClients.Add(client);
|
||||
internal static void AddClient(QNetworkClient client) => allClients.Add(client);
|
||||
|
||||
internal static bool RemoveClient(QSBNetworkClient client) => allClients.Remove(client);
|
||||
internal static bool RemoveClient(QNetworkClient client) => allClients.Remove(client);
|
||||
|
||||
internal static void UpdateClients()
|
||||
{
|
||||
@ -798,9 +794,9 @@ namespace QuantumUNET
|
||||
{
|
||||
allClients[0].Shutdown();
|
||||
}
|
||||
allClients = new List<QSBNetworkClient>();
|
||||
allClients = new List<QNetworkClient>();
|
||||
active = false;
|
||||
QSBClientScene.Shutdown();
|
||||
QClientScene.Shutdown();
|
||||
}
|
||||
|
||||
internal static void SetActive(bool state)
|
||||
@ -826,11 +822,11 @@ namespace QuantumUNET
|
||||
|
||||
private EndPoint m_RemoteEndPoint;
|
||||
|
||||
private static readonly QSBCRCMessage s_CRCMessage = new QSBCRCMessage();
|
||||
private static readonly QCRCMessage s_CRCMessage = new QCRCMessage();
|
||||
|
||||
private readonly QSBNetworkMessageHandlers m_MessageHandlers = new QSBNetworkMessageHandlers();
|
||||
private readonly QNetworkMessageHandlers m_MessageHandlers = new QNetworkMessageHandlers();
|
||||
|
||||
protected QSBNetworkConnection m_Connection;
|
||||
protected QNetworkConnection m_Connection;
|
||||
|
||||
private readonly byte[] m_MsgBuffer;
|
||||
|
@ -1,5 +1,5 @@
|
||||
using OWML.Logging;
|
||||
using QuantumUNET.Components;
|
||||
using QuantumUNET.Components;
|
||||
using QuantumUNET.Logging;
|
||||
using QuantumUNET.Messages;
|
||||
using QuantumUNET.Transport;
|
||||
using System;
|
||||
@ -10,16 +10,16 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
public class QSBNetworkConnection : IDisposable
|
||||
public class QNetworkConnection : IDisposable
|
||||
{
|
||||
public QSBNetworkConnection()
|
||||
public QNetworkConnection()
|
||||
{
|
||||
m_Writer = new QSBNetworkWriter();
|
||||
m_Writer = new QNetworkWriter();
|
||||
}
|
||||
|
||||
internal HashSet<QSBNetworkIdentity> VisList { get; } = new HashSet<QSBNetworkIdentity>();
|
||||
internal HashSet<QNetworkIdentity> VisList { get; } = new HashSet<QNetworkIdentity>();
|
||||
|
||||
public List<QSBPlayerController> PlayerControllers { get; } = new List<QSBPlayerController>();
|
||||
public List<QPlayerController> PlayerControllers { get; } = new List<QPlayerController>();
|
||||
|
||||
public HashSet<NetworkInstanceId> ClientOwnedObjects { get; private set; }
|
||||
|
||||
@ -31,7 +31,7 @@ namespace QuantumUNET
|
||||
|
||||
public virtual void Initialize(string networkAddress, int networkHostId, int networkConnectionId, HostTopology hostTopology)
|
||||
{
|
||||
m_Writer = new QSBNetworkWriter();
|
||||
m_Writer = new QNetworkWriter();
|
||||
address = networkAddress;
|
||||
hostId = networkHostId;
|
||||
connectionId = networkConnectionId;
|
||||
@ -41,7 +41,7 @@ namespace QuantumUNET
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
|
||||
}
|
||||
m_Channels = new QSBChannelBuffer[channelCount];
|
||||
m_Channels = new QChannelBuffer[channelCount];
|
||||
for (var i = 0; i < channelCount; i++)
|
||||
{
|
||||
var channelQOS = hostTopology.DefaultConfig.Channels[i];
|
||||
@ -50,11 +50,11 @@ namespace QuantumUNET
|
||||
{
|
||||
bufferSize = hostTopology.DefaultConfig.FragmentSize * 128;
|
||||
}
|
||||
m_Channels[i] = new QSBChannelBuffer(this, bufferSize, (byte)i, IsReliableQoS(channelQOS.QOS), IsSequencedQoS(channelQOS.QOS));
|
||||
m_Channels[i] = new QChannelBuffer(this, bufferSize, (byte)i, IsReliableQoS(channelQOS.QOS), IsSequencedQoS(channelQOS.QOS));
|
||||
}
|
||||
}
|
||||
|
||||
~QSBNetworkConnection()
|
||||
~QNetworkConnection()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
@ -79,10 +79,10 @@ namespace QuantumUNET
|
||||
{
|
||||
foreach (var netId in ClientOwnedObjects)
|
||||
{
|
||||
var gameObject = QSBNetworkServer.FindLocalObject(netId);
|
||||
var gameObject = QNetworkServer.FindLocalObject(netId);
|
||||
if (gameObject != null)
|
||||
{
|
||||
gameObject.GetComponent<QSBNetworkIdentity>().ClearClientOwner();
|
||||
gameObject.GetComponent<QNetworkIdentity>().ClearClientOwner();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -100,7 +100,7 @@ namespace QuantumUNET
|
||||
{
|
||||
address = "";
|
||||
isReady = false;
|
||||
QSBClientScene.HandleClientDisconnect(this);
|
||||
QClientScene.HandleClientDisconnect(this);
|
||||
if (hostId != -1)
|
||||
{
|
||||
NetworkTransport.Disconnect(hostId, connectionId, out var b);
|
||||
@ -108,7 +108,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
internal void SetHandlers(QSBNetworkMessageHandlers handlers)
|
||||
internal void SetHandlers(QNetworkMessageHandlers handlers)
|
||||
{
|
||||
m_MessageHandlers = handlers;
|
||||
m_MessageHandlersDict = handlers.GetHandlers();
|
||||
@ -118,7 +118,7 @@ namespace QuantumUNET
|
||||
|
||||
public bool InvokeHandlerNoData(short msgType) => InvokeHandler(msgType, null, 0);
|
||||
|
||||
public bool InvokeHandler(short msgType, QSBNetworkReader reader, int channelId)
|
||||
public bool InvokeHandler(short msgType, QNetworkReader reader, int channelId)
|
||||
{
|
||||
bool result;
|
||||
if (m_MessageHandlersDict.ContainsKey(msgType))
|
||||
@ -145,7 +145,7 @@ namespace QuantumUNET
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool InvokeHandler(QSBNetworkMessage netMsg)
|
||||
public bool InvokeHandler(QNetworkMessage netMsg)
|
||||
{
|
||||
bool result;
|
||||
if (m_MessageHandlersDict.ContainsKey(netMsg.MsgType))
|
||||
@ -161,14 +161,14 @@ namespace QuantumUNET
|
||||
return result;
|
||||
}
|
||||
|
||||
internal void HandleFragment(QSBNetworkReader reader, int channelId)
|
||||
internal void HandleFragment(QNetworkReader reader, int channelId)
|
||||
{
|
||||
if (channelId >= 0 && channelId < m_Channels.Length)
|
||||
{
|
||||
var channelBuffer = m_Channels[channelId];
|
||||
if (channelBuffer.HandleFragment(reader))
|
||||
{
|
||||
var networkReader = new QSBNetworkReader(channelBuffer._fragmentBuffer.AsArraySegment().Array);
|
||||
var networkReader = new QNetworkReader(channelBuffer._fragmentBuffer.AsArraySegment().Array);
|
||||
networkReader.ReadInt16();
|
||||
var msgType = networkReader.ReadInt16();
|
||||
InvokeHandler(msgType, networkReader, channelId);
|
||||
@ -176,15 +176,15 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterHandler(short msgType, QSBNetworkMessageDelegate handler) => m_MessageHandlers.RegisterHandler(msgType, handler);
|
||||
public void RegisterHandler(short msgType, QNetworkMessageDelegate handler) => m_MessageHandlers.RegisterHandler(msgType, handler);
|
||||
|
||||
public void UnregisterHandler(short msgType) => m_MessageHandlers.UnregisterHandler(msgType);
|
||||
|
||||
internal void SetPlayerController(QSBPlayerController player)
|
||||
internal void SetPlayerController(QPlayerController player)
|
||||
{
|
||||
while (player.PlayerControllerId >= PlayerControllers.Count)
|
||||
{
|
||||
PlayerControllers.Add(new QSBPlayerController());
|
||||
PlayerControllers.Add(new QPlayerController());
|
||||
}
|
||||
PlayerControllers[player.PlayerControllerId] = player;
|
||||
}
|
||||
@ -195,14 +195,14 @@ namespace QuantumUNET
|
||||
{
|
||||
if (playerControllerId == i && playerControllerId == PlayerControllers[i].PlayerControllerId)
|
||||
{
|
||||
PlayerControllers[i] = new QSBPlayerController();
|
||||
PlayerControllers[i] = new QPlayerController();
|
||||
return;
|
||||
}
|
||||
}
|
||||
Debug.LogError($"RemovePlayer player at playerControllerId {playerControllerId} not found");
|
||||
QLog.LogError($"RemovePlayer player at playerControllerId {playerControllerId} not found");
|
||||
}
|
||||
|
||||
internal bool GetPlayerController(short playerControllerId, out QSBPlayerController playerController)
|
||||
internal bool GetPlayerController(short playerControllerId, out QPlayerController playerController)
|
||||
{
|
||||
playerController = null;
|
||||
bool result;
|
||||
@ -248,11 +248,11 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool Send(short msgType, QSBMessageBase msg) => SendByChannel(msgType, msg, 0);
|
||||
public virtual bool Send(short msgType, QMessageBase msg) => SendByChannel(msgType, msg, 0);
|
||||
|
||||
public virtual bool SendUnreliable(short msgType, QSBMessageBase msg) => SendByChannel(msgType, msg, 1);
|
||||
public virtual bool SendUnreliable(short msgType, QMessageBase msg) => SendByChannel(msgType, msg, 1);
|
||||
|
||||
public virtual bool SendByChannel(short msgType, QSBMessageBase msg, int channelId)
|
||||
public virtual bool SendByChannel(short msgType, QMessageBase msg, int channelId)
|
||||
{
|
||||
m_Writer.StartMessage(msgType);
|
||||
msg.Serialize(m_Writer);
|
||||
@ -262,11 +262,11 @@ namespace QuantumUNET
|
||||
|
||||
public virtual bool SendBytes(byte[] bytes, int numBytes, int channelId) => CheckChannel(channelId) && m_Channels[channelId].SendBytes(bytes, numBytes);
|
||||
|
||||
public virtual bool SendWriter(QSBNetworkWriter writer, int channelId) => CheckChannel(channelId) && m_Channels[channelId].SendWriter(writer);
|
||||
public virtual bool SendWriter(QNetworkWriter writer, int channelId) => CheckChannel(channelId) && m_Channels[channelId].SendWriter(writer);
|
||||
|
||||
private void LogSend(byte[] bytes)
|
||||
{
|
||||
var networkReader = new QSBNetworkReader(bytes);
|
||||
var networkReader = new QNetworkReader(bytes);
|
||||
var num = networkReader.ReadUInt16();
|
||||
var num2 = networkReader.ReadUInt16();
|
||||
var stringBuilder = new StringBuilder();
|
||||
@ -278,7 +278,7 @@ namespace QuantumUNET
|
||||
break;
|
||||
}
|
||||
}
|
||||
ModConsole.OwmlConsole.WriteLine(
|
||||
QLog.Log(
|
||||
$"ConnectionSend con:{connectionId} bytes:{num} msgId:{num2} {stringBuilder}");
|
||||
}
|
||||
|
||||
@ -287,12 +287,12 @@ namespace QuantumUNET
|
||||
bool result;
|
||||
if (m_Channels == null)
|
||||
{
|
||||
Debug.LogWarning($"Channels not initialized sending on id '{channelId}");
|
||||
QLog.LogWarning($"Channels not initialized sending on id '{channelId}");
|
||||
result = false;
|
||||
}
|
||||
else if (channelId < 0 || channelId >= m_Channels.Length)
|
||||
{
|
||||
Debug.LogError(
|
||||
QLog.LogError(
|
||||
$"Invalid channel when sending buffered data, '{channelId}'. Current channel count is {m_Channels.Length}");
|
||||
result = false;
|
||||
}
|
||||
@ -309,26 +309,26 @@ namespace QuantumUNET
|
||||
|
||||
protected void HandleBytes(byte[] buffer, int receivedSize, int channelId)
|
||||
{
|
||||
var reader = new QSBNetworkReader(buffer);
|
||||
var reader = new QNetworkReader(buffer);
|
||||
HandleReader(reader, receivedSize, channelId);
|
||||
}
|
||||
|
||||
protected void HandleReader(QSBNetworkReader reader, int receivedSize, int channelId)
|
||||
protected void HandleReader(QNetworkReader reader, int receivedSize, int channelId)
|
||||
{
|
||||
while (reader.Position < receivedSize)
|
||||
{
|
||||
var num = reader.ReadUInt16();
|
||||
var num2 = reader.ReadInt16();
|
||||
var array = reader.ReadBytes(num);
|
||||
var reader2 = new QSBNetworkReader(array);
|
||||
QSBNetworkMessageDelegate networkMessageDelegate = null;
|
||||
var reader2 = new QNetworkReader(array);
|
||||
QNetworkMessageDelegate networkMessageDelegate = null;
|
||||
if (m_MessageHandlersDict.ContainsKey(num2))
|
||||
{
|
||||
networkMessageDelegate = m_MessageHandlersDict[num2];
|
||||
}
|
||||
if (networkMessageDelegate == null)
|
||||
{
|
||||
ModConsole.OwmlConsole.WriteLine($"Unknown message ID {num2} connId:{connectionId}");
|
||||
QLog.LogError($"Unknown message ID {num2} connId:{connectionId}");
|
||||
break;
|
||||
}
|
||||
m_NetMsg.MsgType = num2;
|
||||
@ -369,18 +369,18 @@ namespace QuantumUNET
|
||||
public override string ToString() =>
|
||||
$"hostId: {hostId} connectionId: {connectionId} isReady: {isReady} channel count: {m_Channels?.Length ?? 0}";
|
||||
|
||||
internal void AddToVisList(QSBNetworkIdentity uv)
|
||||
internal void AddToVisList(QNetworkIdentity uv)
|
||||
{
|
||||
VisList.Add(uv);
|
||||
QSBNetworkServer.ShowForConnection(uv, this);
|
||||
QNetworkServer.ShowForConnection(uv, this);
|
||||
}
|
||||
|
||||
internal void RemoveFromVisList(QSBNetworkIdentity uv, bool isDestroyed)
|
||||
internal void RemoveFromVisList(QNetworkIdentity uv, bool isDestroyed)
|
||||
{
|
||||
VisList.Remove(uv);
|
||||
if (!isDestroyed)
|
||||
{
|
||||
QSBNetworkServer.HideForConnection(uv, this);
|
||||
QNetworkServer.HideForConnection(uv, this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -397,7 +397,7 @@ namespace QuantumUNET
|
||||
|
||||
public virtual bool TransportSend(byte[] bytes, int numBytes, int channelId, out byte error) => NetworkTransport.Send(hostId, connectionId, channelId, bytes, numBytes, out error);
|
||||
|
||||
internal void AddOwnedObject(QSBNetworkIdentity obj)
|
||||
internal void AddOwnedObject(QNetworkIdentity obj)
|
||||
{
|
||||
if (ClientOwnedObjects == null)
|
||||
{
|
||||
@ -406,18 +406,18 @@ namespace QuantumUNET
|
||||
ClientOwnedObjects.Add(obj.NetId);
|
||||
}
|
||||
|
||||
internal void RemoveOwnedObject(QSBNetworkIdentity obj) => ClientOwnedObjects?.Remove(obj.NetId);
|
||||
internal void RemoveOwnedObject(QNetworkIdentity obj) => ClientOwnedObjects?.Remove(obj.NetId);
|
||||
|
||||
internal static void OnFragment(QSBNetworkMessage netMsg) => netMsg.Connection.HandleFragment(netMsg.Reader, netMsg.ChannelId);
|
||||
internal static void OnFragment(QNetworkMessage netMsg) => netMsg.Connection.HandleFragment(netMsg.Reader, netMsg.ChannelId);
|
||||
|
||||
private QSBChannelBuffer[] m_Channels;
|
||||
private readonly QSBNetworkMessage m_NetMsg = new QSBNetworkMessage();
|
||||
private QSBNetworkWriter m_Writer;
|
||||
private QChannelBuffer[] m_Channels;
|
||||
private readonly QNetworkMessage m_NetMsg = new QNetworkMessage();
|
||||
private QNetworkWriter m_Writer;
|
||||
|
||||
private Dictionary<short, QSBNetworkMessageDelegate> m_MessageHandlersDict;
|
||||
private Dictionary<short, QNetworkMessageDelegate> m_MessageHandlersDict;
|
||||
|
||||
private QSBNetworkMessageHandlers m_MessageHandlers;
|
||||
private readonly QSBNetworkMessage m_MessageInfo = new QSBNetworkMessage();
|
||||
private QNetworkMessageHandlers m_MessageHandlers;
|
||||
private readonly QNetworkMessage m_MessageInfo = new QNetworkMessage();
|
||||
|
||||
private const int k_MaxMessageLogSize = 150;
|
||||
public int hostId = -1;
|
||||
@ -449,7 +449,7 @@ namespace QuantumUNET
|
||||
bytes = s.bytes;
|
||||
}
|
||||
|
||||
public override string ToString() => $"{QSBMsgType.MsgTypeToString(msgType)}: count={count} bytes={bytes}";
|
||||
public override string ToString() => $"{QMsgType.MsgTypeToString(msgType)}: count={count} bytes={bytes}";
|
||||
|
||||
public short msgType;
|
||||
|
59
QuantumUNET/QNetworkMessageHandlers.cs
Normal file
59
QuantumUNET/QNetworkMessageHandlers.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using QuantumUNET.Logging;
|
||||
using QuantumUNET.Messages;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
internal class QNetworkMessageHandlers
|
||||
{
|
||||
private readonly Dictionary<short, QNetworkMessageDelegate> _msgHandlers = new Dictionary<short, QNetworkMessageDelegate>();
|
||||
|
||||
internal void RegisterHandlerSafe(short msgType, QNetworkMessageDelegate handler)
|
||||
{
|
||||
if (handler == null)
|
||||
{
|
||||
QLog.LogError($"RegisterHandlerSafe id:{msgType} handler is null");
|
||||
}
|
||||
else
|
||||
{
|
||||
QLog.LogDebug($"RegisterHandlerSafe id:{msgType} handler:{handler.GetMethodName()}");
|
||||
if (!_msgHandlers.ContainsKey(msgType))
|
||||
{
|
||||
_msgHandlers.Add(msgType, handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterHandler(short msgType, QNetworkMessageDelegate handler)
|
||||
{
|
||||
if (handler == null)
|
||||
{
|
||||
QLog.LogError($"RegisterHandler id:{msgType} handler is null");
|
||||
}
|
||||
else if (msgType <= 31)
|
||||
{
|
||||
QLog.LogError($"RegisterHandler: Cannot replace system message handler {msgType}");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_msgHandlers.ContainsKey(msgType))
|
||||
{
|
||||
QLog.Log($"RegisterHandler replacing {msgType}");
|
||||
_msgHandlers.Remove(msgType);
|
||||
}
|
||||
QLog.LogDebug($"RegisterHandler id:{msgType} handler:{handler.GetMethodName()}");
|
||||
_msgHandlers.Add(msgType, handler);
|
||||
}
|
||||
}
|
||||
|
||||
public void UnregisterHandler(short msgType) =>
|
||||
_msgHandlers.Remove(msgType);
|
||||
|
||||
internal QNetworkMessageDelegate GetHandler(short msgType) =>
|
||||
_msgHandlers.ContainsKey(msgType) ? _msgHandlers[msgType] : null;
|
||||
|
||||
internal Dictionary<short, QNetworkMessageDelegate> GetHandlers() => _msgHandlers;
|
||||
|
||||
internal void ClearMessageHandlers() => _msgHandlers.Clear();
|
||||
}
|
||||
}
|
@ -5,15 +5,15 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
internal class QSBNetworkScene
|
||||
internal class QNetworkScene
|
||||
{
|
||||
internal static Dictionary<NetworkHash128, GameObject> guidToPrefab { get; } = new Dictionary<NetworkHash128, GameObject>();
|
||||
|
||||
internal static Dictionary<NetworkHash128, QSBSpawnDelegate> spawnHandlers { get; } = new Dictionary<NetworkHash128, QSBSpawnDelegate>();
|
||||
internal static Dictionary<NetworkHash128, QSpawnDelegate> spawnHandlers { get; } = new Dictionary<NetworkHash128, QSpawnDelegate>();
|
||||
|
||||
internal static Dictionary<NetworkHash128, UnSpawnDelegate> unspawnHandlers { get; } = new Dictionary<NetworkHash128, UnSpawnDelegate>();
|
||||
|
||||
internal Dictionary<NetworkInstanceId, QSBNetworkIdentity> localObjects { get; } = new Dictionary<NetworkInstanceId, QSBNetworkIdentity>();
|
||||
internal Dictionary<NetworkInstanceId, QNetworkIdentity> localObjects { get; } = new Dictionary<NetworkInstanceId, QNetworkIdentity>();
|
||||
|
||||
internal void Shutdown()
|
||||
{
|
||||
@ -29,14 +29,14 @@ namespace QuantumUNET
|
||||
}
|
||||
else
|
||||
{
|
||||
QSBNetworkIdentity networkIdentity = null;
|
||||
QNetworkIdentity networkIdentity = null;
|
||||
if (localObjects.ContainsKey(netId))
|
||||
{
|
||||
networkIdentity = localObjects[netId];
|
||||
}
|
||||
if (networkIdentity == null)
|
||||
{
|
||||
networkIdentity = obj.GetComponent<QSBNetworkIdentity>();
|
||||
networkIdentity = obj.GetComponent<QNetworkIdentity>();
|
||||
localObjects[netId] = networkIdentity;
|
||||
}
|
||||
networkIdentity.UpdateClientServer(isClient, isServer);
|
||||
@ -56,7 +56,7 @@ namespace QuantumUNET
|
||||
return null;
|
||||
}
|
||||
|
||||
internal bool GetNetworkIdentity(NetworkInstanceId netId, out QSBNetworkIdentity uv)
|
||||
internal bool GetNetworkIdentity(NetworkInstanceId netId, out QNetworkIdentity uv)
|
||||
{
|
||||
bool result;
|
||||
if (localObjects.ContainsKey(netId) && localObjects[netId] != null)
|
||||
@ -94,7 +94,7 @@ namespace QuantumUNET
|
||||
|
||||
internal static void RegisterPrefab(GameObject prefab, NetworkHash128 newAssetId)
|
||||
{
|
||||
var component = prefab.GetComponent<QSBNetworkIdentity>();
|
||||
var component = prefab.GetComponent<QNetworkIdentity>();
|
||||
if (component)
|
||||
{
|
||||
component.SetDynamicAssetId(newAssetId);
|
||||
@ -108,7 +108,7 @@ namespace QuantumUNET
|
||||
|
||||
internal static void RegisterPrefab(GameObject prefab)
|
||||
{
|
||||
var component = prefab.GetComponent<QSBNetworkIdentity>();
|
||||
var component = prefab.GetComponent<QNetworkIdentity>();
|
||||
if (component)
|
||||
{
|
||||
guidToPrefab[component.AssetId] = prefab;
|
||||
@ -159,7 +159,7 @@ namespace QuantumUNET
|
||||
unspawnHandlers.Remove(assetId);
|
||||
}
|
||||
|
||||
internal static void RegisterSpawnHandler(NetworkHash128 assetId, QSBSpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
|
||||
internal static void RegisterSpawnHandler(NetworkHash128 assetId, QSpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
|
||||
{
|
||||
if (spawnHandler == null || unspawnHandler == null)
|
||||
{
|
||||
@ -174,7 +174,7 @@ namespace QuantumUNET
|
||||
|
||||
internal static void UnregisterPrefab(GameObject prefab)
|
||||
{
|
||||
var component = prefab.GetComponent<QSBNetworkIdentity>();
|
||||
var component = prefab.GetComponent<QNetworkIdentity>();
|
||||
if (component == null)
|
||||
{
|
||||
Debug.LogError($"Could not unregister '{prefab.name}' since it contains no NetworkIdentity component");
|
||||
@ -186,9 +186,9 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
internal static void RegisterPrefab(GameObject prefab, QSBSpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
|
||||
internal static void RegisterPrefab(GameObject prefab, QSpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
|
||||
{
|
||||
var component = prefab.GetComponent<QSBNetworkIdentity>();
|
||||
var component = prefab.GetComponent<QNetworkIdentity>();
|
||||
if (component == null)
|
||||
{
|
||||
Debug.LogError($"Could not register '{prefab.name}' since it contains no NetworkIdentity component");
|
||||
@ -208,7 +208,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool GetSpawnHandler(NetworkHash128 assetId, out QSBSpawnDelegate handler)
|
||||
internal static bool GetSpawnHandler(NetworkHash128 assetId, out QSpawnDelegate handler)
|
||||
{
|
||||
bool result;
|
||||
if (spawnHandlers.ContainsKey(assetId))
|
File diff suppressed because it is too large
Load Diff
@ -10,11 +10,11 @@ using UnityEngine.Networking.Types;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
public class QSBNetworkServerSimple
|
||||
public class QNetworkServerSimple
|
||||
{
|
||||
public QSBNetworkServerSimple()
|
||||
public QNetworkServerSimple()
|
||||
{
|
||||
connections = new ReadOnlyCollection<QSBNetworkConnection>(m_Connections);
|
||||
connections = new ReadOnlyCollection<QNetworkConnection>(m_Connections);
|
||||
}
|
||||
|
||||
public int listenPort { get; set; }
|
||||
@ -25,17 +25,17 @@ namespace QuantumUNET
|
||||
|
||||
public bool useWebSockets { get; set; }
|
||||
|
||||
public ReadOnlyCollection<QSBNetworkConnection> connections { get; }
|
||||
public ReadOnlyCollection<QNetworkConnection> connections { get; }
|
||||
|
||||
public Dictionary<short, QSBNetworkMessageDelegate> handlers => m_MessageHandlers.GetHandlers();
|
||||
public Dictionary<short, QNetworkMessageDelegate> handlers => m_MessageHandlers.GetHandlers();
|
||||
|
||||
public byte[] messageBuffer { get; private set; }
|
||||
|
||||
public NetworkReader messageReader { get; private set; }
|
||||
|
||||
public Type networkConnectionClass { get; private set; } = typeof(QSBNetworkConnection);
|
||||
public Type networkConnectionClass { get; private set; } = typeof(QNetworkConnection);
|
||||
|
||||
public void SetNetworkConnectionClass<T>() where T : QSBNetworkConnection => networkConnectionClass = typeof(T);
|
||||
public void SetNetworkConnectionClass<T>() where T : QNetworkConnection => networkConnectionClass = typeof(T);
|
||||
|
||||
public virtual void Initialize()
|
||||
{
|
||||
@ -129,9 +129,9 @@ namespace QuantumUNET
|
||||
serverHostId = -1;
|
||||
}
|
||||
|
||||
internal void RegisterHandlerSafe(short msgType, QSBNetworkMessageDelegate handler) => m_MessageHandlers.RegisterHandlerSafe(msgType, handler);
|
||||
internal void RegisterHandlerSafe(short msgType, QNetworkMessageDelegate handler) => m_MessageHandlers.RegisterHandlerSafe(msgType, handler);
|
||||
|
||||
public void RegisterHandler(short msgType, QSBNetworkMessageDelegate handler) => m_MessageHandlers.RegisterHandler(msgType, handler);
|
||||
public void RegisterHandler(short msgType, QNetworkMessageDelegate handler) => m_MessageHandlers.RegisterHandler(msgType, handler);
|
||||
|
||||
public void UnregisterHandler(short msgType) => m_MessageHandlers.UnregisterHandler(msgType);
|
||||
|
||||
@ -200,9 +200,9 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
public QSBNetworkConnection FindConnection(int connectionId)
|
||||
public QNetworkConnection FindConnection(int connectionId)
|
||||
{
|
||||
QSBNetworkConnection result;
|
||||
QNetworkConnection result;
|
||||
if (connectionId < 0 || connectionId >= m_Connections.Count)
|
||||
{
|
||||
result = null;
|
||||
@ -214,7 +214,7 @@ namespace QuantumUNET
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool SetConnectionAtIndex(QSBNetworkConnection conn)
|
||||
public bool SetConnectionAtIndex(QNetworkConnection conn)
|
||||
{
|
||||
while (m_Connections.Count <= conn.connectionId)
|
||||
{
|
||||
@ -259,7 +259,7 @@ namespace QuantumUNET
|
||||
else
|
||||
{
|
||||
NetworkTransport.GetConnectionInfo(serverHostId, connectionId, out var networkAddress, out var num, out var networkID, out var nodeID, out var lastError);
|
||||
var networkConnection = (QSBNetworkConnection)Activator.CreateInstance(networkConnectionClass);
|
||||
var networkConnection = (QNetworkConnection)Activator.CreateInstance(networkConnectionClass);
|
||||
networkConnection.SetHandlers(m_MessageHandlers);
|
||||
networkConnection.Initialize(networkAddress, serverHostId, connectionId, hostTopology);
|
||||
networkConnection.LastError = (NetworkError)lastError;
|
||||
@ -325,7 +325,7 @@ namespace QuantumUNET
|
||||
networkConnection?.SendBytes(bytes, numBytes, channelId);
|
||||
}
|
||||
|
||||
public void SendWriterTo(int connectionId, QSBNetworkWriter writer, int channelId)
|
||||
public void SendWriterTo(int connectionId, QNetworkWriter writer, int channelId)
|
||||
{
|
||||
var networkConnection = FindConnection(connectionId);
|
||||
networkConnection?.SendWriter(writer, channelId);
|
||||
@ -353,21 +353,21 @@ namespace QuantumUNET
|
||||
public virtual void OnConnectError(int connectionId, byte error) => Debug.LogError(
|
||||
$"OnConnectError error:{error}");
|
||||
|
||||
public virtual void OnDataError(QSBNetworkConnection conn, byte error) => Debug.LogError(
|
||||
public virtual void OnDataError(QNetworkConnection conn, byte error) => Debug.LogError(
|
||||
$"OnDataError error:{error}");
|
||||
|
||||
public virtual void OnDisconnectError(QSBNetworkConnection conn, byte error) => Debug.LogError(
|
||||
public virtual void OnDisconnectError(QNetworkConnection conn, byte error) => Debug.LogError(
|
||||
$"OnDisconnectError error:{error}");
|
||||
|
||||
public virtual void OnConnected(QSBNetworkConnection conn) => conn.InvokeHandlerNoData(32);
|
||||
public virtual void OnConnected(QNetworkConnection conn) => conn.InvokeHandlerNoData(32);
|
||||
|
||||
public virtual void OnDisconnected(QSBNetworkConnection conn) => conn.InvokeHandlerNoData(33);
|
||||
public virtual void OnDisconnected(QNetworkConnection conn) => conn.InvokeHandlerNoData(33);
|
||||
|
||||
public virtual void OnData(QSBNetworkConnection conn, int receivedSize, int channelId) => conn.TransportReceive(messageBuffer, receivedSize, channelId);
|
||||
public virtual void OnData(QNetworkConnection conn, int receivedSize, int channelId) => conn.TransportReceive(messageBuffer, receivedSize, channelId);
|
||||
|
||||
private bool m_Initialized;
|
||||
private int m_RelaySlotId = -1;
|
||||
private readonly List<QSBNetworkConnection> m_Connections = new List<QSBNetworkConnection>();
|
||||
private readonly QSBNetworkMessageHandlers m_MessageHandlers = new QSBNetworkMessageHandlers();
|
||||
private readonly List<QNetworkConnection> m_Connections = new List<QNetworkConnection>();
|
||||
private readonly QNetworkMessageHandlers m_MessageHandlers = new QNetworkMessageHandlers();
|
||||
}
|
||||
}
|
@ -3,24 +3,24 @@ using UnityEngine;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
public class QSBPlayerController
|
||||
public class QPlayerController
|
||||
{
|
||||
public short PlayerControllerId = -1;
|
||||
public QSBNetworkIdentity UnetView;
|
||||
public QNetworkIdentity UnetView;
|
||||
public GameObject Gameobject;
|
||||
public const int MaxPlayersPerClient = 32;
|
||||
public bool IsValid => PlayerControllerId != -1;
|
||||
|
||||
internal const short kMaxLocalPlayers = 8;
|
||||
|
||||
public QSBPlayerController()
|
||||
public QPlayerController()
|
||||
{
|
||||
}
|
||||
|
||||
internal QSBPlayerController(GameObject go, short playerControllerId)
|
||||
internal QPlayerController(GameObject go, short playerControllerId)
|
||||
{
|
||||
Gameobject = go;
|
||||
UnetView = go.GetComponent<QSBNetworkIdentity>();
|
||||
UnetView = go.GetComponent<QNetworkIdentity>();
|
||||
PlayerControllerId = playerControllerId;
|
||||
}
|
||||
|
@ -1,59 +0,0 @@
|
||||
using QuantumUNET.Messages;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
internal class QSBNetworkMessageHandlers
|
||||
{
|
||||
private readonly Dictionary<short, QSBNetworkMessageDelegate> _msgHandlers = new Dictionary<short, QSBNetworkMessageDelegate>();
|
||||
|
||||
internal void RegisterHandlerSafe(short msgType, QSBNetworkMessageDelegate handler)
|
||||
{
|
||||
if (handler == null)
|
||||
{
|
||||
Debug.LogError($"RegisterHandlerSafe id:{msgType} handler is null");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"RegisterHandlerSafe id:{msgType} handler:{handler.GetMethodName()}");
|
||||
if (!_msgHandlers.ContainsKey(msgType))
|
||||
{
|
||||
_msgHandlers.Add(msgType, handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterHandler(short msgType, QSBNetworkMessageDelegate handler)
|
||||
{
|
||||
if (handler == null)
|
||||
{
|
||||
Debug.LogError($"RegisterHandler id:{msgType} handler is null");
|
||||
}
|
||||
else if (msgType <= 31)
|
||||
{
|
||||
Debug.LogError($"RegisterHandler: Cannot replace system message handler {msgType}");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_msgHandlers.ContainsKey(msgType))
|
||||
{
|
||||
Debug.Log($"RegisterHandler replacing {msgType}");
|
||||
_msgHandlers.Remove(msgType);
|
||||
}
|
||||
Debug.Log($"RegisterHandler id:{msgType} handler:{handler.GetMethodName()}");
|
||||
_msgHandlers.Add(msgType, handler);
|
||||
}
|
||||
}
|
||||
|
||||
public void UnregisterHandler(short msgType) =>
|
||||
_msgHandlers.Remove(msgType);
|
||||
|
||||
internal QSBNetworkMessageDelegate GetHandler(short msgType) =>
|
||||
_msgHandlers.ContainsKey(msgType) ? _msgHandlers[msgType] : null;
|
||||
|
||||
internal Dictionary<short, QSBNetworkMessageDelegate> GetHandlers() => _msgHandlers;
|
||||
|
||||
internal void ClearMessageHandlers() => _msgHandlers.Clear();
|
||||
}
|
||||
}
|
@ -3,29 +3,29 @@ using QuantumUNET.Transport;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
internal class QSBULocalConnectionToClient : QSBNetworkConnection
|
||||
internal class QULocalConnectionToClient : QNetworkConnection
|
||||
{
|
||||
public QSBULocalConnectionToClient(QSBLocalClient localClient)
|
||||
public QULocalConnectionToClient(QLocalClient localClient)
|
||||
{
|
||||
address = "localClient";
|
||||
LocalClient = localClient;
|
||||
}
|
||||
|
||||
public QSBLocalClient LocalClient { get; }
|
||||
public QLocalClient LocalClient { get; }
|
||||
|
||||
public override bool Send(short msgType, QSBMessageBase msg)
|
||||
public override bool Send(short msgType, QMessageBase msg)
|
||||
{
|
||||
LocalClient.InvokeHandlerOnClient(msgType, msg, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool SendUnreliable(short msgType, QSBMessageBase msg)
|
||||
public override bool SendUnreliable(short msgType, QMessageBase msg)
|
||||
{
|
||||
LocalClient.InvokeHandlerOnClient(msgType, msg, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool SendByChannel(short msgType, QSBMessageBase msg, int channelId)
|
||||
public override bool SendByChannel(short msgType, QMessageBase msg, int channelId)
|
||||
{
|
||||
LocalClient.InvokeHandlerOnClient(msgType, msg, channelId);
|
||||
return true;
|
||||
@ -37,7 +37,7 @@ namespace QuantumUNET
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool SendWriter(QSBNetworkWriter writer, int channelId)
|
||||
public override bool SendWriter(QNetworkWriter writer, int channelId)
|
||||
{
|
||||
LocalClient.InvokeBytesOnClient(writer.AsArray(), channelId);
|
||||
return true;
|
@ -4,21 +4,21 @@ using UnityEngine;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
internal class QSBULocalConnectionToServer : QSBNetworkConnection
|
||||
internal class QULocalConnectionToServer : QNetworkConnection
|
||||
{
|
||||
public QSBULocalConnectionToServer(QSBNetworkServer localServer)
|
||||
public QULocalConnectionToServer(QNetworkServer localServer)
|
||||
{
|
||||
address = "localServer";
|
||||
m_LocalServer = localServer;
|
||||
}
|
||||
|
||||
public override bool Send(short msgType, QSBMessageBase msg) =>
|
||||
public override bool Send(short msgType, QMessageBase msg) =>
|
||||
m_LocalServer.InvokeHandlerOnServer(this, msgType, msg, 0);
|
||||
|
||||
public override bool SendUnreliable(short msgType, QSBMessageBase msg) =>
|
||||
public override bool SendUnreliable(short msgType, QMessageBase msg) =>
|
||||
m_LocalServer.InvokeHandlerOnServer(this, msgType, msg, 1);
|
||||
|
||||
public override bool SendByChannel(short msgType, QSBMessageBase msg, int channelId) =>
|
||||
public override bool SendByChannel(short msgType, QMessageBase msg, int channelId) =>
|
||||
m_LocalServer.InvokeHandlerOnServer(this, msgType, msg, channelId);
|
||||
|
||||
public override bool SendBytes(byte[] bytes, int numBytes, int channelId)
|
||||
@ -36,7 +36,7 @@ namespace QuantumUNET
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool SendWriter(QSBNetworkWriter writer, int channelId) =>
|
||||
public override bool SendWriter(QNetworkWriter writer, int channelId) =>
|
||||
m_LocalServer.InvokeBytes(this, writer.AsArray(), (short)writer.AsArray().Length, channelId);
|
||||
|
||||
public override void GetStatsOut(out int numMsgs, out int numBufferedMsgs, out int numBytes, out int lastBufferedPerSecond)
|
||||
@ -53,6 +53,6 @@ namespace QuantumUNET
|
||||
numBytes = 0;
|
||||
}
|
||||
|
||||
private readonly QSBNetworkServer m_LocalServer;
|
||||
private readonly QNetworkServer m_LocalServer;
|
||||
}
|
||||
}
|
@ -34,39 +34,9 @@
|
||||
<Reference Include="0Harmony, Version=1.2.0.1, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Lib.Harmony.1.2.0.1\lib\net35\0Harmony.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NAudio-Unity, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OWML.1.1.4\lib\net35\NAudio-Unity.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Json.Net.Unity3D.9.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OWML.Common, Version=1.1.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OWML.1.1.4\lib\net35\OWML.Common.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OWML.Logging, Version=1.1.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OWML.1.1.4\lib\net35\OWML.Logging.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OWML.ModHelper, Version=1.1.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OWML.1.1.4\lib\net35\OWML.ModHelper.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OWML.ModHelper.Assets, Version=1.1.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OWML.1.1.4\lib\net35\OWML.ModHelper.Assets.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OWML.ModHelper.Events, Version=1.1.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OWML.1.1.4\lib\net35\OWML.ModHelper.Events.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OWML.ModHelper.Input, Version=1.1.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OWML.1.1.4\lib\net35\OWML.ModHelper.Input.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OWML.ModHelper.Interaction, Version=1.1.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OWML.1.1.4\lib\net35\OWML.ModHelper.Interaction.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OWML.ModHelper.Menus, Version=1.1.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OWML.1.1.4\lib\net35\OWML.ModHelper.Menus.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OWML.Utils, Version=1.1.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OWML.1.1.4\lib\net35\OWML.Utils.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
@ -94,53 +64,56 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Messages\QSBMsgType.cs" />
|
||||
<Compile Include="Logging\FlagsHelper.cs" />
|
||||
<Compile Include="Messages\QMsgType.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Messages\QSBAddPlayerMessage.cs" />
|
||||
<Compile Include="Messages\QSBAnimationMessage.cs" />
|
||||
<Compile Include="Messages\QSBAnimationParametersMessage.cs" />
|
||||
<Compile Include="Messages\QSBAnimationTriggerMessage.cs" />
|
||||
<Compile Include="Transport\QSBChannelBuffer.cs" />
|
||||
<Compile Include="Transport\QSBChannelPacket.cs" />
|
||||
<Compile Include="Messages\QSBClientAuthorityMessage.cs" />
|
||||
<Compile Include="QSBClientScene.cs" />
|
||||
<Compile Include="Messages\QSBCRCMessage.cs" />
|
||||
<Compile Include="QSBCRCMessageEntry.cs" />
|
||||
<Compile Include="Messages\QSBEmptyMessage.cs" />
|
||||
<Compile Include="Messages\QSBErrorMessage.cs" />
|
||||
<Compile Include="QSBLocalClient.cs" />
|
||||
<Compile Include="Messages\QSBMessageBase.cs" />
|
||||
<Compile Include="Transport\QSBNetBuffer.cs" />
|
||||
<Compile Include="Components\QSBNetworkAnimator.cs" />
|
||||
<Compile Include="QSBNetworkBehaviour.cs" />
|
||||
<Compile Include="QSBNetworkClient.cs" />
|
||||
<Compile Include="QSBNetworkConnection.cs" />
|
||||
<Compile Include="QSBNetworkCRC.cs" />
|
||||
<Compile Include="Components\QSBNetworkIdentity.cs" />
|
||||
<Compile Include="Components\QSBNetworkManagerHUD.cs" />
|
||||
<Compile Include="Components\QSBNetworkManagerUNET.cs" />
|
||||
<Compile Include="Messages\QSBNetworkMessage.cs" />
|
||||
<Compile Include="Messages\QSBNetworkMessageDelegate.cs" />
|
||||
<Compile Include="QSBNetworkMessageHandlers.cs" />
|
||||
<Compile Include="Transport\QSBNetworkReader.cs" />
|
||||
<Compile Include="QSBNetworkScene.cs" />
|
||||
<Compile Include="QSBNetworkServer.cs" />
|
||||
<Compile Include="QSBNetworkServerSimple.cs" />
|
||||
<Compile Include="Components\QSBNetworkTransform.cs" />
|
||||
<Compile Include="Transport\QSBNetworkWriter.cs" />
|
||||
<Compile Include="Messages\QSBNotReadyMessage.cs" />
|
||||
<Compile Include="Messages\QSBObjectDestroyMessage.cs" />
|
||||
<Compile Include="Messages\QSBObjectSpawnFinishedMessage.cs" />
|
||||
<Compile Include="Messages\QSBObjectSpawnMessage.cs" />
|
||||
<Compile Include="Messages\QSBObjectSpawnSceneMessage.cs" />
|
||||
<Compile Include="Messages\QSBOwnerMessage.cs" />
|
||||
<Compile Include="QSBPlayerController.cs" />
|
||||
<Compile Include="Messages\QSBReadyMessage.cs" />
|
||||
<Compile Include="Messages\QSBRemovePlayerMessage.cs" />
|
||||
<Compile Include="Messages\QSBStringMessage.cs" />
|
||||
<Compile Include="Messages\QSBSpawnDelegate.cs" />
|
||||
<Compile Include="QSBULocalConnectionToClient.cs" />
|
||||
<Compile Include="QSBULocalConnectionToServer.cs" />
|
||||
<Compile Include="Messages\QAddPlayerMessage.cs" />
|
||||
<Compile Include="Messages\QAnimationMessage.cs" />
|
||||
<Compile Include="Messages\QAnimationParametersMessage.cs" />
|
||||
<Compile Include="Messages\QAnimationTriggerMessage.cs" />
|
||||
<Compile Include="Logging\QLog.cs" />
|
||||
<Compile Include="Logging\QLogType.cs" />
|
||||
<Compile Include="Transport\QChannelBuffer.cs" />
|
||||
<Compile Include="Transport\QChannelPacket.cs" />
|
||||
<Compile Include="Messages\QClientAuthorityMessage.cs" />
|
||||
<Compile Include="QClientScene.cs" />
|
||||
<Compile Include="Messages\QCRCMessage.cs" />
|
||||
<Compile Include="QCRCMessageEntry.cs" />
|
||||
<Compile Include="Messages\QEmptyMessage.cs" />
|
||||
<Compile Include="Messages\QErrorMessage.cs" />
|
||||
<Compile Include="QLocalClient.cs" />
|
||||
<Compile Include="Messages\QMessageBase.cs" />
|
||||
<Compile Include="Transport\QNetBuffer.cs" />
|
||||
<Compile Include="Components\QNetworkAnimator.cs" />
|
||||
<Compile Include="QNetworkBehaviour.cs" />
|
||||
<Compile Include="QNetworkClient.cs" />
|
||||
<Compile Include="QNetworkConnection.cs" />
|
||||
<Compile Include="QNetworkCRC.cs" />
|
||||
<Compile Include="Components\QNetworkIdentity.cs" />
|
||||
<Compile Include="Components\QNetworkManagerHUD.cs" />
|
||||
<Compile Include="Components\QNetworkManager.cs" />
|
||||
<Compile Include="Messages\QNetworkMessage.cs" />
|
||||
<Compile Include="Messages\QNetworkMessageDelegate.cs" />
|
||||
<Compile Include="QNetworkMessageHandlers.cs" />
|
||||
<Compile Include="Transport\QNetworkReader.cs" />
|
||||
<Compile Include="QNetworkScene.cs" />
|
||||
<Compile Include="QNetworkServer.cs" />
|
||||
<Compile Include="QNetworkServerSimple.cs" />
|
||||
<Compile Include="Components\QNetworkTransform.cs" />
|
||||
<Compile Include="Transport\QNetworkWriter.cs" />
|
||||
<Compile Include="Messages\QNotReadyMessage.cs" />
|
||||
<Compile Include="Messages\QObjectDestroyMessage.cs" />
|
||||
<Compile Include="Messages\QObjectSpawnFinishedMessage.cs" />
|
||||
<Compile Include="Messages\QObjectSpawnMessage.cs" />
|
||||
<Compile Include="Messages\QObjectSpawnSceneMessage.cs" />
|
||||
<Compile Include="Messages\QOwnerMessage.cs" />
|
||||
<Compile Include="QPlayerController.cs" />
|
||||
<Compile Include="Messages\QReadyMessage.cs" />
|
||||
<Compile Include="Messages\QRemovePlayerMessage.cs" />
|
||||
<Compile Include="Messages\QStringMessage.cs" />
|
||||
<Compile Include="Messages\QSpawnDelegate.cs" />
|
||||
<Compile Include="QULocalConnectionToClient.cs" />
|
||||
<Compile Include="QULocalConnectionToServer.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
@ -6,7 +6,7 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Transport
|
||||
{
|
||||
internal class QSBChannelBuffer : IDisposable
|
||||
internal class QChannelBuffer : IDisposable
|
||||
{
|
||||
public int NumMsgsOut { get; private set; }
|
||||
public int NumBufferedMsgsOut { get; private set; }
|
||||
@ -19,8 +19,8 @@ namespace QuantumUNET.Transport
|
||||
public const int MaxBufferedPackets = 512;
|
||||
public float MaxDelay = 0.01f;
|
||||
|
||||
private readonly QSBNetworkConnection _connection;
|
||||
private QSBChannelPacket _currentPacket;
|
||||
private readonly QNetworkConnection _connection;
|
||||
private QChannelPacket _currentPacket;
|
||||
private float _lastFlushTime;
|
||||
private readonly byte _channelId;
|
||||
private int _maxPacketSize;
|
||||
@ -29,32 +29,32 @@ namespace QuantumUNET.Transport
|
||||
private bool _isBroken;
|
||||
private int _maxPendingPacketCount;
|
||||
private const int _maxFreePacketCount = 512;
|
||||
private readonly Queue<QSBChannelPacket> _pendingPackets;
|
||||
private static List<QSBChannelPacket> _freePackets;
|
||||
private readonly Queue<QChannelPacket> _pendingPackets;
|
||||
private static List<QChannelPacket> _freePackets;
|
||||
internal static int _pendingPacketCount;
|
||||
private float _lastBufferedMessageCountTimer = Time.realtimeSinceStartup;
|
||||
private static readonly QSBNetworkWriter _sendWriter = new QSBNetworkWriter();
|
||||
private static readonly QSBNetworkWriter _fragmentWriter = new QSBNetworkWriter();
|
||||
private static readonly QNetworkWriter _sendWriter = new QNetworkWriter();
|
||||
private static readonly QNetworkWriter _fragmentWriter = new QNetworkWriter();
|
||||
private const int _packetHeaderReserveSize = 100;
|
||||
private bool _disposed;
|
||||
internal QSBNetBuffer _fragmentBuffer = new QSBNetBuffer();
|
||||
internal QNetBuffer _fragmentBuffer = new QNetBuffer();
|
||||
private bool _readingFragment;
|
||||
|
||||
public QSBChannelBuffer(QSBNetworkConnection conn, int bufferSize, byte cid, bool isReliable, bool isSequenced)
|
||||
public QChannelBuffer(QNetworkConnection conn, int bufferSize, byte cid, bool isReliable, bool isSequenced)
|
||||
{
|
||||
_connection = conn;
|
||||
_maxPacketSize = bufferSize - 100;
|
||||
_currentPacket = new QSBChannelPacket(_maxPacketSize, isReliable);
|
||||
_currentPacket = new QChannelPacket(_maxPacketSize, isReliable);
|
||||
_channelId = cid;
|
||||
_maxPendingPacketCount = 16;
|
||||
_isReliable = isReliable;
|
||||
_allowFragmentation = isReliable && isSequenced;
|
||||
if (isReliable)
|
||||
{
|
||||
_pendingPackets = new Queue<QSBChannelPacket>();
|
||||
_pendingPackets = new Queue<QChannelPacket>();
|
||||
if (_freePackets == null)
|
||||
{
|
||||
_freePackets = new List<QSBChannelPacket>();
|
||||
_freePackets = new List<QChannelPacket>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -115,7 +115,7 @@ namespace QuantumUNET.Transport
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentPacket = new QSBChannelPacket(value, _isReliable);
|
||||
_currentPacket = new QChannelPacket(value, _isReliable);
|
||||
_maxPacketSize = value;
|
||||
result = true;
|
||||
}
|
||||
@ -159,13 +159,13 @@ namespace QuantumUNET.Transport
|
||||
}
|
||||
}
|
||||
|
||||
public bool SendWriter(QSBNetworkWriter writer)
|
||||
public bool SendWriter(QNetworkWriter writer)
|
||||
{
|
||||
var arraySegment = writer.AsArraySegment();
|
||||
return SendBytes(arraySegment.Array, arraySegment.Count);
|
||||
}
|
||||
|
||||
public bool Send(short msgType, QSBMessageBase msg)
|
||||
public bool Send(short msgType, QMessageBase msg)
|
||||
{
|
||||
_sendWriter.StartMessage(msgType);
|
||||
msg.Serialize(_sendWriter);
|
||||
@ -174,7 +174,7 @@ namespace QuantumUNET.Transport
|
||||
return SendWriter(_sendWriter);
|
||||
}
|
||||
|
||||
internal bool HandleFragment(QSBNetworkReader reader)
|
||||
internal bool HandleFragment(QNetworkReader reader)
|
||||
{
|
||||
bool result;
|
||||
if (reader.ReadByte() == 0)
|
||||
@ -300,12 +300,12 @@ namespace QuantumUNET.Transport
|
||||
_currentPacket = AllocPacket();
|
||||
}
|
||||
|
||||
private QSBChannelPacket AllocPacket()
|
||||
private QChannelPacket AllocPacket()
|
||||
{
|
||||
QSBChannelPacket result;
|
||||
QChannelPacket result;
|
||||
if (_freePackets.Count == 0)
|
||||
{
|
||||
result = new QSBChannelPacket(_maxPacketSize, _isReliable);
|
||||
result = new QChannelPacket(_maxPacketSize, _isReliable);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -317,7 +317,7 @@ namespace QuantumUNET.Transport
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void FreePacket(QSBChannelPacket packet)
|
||||
private static void FreePacket(QChannelPacket packet)
|
||||
{
|
||||
if (_freePackets.Count < 512)
|
||||
{
|
@ -4,13 +4,13 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Transport
|
||||
{
|
||||
internal struct QSBChannelPacket
|
||||
internal struct QChannelPacket
|
||||
{
|
||||
private int m_Position;
|
||||
private readonly byte[] m_Buffer;
|
||||
private readonly bool m_IsReliable;
|
||||
|
||||
public QSBChannelPacket(int packetSize, bool isReliable)
|
||||
public QChannelPacket(int packetSize, bool isReliable)
|
||||
{
|
||||
m_Position = 0;
|
||||
m_Buffer = new byte[packetSize];
|
||||
@ -29,7 +29,7 @@ namespace QuantumUNET.Transport
|
||||
|
||||
public bool HasSpace(int numBytes) => m_Position + numBytes <= m_Buffer.Length;
|
||||
|
||||
public bool SendToTransport(QSBNetworkConnection conn, int channelId)
|
||||
public bool SendToTransport(QNetworkConnection conn, int channelId)
|
||||
{
|
||||
var result = true;
|
||||
if (!conn.TransportSend(m_Buffer, (ushort)m_Position, channelId, out var b))
|
@ -3,14 +3,14 @@ using UnityEngine;
|
||||
|
||||
namespace QuantumUNET.Transport
|
||||
{
|
||||
internal class QSBNetBuffer
|
||||
internal class QNetBuffer
|
||||
{
|
||||
public QSBNetBuffer()
|
||||
public QNetBuffer()
|
||||
{
|
||||
m_Buffer = new byte[64];
|
||||
}
|
||||
|
||||
public QSBNetBuffer(byte[] buffer)
|
||||
public QNetBuffer(byte[] buffer)
|
||||
{
|
||||
m_Buffer = buffer;
|
||||
}
|
@ -7,21 +7,21 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Transport
|
||||
{
|
||||
public class QSBNetworkReader
|
||||
public class QNetworkReader
|
||||
{
|
||||
private readonly QSBNetBuffer m_buf;
|
||||
private readonly QNetBuffer m_buf;
|
||||
private static byte[] s_StringReaderBuffer;
|
||||
private static Encoding s_Encoding;
|
||||
|
||||
public QSBNetworkReader(QSBNetworkWriter writer)
|
||||
public QNetworkReader(QNetworkWriter writer)
|
||||
{
|
||||
m_buf = new QSBNetBuffer(writer.AsArray());
|
||||
m_buf = new QNetBuffer(writer.AsArray());
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public QSBNetworkReader(byte[] buffer)
|
||||
public QNetworkReader(byte[] buffer)
|
||||
{
|
||||
m_buf = new QSBNetBuffer(buffer);
|
||||
m_buf = new QNetBuffer(buffer);
|
||||
Initialize();
|
||||
}
|
||||
|
||||
@ -384,7 +384,7 @@ namespace QuantumUNET.Transport
|
||||
}
|
||||
else
|
||||
{
|
||||
var gameObject = QSBClientScene.FindLocalObject(networkInstanceId);
|
||||
var gameObject = QClientScene.FindLocalObject(networkInstanceId);
|
||||
if (gameObject == null)
|
||||
{
|
||||
Debug.Log($"ReadTransform netId:{networkInstanceId}");
|
||||
@ -408,9 +408,9 @@ namespace QuantumUNET.Transport
|
||||
}
|
||||
else
|
||||
{
|
||||
var gameObject = QSBNetworkServer.active
|
||||
? QSBNetworkServer.FindLocalObject(networkInstanceId)
|
||||
: QSBClientScene.FindLocalObject(networkInstanceId);
|
||||
var gameObject = QNetworkServer.active
|
||||
? QNetworkServer.FindLocalObject(networkInstanceId)
|
||||
: QClientScene.FindLocalObject(networkInstanceId);
|
||||
if (gameObject == null)
|
||||
{
|
||||
Debug.Log($"ReadGameObject netId:{networkInstanceId}go: null");
|
||||
@ -420,19 +420,19 @@ namespace QuantumUNET.Transport
|
||||
return result;
|
||||
}
|
||||
|
||||
public QSBNetworkIdentity ReadNetworkIdentity()
|
||||
public QNetworkIdentity ReadNetworkIdentity()
|
||||
{
|
||||
var networkInstanceId = ReadNetworkId();
|
||||
QSBNetworkIdentity result;
|
||||
QNetworkIdentity result;
|
||||
if (networkInstanceId.IsEmpty())
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var gameObject = QSBNetworkServer.active
|
||||
? QSBNetworkServer.FindLocalObject(networkInstanceId)
|
||||
: QSBClientScene.FindLocalObject(networkInstanceId);
|
||||
var gameObject = QNetworkServer.active
|
||||
? QNetworkServer.FindLocalObject(networkInstanceId)
|
||||
: QClientScene.FindLocalObject(networkInstanceId);
|
||||
if (gameObject == null)
|
||||
{
|
||||
Debug.Log($"ReadNetworkIdentity netId:{networkInstanceId}go: null");
|
||||
@ -440,7 +440,7 @@ namespace QuantumUNET.Transport
|
||||
}
|
||||
else
|
||||
{
|
||||
result = gameObject.GetComponent<QSBNetworkIdentity>();
|
||||
result = gameObject.GetComponent<QNetworkIdentity>();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@ -448,7 +448,7 @@ namespace QuantumUNET.Transport
|
||||
|
||||
public override string ToString() => m_buf.ToString();
|
||||
|
||||
public TMsg ReadMessage<TMsg>() where TMsg : QSBMessageBase, new()
|
||||
public TMsg ReadMessage<TMsg>() where TMsg : QMessageBase, new()
|
||||
{
|
||||
var result = Activator.CreateInstance<TMsg>();
|
||||
result.Deserialize(this);
|
@ -7,11 +7,11 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Transport
|
||||
{
|
||||
public class QSBNetworkWriter
|
||||
public class QNetworkWriter
|
||||
{
|
||||
public QSBNetworkWriter()
|
||||
public QNetworkWriter()
|
||||
{
|
||||
m_Buffer = new QSBNetBuffer();
|
||||
m_Buffer = new QNetBuffer();
|
||||
if (s_Encoding == null)
|
||||
{
|
||||
s_Encoding = new UTF8Encoding();
|
||||
@ -19,9 +19,9 @@ namespace QuantumUNET.Transport
|
||||
}
|
||||
}
|
||||
|
||||
public QSBNetworkWriter(byte[] buffer)
|
||||
public QNetworkWriter(byte[] buffer)
|
||||
{
|
||||
m_Buffer = new QSBNetBuffer(buffer);
|
||||
m_Buffer = new QNetBuffer(buffer);
|
||||
if (s_Encoding == null)
|
||||
{
|
||||
s_Encoding = new UTF8Encoding();
|
||||
@ -379,7 +379,7 @@ namespace QuantumUNET.Transport
|
||||
Write(value.i15);
|
||||
}
|
||||
|
||||
public void Write(QSBNetworkIdentity value)
|
||||
public void Write(QNetworkIdentity value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
@ -399,7 +399,7 @@ namespace QuantumUNET.Transport
|
||||
}
|
||||
else
|
||||
{
|
||||
var component = value.gameObject.GetComponent<QSBNetworkIdentity>();
|
||||
var component = value.gameObject.GetComponent<QNetworkIdentity>();
|
||||
if (component != null)
|
||||
{
|
||||
Write(component.NetId);
|
||||
@ -420,7 +420,7 @@ namespace QuantumUNET.Transport
|
||||
}
|
||||
else
|
||||
{
|
||||
var component = value.GetComponent<QSBNetworkIdentity>();
|
||||
var component = value.GetComponent<QNetworkIdentity>();
|
||||
if (component != null)
|
||||
{
|
||||
Write(component.NetId);
|
||||
@ -433,7 +433,7 @@ namespace QuantumUNET.Transport
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(QSBMessageBase msg) => msg.Serialize(this);
|
||||
public void Write(QMessageBase msg) => msg.Serialize(this);
|
||||
|
||||
public void SeekZero() => m_Buffer.SeekZero();
|
||||
|
||||
@ -448,7 +448,7 @@ namespace QuantumUNET.Transport
|
||||
|
||||
private const int k_MaxStringLength = 32768;
|
||||
|
||||
private readonly QSBNetBuffer m_Buffer;
|
||||
private readonly QNetBuffer m_Buffer;
|
||||
|
||||
private static Encoding s_Encoding;
|
||||
|
@ -2,5 +2,4 @@
|
||||
<packages>
|
||||
<package id="Json.Net.Unity3D" version="9.0.1" targetFramework="net35" />
|
||||
<package id="Lib.Harmony" version="1.2.0.1" targetFramework="net35" />
|
||||
<package id="OWML" version="1.1.4" targetFramework="net35" />
|
||||
</packages>
|
Loading…
x
Reference in New Issue
Block a user