diff --git a/QSB/Animation/AnimationSync.cs b/QSB/Animation/AnimationSync.cs index 515bc2d5..6ecd8294 100644 --- a/QSB/Animation/AnimationSync.cs +++ b/QSB/Animation/AnimationSync.cs @@ -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(); - _netAnim = gameObject.AddComponent(); + _netAnim = gameObject.AddComponent(); _netAnim.enabled = false; _netAnim.animator = _anim; diff --git a/QSB/Animation/CrouchSync.cs b/QSB/Animation/CrouchSync.cs index 6fe80245..84e4820b 100644 --- a/QSB/Animation/CrouchSync.cs +++ b/QSB/Animation/CrouchSync.cs @@ -4,7 +4,7 @@ using UnityEngine; namespace QSB.Animation { - public class CrouchSync : QSBNetworkBehaviour + public class CrouchSync : QNetworkBehaviour { public AnimFloatParam CrouchParam { get; } = new AnimFloatParam(); diff --git a/QSB/ConversationSync/Events/ConversationMessage.cs b/QSB/ConversationSync/Events/ConversationMessage.cs index 9a5c85e4..4dde378d 100644 --- a/QSB/ConversationSync/Events/ConversationMessage.cs +++ b/QSB/ConversationSync/Events/ConversationMessage.cs @@ -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); diff --git a/QSB/ConversationSync/Events/ConversationStartEndMessage.cs b/QSB/ConversationSync/Events/ConversationStartEndMessage.cs index c836868b..2c8d078d 100644 --- a/QSB/ConversationSync/Events/ConversationStartEndMessage.cs +++ b/QSB/ConversationSync/Events/ConversationStartEndMessage.cs @@ -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); diff --git a/QSB/ConversationSync/Events/DialogueConditionMessage.cs b/QSB/ConversationSync/Events/DialogueConditionMessage.cs index 79e9f509..6083d690 100644 --- a/QSB/ConversationSync/Events/DialogueConditionMessage.cs +++ b/QSB/ConversationSync/Events/DialogueConditionMessage.cs @@ -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); diff --git a/QSB/Events/QSBEvent.cs b/QSB/Events/QSBEvent.cs index 6d42c287..ef8f3d12 100644 --- a/QSB/Events/QSBEvent.cs +++ b/QSB/Events/QSBEvent.cs @@ -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() == null) + if (PlayerTransformSync.LocalInstance == null || PlayerTransformSync.LocalInstance.GetComponent() == 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); } } } \ No newline at end of file diff --git a/QSB/GeyserSync/QSBGeyser.cs b/QSB/GeyserSync/QSBGeyser.cs index 93481256..5963b21b 100644 --- a/QSB/GeyserSync/QSBGeyser.cs +++ b/QSB/GeyserSync/QSBGeyser.cs @@ -19,7 +19,7 @@ namespace QSB.GeyserSync private void HandleEvent(bool state) { - if (QSBNetworkServer.active) + if (QNetworkServer.active) { GlobalMessenger.FireEvent(EventNames.QSBGeyserState, ObjectId, state); } diff --git a/QSB/Instruments/QSBCamera/CameraManager.cs b/QSB/Instruments/QSBCamera/CameraManager.cs index 85e54fb1..15099943 100644 --- a/QSB/Instruments/QSBCamera/CameraManager.cs +++ b/QSB/Instruments/QSBCamera/CameraManager.cs @@ -28,7 +28,6 @@ namespace QSB.Instruments.QSBCamera { _cameraBase = new GameObject(); _cameraBase.SetActive(false); - _cameraBase.AddComponent(); _cameraBase.transform.parent = Locator.GetPlayerTransform(); _cameraBase.transform.localPosition = Vector3.zero; _cameraBase.transform.localRotation = Quaternion.Euler(0, 0, 0); diff --git a/QSB/LogSync/Events/RevealFactMessage.cs b/QSB/LogSync/Events/RevealFactMessage.cs index 33bcb6a2..4b0eb598 100644 --- a/QSB/LogSync/Events/RevealFactMessage.cs +++ b/QSB/LogSync/Events/RevealFactMessage.cs @@ -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); diff --git a/QSB/Messaging/EnumMessage.cs b/QSB/Messaging/EnumMessage.cs index 4886c66b..48a8afbf 100644 --- a/QSB/Messaging/EnumMessage.cs +++ b/QSB/Messaging/EnumMessage.cs @@ -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); diff --git a/QSB/Messaging/FloatMessage.cs b/QSB/Messaging/FloatMessage.cs index 5d1685f7..7e65a30c 100644 --- a/QSB/Messaging/FloatMessage.cs +++ b/QSB/Messaging/FloatMessage.cs @@ -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); diff --git a/QSB/Messaging/MessageHandler.cs b/QSB/Messaging/MessageHandler.cs index b51ef2de..190be654 100644 --- a/QSB/Messaging/MessageHandler.cs +++ b/QSB/Messaging/MessageHandler.cs @@ -7,7 +7,7 @@ using System.Linq; namespace QSB.Messaging { - public class MessageHandler where T : QSBMessageBase, new() + public class MessageHandler where T : QMessageBase, new() { public event Action OnClientReceiveMessage; public event Action 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(); OnClientReceiveMessage?.Invoke(message); } - private void OnServerReceiveMessageHandler(QSBNetworkMessage netMsg) + private void OnServerReceiveMessageHandler(QNetworkMessage netMsg) { var message = netMsg.ReadMessage(); OnServerReceiveMessage?.Invoke(message); diff --git a/QSB/Messaging/PlayerMessage.cs b/QSB/Messaging/PlayerMessage.cs index e5a2b1c5..3f7a5abf 100644 --- a/QSB/Messaging/PlayerMessage.cs +++ b/QSB/Messaging/PlayerMessage.cs @@ -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); diff --git a/QSB/Messaging/ToggleMessage.cs b/QSB/Messaging/ToggleMessage.cs index 19299079..001cac97 100644 --- a/QSB/Messaging/ToggleMessage.cs +++ b/QSB/Messaging/ToggleMessage.cs @@ -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); diff --git a/QSB/OrbSync/Events/OrbSlotMessage.cs b/QSB/OrbSync/Events/OrbSlotMessage.cs index 553d6dc8..5e48324e 100644 --- a/QSB/OrbSync/Events/OrbSlotMessage.cs +++ b/QSB/OrbSync/Events/OrbSlotMessage.cs @@ -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); diff --git a/QSB/OrbSync/Events/OrbUserEvent.cs b/QSB/OrbSync/Events/OrbUserEvent.cs index e29e0c57..da685ac5 100644 --- a/QSB/OrbSync/Events/OrbUserEvent.cs +++ b/QSB/OrbSync/Events/OrbUserEvent.cs @@ -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(); + var orbIdentity = orbSync.GetComponent(); if (orbIdentity == null) { DebugLog.ToConsole($"Error - Orb identity is null. (ID {message.ObjectId})", MessageType.Error); diff --git a/QSB/OrbSync/OrbManager.cs b/QSB/OrbSync/OrbManager.cs index 27556b3f..7da6f60c 100644 --- a/QSB/OrbSync/OrbManager.cs +++ b/QSB/OrbSync/OrbManager.cs @@ -30,16 +30,16 @@ namespace QSB.OrbSync { QSBWorldSync.OldOrbList.Clear(); QSBWorldSync.OldOrbList = Resources.FindObjectsOfTypeAll().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); } } \ No newline at end of file diff --git a/QSB/Player/Events/PlayerJoinMessage.cs b/QSB/Player/Events/PlayerJoinMessage.cs index 51f86cce..2aeb1ba2 100644 --- a/QSB/Player/Events/PlayerJoinMessage.cs +++ b/QSB/Player/Events/PlayerJoinMessage.cs @@ -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); diff --git a/QSB/Player/Events/PlayerStateMessage.cs b/QSB/Player/Events/PlayerStateMessage.cs index 3af9a69c..6e5fb9ea 100644 --- a/QSB/Player/Events/PlayerStateMessage.cs +++ b/QSB/Player/Events/PlayerStateMessage.cs @@ -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); diff --git a/QSB/Player/PlayerSyncObject.cs b/QSB/Player/PlayerSyncObject.cs index 87de74ac..be08fa58 100644 --- a/QSB/Player/PlayerSyncObject.cs +++ b/QSB/Player/PlayerSyncObject.cs @@ -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; diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index 430e14f5..b39febbb 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -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(); - gameObject.AddComponent(); + gameObject.AddComponent(); gameObject.AddComponent(); gameObject.AddComponent(); gameObject.AddComponent(); @@ -82,7 +82,7 @@ namespace QSB } public void Update() => - QSBNetworkIdentity.UNetStaticUpdate(); + QNetworkIdentity.UNetStaticUpdate(); public override void Configure(IModConfig config) { diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index 1e1f9425..a2441b06 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -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(); + var ident = go.AddComponent(); ident.LocalPlayerAuthority = true; ident.SetValue("m_AssetId", go.GetComponent().assetId); ident.SetValue("m_SceneId", go.GetComponent().sceneId); @@ -95,9 +95,9 @@ namespace QSB private void SetupNetworkTransform(GameObject go) { - var trans = go.AddComponent(); - trans.SyncRotationAxis = QSBNetworkTransform.AxisSyncMode.AxisXYZ; - Destroy(go.GetComponent()); + var trans = go.AddComponent(); + trans.SyncRotationAxis = QuantumUNET.Components.QNetworkTransform.AxisSyncMode.AxisXYZ; + Destroy(go.GetComponent()); Destroy(go.GetComponent()); } @@ -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(); + var identity = item.GetComponent(); if (identity.ClientAuthorityOwner == connection) { identity.RemoveClientAuthority(connection); diff --git a/QSB/QuantumSync/Events/MultiStateChangeEvent.cs b/QSB/QuantumSync/Events/MultiStateChangeEvent.cs index 887e8e73..c859ef06 100644 --- a/QSB/QuantumSync/Events/MultiStateChangeEvent.cs +++ b/QSB/QuantumSync/Events/MultiStateChangeEvent.cs @@ -1,8 +1,4 @@ using QSB.Events; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace QSB.QuantumSync.Events { diff --git a/QSB/QuantumSync/Events/MultiStateChangeMessage.cs b/QSB/QuantumSync/Events/MultiStateChangeMessage.cs index 55cc300c..4f81dd0f 100644 --- a/QSB/QuantumSync/Events/MultiStateChangeMessage.cs +++ b/QSB/QuantumSync/Events/MultiStateChangeMessage.cs @@ -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); diff --git a/QSB/QuantumSync/Events/SocketStateChangeMessage.cs b/QSB/QuantumSync/Events/SocketStateChangeMessage.cs index 5f15524d..af4d294d 100644 --- a/QSB/QuantumSync/Events/SocketStateChangeMessage.cs +++ b/QSB/QuantumSync/Events/SocketStateChangeMessage.cs @@ -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); diff --git a/QSB/QuantumSync/QSBMultiStateQuantumObject.cs b/QSB/QuantumSync/QSBMultiStateQuantumObject.cs index dc4a7ac5..aa421f51 100644 --- a/QSB/QuantumSync/QSBMultiStateQuantumObject.cs +++ b/QSB/QuantumSync/QSBMultiStateQuantumObject.cs @@ -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 { } } diff --git a/QSB/TimeSync/Events/ServerTimeMessage.cs b/QSB/TimeSync/Events/ServerTimeMessage.cs index 1979069a..1c31a57d 100644 --- a/QSB/TimeSync/Events/ServerTimeMessage.cs +++ b/QSB/TimeSync/Events/ServerTimeMessage.cs @@ -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); diff --git a/QSB/TimeSync/PreserveTimeScale.cs b/QSB/TimeSync/PreserveTimeScale.cs index eb868ffc..23b8d1bb 100644 --- a/QSB/TimeSync/PreserveTimeScale.cs +++ b/QSB/TimeSync/PreserveTimeScale.cs @@ -3,7 +3,7 @@ using QuantumUNET; namespace QSB.TimeSync { - public class PreserveTimeScale : QSBNetworkBehaviour + public class PreserveTimeScale : QNetworkBehaviour { public void Start() { diff --git a/QSB/TimeSync/WakeUpSync.cs b/QSB/TimeSync/WakeUpSync.cs index cfbe8b69..285a6aa6 100644 --- a/QSB/TimeSync/WakeUpSync.cs +++ b/QSB/TimeSync/WakeUpSync.cs @@ -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; } diff --git a/QSB/TransformSync/NomaiOrbTransformSync.cs b/QSB/TransformSync/NomaiOrbTransformSync.cs index 93863988..0aa696e4 100644 --- a/QSB/TransformSync/NomaiOrbTransformSync.cs +++ b/QSB/TransformSync/NomaiOrbTransformSync.cs @@ -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; } diff --git a/QSB/Utility/UnetExtensions.cs b/QSB/Utility/UnetExtensions.cs index 60fdfad7..0382add4 100644 --- a/QSB/Utility/UnetExtensions.cs +++ b/QSB/Utility/UnetExtensions.cs @@ -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(); diff --git a/QSB/WorldSync/Events/BoolWorldObjectMessage.cs b/QSB/WorldSync/Events/BoolWorldObjectMessage.cs index a5456a02..f0549d03 100644 --- a/QSB/WorldSync/Events/BoolWorldObjectMessage.cs +++ b/QSB/WorldSync/Events/BoolWorldObjectMessage.cs @@ -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); diff --git a/QSB/WorldSync/Events/WorldObjectMessage.cs b/QSB/WorldSync/Events/WorldObjectMessage.cs index f6f47fdf..a265be0e 100644 --- a/QSB/WorldSync/Events/WorldObjectMessage.cs +++ b/QSB/WorldSync/Events/WorldObjectMessage.cs @@ -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); diff --git a/QuantumUNET/Components/QSBNetworkAnimator.cs b/QuantumUNET/Components/QNetworkAnimator.cs similarity index 66% rename from QuantumUNET/Components/QSBNetworkAnimator.cs rename to QuantumUNET/Components/QNetworkAnimator.cs index 7b3e0108..c72eaa4f 100644 --- a/QuantumUNET/Components/QSBNetworkAnimator.cs +++ b/QuantumUNET/Components/QNetworkAnimator.cs @@ -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(); - var reader = new QSBNetworkReader(AnimationMessage.parameters); + var component = localObject.GetComponent(); + 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(); - var reader = new QSBNetworkReader(ParametersMessage.parameters); + var component = localObject.GetComponent(); + 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(); + var component = localObject.GetComponent(); 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(); + var component = localObject.GetComponent(); 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(); + var component = localObject.GetComponent(); 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(); + var component = localObject.GetComponent(); if (component == null) { return; diff --git a/QuantumUNET/Components/QSBNetworkIdentity.cs b/QuantumUNET/Components/QNetworkIdentity.cs similarity index 63% rename from QuantumUNET/Components/QSBNetworkIdentity.cs rename to QuantumUNET/Components/QNetworkIdentity.cs index 81169e22..d5c2b19c 100644 --- a/QuantumUNET/Components/QSBNetworkIdentity.cs +++ b/QuantumUNET/Components/QNetworkIdentity.cs @@ -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 SubIdentities { get; private set; } = new List(); + public QNetworkConnection ConnectionToServer { get; private set; } + public QNetworkConnection ConnectionToClient { get; private set; } + public QNetworkIdentity RootIdentity { get; private set; } + public List SubIdentities { get; private set; } = new List(); 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 Observers + public ReadOnlyCollection Observers { get { - ReadOnlyCollection result; + ReadOnlyCollection result; if (m_Observers == null) { result = null; } else { - result = new ReadOnlyCollection(m_Observers); + result = new ReadOnlyCollection(m_Observers); } return result; } @@ -121,7 +121,7 @@ namespace QuantumUNET.Components { if (m_NetworkBehaviours == null) { - m_NetworkBehaviours = GetComponents(); + m_NetworkBehaviours = GetComponents(); } } @@ -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(); + m_Observers = new List(); m_ObserverConnections = new HashSet(); 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(); + m_NetworkBehaviours = GetComponents(); } 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(); - var hashSet2 = new HashSet(m_Observers); + var hashSet = new HashSet(); + var hashSet2 = new HashSet(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(hashSet); + m_Observers = new List(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 m_ObserverConnections; - private List m_Observers; + private List 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); } } \ No newline at end of file diff --git a/QuantumUNET/Components/QSBNetworkManagerUNET.cs b/QuantumUNET/Components/QNetworkManager.cs similarity index 60% rename from QuantumUNET/Components/QSBNetworkManagerUNET.cs rename to QuantumUNET/Components/QNetworkManager.cs index 1c0bcb6f..d8c0cd48 100644 --- a/QuantumUNET/Components/QSBNetworkManagerUNET.cs +++ b/QuantumUNET/Components/QNetworkManager.cs @@ -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 spawnPrefabs { get; } = new List(); - public QSBNetworkClient client; + public QNetworkClient client; public int maxConnections { get; set; } = 4; public List channels { get; } = new List(); @@ -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()) + foreach (var networkIdentity in Resources.FindObjectsOfTypeAll()) { 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() == null) + else if (playerPrefab.GetComponent() == 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) { } diff --git a/QuantumUNET/Components/QSBNetworkManagerHUD.cs b/QuantumUNET/Components/QNetworkManagerHUD.cs similarity index 77% rename from QuantumUNET/Components/QSBNetworkManagerHUD.cs rename to QuantumUNET/Components/QNetworkManagerHUD.cs index 701bf0c9..c9cbd197 100644 --- a/QuantumUNET/Components/QSBNetworkManagerHUD.cs +++ b/QuantumUNET/Components/QNetworkManagerHUD.cs @@ -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(); + private void Awake() => manager = GetComponent(); 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")) { diff --git a/QuantumUNET/Components/QSBNetworkTransform.cs b/QuantumUNET/Components/QNetworkTransform.cs similarity index 79% rename from QuantumUNET/Components/QSBNetworkTransform.cs rename to QuantumUNET/Components/QNetworkTransform.cs index 83609dc8..5db20658 100644 --- a/QuantumUNET/Components/QSBNetworkTransform.cs +++ b/QuantumUNET/Components/QNetworkTransform.cs @@ -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(); + var component = gameObject.GetComponent(); 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 { diff --git a/QuantumUNET/Logging/FlagsHelper.cs b/QuantumUNET/Logging/FlagsHelper.cs new file mode 100644 index 00000000..18d49b0e --- /dev/null +++ b/QuantumUNET/Logging/FlagsHelper.cs @@ -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 flags, T flag) where T : struct + { + var flagsValue = (int)(object)flags; + var flagValue = (int)(object)flag; + + return (flagsValue & flagValue) != 0; + } + + public static void Set(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(ref T flags, T flag) where T : struct + { + var flagsValue = (int)(object)flags; + var flagValue = (int)(object)flag; + + flags = (T)(object)(flagsValue & ~flagValue); + } + } +} \ No newline at end of file diff --git a/QuantumUNET/Logging/QLog.cs b/QuantumUNET/Logging/QLog.cs new file mode 100644 index 00000000..9e33b1f6 --- /dev/null +++ b/QuantumUNET/Logging/QLog.cs @@ -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}"); + } + } +} diff --git a/QuantumUNET/Logging/QLogType.cs b/QuantumUNET/Logging/QLogType.cs new file mode 100644 index 00000000..9267e0a8 --- /dev/null +++ b/QuantumUNET/Logging/QLogType.cs @@ -0,0 +1,14 @@ +using System; + +namespace QuantumUNET.Logging +{ + [Flags] + public enum QLogType + { + Debug, + Log, + Warning, + Error, + FatalError + } +} diff --git a/QuantumUNET/Messages/QSBAddPlayerMessage.cs b/QuantumUNET/Messages/QAddPlayerMessage.cs similarity index 68% rename from QuantumUNET/Messages/QSBAddPlayerMessage.cs rename to QuantumUNET/Messages/QAddPlayerMessage.cs index 89145848..2697a6ec 100644 --- a/QuantumUNET/Messages/QSBAddPlayerMessage.cs +++ b/QuantumUNET/Messages/QAddPlayerMessage.cs @@ -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(); diff --git a/QuantumUNET/Messages/QSBAnimationMessage.cs b/QuantumUNET/Messages/QAnimationMessage.cs similarity index 77% rename from QuantumUNET/Messages/QSBAnimationMessage.cs rename to QuantumUNET/Messages/QAnimationMessage.cs index 6f000ea9..a8ffb207 100644 --- a/QuantumUNET/Messages/QSBAnimationMessage.cs +++ b/QuantumUNET/Messages/QAnimationMessage.cs @@ -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(); diff --git a/QuantumUNET/Messages/QSBAnimationParametersMessage.cs b/QuantumUNET/Messages/QAnimationParametersMessage.cs similarity index 65% rename from QuantumUNET/Messages/QSBAnimationParametersMessage.cs rename to QuantumUNET/Messages/QAnimationParametersMessage.cs index 6119894e..e9bf239d 100644 --- a/QuantumUNET/Messages/QSBAnimationParametersMessage.cs +++ b/QuantumUNET/Messages/QAnimationParametersMessage.cs @@ -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); diff --git a/QuantumUNET/Messages/QSBAnimationTriggerMessage.cs b/QuantumUNET/Messages/QAnimationTriggerMessage.cs similarity index 63% rename from QuantumUNET/Messages/QSBAnimationTriggerMessage.cs rename to QuantumUNET/Messages/QAnimationTriggerMessage.cs index b4291bea..fe75eaed 100644 --- a/QuantumUNET/Messages/QSBAnimationTriggerMessage.cs +++ b/QuantumUNET/Messages/QAnimationTriggerMessage.cs @@ -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); diff --git a/QuantumUNET/Messages/QSBCRCMessage.cs b/QuantumUNET/Messages/QCRCMessage.cs similarity index 61% rename from QuantumUNET/Messages/QSBCRCMessage.cs rename to QuantumUNET/Messages/QCRCMessage.cs index b0848085..60e4537e 100644 --- a/QuantumUNET/Messages/QSBCRCMessage.cs +++ b/QuantumUNET/Messages/QCRCMessage.cs @@ -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++) diff --git a/QuantumUNET/Messages/QSBClientAuthorityMessage.cs b/QuantumUNET/Messages/QClientAuthorityMessage.cs similarity index 63% rename from QuantumUNET/Messages/QSBClientAuthorityMessage.cs rename to QuantumUNET/Messages/QClientAuthorityMessage.cs index d99690e7..dfce5ec7 100644 --- a/QuantumUNET/Messages/QSBClientAuthorityMessage.cs +++ b/QuantumUNET/Messages/QClientAuthorityMessage.cs @@ -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); diff --git a/QuantumUNET/Messages/QEmptyMessage.cs b/QuantumUNET/Messages/QEmptyMessage.cs new file mode 100644 index 00000000..2fda2a87 --- /dev/null +++ b/QuantumUNET/Messages/QEmptyMessage.cs @@ -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) { } + } +} \ No newline at end of file diff --git a/QuantumUNET/Messages/QErrorMessage.cs b/QuantumUNET/Messages/QErrorMessage.cs new file mode 100644 index 00000000..680d0e7f --- /dev/null +++ b/QuantumUNET/Messages/QErrorMessage.cs @@ -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(); + } +} \ No newline at end of file diff --git a/QuantumUNET/Messages/QMessageBase.cs b/QuantumUNET/Messages/QMessageBase.cs new file mode 100644 index 00000000..463ce7ce --- /dev/null +++ b/QuantumUNET/Messages/QMessageBase.cs @@ -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) { } + } +} \ No newline at end of file diff --git a/QuantumUNET/Messages/QSBMsgType.cs b/QuantumUNET/Messages/QMsgType.cs similarity index 99% rename from QuantumUNET/Messages/QSBMsgType.cs rename to QuantumUNET/Messages/QMsgType.cs index 7181ea4b..252d1fbb 100644 --- a/QuantumUNET/Messages/QSBMsgType.cs +++ b/QuantumUNET/Messages/QMsgType.cs @@ -1,6 +1,6 @@ namespace QuantumUNET.Messages { - public class QSBMsgType + public class QMsgType { public static string MsgTypeToString(short value) { diff --git a/QuantumUNET/Messages/QSBNetworkMessage.cs b/QuantumUNET/Messages/QNetworkMessage.cs similarity index 52% rename from QuantumUNET/Messages/QSBNetworkMessage.cs rename to QuantumUNET/Messages/QNetworkMessage.cs index 16ca1065..e5dbc590 100644 --- a/QuantumUNET/Messages/QSBNetworkMessage.cs +++ b/QuantumUNET/Messages/QNetworkMessage.cs @@ -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() where TMsg : QSBMessageBase, new() + public TMsg ReadMessage() where TMsg : QMessageBase, new() { var result = Activator.CreateInstance(); result.Deserialize(Reader); return result; } - public void ReadMessage(TMsg msg) where TMsg : QSBMessageBase => + public void ReadMessage(TMsg msg) where TMsg : QMessageBase => msg.Deserialize(Reader); } } \ No newline at end of file diff --git a/QuantumUNET/Messages/QNetworkMessageDelegate.cs b/QuantumUNET/Messages/QNetworkMessageDelegate.cs new file mode 100644 index 00000000..3ebaae64 --- /dev/null +++ b/QuantumUNET/Messages/QNetworkMessageDelegate.cs @@ -0,0 +1,4 @@ +namespace QuantumUNET.Messages +{ + public delegate void QNetworkMessageDelegate(QNetworkMessage netMsg); +} \ No newline at end of file diff --git a/QuantumUNET/Messages/QNotReadyMessage.cs b/QuantumUNET/Messages/QNotReadyMessage.cs new file mode 100644 index 00000000..24da1bec --- /dev/null +++ b/QuantumUNET/Messages/QNotReadyMessage.cs @@ -0,0 +1,6 @@ +namespace QuantumUNET.Messages +{ + public class QNotReadyMessage : QEmptyMessage + { + } +} \ No newline at end of file diff --git a/QuantumUNET/Messages/QObjectDestroyMessage.cs b/QuantumUNET/Messages/QObjectDestroyMessage.cs new file mode 100644 index 00000000..4664a3e4 --- /dev/null +++ b/QuantumUNET/Messages/QObjectDestroyMessage.cs @@ -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(); + } +} \ No newline at end of file diff --git a/QuantumUNET/Messages/QObjectSpawnFinishedMessage.cs b/QuantumUNET/Messages/QObjectSpawnFinishedMessage.cs new file mode 100644 index 00000000..f85392bc --- /dev/null +++ b/QuantumUNET/Messages/QObjectSpawnFinishedMessage.cs @@ -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(); + } +} \ No newline at end of file diff --git a/QuantumUNET/Messages/QSBObjectSpawnMessage.cs b/QuantumUNET/Messages/QObjectSpawnMessage.cs similarity index 79% rename from QuantumUNET/Messages/QSBObjectSpawnMessage.cs rename to QuantumUNET/Messages/QObjectSpawnMessage.cs index 3236cc1a..9376e042 100644 --- a/QuantumUNET/Messages/QSBObjectSpawnMessage.cs +++ b/QuantumUNET/Messages/QObjectSpawnMessage.cs @@ -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(); diff --git a/QuantumUNET/Messages/QSBObjectSpawnSceneMessage.cs b/QuantumUNET/Messages/QObjectSpawnSceneMessage.cs similarity index 74% rename from QuantumUNET/Messages/QSBObjectSpawnSceneMessage.cs rename to QuantumUNET/Messages/QObjectSpawnSceneMessage.cs index 9a8212a9..845093be 100644 --- a/QuantumUNET/Messages/QSBObjectSpawnSceneMessage.cs +++ b/QuantumUNET/Messages/QObjectSpawnSceneMessage.cs @@ -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(); diff --git a/QuantumUNET/Messages/QSBOwnerMessage.cs b/QuantumUNET/Messages/QOwnerMessage.cs similarity index 68% rename from QuantumUNET/Messages/QSBOwnerMessage.cs rename to QuantumUNET/Messages/QOwnerMessage.cs index 944c9d6e..29d025f2 100644 --- a/QuantumUNET/Messages/QSBOwnerMessage.cs +++ b/QuantumUNET/Messages/QOwnerMessage.cs @@ -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(); diff --git a/QuantumUNET/Messages/QReadyMessage.cs b/QuantumUNET/Messages/QReadyMessage.cs new file mode 100644 index 00000000..a11a4ab4 --- /dev/null +++ b/QuantumUNET/Messages/QReadyMessage.cs @@ -0,0 +1,6 @@ +namespace QuantumUNET.Messages +{ + public class QReadyMessage : QEmptyMessage + { + } +} \ No newline at end of file diff --git a/QuantumUNET/Messages/QRemovePlayerMessage.cs b/QuantumUNET/Messages/QRemovePlayerMessage.cs new file mode 100644 index 00000000..a77c7e5b --- /dev/null +++ b/QuantumUNET/Messages/QRemovePlayerMessage.cs @@ -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(); + } +} \ No newline at end of file diff --git a/QuantumUNET/Messages/QSBEmptyMessage.cs b/QuantumUNET/Messages/QSBEmptyMessage.cs deleted file mode 100644 index b89526b3..00000000 --- a/QuantumUNET/Messages/QSBEmptyMessage.cs +++ /dev/null @@ -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) { } - } -} \ No newline at end of file diff --git a/QuantumUNET/Messages/QSBErrorMessage.cs b/QuantumUNET/Messages/QSBErrorMessage.cs deleted file mode 100644 index 97d7ecaf..00000000 --- a/QuantumUNET/Messages/QSBErrorMessage.cs +++ /dev/null @@ -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(); - } -} \ No newline at end of file diff --git a/QuantumUNET/Messages/QSBMessageBase.cs b/QuantumUNET/Messages/QSBMessageBase.cs deleted file mode 100644 index 969dd732..00000000 --- a/QuantumUNET/Messages/QSBMessageBase.cs +++ /dev/null @@ -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) { } - } -} \ No newline at end of file diff --git a/QuantumUNET/Messages/QSBNetworkMessageDelegate.cs b/QuantumUNET/Messages/QSBNetworkMessageDelegate.cs deleted file mode 100644 index c88035d5..00000000 --- a/QuantumUNET/Messages/QSBNetworkMessageDelegate.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace QuantumUNET.Messages -{ - public delegate void QSBNetworkMessageDelegate(QSBNetworkMessage netMsg); -} \ No newline at end of file diff --git a/QuantumUNET/Messages/QSBNotReadyMessage.cs b/QuantumUNET/Messages/QSBNotReadyMessage.cs deleted file mode 100644 index 619c7e24..00000000 --- a/QuantumUNET/Messages/QSBNotReadyMessage.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace QuantumUNET.Messages -{ - public class QSBNotReadyMessage : QSBEmptyMessage - { - } -} \ No newline at end of file diff --git a/QuantumUNET/Messages/QSBObjectDestroyMessage.cs b/QuantumUNET/Messages/QSBObjectDestroyMessage.cs deleted file mode 100644 index 08f74a77..00000000 --- a/QuantumUNET/Messages/QSBObjectDestroyMessage.cs +++ /dev/null @@ -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(); - } -} \ No newline at end of file diff --git a/QuantumUNET/Messages/QSBObjectSpawnFinishedMessage.cs b/QuantumUNET/Messages/QSBObjectSpawnFinishedMessage.cs deleted file mode 100644 index 4255bccb..00000000 --- a/QuantumUNET/Messages/QSBObjectSpawnFinishedMessage.cs +++ /dev/null @@ -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(); - } -} \ No newline at end of file diff --git a/QuantumUNET/Messages/QSBReadyMessage.cs b/QuantumUNET/Messages/QSBReadyMessage.cs deleted file mode 100644 index c100560f..00000000 --- a/QuantumUNET/Messages/QSBReadyMessage.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace QuantumUNET.Messages -{ - public class QSBReadyMessage : QSBEmptyMessage - { - } -} \ No newline at end of file diff --git a/QuantumUNET/Messages/QSBRemovePlayerMessage.cs b/QuantumUNET/Messages/QSBRemovePlayerMessage.cs deleted file mode 100644 index 7bebaef3..00000000 --- a/QuantumUNET/Messages/QSBRemovePlayerMessage.cs +++ /dev/null @@ -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(); - } -} \ No newline at end of file diff --git a/QuantumUNET/Messages/QSBSpawnDelegate.cs b/QuantumUNET/Messages/QSBSpawnDelegate.cs deleted file mode 100644 index 010d8e40..00000000 --- a/QuantumUNET/Messages/QSBSpawnDelegate.cs +++ /dev/null @@ -1,7 +0,0 @@ -using UnityEngine; -using UnityEngine.Networking; - -namespace QuantumUNET -{ - public delegate GameObject QSBSpawnDelegate(Vector3 position, NetworkHash128 assetId); -} diff --git a/QuantumUNET/Messages/QSBStringMessage.cs b/QuantumUNET/Messages/QSBStringMessage.cs deleted file mode 100644 index 7e52a4e9..00000000 --- a/QuantumUNET/Messages/QSBStringMessage.cs +++ /dev/null @@ -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(); - } -} \ No newline at end of file diff --git a/QuantumUNET/Messages/QSpawnDelegate.cs b/QuantumUNET/Messages/QSpawnDelegate.cs new file mode 100644 index 00000000..066c5271 --- /dev/null +++ b/QuantumUNET/Messages/QSpawnDelegate.cs @@ -0,0 +1,7 @@ +using UnityEngine; +using UnityEngine.Networking; + +namespace QuantumUNET +{ + public delegate GameObject QSpawnDelegate(Vector3 position, NetworkHash128 assetId); +} diff --git a/QuantumUNET/Messages/QStringMessage.cs b/QuantumUNET/Messages/QStringMessage.cs new file mode 100644 index 00000000..96b3dcf0 --- /dev/null +++ b/QuantumUNET/Messages/QStringMessage.cs @@ -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(); + } +} \ No newline at end of file diff --git a/QuantumUNET/QSBCRCMessageEntry.cs b/QuantumUNET/QCRCMessageEntry.cs similarity index 68% rename from QuantumUNET/QSBCRCMessageEntry.cs rename to QuantumUNET/QCRCMessageEntry.cs index 1d9c7895..747468f7 100644 --- a/QuantumUNET/QSBCRCMessageEntry.cs +++ b/QuantumUNET/QCRCMessageEntry.cs @@ -1,6 +1,6 @@ namespace QuantumUNET { - internal struct QSBCRCMessageEntry + internal struct QCRCMessageEntry { public string name; public byte channel; diff --git a/QuantumUNET/QSBClientScene.cs b/QuantumUNET/QClientScene.cs similarity index 75% rename from QuantumUNET/QSBClientScene.cs rename to QuantumUNET/QClientScene.cs index 68730080..dfb5bc2f 100644 --- a/QuantumUNET/QSBClientScene.cs +++ b/QuantumUNET/QClientScene.cs @@ -7,28 +7,28 @@ using UnityEngine.Networking; namespace QuantumUNET { - public class QSBClientScene + public class QClientScene { internal static void SetNotReady() => ready = false; - public static List localPlayers { get; private set; } = new List(); + public static List localPlayers { get; private set; } = new List(); 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 Objects => s_NetworkScene.localObjects; + public static Dictionary Objects => s_NetworkScene.localObjects; - public static Dictionary Prefabs => QSBNetworkScene.guidToPrefab; + public static Dictionary Prefabs => QNetworkScene.guidToPrefab; - public static Dictionary SpawnableObjects { get; private set; } + public static Dictionary SpawnableObjects { get; private set; } internal static void Shutdown() { s_NetworkScene.Shutdown(); - localPlayers = new List(); + localPlayers = new List(); s_PendingOwnerIds = new List(); 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(); - foreach (var networkIdentity in Resources.FindObjectsOfTypeAll()) + SpawnableObjects = new Dictionary(); + foreach (var networkIdentity in Resources.FindObjectsOfTypeAll()) { 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(); + component = gameObject.GetComponent(); 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(); + component = gameObject2.GetComponent(); 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; diff --git a/QuantumUNET/QSBLocalClient.cs b/QuantumUNET/QLocalClient.cs similarity index 80% rename from QuantumUNET/QSBLocalClient.cs rename to QuantumUNET/QLocalClient.cs index 803411e8..9eeb5b7c 100644 --- a/QuantumUNET/QSBLocalClient.cs +++ b/QuantumUNET/QLocalClient.cs @@ -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 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 { diff --git a/QuantumUNET/QSBNetworkBehaviour.cs b/QuantumUNET/QNetworkBehaviour.cs similarity index 75% rename from QuantumUNET/QSBNetworkBehaviour.cs rename to QuantumUNET/QNetworkBehaviour.cs index 820baf19..7c511742 100644 --- a/QuantumUNET/QSBNetworkBehaviour.cs +++ b/QuantumUNET/QNetworkBehaviour.cs @@ -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(); + m_MyView = GetComponent(); 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(); + var component = newGameObject.GetComponent(); 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().NetId; + networkInstanceId2 = gameObjectField.GetComponent().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 observers, bool initialize) => false; + public virtual bool OnRebuildObservers(HashSet 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 s_CmdHandlerDelegates = new Dictionary(); - public delegate void CmdDelegate(QSBNetworkBehaviour obj, QSBNetworkReader reader); + public delegate void CmdDelegate(QNetworkBehaviour obj, QNetworkReader reader); - protected delegate void EventDelegate(List targets, QSBNetworkReader reader); + protected delegate void EventDelegate(List targets, QNetworkReader reader); protected enum UNetInvokeType { diff --git a/QuantumUNET/QSBNetworkCRC.cs b/QuantumUNET/QNetworkCRC.cs similarity index 82% rename from QuantumUNET/QSBNetworkCRC.cs rename to QuantumUNET/QNetworkCRC.cs index 0c717be0..967775a6 100644 --- a/QuantumUNET/QSBNetworkCRC.cs +++ b/QuantumUNET/QNetworkCRC.cs @@ -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; } } \ No newline at end of file diff --git a/QuantumUNET/QSBNetworkClient.cs b/QuantumUNET/QNetworkClient.cs similarity index 72% rename from QuantumUNET/QSBNetworkClient.cs rename to QuantumUNET/QNetworkClient.cs index 408c6ef3..dceae214 100644 --- a/QuantumUNET/QSBNetworkClient.cs +++ b/QuantumUNET/QNetworkClient.cs @@ -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 allClients { get; private set; } = new List(); + public static List allClients { get; private set; } = new List(); 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 handlers => m_MessageHandlers.GetHandlers(); + public Dictionary 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() where T : QSBNetworkConnection => networkConnectionClass = typeof(T); + public void SetNetworkConnectionClass() 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 GetConnectionStats() => + public Dictionary 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 GetTotalConnectionStats() + public static Dictionary GetTotalConnectionStats() { - var dictionary = new Dictionary(); + var dictionary = new Dictionary(); 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(); + allClients = new List(); 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; diff --git a/QuantumUNET/QSBNetworkConnection.cs b/QuantumUNET/QNetworkConnection.cs similarity index 72% rename from QuantumUNET/QSBNetworkConnection.cs rename to QuantumUNET/QNetworkConnection.cs index 498c2161..aa1989d5 100644 --- a/QuantumUNET/QSBNetworkConnection.cs +++ b/QuantumUNET/QNetworkConnection.cs @@ -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 VisList { get; } = new HashSet(); + internal HashSet VisList { get; } = new HashSet(); - public List PlayerControllers { get; } = new List(); + public List PlayerControllers { get; } = new List(); public HashSet 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().ClearClientOwner(); + gameObject.GetComponent().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 m_MessageHandlersDict; + private Dictionary 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; diff --git a/QuantumUNET/QNetworkMessageHandlers.cs b/QuantumUNET/QNetworkMessageHandlers.cs new file mode 100644 index 00000000..49b9a3c2 --- /dev/null +++ b/QuantumUNET/QNetworkMessageHandlers.cs @@ -0,0 +1,59 @@ +using QuantumUNET.Logging; +using QuantumUNET.Messages; +using System.Collections.Generic; + +namespace QuantumUNET +{ + internal class QNetworkMessageHandlers + { + private readonly Dictionary _msgHandlers = new Dictionary(); + + 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 GetHandlers() => _msgHandlers; + + internal void ClearMessageHandlers() => _msgHandlers.Clear(); + } +} \ No newline at end of file diff --git a/QuantumUNET/QSBNetworkScene.cs b/QuantumUNET/QNetworkScene.cs similarity index 87% rename from QuantumUNET/QSBNetworkScene.cs rename to QuantumUNET/QNetworkScene.cs index bdf357a3..62cd264f 100644 --- a/QuantumUNET/QSBNetworkScene.cs +++ b/QuantumUNET/QNetworkScene.cs @@ -5,15 +5,15 @@ using UnityEngine.Networking; namespace QuantumUNET { - internal class QSBNetworkScene + internal class QNetworkScene { internal static Dictionary guidToPrefab { get; } = new Dictionary(); - internal static Dictionary spawnHandlers { get; } = new Dictionary(); + internal static Dictionary spawnHandlers { get; } = new Dictionary(); internal static Dictionary unspawnHandlers { get; } = new Dictionary(); - internal Dictionary localObjects { get; } = new Dictionary(); + internal Dictionary localObjects { get; } = new Dictionary(); 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(); + networkIdentity = obj.GetComponent(); 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(); + var component = prefab.GetComponent(); if (component) { component.SetDynamicAssetId(newAssetId); @@ -108,7 +108,7 @@ namespace QuantumUNET internal static void RegisterPrefab(GameObject prefab) { - var component = prefab.GetComponent(); + var component = prefab.GetComponent(); 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(); + var component = prefab.GetComponent(); 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(); + var component = prefab.GetComponent(); 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)) diff --git a/QuantumUNET/QSBNetworkServer.cs b/QuantumUNET/QNetworkServer.cs similarity index 66% rename from QuantumUNET/QSBNetworkServer.cs rename to QuantumUNET/QNetworkServer.cs index c57fa042..27c4884c 100644 --- a/QuantumUNET/QSBNetworkServer.cs +++ b/QuantumUNET/QNetworkServer.cs @@ -1,5 +1,5 @@ -using OWML.Logging; -using QuantumUNET.Components; +using QuantumUNET.Components; +using QuantumUNET.Logging; using QuantumUNET.Messages; using QuantumUNET.Transport; using System; @@ -12,30 +12,30 @@ using UnityEngine.Networking.Types; namespace QuantumUNET { - public class QSBNetworkServer + public class QNetworkServer { - private QSBNetworkServer() + private QNetworkServer() { NetworkTransport.Init(); m_RemoveList = new HashSet(); m_ExternalConnections = new HashSet(); - m_NetworkScene = new QSBNetworkScene(); + m_NetworkScene = new QNetworkScene(); m_SimpleServerSimple = new ServerSimpleWrapper(this); } - public static List localConnections => instance.m_LocalConnectionsFakeList; + public static List localConnections => instance.m_LocalConnectionsFakeList; public static int listenPort => instance.m_SimpleServerSimple.listenPort; public static int serverHostId => instance.m_SimpleServerSimple.serverHostId; - public static ReadOnlyCollection connections => instance.m_SimpleServerSimple.connections; + public static ReadOnlyCollection connections => instance.m_SimpleServerSimple.connections; - public static Dictionary handlers => instance.m_SimpleServerSimple.handlers; + public static Dictionary handlers => instance.m_SimpleServerSimple.handlers; public static HostTopology hostTopology => instance.m_SimpleServerSimple.hostTopology; - public static Dictionary objects => instance.m_NetworkScene.localObjects; + public static Dictionary objects => instance.m_NetworkScene.localObjects; public static bool dontListen { get; set; } @@ -45,7 +45,7 @@ namespace QuantumUNET set => instance.m_SimpleServerSimple.useWebSockets = value; } - internal static QSBNetworkServer instance + internal static QNetworkServer instance { get { @@ -56,7 +56,7 @@ namespace QuantumUNET { if (s_Instance == null) { - s_Instance = new QSBNetworkServer(); + s_Instance = new QNetworkServer(); } } } @@ -78,7 +78,7 @@ namespace QuantumUNET public static Type networkConnectionClass => instance.m_SimpleServerSimple.networkConnectionClass; - public static void SetNetworkConnectionClass() where T : QSBNetworkConnection => instance.m_SimpleServerSimple.SetNetworkConnectionClass(); + public static void SetNetworkConnectionClass() where T : QNetworkConnection => instance.m_SimpleServerSimple.SetNetworkConnectionClass(); public static bool Configure(ConnectionConfig config, int maxConnections) => instance.m_SimpleServerSimple.Configure(config, maxConnections); @@ -109,14 +109,14 @@ namespace QuantumUNET internal void RegisterMessageHandlers() { - m_SimpleServerSimple.RegisterHandlerSafe(QSBMsgType.Ready, OnClientReadyMessage); - m_SimpleServerSimple.RegisterHandlerSafe(QSBMsgType.Command, OnCommandMessage); - m_SimpleServerSimple.RegisterHandlerSafe(QSBMsgType.LocalPlayerTransform, QSBNetworkTransform.HandleTransform); + m_SimpleServerSimple.RegisterHandlerSafe(QMsgType.Ready, OnClientReadyMessage); + m_SimpleServerSimple.RegisterHandlerSafe(QMsgType.Command, OnCommandMessage); + m_SimpleServerSimple.RegisterHandlerSafe(QMsgType.LocalPlayerTransform, Components.QNetworkTransform.HandleTransform); //m_SimpleServerSimple.RegisterHandlerSafe((short)16, new QSBNetworkMessageDelegate(NetworkTransformChild.HandleChildTransform)); - m_SimpleServerSimple.RegisterHandlerSafe(QSBMsgType.RemovePlayer, OnRemovePlayerMessage); - m_SimpleServerSimple.RegisterHandlerSafe(QSBMsgType.Animation, QSBNetworkAnimator.OnAnimationServerMessage); - m_SimpleServerSimple.RegisterHandlerSafe(QSBMsgType.AnimationParameters, QSBNetworkAnimator.OnAnimationParametersServerMessage); - m_SimpleServerSimple.RegisterHandlerSafe(QSBMsgType.AnimationTrigger, QSBNetworkAnimator.OnAnimationTriggerServerMessage); + m_SimpleServerSimple.RegisterHandlerSafe(QMsgType.RemovePlayer, OnRemovePlayerMessage); + m_SimpleServerSimple.RegisterHandlerSafe(QMsgType.Animation, QNetworkAnimator.OnAnimationServerMessage); + m_SimpleServerSimple.RegisterHandlerSafe(QMsgType.AnimationParameters, QNetworkAnimator.OnAnimationParametersServerMessage); + m_SimpleServerSimple.RegisterHandlerSafe(QMsgType.AnimationTrigger, QNetworkAnimator.OnAnimationTriggerServerMessage); maxPacketSize = hostTopology.DefaultConfig.PacketSize; } @@ -159,17 +159,17 @@ namespace QuantumUNET m_MaxDelay = seconds; } - internal int AddLocalClient(QSBLocalClient localClient) + internal int AddLocalClient(QLocalClient localClient) { int result; if (m_LocalConnectionsFakeList.Count != 0) { - Debug.LogError("Local Connection already exists"); + QLog.LogError("Local Connection already exists"); result = -1; } else { - m_LocalConnection = new QSBULocalConnectionToClient(localClient) + m_LocalConnection = new QULocalConnectionToClient(localClient) { connectionId = 0 }; @@ -181,7 +181,7 @@ namespace QuantumUNET return result; } - internal void RemoveLocalClient(QSBNetworkConnection localClientConnection) + internal void RemoveLocalClient(QNetworkConnection localClientConnection) { for (var i = 0; i < m_LocalConnectionsFakeList.Count; i++) { @@ -203,7 +203,7 @@ namespace QuantumUNET internal void SetLocalObjectOnServer(NetworkInstanceId netId, GameObject obj) { - Debug.Log($"SetLocalObjectOnServer {netId} {obj}"); + QLog.LogDebug($"SetLocalObjectOnServer {netId} {obj}"); m_NetworkScene.SetLocalObject(netId, obj, false, true); } @@ -216,17 +216,17 @@ namespace QuantumUNET { if (!networkIdentity.IsClient) { - Debug.Log($"ActivateClientScene {networkIdentity.NetId} {networkIdentity.gameObject}"); - QSBClientScene.SetLocalObject(networkIdentity.NetId, networkIdentity.gameObject); + QLog.Log($"ActivateClientScene {networkIdentity.NetId} {networkIdentity.gameObject}"); + QClientScene.SetLocalObject(networkIdentity.NetId, networkIdentity.gameObject); networkIdentity.OnStartClient(); } } } } - public static bool SendToAll(short msgType, QSBMessageBase msg) + public static bool SendToAll(short msgType, QMessageBase msg) { - Debug.Log($"Server.SendToAll msgType:{msgType}"); + QLog.LogDebug($"Server.SendToAll msgType:{msgType}"); var flag = true; foreach (var networkConnection in connections) { @@ -238,11 +238,11 @@ namespace QuantumUNET return flag; } - private static bool SendToObservers(GameObject contextObj, short msgType, QSBMessageBase msg) + private static bool SendToObservers(GameObject contextObj, short msgType, QMessageBase msg) { - Debug.Log($"Server.SendToObservers id:{msgType}"); + QLog.LogDebug($"Server.SendToObservers id:{msgType}"); var flag = true; - var component = contextObj.GetComponent(); + var component = contextObj.GetComponent(); bool result; if (component == null || component.Observers == null) { @@ -261,9 +261,9 @@ namespace QuantumUNET return result; } - public static bool SendToReady(GameObject contextObj, short msgType, QSBMessageBase msg) + public static bool SendToReady(GameObject contextObj, short msgType, QMessageBase msg) { - Debug.Log($"Server.SendToReady id:{msgType}"); + QLog.LogDebug($"Server.SendToReady id:{msgType}"); bool result; if (contextObj == null) { @@ -280,7 +280,7 @@ namespace QuantumUNET else { var flag = true; - var component = contextObj.GetComponent(); + var component = contextObj.GetComponent(); if (component == null || component.Observers == null) { result = false; @@ -302,7 +302,7 @@ namespace QuantumUNET return result; } - public static void SendWriterToReady(GameObject contextObj, QSBNetworkWriter writer, int channelId) + public static void SendWriterToReady(GameObject contextObj, QNetworkWriter writer, int channelId) { var arraySegment = writer.AsArraySegment(); if (arraySegment.Count > 32767) @@ -329,12 +329,12 @@ namespace QuantumUNET } if (!flag) { - ModConsole.OwmlConsole.WriteLine("SendBytesToReady failed"); + QLog.LogError("SendBytesToReady failed"); } } else { - var component = contextObj.GetComponent(); + var component = contextObj.GetComponent(); try { var flag2 = true; @@ -352,12 +352,12 @@ namespace QuantumUNET } if (!flag2) { - ModConsole.OwmlConsole.WriteLine($"SendBytesToReady failed for {contextObj}"); + QLog.LogError($"SendBytesToReady failed for {contextObj}"); } } catch (NullReferenceException) { - ModConsole.OwmlConsole.WriteLine($"SendBytesToReady object {contextObj} has not been spawned"); + QLog.LogError($"SendBytesToReady object {contextObj} has not been spawned"); } } } @@ -380,9 +380,9 @@ namespace QuantumUNET } } - public static bool SendUnreliableToAll(short msgType, QSBMessageBase msg) + public static bool SendUnreliableToAll(short msgType, QMessageBase msg) { - Debug.Log($"Server.SendUnreliableToAll msgType:{msgType}"); + QLog.Log($"Server.SendUnreliableToAll msgType:{msgType}"); var flag = true; foreach (var networkConnection in connections) { @@ -394,9 +394,9 @@ namespace QuantumUNET return flag; } - public static bool SendUnreliableToReady(GameObject contextObj, short msgType, QSBMessageBase msg) + public static bool SendUnreliableToReady(GameObject contextObj, short msgType, QMessageBase msg) { - Debug.Log($"Server.SendUnreliableToReady id:{msgType}"); + QLog.Log($"Server.SendUnreliableToReady id:{msgType}"); bool result; if (contextObj == null) { @@ -413,7 +413,7 @@ namespace QuantumUNET else { var flag = true; - var component = contextObj.GetComponent(); + var component = contextObj.GetComponent(); var count = component.Observers.Count; for (var j = 0; j < count; j++) { @@ -428,9 +428,9 @@ namespace QuantumUNET return result; } - public static bool SendByChannelToAll(short msgType, QSBMessageBase msg, int channelId) + public static bool SendByChannelToAll(short msgType, QMessageBase msg, int channelId) { - Debug.Log($"Server.SendByChannelToAll id:{msgType}"); + QLog.Log($"Server.SendByChannelToAll id:{msgType}"); var flag = true; foreach (var networkConnection in connections) { @@ -442,9 +442,9 @@ namespace QuantumUNET return flag; } - public static bool SendByChannelToReady(GameObject contextObj, short msgType, QSBMessageBase msg, int channelId) + public static bool SendByChannelToReady(GameObject contextObj, short msgType, QMessageBase msg, int channelId) { - Debug.Log($"Server.SendByChannelToReady msgType:{msgType}"); + QLog.Log($"Server.SendByChannelToReady msgType:{msgType}"); bool result; if (contextObj == null) { @@ -461,7 +461,7 @@ namespace QuantumUNET else { var flag = true; - var component = contextObj.GetComponent(); + var component = contextObj.GetComponent(); var count = component.Observers.Count; for (var j = 0; j < count; j++) { @@ -543,71 +543,71 @@ namespace QuantumUNET UpdateServerObjects(); } - private void OnConnected(QSBNetworkConnection conn) + private void OnConnected(QNetworkConnection conn) { - Debug.Log($"Server accepted client:{conn.connectionId}"); + QLog.Log($"Server accepted client:{conn.connectionId}"); conn.SetMaxDelay(m_MaxDelay); conn.InvokeHandlerNoData(32); SendCrc(conn); } - private void OnDisconnected(QSBNetworkConnection conn) + private void OnDisconnected(QNetworkConnection conn) { conn.InvokeHandlerNoData(33); foreach (var controller in conn.PlayerControllers) { if (controller.Gameobject != null) { - Debug.LogWarning("Player not destroyed when connection disconnected."); + QLog.LogWarning("Player not destroyed when connection disconnected."); } } - Debug.Log($"Server lost client:{conn.connectionId}"); + QLog.Log($"Server lost client:{conn.connectionId}"); conn.RemoveObservers(); conn.Dispose(); } - private void OnData(QSBNetworkConnection conn, int receivedSize, int channelId) => conn.TransportReceive(m_SimpleServerSimple.messageBuffer, receivedSize, channelId); + private void OnData(QNetworkConnection conn, int receivedSize, int channelId) => conn.TransportReceive(m_SimpleServerSimple.messageBuffer, receivedSize, channelId); private void GenerateConnectError(int error) { - Debug.LogError($"UNet Server Connect Error: {error}"); + QLog.LogError($"UNet Server Connect Error: {error}"); GenerateError(null, error); } - private void GenerateDataError(QSBNetworkConnection conn, int error) + private void GenerateDataError(QNetworkConnection conn, int error) { - Debug.LogError($"UNet Server Data Error: {(NetworkError)error}"); + QLog.LogError($"UNet Server Data Error: {(NetworkError)error}"); GenerateError(conn, error); } - private void GenerateDisconnectError(QSBNetworkConnection conn, int error) + private void GenerateDisconnectError(QNetworkConnection conn, int error) { - Debug.LogError($"UNet Server Disconnect Error: {(NetworkError)error} conn:[{conn}]:{conn.connectionId}"); + QLog.LogError($"UNet Server Disconnect Error: {(NetworkError)error} conn:[{conn}]:{conn.connectionId}"); GenerateError(conn, error); } - private void GenerateError(QSBNetworkConnection conn, int error) + private void GenerateError(QNetworkConnection conn, int error) { if (handlers.ContainsKey(34)) { - var errorMessage = new QSBErrorMessage + var errorMessage = new QErrorMessage { errorCode = error }; - var writer = new QSBNetworkWriter(); + var writer = new QNetworkWriter(); errorMessage.Serialize(writer); - var reader = new QSBNetworkReader(writer); + var reader = new QNetworkReader(writer); conn.InvokeHandler(34, reader, 0); } } - public static void RegisterHandler(short msgType, QSBNetworkMessageDelegate handler) => instance.m_SimpleServerSimple.RegisterHandler(msgType, handler); + public static void RegisterHandler(short msgType, QNetworkMessageDelegate handler) => instance.m_SimpleServerSimple.RegisterHandler(msgType, handler); public static void UnregisterHandler(short msgType) => instance.m_SimpleServerSimple.UnregisterHandler(msgType); public static void ClearHandlers() => instance.m_SimpleServerSimple.ClearHandlers(); - public static void ClearSpawners() => QSBNetworkScene.ClearSpawners(); + public static void ClearSpawners() => QNetworkScene.ClearSpawners(); public static void GetStatsOut(out int numMsgs, out int numBufferedMsgs, out int numBytes, out int lastBufferedPerSecond) { @@ -643,7 +643,7 @@ namespace QuantumUNET } } - public static void SendToClientOfPlayer(GameObject player, short msgType, QSBMessageBase msg) + public static void SendToClientOfPlayer(GameObject player, short msgType, QMessageBase msg) { foreach (var networkConnection in connections) { @@ -659,10 +659,10 @@ namespace QuantumUNET } } } - Debug.LogError($"Failed to send message to player object '{player.name}, not found in connection list"); + QLog.LogError($"Failed to send message to player object '{player.name}, not found in connection list"); } - public static void SendToClient(int connectionId, short msgType, QSBMessageBase msg) + public static void SendToClient(int connectionId, short msgType, QMessageBase msg) { if (connectionId < connections.Count) { @@ -673,17 +673,17 @@ namespace QuantumUNET return; } } - Debug.LogError($"Failed to send message to connection ID '{connectionId}, not found in connection list"); + QLog.LogError($"Failed to send message to connection ID '{connectionId}, not found in connection list"); } - public static bool AddPlayerForConnection(QSBNetworkConnection conn, GameObject player, short playerControllerId) => instance.InternalAddPlayerForConnection(conn, player, playerControllerId); + public static bool AddPlayerForConnection(QNetworkConnection conn, GameObject player, short playerControllerId) => instance.InternalAddPlayerForConnection(conn, player, playerControllerId); - internal bool InternalAddPlayerForConnection(QSBNetworkConnection conn, GameObject playerGameObject, short playerControllerId) + internal bool InternalAddPlayerForConnection(QNetworkConnection conn, GameObject playerGameObject, short playerControllerId) { bool result; if (!GetNetworkIdentity(playerGameObject, out var networkIdentity)) { - Debug.Log( + QLog.Log( $"AddPlayer: playerGameObject has no NetworkIdentity. Please add a NetworkIdentity to {playerGameObject}"); result = false; } @@ -703,13 +703,13 @@ namespace QuantumUNET } if (x != null) { - Debug.Log( + QLog.Log( $"AddPlayer: player object already exists for playerControllerId of {playerControllerId}"); result = false; } else { - var playerController2 = new QSBPlayerController(playerGameObject, playerControllerId); + var playerController2 = new QPlayerController(playerGameObject, playerControllerId); conn.SetPlayerController(playerController2); networkIdentity.SetConnectionToClient(conn, playerController2.PlayerControllerId); SetClientReady(conn); @@ -719,8 +719,8 @@ namespace QuantumUNET } else { - Debug.Log( - $"Adding new playerGameObject object netId: {playerGameObject.GetComponent().NetId} asset ID {playerGameObject.GetComponent().AssetId}"); + QLog.Log( + $"Adding new playerGameObject object netId: {playerGameObject.GetComponent().NetId} asset ID {playerGameObject.GetComponent().AssetId}"); FinishPlayerForConnection(conn, networkIdentity, playerGameObject); if (networkIdentity.LocalPlayerAuthority) { @@ -734,37 +734,37 @@ namespace QuantumUNET return result; } - private static bool CheckPlayerControllerIdForConnection(QSBNetworkConnection conn, short playerControllerId) + private static bool CheckPlayerControllerIdForConnection(QNetworkConnection conn, short playerControllerId) { bool result; if (playerControllerId < 0) { - Debug.LogError($"AddPlayer: playerControllerId of {playerControllerId} is negative"); + QLog.LogError($"AddPlayer: playerControllerId of {playerControllerId} is negative"); result = false; } else if (playerControllerId > 32) { - Debug.Log($"AddPlayer: playerControllerId of {playerControllerId} is too high. max is {32}"); + QLog.Log($"AddPlayer: playerControllerId of {playerControllerId} is too high. max is {32}"); result = false; } else { if (playerControllerId > 16) { - Debug.LogWarning($"AddPlayer: playerControllerId of {playerControllerId} is unusually high"); + QLog.LogWarning($"AddPlayer: playerControllerId of {playerControllerId} is unusually high"); } result = true; } return result; } - private bool SetupLocalPlayerForConnection(QSBNetworkConnection conn, QSBNetworkIdentity uv, QSBPlayerController newPlayerController) + private bool SetupLocalPlayerForConnection(QNetworkConnection conn, QNetworkIdentity uv, QPlayerController newPlayerController) { - Debug.Log($"NetworkServer SetupLocalPlayerForConnection netID:{uv.NetId}"); + QLog.Log($"NetworkServer SetupLocalPlayerForConnection netID:{uv.NetId}"); bool result; - if (conn is QSBULocalConnectionToClient ulocalConnectionToClient) + if (conn is QULocalConnectionToClient ulocalConnectionToClient) { - Debug.Log("NetworkServer AddPlayer handling ULocalConnectionToClient"); + QLog.Log("NetworkServer AddPlayer handling ULocalConnectionToClient"); if (uv.NetId.IsEmpty()) { uv.OnStartServer(true); @@ -784,25 +784,25 @@ namespace QuantumUNET return result; } - private static void FinishPlayerForConnection(QSBNetworkConnection conn, QSBNetworkIdentity uv, GameObject playerGameObject) + private static void FinishPlayerForConnection(QNetworkConnection conn, QNetworkIdentity uv, GameObject playerGameObject) { if (uv.NetId.IsEmpty()) { Spawn(playerGameObject); } - conn.Send(4, new QSBOwnerMessage + conn.Send(4, new QOwnerMessage { NetId = uv.NetId, PlayerControllerId = uv.PlayerControllerId }); } - internal bool InternalReplacePlayerForConnection(QSBNetworkConnection conn, GameObject playerGameObject, short playerControllerId) + internal bool InternalReplacePlayerForConnection(QNetworkConnection conn, GameObject playerGameObject, short playerControllerId) { bool result; if (!GetNetworkIdentity(playerGameObject, out var networkIdentity)) { - Debug.LogError($"ReplacePlayer: playerGameObject has no NetworkIdentity. Please add a NetworkIdentity to {playerGameObject}"); + QLog.LogError($"ReplacePlayer: playerGameObject has no NetworkIdentity. Please add a NetworkIdentity to {playerGameObject}"); result = false; } else if (!CheckPlayerControllerIdForConnection(conn, playerControllerId)) @@ -811,23 +811,23 @@ namespace QuantumUNET } else { - Debug.Log("NetworkServer ReplacePlayer"); + QLog.Log("NetworkServer ReplacePlayer"); if (conn.GetPlayerController(playerControllerId, out var playerController)) { playerController.UnetView.SetNotLocalPlayer(); playerController.UnetView.ClearClientOwner(); } - var playerController2 = new QSBPlayerController(playerGameObject, playerControllerId); + var playerController2 = new QPlayerController(playerGameObject, playerControllerId); conn.SetPlayerController(playerController2); networkIdentity.SetConnectionToClient(conn, playerController2.PlayerControllerId); - Debug.Log("NetworkServer ReplacePlayer setup local"); + QLog.Log("NetworkServer ReplacePlayer setup local"); if (SetupLocalPlayerForConnection(conn, networkIdentity, playerController2)) { result = true; } else { - Debug.Log( + QLog.Log( $"Replacing playerGameObject object netId: {playerGameObject.GetComponent().netId} asset ID {playerGameObject.GetComponent().assetId}"); FinishPlayerForConnection(conn, networkIdentity, playerGameObject); if (networkIdentity.LocalPlayerAuthority) @@ -840,13 +840,13 @@ namespace QuantumUNET return result; } - private static bool GetNetworkIdentity(GameObject go, out QSBNetworkIdentity view) + private static bool GetNetworkIdentity(GameObject go, out QNetworkIdentity view) { - view = go.GetComponent(); + view = go.GetComponent(); bool result; if (view == null) { - Debug.LogError("UNET failure. GameObject doesn't have NetworkIdentity."); + QLog.LogError("UNET failure. GameObject doesn't have NetworkIdentity."); result = false; } else @@ -856,25 +856,25 @@ namespace QuantumUNET return result; } - public static void SetClientReady(QSBNetworkConnection conn) => instance.SetClientReadyInternal(conn); + public static void SetClientReady(QNetworkConnection conn) => instance.SetClientReadyInternal(conn); - internal void SetClientReadyInternal(QSBNetworkConnection conn) + internal void SetClientReadyInternal(QNetworkConnection conn) { - Debug.Log($"SetClientReadyInternal for conn:{conn.connectionId}"); + QLog.Log($"SetClientReadyInternal for conn:{conn.connectionId}"); if (conn.isReady) { - Debug.Log($"SetClientReady conn {conn.connectionId} already ready"); + QLog.Log($"SetClientReady conn {conn.connectionId} already ready"); } else { if (conn.PlayerControllers.Count == 0) { - Debug.LogWarning("Ready with no player object"); + QLog.LogWarning("Ready with no player object"); } conn.isReady = true; - if (conn is QSBULocalConnectionToClient) + if (conn is QULocalConnectionToClient) { - Debug.Log("NetworkServer Ready handling ULocalConnectionToClient"); + QLog.Log("NetworkServer Ready handling ULocalConnectionToClient"); foreach (var networkIdentity in objects.Values) { if (networkIdentity != null && networkIdentity.gameObject != null) @@ -886,7 +886,7 @@ namespace QuantumUNET } if (!networkIdentity.IsClient) { - Debug.Log("LocalClient.SetSpawnObject calling OnStartClient"); + QLog.Log("LocalClient.SetSpawnObject calling OnStartClient"); networkIdentity.OnStartClient(); } } @@ -894,8 +894,8 @@ namespace QuantumUNET } else { - Debug.Log($"Spawning {objects.Count} objects for conn {conn.connectionId}"); - var objectSpawnFinishedMessage = new QSBObjectSpawnFinishedMessage + QLog.Log($"Spawning {objects.Count} objects for conn {conn.connectionId}"); + var objectSpawnFinishedMessage = new QObjectSpawnFinishedMessage { State = 0U }; @@ -904,11 +904,11 @@ namespace QuantumUNET { if (networkIdentity2 == null) { - Debug.LogWarning("Invalid object found in server local object list (null NetworkIdentity)."); + QLog.LogWarning("Invalid object found in server local object list (null NetworkIdentity)."); } else if (networkIdentity2.gameObject.activeSelf) { - Debug.Log( + QLog.LogDebug( $"Sending spawn message for current server objects name='{networkIdentity2.gameObject.name}' netId={networkIdentity2.NetId}"); var flag2 = networkIdentity2.OnCheckObserver(conn); if (flag2) @@ -923,7 +923,7 @@ namespace QuantumUNET } } - internal static void ShowForConnection(QSBNetworkIdentity uv, QSBNetworkConnection conn) + internal static void ShowForConnection(QNetworkIdentity uv, QNetworkConnection conn) { if (conn.isReady) { @@ -931,9 +931,9 @@ namespace QuantumUNET } } - internal static void HideForConnection(QSBNetworkIdentity uv, QSBNetworkConnection conn) + internal static void HideForConnection(QNetworkIdentity uv, QNetworkConnection conn) { - conn.Send(13, new QSBObjectDestroyMessage + conn.Send(13, new QObjectDestroyMessage { NetId = uv.NetId }); @@ -950,27 +950,27 @@ namespace QuantumUNET } } - public static void SetClientNotReady(QSBNetworkConnection conn) => instance.InternalSetClientNotReady(conn); + public static void SetClientNotReady(QNetworkConnection conn) => instance.InternalSetClientNotReady(conn); - internal void InternalSetClientNotReady(QSBNetworkConnection conn) + internal void InternalSetClientNotReady(QNetworkConnection conn) { if (conn.isReady) { - Debug.Log($"PlayerNotReady {conn}"); + QLog.Log($"PlayerNotReady {conn}"); conn.isReady = false; conn.RemoveObservers(); - var msg = new QSBNotReadyMessage(); + var msg = new QNotReadyMessage(); conn.Send(36, msg); } } - private static void OnClientReadyMessage(QSBNetworkMessage netMsg) + private static void OnClientReadyMessage(QNetworkMessage netMsg) { - Debug.Log($"Default handler for ready message from {netMsg.Connection}"); + QLog.Log($"Default handler for ready message from {netMsg.Connection}"); SetClientReady(netMsg.Connection); } - private static void OnRemovePlayerMessage(QSBNetworkMessage netMsg) + private static void OnRemovePlayerMessage(QNetworkMessage netMsg) { netMsg.ReadMessage(s_RemovePlayerMessage); netMsg.Connection.GetPlayerController(s_RemovePlayerMessage.PlayerControllerId, out var playerController); @@ -981,26 +981,26 @@ namespace QuantumUNET } else { - Debug.LogError( + QLog.LogError( $"Received remove player message but could not find the player ID: {s_RemovePlayerMessage.PlayerControllerId}"); } } - private static void OnCommandMessage(QSBNetworkMessage netMsg) + private static void OnCommandMessage(QNetworkMessage netMsg) { var cmdHash = (int)netMsg.Reader.ReadPackedUInt32(); var networkInstanceId = netMsg.Reader.ReadNetworkId(); var gameObject = FindLocalObject(networkInstanceId); if (gameObject == null) { - Debug.LogWarning($"Instance not found when handling Command message [netId={networkInstanceId}]"); + QLog.LogWarning($"Instance not found when handling Command message [netId={networkInstanceId}]"); } else { - var component = gameObject.GetComponent(); + var component = gameObject.GetComponent(); if (component == null) { - Debug.LogWarning( + QLog.LogWarning( $"NetworkIdentity deleted when handling Command message [netId={networkInstanceId}]"); } else @@ -1008,7 +1008,7 @@ namespace QuantumUNET var flag = false; foreach (var playerController in netMsg.Connection.PlayerControllers) { - if (playerController.Gameobject != null && playerController.Gameobject.GetComponent().NetId == component.NetId) + if (playerController.Gameobject != null && playerController.Gameobject.GetComponent().NetId == component.NetId) { flag = true; break; @@ -1018,11 +1018,11 @@ namespace QuantumUNET { if (component.ClientAuthorityOwner != netMsg.Connection) { - Debug.LogWarning($"Command for object without authority [netId={networkInstanceId}]"); + QLog.LogWarning($"Command for object without authority [netId={networkInstanceId}]"); return; } } - Debug.Log($"OnCommandMessage for netId={networkInstanceId} conn={netMsg.Connection}"); + QLog.Log($"OnCommandMessage for netId={networkInstanceId} conn={netMsg.Connection}"); component.HandleCommand(cmdHash, netMsg.Reader); } } @@ -1032,12 +1032,12 @@ namespace QuantumUNET { if (!active) { - ModConsole.OwmlConsole.WriteLine( - $"Error - SpawnObject for {obj}, NetworkServer is not active. Cannot spawn objects without an active server."); + QLog.LogError( + $"SpawnObject for {obj}, NetworkServer is not active. Cannot spawn objects without an active server."); } else if (!GetNetworkIdentity(obj, out var networkIdentity)) { - Debug.LogError($"SpawnObject {obj} has no QSBNetworkIdentity. Please add a NetworkIdentity to {obj}"); + QLog.LogError($"SpawnObject {obj} has no QSBNetworkIdentity. Please add a NetworkIdentity to {obj}"); } else { @@ -1047,20 +1047,20 @@ namespace QuantumUNET } } - internal void SendSpawnMessage(QSBNetworkIdentity uv, QSBNetworkConnection conn) + internal void SendSpawnMessage(QNetworkIdentity uv, QNetworkConnection conn) { if (!uv.ServerOnly) { if (uv.SceneId.IsEmpty()) { - var objectSpawnMessage = new QSBObjectSpawnMessage + var objectSpawnMessage = new QObjectSpawnMessage { NetId = uv.NetId, assetId = uv.AssetId, Position = uv.transform.position, Rotation = uv.transform.rotation }; - var networkWriter = new QSBNetworkWriter(); + var networkWriter = new QNetworkWriter(); uv.UNetSerializeAllVars(networkWriter); if (networkWriter.Position > 0) { @@ -1077,13 +1077,13 @@ namespace QuantumUNET } else { - var objectSpawnSceneMessage = new QSBObjectSpawnSceneMessage + var objectSpawnSceneMessage = new QObjectSpawnSceneMessage { NetId = uv.NetId, SceneId = uv.SceneId, Position = uv.transform.position }; - var networkWriter2 = new QSBNetworkWriter(); + var networkWriter2 = new QNetworkWriter(); uv.UNetSerializeAllVars(networkWriter2); if (networkWriter2.Position > 0) { @@ -1101,11 +1101,11 @@ namespace QuantumUNET } } - public static void DestroyPlayersForConnection(QSBNetworkConnection conn) + public static void DestroyPlayersForConnection(QNetworkConnection conn) { if (conn.PlayerControllers.Count == 0) { - Debug.LogWarning("Empty player list given to NetworkServer.Destroy(), nothing to do."); + QLog.LogWarning("Empty player list given to NetworkServer.Destroy(), nothing to do."); } else { @@ -1136,7 +1136,7 @@ namespace QuantumUNET { if (obj == null) { - Debug.Log("NetworkServer UnspawnObject is null"); + QLog.Log("NetworkServer UnspawnObject is null"); } else if (GetNetworkIdentity(obj, out var uv)) { @@ -1144,13 +1144,13 @@ namespace QuantumUNET } } - private static void UnSpawnObject(QSBNetworkIdentity uv) => DestroyObject(uv, false); + private static void UnSpawnObject(QNetworkIdentity uv) => DestroyObject(uv, false); private static void DestroyObject(GameObject obj) { if (obj == null) { - Debug.Log("NetworkServer DestroyObject is null"); + QLog.Log("NetworkServer DestroyObject is null"); } else if (GetNetworkIdentity(obj, out var uv)) { @@ -1158,25 +1158,25 @@ namespace QuantumUNET } } - private static void DestroyObject(QSBNetworkIdentity uv, bool destroyServerObject) + private static void DestroyObject(QNetworkIdentity uv, bool destroyServerObject) { - Debug.Log($"DestroyObject instance:{uv.NetId}"); + QLog.Log($"DestroyObject instance:{uv.NetId}"); if (objects.ContainsKey(uv.NetId)) { objects.Remove(uv.NetId); } uv.ClientAuthorityOwner?.RemoveOwnedObject(uv); - var objectDestroyMessage = new QSBObjectDestroyMessage + var objectDestroyMessage = new QObjectDestroyMessage { NetId = uv.NetId }; SendToObservers(uv.gameObject, 1, objectDestroyMessage); uv.ClearObservers(); - if (QSBNetworkClient.active && instance.m_LocalClientActive) + if (QNetworkClient.active && instance.m_LocalClientActive) { uv.OnNetworkDestroy(); - QSBClientScene.SetLocalObject(objectDestroyMessage.NetId, null); + QClientScene.SetLocalObject(objectDestroyMessage.NetId, null); } if (destroyServerObject) { @@ -1202,7 +1202,7 @@ namespace QuantumUNET bool result; if (CheckForPrefab(obj)) { - Debug.LogErrorFormat("GameObject {0} is a prefab, it can't be spawned. This will cause errors in builds.", obj.name); + QLog.LogError($"GameObject {obj.name} is a prefab, it can't be spawned. This will cause errors in builds."); result = false; } else @@ -1214,16 +1214,16 @@ namespace QuantumUNET public static bool SpawnWithClientAuthority(GameObject obj, GameObject player) { - var component = player.GetComponent(); + var component = player.GetComponent(); bool result; if (component == null) { - Debug.LogError("SpawnWithClientAuthority player object has no NetworkIdentity"); + QLog.LogError("SpawnWithClientAuthority player object has no NetworkIdentity"); result = false; } else if (component.ConnectionToClient == null) { - Debug.LogError("SpawnWithClientAuthority player object is not a player."); + QLog.LogError("SpawnWithClientAuthority player object is not a player."); result = false; } else @@ -1233,27 +1233,27 @@ namespace QuantumUNET return result; } - public static bool SpawnWithClientAuthority(GameObject obj, QSBNetworkConnection conn) + public static bool SpawnWithClientAuthority(GameObject obj, QNetworkConnection conn) { bool result; if (!conn.isReady) { - Debug.LogError("SpawnWithClientAuthority NetworkConnection is not ready!"); + QLog.LogError("SpawnWithClientAuthority NetworkConnection is not ready!"); result = false; } else { Spawn(obj); - var component = obj.GetComponent(); + var component = obj.GetComponent(); result = !(component == null) && component.IsServer && component.AssignClientAuthority(conn); } return result; } - public static bool SpawnWithClientAuthority(GameObject obj, NetworkHash128 assetId, QSBNetworkConnection conn) + public static bool SpawnWithClientAuthority(GameObject obj, NetworkHash128 assetId, QNetworkConnection conn) { Spawn(obj, assetId); - var component = obj.GetComponent(); + var component = obj.GetComponent(); return !(component == null) && component.IsServer && component.AssignClientAuthority(conn); } @@ -1273,9 +1273,9 @@ namespace QuantumUNET public static void UnSpawn(GameObject obj) => UnSpawnObject(obj); - internal bool InvokeBytes(QSBULocalConnectionToServer conn, byte[] buffer, int numBytes, int channelId) + internal bool InvokeBytes(QULocalConnectionToServer conn, byte[] buffer, int numBytes, int channelId) { - var networkReader = new QSBNetworkReader(buffer); + var networkReader = new QNetworkReader(buffer); networkReader.ReadInt16(); var num = networkReader.ReadInt16(); bool result; @@ -1291,20 +1291,20 @@ namespace QuantumUNET return result; } - internal bool InvokeHandlerOnServer(QSBULocalConnectionToServer conn, short msgType, QSBMessageBase msg, int channelId) + internal bool InvokeHandlerOnServer(QULocalConnectionToServer conn, short msgType, QMessageBase msg, int channelId) { bool result; if (handlers.ContainsKey(msgType) && m_LocalConnection != null) { - var writer = new QSBNetworkWriter(); + var writer = new QNetworkWriter(); msg.Serialize(writer); - var reader = new QSBNetworkReader(writer); + var reader = new QNetworkReader(writer); m_LocalConnection.InvokeHandler(msgType, reader, channelId); result = true; } else { - Debug.LogError($"Local invoke: Failed to find local connection to invoke handler on [connectionId={conn.connectionId}] for MsgId:{msgType}"); + QLog.LogError($"Local invoke: Failed to find local connection to invoke handler on [connectionId={conn.connectionId}] for MsgId:{msgType}"); result = false; } return result; @@ -1312,7 +1312,7 @@ namespace QuantumUNET public static GameObject FindLocalObject(NetworkInstanceId netId) => instance.m_NetworkScene.FindLocalObject(netId); - private static bool ValidateSceneObject(QSBNetworkIdentity netId) => netId.gameObject.hideFlags != HideFlags.NotEditable && netId.gameObject.hideFlags != HideFlags.HideAndDontSave && !netId.SceneId.IsEmpty(); + private static bool ValidateSceneObject(QNetworkIdentity netId) => netId.gameObject.hideFlags != HideFlags.NotEditable && netId.gameObject.hideFlags != HideFlags.HideAndDontSave && !netId.SceneId.IsEmpty(); public static bool SpawnObjects() { @@ -1323,7 +1323,7 @@ namespace QuantumUNET } else { - var objectsOfTypeAll = Resources.FindObjectsOfTypeAll(); + var objectsOfTypeAll = Resources.FindObjectsOfTypeAll(); foreach (var networkIdentity in objectsOfTypeAll) { if (ValidateSceneObject(networkIdentity)) @@ -1347,20 +1347,20 @@ namespace QuantumUNET return result; } - private static void SendCrc(QSBNetworkConnection targetConnection) + private static void SendCrc(QNetworkConnection targetConnection) { - if (QSBNetworkCRC.singleton != null) + if (QNetworkCRC.singleton != null) { - if (QSBNetworkCRC.scriptCRCCheck) + if (QNetworkCRC.scriptCRCCheck) { - var crcmessage = new QSBCRCMessage(); - var list = new List(); - foreach (var text in QSBNetworkCRC.singleton.scripts.Keys) + var crcmessage = new QCRCMessage(); + var list = new List(); + foreach (var text in QNetworkCRC.singleton.scripts.Keys) { - list.Add(new QSBCRCMessageEntry + list.Add(new QCRCMessageEntry { name = text, - channel = (byte)QSBNetworkCRC.singleton.scripts[text] + channel = (byte)QNetworkCRC.singleton.scripts[text] }); } crcmessage.scripts = list.ToArray(); @@ -1369,17 +1369,17 @@ namespace QuantumUNET } } - private static volatile QSBNetworkServer s_Instance; + private static volatile QNetworkServer s_Instance; private static readonly object s_Sync = new UnityEngine.Object(); private bool m_LocalClientActive; - private readonly List m_LocalConnectionsFakeList = new List(); + private readonly List m_LocalConnectionsFakeList = new List(); - private QSBULocalConnectionToClient m_LocalConnection; + private QULocalConnectionToClient m_LocalConnection; - private readonly QSBNetworkScene m_NetworkScene; + private readonly QNetworkScene m_NetworkScene; private readonly HashSet m_ExternalConnections; @@ -1395,28 +1395,28 @@ namespace QuantumUNET internal static ushort maxPacketSize; - private static readonly QSBRemovePlayerMessage s_RemovePlayerMessage = new QSBRemovePlayerMessage(); + private static readonly QRemovePlayerMessage s_RemovePlayerMessage = new QRemovePlayerMessage(); - private class ServerSimpleWrapper : QSBNetworkServerSimple + private class ServerSimpleWrapper : QNetworkServerSimple { - public ServerSimpleWrapper(QSBNetworkServer server) + public ServerSimpleWrapper(QNetworkServer server) { m_Server = server; } public override void OnConnectError(int connectionId, byte error) => m_Server.GenerateConnectError(error); - public override void OnDataError(QSBNetworkConnection conn, byte error) => m_Server.GenerateDataError(conn, error); + public override void OnDataError(QNetworkConnection conn, byte error) => m_Server.GenerateDataError(conn, error); - public override void OnDisconnectError(QSBNetworkConnection conn, byte error) => m_Server.GenerateDisconnectError(conn, error); + public override void OnDisconnectError(QNetworkConnection conn, byte error) => m_Server.GenerateDisconnectError(conn, error); - public override void OnConnected(QSBNetworkConnection conn) => m_Server.OnConnected(conn); + public override void OnConnected(QNetworkConnection conn) => m_Server.OnConnected(conn); - public override void OnDisconnected(QSBNetworkConnection conn) => m_Server.OnDisconnected(conn); + public override void OnDisconnected(QNetworkConnection conn) => m_Server.OnDisconnected(conn); - public override void OnData(QSBNetworkConnection conn, int receivedSize, int channelId) => m_Server.OnData(conn, receivedSize, channelId); + public override void OnData(QNetworkConnection conn, int receivedSize, int channelId) => m_Server.OnData(conn, receivedSize, channelId); - private readonly QSBNetworkServer m_Server; + private readonly QNetworkServer m_Server; } } } \ No newline at end of file diff --git a/QuantumUNET/QSBNetworkServerSimple.cs b/QuantumUNET/QNetworkServerSimple.cs similarity index 83% rename from QuantumUNET/QSBNetworkServerSimple.cs rename to QuantumUNET/QNetworkServerSimple.cs index 43f7ab45..91bbd4b1 100644 --- a/QuantumUNET/QSBNetworkServerSimple.cs +++ b/QuantumUNET/QNetworkServerSimple.cs @@ -10,11 +10,11 @@ using UnityEngine.Networking.Types; namespace QuantumUNET { - public class QSBNetworkServerSimple + public class QNetworkServerSimple { - public QSBNetworkServerSimple() + public QNetworkServerSimple() { - connections = new ReadOnlyCollection(m_Connections); + connections = new ReadOnlyCollection(m_Connections); } public int listenPort { get; set; } @@ -25,17 +25,17 @@ namespace QuantumUNET public bool useWebSockets { get; set; } - public ReadOnlyCollection connections { get; } + public ReadOnlyCollection connections { get; } - public Dictionary handlers => m_MessageHandlers.GetHandlers(); + public Dictionary 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() where T : QSBNetworkConnection => networkConnectionClass = typeof(T); + public void SetNetworkConnectionClass() 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 m_Connections = new List(); - private readonly QSBNetworkMessageHandlers m_MessageHandlers = new QSBNetworkMessageHandlers(); + private readonly List m_Connections = new List(); + private readonly QNetworkMessageHandlers m_MessageHandlers = new QNetworkMessageHandlers(); } } \ No newline at end of file diff --git a/QuantumUNET/QSBPlayerController.cs b/QuantumUNET/QPlayerController.cs similarity index 74% rename from QuantumUNET/QSBPlayerController.cs rename to QuantumUNET/QPlayerController.cs index 02db9d4e..ce7a2c42 100644 --- a/QuantumUNET/QSBPlayerController.cs +++ b/QuantumUNET/QPlayerController.cs @@ -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(); + UnetView = go.GetComponent(); PlayerControllerId = playerControllerId; } diff --git a/QuantumUNET/QSBNetworkMessageHandlers.cs b/QuantumUNET/QSBNetworkMessageHandlers.cs deleted file mode 100644 index 6c7e2041..00000000 --- a/QuantumUNET/QSBNetworkMessageHandlers.cs +++ /dev/null @@ -1,59 +0,0 @@ -using QuantumUNET.Messages; -using System.Collections.Generic; -using UnityEngine; - -namespace QuantumUNET -{ - internal class QSBNetworkMessageHandlers - { - private readonly Dictionary _msgHandlers = new Dictionary(); - - 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 GetHandlers() => _msgHandlers; - - internal void ClearMessageHandlers() => _msgHandlers.Clear(); - } -} \ No newline at end of file diff --git a/QuantumUNET/QSBULocalConnectionToClient.cs b/QuantumUNET/QULocalConnectionToClient.cs similarity index 67% rename from QuantumUNET/QSBULocalConnectionToClient.cs rename to QuantumUNET/QULocalConnectionToClient.cs index 3c83fbe9..331851c0 100644 --- a/QuantumUNET/QSBULocalConnectionToClient.cs +++ b/QuantumUNET/QULocalConnectionToClient.cs @@ -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; diff --git a/QuantumUNET/QSBULocalConnectionToServer.cs b/QuantumUNET/QULocalConnectionToServer.cs similarity index 69% rename from QuantumUNET/QSBULocalConnectionToServer.cs rename to QuantumUNET/QULocalConnectionToServer.cs index 16d849cb..80e7830e 100644 --- a/QuantumUNET/QSBULocalConnectionToServer.cs +++ b/QuantumUNET/QULocalConnectionToServer.cs @@ -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; } } \ No newline at end of file diff --git a/QuantumUNET/QuantumUNET.csproj b/QuantumUNET/QuantumUNET.csproj index c8ea896a..0f9ab2c1 100644 --- a/QuantumUNET/QuantumUNET.csproj +++ b/QuantumUNET/QuantumUNET.csproj @@ -34,39 +34,9 @@ ..\packages\Lib.Harmony.1.2.0.1\lib\net35\0Harmony.dll - - ..\packages\OWML.1.1.4\lib\net35\NAudio-Unity.dll - ..\packages\Json.Net.Unity3D.9.0.1\lib\net35\Newtonsoft.Json.dll - - ..\packages\OWML.1.1.4\lib\net35\OWML.Common.dll - - - ..\packages\OWML.1.1.4\lib\net35\OWML.Logging.dll - - - ..\packages\OWML.1.1.4\lib\net35\OWML.ModHelper.dll - - - ..\packages\OWML.1.1.4\lib\net35\OWML.ModHelper.Assets.dll - - - ..\packages\OWML.1.1.4\lib\net35\OWML.ModHelper.Events.dll - - - ..\packages\OWML.1.1.4\lib\net35\OWML.ModHelper.Input.dll - - - ..\packages\OWML.1.1.4\lib\net35\OWML.ModHelper.Interaction.dll - - - ..\packages\OWML.1.1.4\lib\net35\OWML.ModHelper.Menus.dll - - - ..\packages\OWML.1.1.4\lib\net35\OWML.Utils.dll - @@ -94,53 +64,56 @@ - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/QuantumUNET/Transport/QSBChannelBuffer.cs b/QuantumUNET/Transport/QChannelBuffer.cs similarity index 87% rename from QuantumUNET/Transport/QSBChannelBuffer.cs rename to QuantumUNET/Transport/QChannelBuffer.cs index 0c128938..7effb89a 100644 --- a/QuantumUNET/Transport/QSBChannelBuffer.cs +++ b/QuantumUNET/Transport/QChannelBuffer.cs @@ -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 _pendingPackets; - private static List _freePackets; + private readonly Queue _pendingPackets; + private static List _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(); + _pendingPackets = new Queue(); if (_freePackets == null) { - _freePackets = new List(); + _freePackets = new List(); } } } @@ -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) { diff --git a/QuantumUNET/Transport/QSBChannelPacket.cs b/QuantumUNET/Transport/QChannelPacket.cs similarity index 87% rename from QuantumUNET/Transport/QSBChannelPacket.cs rename to QuantumUNET/Transport/QChannelPacket.cs index 99518ce6..26d2d235 100644 --- a/QuantumUNET/Transport/QSBChannelPacket.cs +++ b/QuantumUNET/Transport/QChannelPacket.cs @@ -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)) diff --git a/QuantumUNET/Transport/QSBNetBuffer.cs b/QuantumUNET/Transport/QNetBuffer.cs similarity index 97% rename from QuantumUNET/Transport/QSBNetBuffer.cs rename to QuantumUNET/Transport/QNetBuffer.cs index 3f66644c..8ebc9d8d 100644 --- a/QuantumUNET/Transport/QSBNetBuffer.cs +++ b/QuantumUNET/Transport/QNetBuffer.cs @@ -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; } diff --git a/QuantumUNET/Transport/QSBNetworkReader.cs b/QuantumUNET/Transport/QNetworkReader.cs similarity index 91% rename from QuantumUNET/Transport/QSBNetworkReader.cs rename to QuantumUNET/Transport/QNetworkReader.cs index 76a08700..d68720e1 100644 --- a/QuantumUNET/Transport/QSBNetworkReader.cs +++ b/QuantumUNET/Transport/QNetworkReader.cs @@ -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(); + result = gameObject.GetComponent(); } } return result; @@ -448,7 +448,7 @@ namespace QuantumUNET.Transport public override string ToString() => m_buf.ToString(); - public TMsg ReadMessage() where TMsg : QSBMessageBase, new() + public TMsg ReadMessage() where TMsg : QMessageBase, new() { var result = Activator.CreateInstance(); result.Deserialize(this); diff --git a/QuantumUNET/Transport/QSBNetworkWriter.cs b/QuantumUNET/Transport/QNetworkWriter.cs similarity index 95% rename from QuantumUNET/Transport/QSBNetworkWriter.cs rename to QuantumUNET/Transport/QNetworkWriter.cs index 3ce66ab0..65475f3a 100644 --- a/QuantumUNET/Transport/QSBNetworkWriter.cs +++ b/QuantumUNET/Transport/QNetworkWriter.cs @@ -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(); + var component = value.gameObject.GetComponent(); if (component != null) { Write(component.NetId); @@ -420,7 +420,7 @@ namespace QuantumUNET.Transport } else { - var component = value.GetComponent(); + var component = value.GetComponent(); 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; diff --git a/QuantumUNET/packages.config b/QuantumUNET/packages.config index 429b9e83..3a754bf3 100644 --- a/QuantumUNET/packages.config +++ b/QuantumUNET/packages.config @@ -2,5 +2,4 @@ - \ No newline at end of file