From e34db1af144ef732d6e489e3f9b29354adc3620e Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 29 Aug 2021 16:44:36 +0100 Subject: [PATCH] cleanup qnetworkidentity and qnetworkmanager --- QuantumUNET/Components/QNetworkIdentity.cs | 1 - QuantumUNET/Components/QNetworkManager.cs | 161 +-------------------- 2 files changed, 3 insertions(+), 159 deletions(-) diff --git a/QuantumUNET/Components/QNetworkIdentity.cs b/QuantumUNET/Components/QNetworkIdentity.cs index e70666ae..1ee300ff 100644 --- a/QuantumUNET/Components/QNetworkIdentity.cs +++ b/QuantumUNET/Components/QNetworkIdentity.cs @@ -815,7 +815,6 @@ namespace QuantumUNET.Components { QNetworkServer.Update(); QNetworkClient.UpdateClients(); - QNetworkManager.UpdateScene(); } [SerializeField] diff --git a/QuantumUNET/Components/QNetworkManager.cs b/QuantumUNET/Components/QNetworkManager.cs index a5fff98c..61aeab26 100644 --- a/QuantumUNET/Components/QNetworkManager.cs +++ b/QuantumUNET/Components/QNetworkManager.cs @@ -21,13 +21,9 @@ namespace QuantumUNET.Components public bool scriptCRCCheck { get; set; } = true; public bool autoCreatePlayer { get; set; } = true; public bool isNetworkActive; - public bool useWebSockets { get; set; } - public bool useSimulator { get; set; } public bool clientLoadedScene { get; set; } public string serverBindAddress { get; set; } = ""; public string networkAddress { get; set; } = "localhost"; - public string offlineScene { get; set; } = ""; - public string onlineScene { get; set; } = ""; public float packetLossPercentage { get; set; } public float maxDelay { get; set; } = 0.01f; public GameObject playerPrefab { get; set; } @@ -159,7 +155,6 @@ namespace QuantumUNET.Components } QNetworkCRC.scriptCRCCheck = scriptCRCCheck; - QNetworkServer.useWebSockets = useWebSockets; if (m_GlobalConfig != null) { NetworkTransport.Init(m_GlobalConfig); @@ -207,6 +202,7 @@ namespace QuantumUNET.Components { QNetworkServer.SpawnObjects(); } + QNetworkServer.SpawnObjects(); return true; } @@ -217,7 +213,6 @@ namespace QuantumUNET.Components client.RegisterHandler(QMsgType.Disconnect, OnClientDisconnectInternal); client.RegisterHandler(QMsgType.NotReady, OnClientNotReadyMessageInternal); client.RegisterHandler(QMsgType.Error, OnClientErrorInternal); - client.RegisterHandler(QMsgType.Scene, OnClientSceneInternal); if (playerPrefab != null) { QClientScene.RegisterPrefab(playerPrefab); @@ -232,35 +227,6 @@ namespace QuantumUNET.Components } } - public void UseExternalClient(QNetworkClient externalClient) - { - if (runInBackground) - { - Application.runInBackground = true; - } - - if (externalClient != null) - { - client = externalClient; - isNetworkActive = true; - RegisterClientMessages(client); - OnStartClient(client); - } - else - { - OnStopClient(); - QClientScene.DestroyAllClientObjects(); - QClientScene.HandleClientDisconnect(client.connection); - client = null; - if (!string.IsNullOrEmpty(offlineScene)) - { - ClientChangeScene(offlineScene, false); - } - } - - s_Address = networkAddress; - } - public QNetworkClient StartClient(ConnectionConfig config, int hostPort) { InitializeSingleton(); @@ -382,10 +348,6 @@ namespace QuantumUNET.Components QLog.Log("NetworkManager StopServer"); isNetworkActive = false; QNetworkServer.Shutdown(); - if (!string.IsNullOrEmpty(offlineScene)) - { - ServerChangeScene(offlineScene); - } CleanupNetworkIdentities(); } @@ -404,31 +366,10 @@ namespace QuantumUNET.Components } QClientScene.DestroyAllClientObjects(); - if (!string.IsNullOrEmpty(offlineScene)) - { - ClientChangeScene(offlineScene, false); - } CleanupNetworkIdentities(); } - public virtual void ServerChangeScene(string newSceneName) - { - if (string.IsNullOrEmpty(newSceneName)) - { - QLog.Error("ServerChangeScene empty scene name"); - } - else - { - QLog.Log($"ServerChangeScene {newSceneName}"); - QNetworkServer.SetAllClientsNotReady(); - networkSceneName = newSceneName; - s_LoadingSceneAsync = SceneManager.LoadSceneAsync(newSceneName); - var msg = new QStringMessage(networkSceneName); - QNetworkServer.SendToAll(39, msg); - } - } - private void CleanupNetworkIdentities() { foreach (var networkIdentity in Resources.FindObjectsOfTypeAll()) @@ -437,75 +378,6 @@ namespace QuantumUNET.Components } } - internal void ClientChangeScene(string newSceneName, bool forceReload) - { - if (string.IsNullOrEmpty(newSceneName)) - { - QLog.Error("ClientChangeScene empty scene name"); - } - else - { - QLog.Log($"ClientChangeScene newSceneName:{newSceneName} networkSceneName:{networkSceneName}"); - if (newSceneName == networkSceneName) - { - if (!forceReload) - { - FinishLoadScene(); - return; - } - } - - s_LoadingSceneAsync = SceneManager.LoadSceneAsync(newSceneName); - networkSceneName = newSceneName; - } - } - - private void FinishLoadScene() - { - if (client != null) - { - if (s_ClientReadyConnection != null) - { - clientLoadedScene = true; - OnClientConnect(s_ClientReadyConnection); - s_ClientReadyConnection = null; - } - } - else - { - QLog.Error("FinishLoadScene client is null"); - } - - if (QNetworkServer.active) - { - QNetworkServer.SpawnObjects(); - OnServerSceneChanged(networkSceneName); - } - - if (IsClientConnected() && client != null) - { - RegisterClientMessages(client); - OnClientSceneChanged(client.connection); - } - } - - internal static void UpdateScene() - { - if (!(singleton == null)) - { - if (s_LoadingSceneAsync != null) - { - if (s_LoadingSceneAsync.isDone) - { - QLog.Log($"ClientChangeScene done readyCon:{s_ClientReadyConnection}"); - singleton.FinishLoadScene(); - s_LoadingSceneAsync.allowSceneActivation = true; - s_LoadingSceneAsync = null; - } - } - } - } - public bool IsClientConnected() => client != null && client.isConnected; public static void Shutdown() @@ -538,12 +410,6 @@ namespace QuantumUNET.Components } } - if (networkSceneName != "" && networkSceneName != offlineScene) - { - var msg = new QStringMessage(networkSceneName); - netMsg.Connection.Send(39, msg); - } - OnServerConnect(netMsg.Connection); } @@ -595,24 +461,13 @@ namespace QuantumUNET.Components QLog.Log("NetworkManager:OnClientConnectInternal"); netMsg.Connection.SetMaxDelay(maxDelay); var name = SceneManager.GetSceneAt(0).name; - if (string.IsNullOrEmpty(onlineScene) || onlineScene == offlineScene || name == onlineScene) - { - clientLoadedScene = false; - OnClientConnect(netMsg.Connection); - } - else - { - s_ClientReadyConnection = netMsg.Connection; - } + clientLoadedScene = false; + OnClientConnect(netMsg.Connection); } internal void OnClientDisconnectInternal(QNetworkMessage netMsg) { QLog.Log("NetworkManager:OnClientDisconnectInternal"); - if (!string.IsNullOrEmpty(offlineScene)) - { - ClientChangeScene(offlineScene, false); - } OnClientDisconnect(netMsg.Connection); } @@ -631,16 +486,6 @@ namespace QuantumUNET.Components OnClientError(netMsg.Connection, s_ErrorMessage.errorCode); } - internal void OnClientSceneInternal(QNetworkMessage netMsg) - { - QLog.Log("NetworkManager:OnClientSceneInternal"); - var newSceneName = netMsg.Reader.ReadString(); - if (IsClientConnected() && !QNetworkServer.active) - { - ClientChangeScene(newSceneName, true); - } - } - public virtual void OnServerConnect(QNetworkConnection conn) { }