From df0fa357ad1f01543aaa68669040b900e7377445 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Sun, 2 Jun 2024 11:54:50 +0200 Subject: [PATCH] Add checks to allow reconnection to work --- Fika.Core/Coop/Utils/NetManagerUtils.cs | 14 ++++++++++++-- Fika.Core/Networking/FikaClient.cs | 12 ++++++++++++ Fika.Core/Networking/FikaServer.cs | 11 +++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Fika.Core/Coop/Utils/NetManagerUtils.cs b/Fika.Core/Coop/Utils/NetManagerUtils.cs index f918b373..f3f700a7 100644 --- a/Fika.Core/Coop/Utils/NetManagerUtils.cs +++ b/Fika.Core/Coop/Utils/NetManagerUtils.cs @@ -60,15 +60,25 @@ public static Task InitNetManager(bool isServer) { if (isServer) { - return Singleton.Instance.Init(); + FikaServer server = Singleton.Instance; + if (!server.Started) + { + return server.Init(); + } + return Task.CompletedTask; } else { - Singleton.Instance.Init(); + FikaClient client = Singleton.Instance; + if (!client.Started) + { + client.Init(); + } return Task.CompletedTask; } } + logger.LogError("InitNetManager: FikaGameObject was null!"); return Task.CompletedTask; } diff --git a/Fika.Core/Networking/FikaClient.cs b/Fika.Core/Networking/FikaClient.cs index f428ab30..1418cf93 100644 --- a/Fika.Core/Networking/FikaClient.cs +++ b/Fika.Core/Networking/FikaClient.cs @@ -52,6 +52,17 @@ public NetManager NetClient public int Port { get; private set; }*/ public bool SpawnPointsReceived { get; private set; } = false; private readonly ManualLogSource clientLogger = BepInEx.Logging.Logger.CreateLogSource("Fika.Client"); + public bool Started + { + get + { + if (_netClient == null) + { + return false; + } + return _netClient.IsRunning; + } + } public void Init() { @@ -111,6 +122,7 @@ public void Init() }; FikaEventDispatcher.DispatchEvent(new FikaClientCreatedEvent(this)); + Started = true; } public void SetupGameVariables(CoopPlayer coopPlayer) diff --git a/Fika.Core/Networking/FikaServer.cs b/Fika.Core/Networking/FikaServer.cs index 5951b223..2d410a11 100644 --- a/Fika.Core/Networking/FikaServer.cs +++ b/Fika.Core/Networking/FikaServer.cs @@ -56,6 +56,17 @@ public NetManager NetServer public bool hasHadPeer = false; private readonly ManualLogSource serverLogger = BepInEx.Logging.Logger.CreateLogSource("Fika.Server"); private int _currentNetId; + public bool Started + { + get + { + if (_netServer == null) + { + return false; + } + return _netServer.IsRunning; + } + } public async Task Init() {