From 6d2ce234f57af96c68de0590754660e3c2f46061 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 4 Nov 2020 09:34:01 +0000 Subject: [PATCH] cleanup --- QSB/ConversationSync/ConversationManager.cs | 2 -- QSB/EventsCore/EventType.cs | 2 +- QSB/EventsCore/QSBEvent.cs | 4 ++-- QSB/EventsCore/QSBEventManager.cs | 5 +++-- .../{QSBMessageHandler.cs => MessageHandler.cs} | 6 ++---- QSB/Patches/QSBPatchManager.cs | 2 +- QSB/Player/Events/PlayerReadyEvent.cs | 5 +++++ QSB/Player/Events/PlayerStatesRequestEvent.cs | 2 +- QSB/Player/Events/ServerSendPlayerStatesEvent.cs | 6 +++++- QSB/QSB.cs | 1 - QSB/QSB.csproj | 2 +- QSB/QSBNetworkManager.cs | 7 ++----- QSB/QSBSceneManager.cs | 5 ++++- QSB/SectorSync/QSBSectorManager.cs | 6 +++++- QSB/Utility/DebugLog.cs | 7 ------- 15 files changed, 32 insertions(+), 30 deletions(-) rename QSB/MessagesCore/{QSBMessageHandler.cs => MessageHandler.cs} (88%) diff --git a/QSB/ConversationSync/ConversationManager.cs b/QSB/ConversationSync/ConversationManager.cs index d90b8f35..ebfc74d3 100644 --- a/QSB/ConversationSync/ConversationManager.cs +++ b/QSB/ConversationSync/ConversationManager.cs @@ -23,7 +23,6 @@ namespace QSB.ConversationSync Instance = this; ConversationAssetBundle = QSB.Helper.Assets.LoadBundle("assets/conversation"); - DebugLog.LogState("ConversationBundle", ConversationAssetBundle); BoxPrefab = ConversationAssetBundle.LoadAsset("assets/dialoguebubble.prefab"); var font = (Font)Resources.Load(@"fonts\english - latin\spacemono-bold"); @@ -33,7 +32,6 @@ namespace QSB.ConversationSync } BoxPrefab.GetComponent().font = font; BoxPrefab.GetComponent().color = Color.white; - DebugLog.LogState("BoxPrefab", BoxPrefab); } public uint GetPlayerTalkingToTree(CharacterDialogueTree tree) diff --git a/QSB/EventsCore/EventType.cs b/QSB/EventsCore/EventType.cs index 2e2744f3..660f1e48 100644 --- a/QSB/EventsCore/EventType.cs +++ b/QSB/EventsCore/EventType.cs @@ -6,7 +6,7 @@ ServerTime, AnimTrigger, PlayerState, - FullStateRequest, + PlayerStatesRequest, FlashlightActiveChange, SignalscopeActiveChange, TranslatorActiveChange, diff --git a/QSB/EventsCore/QSBEvent.cs b/QSB/EventsCore/QSBEvent.cs index 9abaf4f4..0d4062cb 100644 --- a/QSB/EventsCore/QSBEvent.cs +++ b/QSB/EventsCore/QSBEvent.cs @@ -13,11 +13,11 @@ namespace QSB.EventsCore { public abstract EventType Type { get; } public uint LocalPlayerId => QSBPlayerManager.LocalPlayerId; - private readonly QSBMessageHandler _eventHandler; + private readonly MessageHandler _eventHandler; protected QSBEvent() { - _eventHandler = new QSBMessageHandler(Type); + _eventHandler = new MessageHandler(Type); _eventHandler.OnClientReceiveMessage += OnClientReceive; _eventHandler.OnServerReceiveMessage += OnServerReceive; } diff --git a/QSB/EventsCore/QSBEventManager.cs b/QSB/EventsCore/QSBEventManager.cs index 2963a8f3..61f3ea64 100644 --- a/QSB/EventsCore/QSBEventManager.cs +++ b/QSB/EventsCore/QSBEventManager.cs @@ -45,14 +45,15 @@ namespace QSB.EventsCore new OrbUserEvent(), new ConversationEvent(), new ConversationStartEndEvent(), - new PlayInstrumentEvent() + new PlayInstrumentEvent(), + new ServerSendPlayerStatesEvent() }; _eventList.ForEach(ev => ev.SetupListener()); Ready = true; - DebugLog.DebugWrite($"Event manager ready.", MessageType.Success); + DebugLog.DebugWrite("Event Manager ready.", MessageType.Success); } public static void Reset() diff --git a/QSB/MessagesCore/QSBMessageHandler.cs b/QSB/MessagesCore/MessageHandler.cs similarity index 88% rename from QSB/MessagesCore/QSBMessageHandler.cs rename to QSB/MessagesCore/MessageHandler.cs index 3a65ad77..125b1087 100644 --- a/QSB/MessagesCore/QSBMessageHandler.cs +++ b/QSB/MessagesCore/MessageHandler.cs @@ -8,14 +8,14 @@ using UnityEngine.Networking; namespace QSB.Messaging { // Extend this to create new message handlers. - public class QSBMessageHandler where T : MessageBase, new() + public class MessageHandler where T : MessageBase, new() { public event Action OnClientReceiveMessage; public event Action OnServerReceiveMessage; private readonly EventType _eventType; - public QSBMessageHandler(EventType eventType) + public MessageHandler(EventType eventType) { _eventType = eventType + MsgType.Highest + 1; if (QSBNetworkManager.Instance.IsReady) @@ -33,13 +33,11 @@ namespace QSB.Messaging var eventName = Enum.GetName(typeof(EventType), _eventType - 1 - MsgType.Highest).ToUpper(); if (NetworkServer.handlers.Keys.Contains((short)_eventType)) { - DebugLog.LogState($"({_eventType}) {eventName} HANDLER", false); DebugLog.ToConsole($"Warning - NetworkServer already contains a handler for EventType {_eventType}", MessageType.Warning); NetworkServer.handlers.Remove((short)_eventType); } NetworkServer.RegisterHandler((short)_eventType, OnServerReceiveMessageHandler); NetworkManager.singleton.client.RegisterHandler((short)_eventType, OnClientReceiveMessageHandler); - DebugLog.LogState($"({_eventType}) {eventName} HANDLER", true); } public void SendToAll(T message) diff --git a/QSB/Patches/QSBPatchManager.cs b/QSB/Patches/QSBPatchManager.cs index 2122ce37..a14601a1 100644 --- a/QSB/Patches/QSBPatchManager.cs +++ b/QSB/Patches/QSBPatchManager.cs @@ -28,7 +28,7 @@ namespace QSB.Patches new ProbePatches() }; - DebugLog.DebugWrite($"Patch manager ready.", MessageType.Success); + DebugLog.DebugWrite("Patch Manager ready.", MessageType.Success); } public static void DoPatchType(QSBPatchTypes type) diff --git a/QSB/Player/Events/PlayerReadyEvent.cs b/QSB/Player/Events/PlayerReadyEvent.cs index 9ac90dc9..796955ae 100644 --- a/QSB/Player/Events/PlayerReadyEvent.cs +++ b/QSB/Player/Events/PlayerReadyEvent.cs @@ -37,6 +37,11 @@ namespace QSB.Player.Events public override void OnReceiveRemote(ToggleMessage message) { DebugLog.DebugWrite($"Get ready event from {message.FromId}", MessageType.Success); + if (!QSBPlayerManager.PlayerExists(message.FromId)) + { + DebugLog.ToConsole("Error - Got ready event for non-existent player! Did we not send a PlayerStatesRequestEvent? Or was it not handled?", MessageType.Error); + return; + } foreach (var item in QSBPlayerManager.GetSyncObjects() .Where(x => x != null && x.IsReady && x.ReferenceSector != null && x.PlayerId == LocalPlayerId)) { diff --git a/QSB/Player/Events/PlayerStatesRequestEvent.cs b/QSB/Player/Events/PlayerStatesRequestEvent.cs index a04a9508..3afb3fa3 100644 --- a/QSB/Player/Events/PlayerStatesRequestEvent.cs +++ b/QSB/Player/Events/PlayerStatesRequestEvent.cs @@ -8,7 +8,7 @@ namespace QSB.Player.Events { public class PlayerStatesRequestEvent : QSBEvent { - public override EventType Type => EventType.FullStateRequest; + public override EventType Type => EventType.PlayerStatesRequest; public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBPlayerStatesRequest, Handler); diff --git a/QSB/Player/Events/ServerSendPlayerStatesEvent.cs b/QSB/Player/Events/ServerSendPlayerStatesEvent.cs index 224e271e..ac9230bd 100644 --- a/QSB/Player/Events/ServerSendPlayerStatesEvent.cs +++ b/QSB/Player/Events/ServerSendPlayerStatesEvent.cs @@ -1,4 +1,6 @@ -using QSB.EventsCore; +using OWML.Common; +using QSB.EventsCore; +using QSB.Utility; namespace QSB.Player.Events { @@ -14,6 +16,7 @@ namespace QSB.Player.Events { foreach (var player in QSBPlayerManager.PlayerList) { + DebugLog.DebugWrite($" - Sending playerstate of player ID {player.PlayerId}", MessageType.Info); SendEvent(CreateMessage(player)); } } @@ -28,6 +31,7 @@ namespace QSB.Player.Events public override void OnReceiveRemote(PlayerStateMessage message) { + DebugLog.DebugWrite($"Received playerstate of player ID {message.AboutId}", MessageType.Info); QSB.Helper.Events.Unity.RunWhen( () => QSBPlayerManager.GetSyncObject(message.AboutId) != null, () => QSBPlayerManager.HandleFullStateMessage(message)); diff --git a/QSB/QSB.cs b/QSB/QSB.cs index 7e13cd66..9a80dbe0 100644 --- a/QSB/QSB.cs +++ b/QSB/QSB.cs @@ -33,7 +33,6 @@ namespace QSB DebugLog.ToConsole($"* Start of QSB version {Helper.Manifest.Version} - authored by {Helper.Manifest.Author}", MessageType.Info); NetworkAssetBundle = Helper.Assets.LoadBundle("assets/network"); - DebugLog.LogState("NetworkBundle", NetworkAssetBundle); QSBPatchManager.Init(); diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index 5c4d148e..34a4ecc4 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -205,7 +205,7 @@ - + diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index 4e67ffd9..a75386ff 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -49,27 +49,22 @@ namespace QSB playerPrefab.AddComponent(); playerPrefab.AddComponent(); playerPrefab.AddComponent(); - DebugLog.LogState("PlayerPrefab", playerPrefab); _shipPrefab = _assetBundle.LoadAsset("assets/networkship.prefab"); _shipPrefab.AddComponent(); spawnPrefabs.Add(_shipPrefab); - DebugLog.LogState("ShipPrefab", _shipPrefab); _cameraPrefab = _assetBundle.LoadAsset("assets/networkcameraroot.prefab"); _cameraPrefab.AddComponent(); spawnPrefabs.Add(_cameraPrefab); - DebugLog.LogState("CameraPrefab", _cameraPrefab); _probePrefab = _assetBundle.LoadAsset("assets/networkprobe.prefab"); _probePrefab.AddComponent(); spawnPrefabs.Add(_probePrefab); - DebugLog.LogState("ProbePrefab", _probePrefab); OrbPrefab = _assetBundle.LoadAsset("assets/networkorb.prefab"); OrbPrefab.AddComponent(); spawnPrefabs.Add(OrbPrefab); - DebugLog.LogState("OrbPrefab", OrbPrefab); ConfigureNetworkManager(); QSBSceneManager.OnSceneLoaded += OnSceneLoaded; @@ -102,6 +97,8 @@ namespace QSB this.SetValue("m_MaxBufferedPackets", MaxBufferedPackets); channels.Add(QosType.Reliable); channels.Add(QosType.Unreliable); + + DebugLog.DebugWrite("Network Manager ready.", MessageType.Success); } public override void OnStartServer() diff --git a/QSB/QSBSceneManager.cs b/QSB/QSBSceneManager.cs index d2d32bfa..e2130ab3 100644 --- a/QSB/QSBSceneManager.cs +++ b/QSB/QSBSceneManager.cs @@ -1,4 +1,6 @@ -using System; +using OWML.Common; +using QSB.Utility; +using System; namespace QSB { @@ -13,6 +15,7 @@ namespace QSB static QSBSceneManager() { LoadManager.OnCompleteSceneLoad += OnCompleteSceneLoad; + DebugLog.DebugWrite("Scene Manager ready.", MessageType.Success); } private static void OnCompleteSceneLoad(OWScene oldScene, OWScene newScene) diff --git a/QSB/SectorSync/QSBSectorManager.cs b/QSB/SectorSync/QSBSectorManager.cs index 00f1f50c..68565ee7 100644 --- a/QSB/SectorSync/QSBSectorManager.cs +++ b/QSB/SectorSync/QSBSectorManager.cs @@ -1,4 +1,6 @@ -using QSB.WorldSync; +using OWML.Common; +using QSB.Utility; +using QSB.WorldSync; using System.Linq; using UnityEngine; @@ -19,10 +21,12 @@ namespace QSB.SectorSync { Instance = this; QSBSceneManager.OnSceneLoaded += (OWScene scene, bool universe) => RebuildSectors(); + DebugLog.DebugWrite("Sector Manager ready.", MessageType.Success); } public void RebuildSectors() { + DebugLog.DebugWrite("Rebuilding sectors...", MessageType.Warning); WorldRegistry.RemoveObjects(); var sectors = Resources.FindObjectsOfTypeAll().ToList(); for (var id = 0; id < sectors.Count; id++) diff --git a/QSB/Utility/DebugLog.cs b/QSB/Utility/DebugLog.cs index 244eae38..e8616400 100644 --- a/QSB/Utility/DebugLog.cs +++ b/QSB/Utility/DebugLog.cs @@ -43,13 +43,6 @@ namespace QSB.Utility } } - public static void LogState(string name, bool state) - { - var status = state ? "OK" : "FAIL"; - var messageType = state ? MessageType.Success : MessageType.Error; - DebugWrite($"* {name} {status}", messageType); - } - private static string GetCallingType(StackTrace frame) { var stackFrame = frame.GetFrames().First(x => x.GetMethod().DeclaringType.Name != "DebugLog");