This commit is contained in:
Mister_Nebula 2020-11-04 09:34:01 +00:00
parent adb334bfe8
commit 6d2ce234f5
15 changed files with 32 additions and 30 deletions

View File

@ -23,7 +23,6 @@ namespace QSB.ConversationSync
Instance = this; Instance = this;
ConversationAssetBundle = QSB.Helper.Assets.LoadBundle("assets/conversation"); ConversationAssetBundle = QSB.Helper.Assets.LoadBundle("assets/conversation");
DebugLog.LogState("ConversationBundle", ConversationAssetBundle);
BoxPrefab = ConversationAssetBundle.LoadAsset<GameObject>("assets/dialoguebubble.prefab"); BoxPrefab = ConversationAssetBundle.LoadAsset<GameObject>("assets/dialoguebubble.prefab");
var font = (Font)Resources.Load(@"fonts\english - latin\spacemono-bold"); var font = (Font)Resources.Load(@"fonts\english - latin\spacemono-bold");
@ -33,7 +32,6 @@ namespace QSB.ConversationSync
} }
BoxPrefab.GetComponent<Text>().font = font; BoxPrefab.GetComponent<Text>().font = font;
BoxPrefab.GetComponent<Text>().color = Color.white; BoxPrefab.GetComponent<Text>().color = Color.white;
DebugLog.LogState("BoxPrefab", BoxPrefab);
} }
public uint GetPlayerTalkingToTree(CharacterDialogueTree tree) public uint GetPlayerTalkingToTree(CharacterDialogueTree tree)

View File

@ -6,7 +6,7 @@
ServerTime, ServerTime,
AnimTrigger, AnimTrigger,
PlayerState, PlayerState,
FullStateRequest, PlayerStatesRequest,
FlashlightActiveChange, FlashlightActiveChange,
SignalscopeActiveChange, SignalscopeActiveChange,
TranslatorActiveChange, TranslatorActiveChange,

View File

@ -13,11 +13,11 @@ namespace QSB.EventsCore
{ {
public abstract EventType Type { get; } public abstract EventType Type { get; }
public uint LocalPlayerId => QSBPlayerManager.LocalPlayerId; public uint LocalPlayerId => QSBPlayerManager.LocalPlayerId;
private readonly QSBMessageHandler<T> _eventHandler; private readonly MessageHandler<T> _eventHandler;
protected QSBEvent() protected QSBEvent()
{ {
_eventHandler = new QSBMessageHandler<T>(Type); _eventHandler = new MessageHandler<T>(Type);
_eventHandler.OnClientReceiveMessage += OnClientReceive; _eventHandler.OnClientReceiveMessage += OnClientReceive;
_eventHandler.OnServerReceiveMessage += OnServerReceive; _eventHandler.OnServerReceiveMessage += OnServerReceive;
} }

View File

@ -45,14 +45,15 @@ namespace QSB.EventsCore
new OrbUserEvent(), new OrbUserEvent(),
new ConversationEvent(), new ConversationEvent(),
new ConversationStartEndEvent(), new ConversationStartEndEvent(),
new PlayInstrumentEvent() new PlayInstrumentEvent(),
new ServerSendPlayerStatesEvent()
}; };
_eventList.ForEach(ev => ev.SetupListener()); _eventList.ForEach(ev => ev.SetupListener());
Ready = true; Ready = true;
DebugLog.DebugWrite($"Event manager ready.", MessageType.Success); DebugLog.DebugWrite("Event Manager ready.", MessageType.Success);
} }
public static void Reset() public static void Reset()

View File

@ -8,14 +8,14 @@ using UnityEngine.Networking;
namespace QSB.Messaging namespace QSB.Messaging
{ {
// Extend this to create new message handlers. // Extend this to create new message handlers.
public class QSBMessageHandler<T> where T : MessageBase, new() public class MessageHandler<T> where T : MessageBase, new()
{ {
public event Action<T> OnClientReceiveMessage; public event Action<T> OnClientReceiveMessage;
public event Action<T> OnServerReceiveMessage; public event Action<T> OnServerReceiveMessage;
private readonly EventType _eventType; private readonly EventType _eventType;
public QSBMessageHandler(EventType eventType) public MessageHandler(EventType eventType)
{ {
_eventType = eventType + MsgType.Highest + 1; _eventType = eventType + MsgType.Highest + 1;
if (QSBNetworkManager.Instance.IsReady) if (QSBNetworkManager.Instance.IsReady)
@ -33,13 +33,11 @@ namespace QSB.Messaging
var eventName = Enum.GetName(typeof(EventType), _eventType - 1 - MsgType.Highest).ToUpper(); var eventName = Enum.GetName(typeof(EventType), _eventType - 1 - MsgType.Highest).ToUpper();
if (NetworkServer.handlers.Keys.Contains((short)_eventType)) 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); DebugLog.ToConsole($"Warning - NetworkServer already contains a handler for EventType {_eventType}", MessageType.Warning);
NetworkServer.handlers.Remove((short)_eventType); NetworkServer.handlers.Remove((short)_eventType);
} }
NetworkServer.RegisterHandler((short)_eventType, OnServerReceiveMessageHandler); NetworkServer.RegisterHandler((short)_eventType, OnServerReceiveMessageHandler);
NetworkManager.singleton.client.RegisterHandler((short)_eventType, OnClientReceiveMessageHandler); NetworkManager.singleton.client.RegisterHandler((short)_eventType, OnClientReceiveMessageHandler);
DebugLog.LogState($"({_eventType}) {eventName} HANDLER", true);
} }
public void SendToAll(T message) public void SendToAll(T message)

View File

@ -28,7 +28,7 @@ namespace QSB.Patches
new ProbePatches() new ProbePatches()
}; };
DebugLog.DebugWrite($"Patch manager ready.", MessageType.Success); DebugLog.DebugWrite("Patch Manager ready.", MessageType.Success);
} }
public static void DoPatchType(QSBPatchTypes type) public static void DoPatchType(QSBPatchTypes type)

View File

@ -37,6 +37,11 @@ namespace QSB.Player.Events
public override void OnReceiveRemote(ToggleMessage message) public override void OnReceiveRemote(ToggleMessage message)
{ {
DebugLog.DebugWrite($"Get ready event from {message.FromId}", MessageType.Success); 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<TransformSync.TransformSync>() foreach (var item in QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>()
.Where(x => x != null && x.IsReady && x.ReferenceSector != null && x.PlayerId == LocalPlayerId)) .Where(x => x != null && x.IsReady && x.ReferenceSector != null && x.PlayerId == LocalPlayerId))
{ {

View File

@ -8,7 +8,7 @@ namespace QSB.Player.Events
{ {
public class PlayerStatesRequestEvent : QSBEvent<PlayerMessage> public class PlayerStatesRequestEvent : QSBEvent<PlayerMessage>
{ {
public override EventType Type => EventType.FullStateRequest; public override EventType Type => EventType.PlayerStatesRequest;
public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBPlayerStatesRequest, Handler); public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBPlayerStatesRequest, Handler);

View File

@ -1,4 +1,6 @@
using QSB.EventsCore; using OWML.Common;
using QSB.EventsCore;
using QSB.Utility;
namespace QSB.Player.Events namespace QSB.Player.Events
{ {
@ -14,6 +16,7 @@ namespace QSB.Player.Events
{ {
foreach (var player in QSBPlayerManager.PlayerList) foreach (var player in QSBPlayerManager.PlayerList)
{ {
DebugLog.DebugWrite($" - Sending playerstate of player ID {player.PlayerId}", MessageType.Info);
SendEvent(CreateMessage(player)); SendEvent(CreateMessage(player));
} }
} }
@ -28,6 +31,7 @@ namespace QSB.Player.Events
public override void OnReceiveRemote(PlayerStateMessage message) public override void OnReceiveRemote(PlayerStateMessage message)
{ {
DebugLog.DebugWrite($"Received playerstate of player ID {message.AboutId}", MessageType.Info);
QSB.Helper.Events.Unity.RunWhen( QSB.Helper.Events.Unity.RunWhen(
() => QSBPlayerManager.GetSyncObject<TransformSync.TransformSync>(message.AboutId) != null, () => QSBPlayerManager.GetSyncObject<TransformSync.TransformSync>(message.AboutId) != null,
() => QSBPlayerManager.HandleFullStateMessage(message)); () => QSBPlayerManager.HandleFullStateMessage(message));

View File

@ -33,7 +33,6 @@ namespace QSB
DebugLog.ToConsole($"* Start of QSB version {Helper.Manifest.Version} - authored by {Helper.Manifest.Author}", MessageType.Info); DebugLog.ToConsole($"* Start of QSB version {Helper.Manifest.Version} - authored by {Helper.Manifest.Author}", MessageType.Info);
NetworkAssetBundle = Helper.Assets.LoadBundle("assets/network"); NetworkAssetBundle = Helper.Assets.LoadBundle("assets/network");
DebugLog.LogState("NetworkBundle", NetworkAssetBundle);
QSBPatchManager.Init(); QSBPatchManager.Init();

View File

@ -205,7 +205,7 @@
<Compile Include="DeathSync\Necronomicon.cs" /> <Compile Include="DeathSync\Necronomicon.cs" />
<Compile Include="Utility\DebugLog.cs" /> <Compile Include="Utility\DebugLog.cs" />
<Compile Include="MessagesCore\PlayerMessage.cs" /> <Compile Include="MessagesCore\PlayerMessage.cs" />
<Compile Include="MessagesCore\QSBMessageHandler.cs" /> <Compile Include="MessagesCore\MessageHandler.cs" />
<Compile Include="EventsCore\EventType.cs" /> <Compile Include="EventsCore\EventType.cs" />
<Compile Include="Player\PlayerInfo.cs" /> <Compile Include="Player\PlayerInfo.cs" />
<Compile Include="Player\State.cs" /> <Compile Include="Player\State.cs" />

View File

@ -49,27 +49,22 @@ namespace QSB
playerPrefab.AddComponent<PlayerTransformSync>(); playerPrefab.AddComponent<PlayerTransformSync>();
playerPrefab.AddComponent<AnimationSync>(); playerPrefab.AddComponent<AnimationSync>();
playerPrefab.AddComponent<WakeUpSync>(); playerPrefab.AddComponent<WakeUpSync>();
DebugLog.LogState("PlayerPrefab", playerPrefab);
_shipPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkship.prefab"); _shipPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkship.prefab");
_shipPrefab.AddComponent<ShipTransformSync>(); _shipPrefab.AddComponent<ShipTransformSync>();
spawnPrefabs.Add(_shipPrefab); spawnPrefabs.Add(_shipPrefab);
DebugLog.LogState("ShipPrefab", _shipPrefab);
_cameraPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkcameraroot.prefab"); _cameraPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkcameraroot.prefab");
_cameraPrefab.AddComponent<PlayerCameraSync>(); _cameraPrefab.AddComponent<PlayerCameraSync>();
spawnPrefabs.Add(_cameraPrefab); spawnPrefabs.Add(_cameraPrefab);
DebugLog.LogState("CameraPrefab", _cameraPrefab);
_probePrefab = _assetBundle.LoadAsset<GameObject>("assets/networkprobe.prefab"); _probePrefab = _assetBundle.LoadAsset<GameObject>("assets/networkprobe.prefab");
_probePrefab.AddComponent<PlayerProbeSync>(); _probePrefab.AddComponent<PlayerProbeSync>();
spawnPrefabs.Add(_probePrefab); spawnPrefabs.Add(_probePrefab);
DebugLog.LogState("ProbePrefab", _probePrefab);
OrbPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkorb.prefab"); OrbPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkorb.prefab");
OrbPrefab.AddComponent<NomaiOrbTransformSync>(); OrbPrefab.AddComponent<NomaiOrbTransformSync>();
spawnPrefabs.Add(OrbPrefab); spawnPrefabs.Add(OrbPrefab);
DebugLog.LogState("OrbPrefab", OrbPrefab);
ConfigureNetworkManager(); ConfigureNetworkManager();
QSBSceneManager.OnSceneLoaded += OnSceneLoaded; QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
@ -102,6 +97,8 @@ namespace QSB
this.SetValue("m_MaxBufferedPackets", MaxBufferedPackets); this.SetValue("m_MaxBufferedPackets", MaxBufferedPackets);
channels.Add(QosType.Reliable); channels.Add(QosType.Reliable);
channels.Add(QosType.Unreliable); channels.Add(QosType.Unreliable);
DebugLog.DebugWrite("Network Manager ready.", MessageType.Success);
} }
public override void OnStartServer() public override void OnStartServer()

View File

@ -1,4 +1,6 @@
using System; using OWML.Common;
using QSB.Utility;
using System;
namespace QSB namespace QSB
{ {
@ -13,6 +15,7 @@ namespace QSB
static QSBSceneManager() static QSBSceneManager()
{ {
LoadManager.OnCompleteSceneLoad += OnCompleteSceneLoad; LoadManager.OnCompleteSceneLoad += OnCompleteSceneLoad;
DebugLog.DebugWrite("Scene Manager ready.", MessageType.Success);
} }
private static void OnCompleteSceneLoad(OWScene oldScene, OWScene newScene) private static void OnCompleteSceneLoad(OWScene oldScene, OWScene newScene)

View File

@ -1,4 +1,6 @@
using QSB.WorldSync; using OWML.Common;
using QSB.Utility;
using QSB.WorldSync;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
@ -19,10 +21,12 @@ namespace QSB.SectorSync
{ {
Instance = this; Instance = this;
QSBSceneManager.OnSceneLoaded += (OWScene scene, bool universe) => RebuildSectors(); QSBSceneManager.OnSceneLoaded += (OWScene scene, bool universe) => RebuildSectors();
DebugLog.DebugWrite("Sector Manager ready.", MessageType.Success);
} }
public void RebuildSectors() public void RebuildSectors()
{ {
DebugLog.DebugWrite("Rebuilding sectors...", MessageType.Warning);
WorldRegistry.RemoveObjects<QSBSector>(); WorldRegistry.RemoveObjects<QSBSector>();
var sectors = Resources.FindObjectsOfTypeAll<Sector>().ToList(); var sectors = Resources.FindObjectsOfTypeAll<Sector>().ToList();
for (var id = 0; id < sectors.Count; id++) for (var id = 0; id < sectors.Count; id++)

View File

@ -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) private static string GetCallingType(StackTrace frame)
{ {
var stackFrame = frame.GetFrames().First(x => x.GetMethod().DeclaringType.Name != "DebugLog"); var stackFrame = frame.GetFrames().First(x => x.GetMethod().DeclaringType.Name != "DebugLog");