From fa688508f8180e1ea077650a663331f008a33ae7 Mon Sep 17 00:00:00 2001 From: baletiballo <75846481+baletiballo@users.noreply.github.com> Date: Thu, 5 Dec 2024 15:55:53 +0100 Subject: [PATCH] Finished refactoring the checkServers routine. CheckServer.cs got completely redundant and thus removed. This includes the "empty_CheckServer" Game objects in the shrink_menu prefabs --- .../Prefabs/UI/MainMenu/Canvas_Shrink.prefab | 48 +------------- .../Prefabs/UI/NetwMenu/ASM_Shrink.prefab | 50 ++------------- Assets/Scripts/CheckServer.cs | 31 --------- Assets/Scripts/CheckServer.cs.meta | 11 ---- Assets/Scripts/CheckServerPush.cs | 6 +- .../InteractionEngine/CommunicationEvents.cs | 63 ++++++++++++------- .../Scripts/UI/NetwMenu/StartMenu_mobile.cs | 8 +-- 7 files changed, 51 insertions(+), 166 deletions(-) delete mode 100644 Assets/Scripts/CheckServer.cs delete mode 100644 Assets/Scripts/CheckServer.cs.meta diff --git a/Assets/Resources/Prefabs/UI/MainMenu/Canvas_Shrink.prefab b/Assets/Resources/Prefabs/UI/MainMenu/Canvas_Shrink.prefab index 0118f999..547c616c 100644 --- a/Assets/Resources/Prefabs/UI/MainMenu/Canvas_Shrink.prefab +++ b/Assets/Resources/Prefabs/UI/MainMenu/Canvas_Shrink.prefab @@ -29,6 +29,7 @@ RectTransform: m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: - {fileID: 2671906578020345377} m_Father: {fileID: 2671906578625095821} @@ -128,6 +129,7 @@ RectTransform: m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 20} m_LocalScale: {x: 1, y: 1, z: 0} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 2671906577552287146} m_RootOrder: 0 @@ -175,50 +177,6 @@ MonoBehaviour: m_FillOrigin: 0 m_UseSpriteMesh: 0 m_PixelsPerUnitMultiplier: 1 ---- !u!1 &2671906578562484302 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 2671906578562484303} - - component: {fileID: 2671906578562484300} - m_Layer: 0 - m_Name: Empty_CheckS - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &2671906578562484303 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2671906578562484302} - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -960.00024, y: -540.00006, z: 0} - m_LocalScale: {x: 0.75, y: 0.75, z: 0.75} - m_Children: [] - m_Father: {fileID: 2671906578625095821} - m_RootOrder: 1 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &2671906578562484300 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2671906578562484302} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: baada65e49c925541b0fa8823b27a801, type: 3} - m_Name: - m_EditorClassIdentifier: - WaitingText: {fileID: 0} --- !u!1 &2671906578625095809 GameObject: m_ObjectHideFlags: 0 @@ -248,9 +206,9 @@ RectTransform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0, y: 0, z: 0} + m_ConstrainProportionsScale: 0 m_Children: - {fileID: 2671906577552287146} - - {fileID: 2671906578562484303} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/Resources/Prefabs/UI/NetwMenu/ASM_Shrink.prefab b/Assets/Resources/Prefabs/UI/NetwMenu/ASM_Shrink.prefab index 8577510f..2ba8ed6f 100644 --- a/Assets/Resources/Prefabs/UI/NetwMenu/ASM_Shrink.prefab +++ b/Assets/Resources/Prefabs/UI/NetwMenu/ASM_Shrink.prefab @@ -29,6 +29,7 @@ RectTransform: m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: - {fileID: 2731443632193976101} m_Father: {fileID: 2731443631456549257} @@ -129,9 +130,9 @@ RectTransform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0, y: 0, z: 0} + m_ConstrainProportionsScale: 0 m_Children: - {fileID: 2731443630484665518} - - {fileID: 2731443631494601035} - {fileID: 8964566867171987283} m_Father: {fileID: 0} m_RootOrder: 0 @@ -202,50 +203,6 @@ MonoBehaviour: m_BlockingMask: serializedVersion: 2 m_Bits: 4294967295 ---- !u!1 &2731443631494601034 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 2731443631494601035} - - component: {fileID: 2731443631494601032} - m_Layer: 0 - m_Name: Empty_CheckS - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &2731443631494601035 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2731443631494601034} - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -960.00024, y: -540.00006, z: 0} - m_LocalScale: {x: 0.75, y: 0.75, z: 0.75} - m_Children: [] - m_Father: {fileID: 2731443631456549257} - m_RootOrder: 1 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &2731443631494601032 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2731443631494601034} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: baada65e49c925541b0fa8823b27a801, type: 3} - m_Name: - m_EditorClassIdentifier: - WaitingText: {fileID: 0} --- !u!1 &2731443632193976100 GameObject: m_ObjectHideFlags: 0 @@ -274,6 +231,7 @@ RectTransform: m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 20} m_LocalScale: {x: 1, y: 1, z: 0} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 2731443630484665518} m_RootOrder: 0 @@ -331,7 +289,7 @@ PrefabInstance: - target: {fileID: 7813080457042928604, guid: 1a271a0b704fdc549825da0c1274d138, type: 3} propertyPath: m_RootOrder - value: 2 + value: 1 objectReference: {fileID: 0} - target: {fileID: 7813080457042928604, guid: 1a271a0b704fdc549825da0c1274d138, type: 3} diff --git a/Assets/Scripts/CheckServer.cs b/Assets/Scripts/CheckServer.cs deleted file mode 100644 index 99ae058a..00000000 --- a/Assets/Scripts/CheckServer.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections; -using System.Diagnostics; -using UnityEngine; -using UnityEngine.Networking; -using static CommunicationEvents; - - -public class CheckServer : MonoBehaviour -{ - [SerializeField] - TMPro.TextMeshProUGUI WaitingText; - - public static Process process; - public static ProcessStartInfo processInfo; - - - // Start is called before the first frame update - void Start() - { - updateAllServers(); - } - - public void updateAllServers() - { - foreach (ServerSlotData server in ServerSlots.Values) - { - StartCoroutine(server.UpdateServerStatus()); - } - } -} diff --git a/Assets/Scripts/CheckServer.cs.meta b/Assets/Scripts/CheckServer.cs.meta deleted file mode 100644 index 190372a3..00000000 --- a/Assets/Scripts/CheckServer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: baada65e49c925541b0fa8823b27a801 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/CheckServerPush.cs b/Assets/Scripts/CheckServerPush.cs index 1dd83e5a..bceb156e 100644 --- a/Assets/Scripts/CheckServerPush.cs +++ b/Assets/Scripts/CheckServerPush.cs @@ -7,11 +7,7 @@ public class CheckServerPush : MonoBehaviour, IPointerDownHandler, IPointerUpHan public void OnPointerDown(PointerEventData eventData) { - foreach (ServerSlotData server in ServerSlots.Values) - { - StartCoroutine(server.UpdateServerStatus()); - } - + StartCoroutine(UpdateAllServers()); // There is likely a better way to handle this, but it works fine } public void OnPointerUp(PointerEventData eventData) diff --git a/Assets/Scripts/InteractionEngine/CommunicationEvents.cs b/Assets/Scripts/InteractionEngine/CommunicationEvents.cs index 7ae148c4..6b493ec1 100644 --- a/Assets/Scripts/InteractionEngine/CommunicationEvents.cs +++ b/Assets/Scripts/InteractionEngine/CommunicationEvents.cs @@ -92,39 +92,47 @@ public class ServerSlotData /// Ping the server to see if it is online. /// Start as a <c>Coroutine</c>, because this involves a <c>WebRequest</c> /// </summary> - public System.Collections.IEnumerator UpdateServerStatus() + public IEnumerator UpdateServerStatus(bool skipIfAlreadyChecked = false) { - currentStatus = ServerStatus.checking; - if (string.IsNullOrEmpty(domain)) + if (skipIfAlreadyChecked && hasBeenChecked) { - currentStatus = CommunicationEvents.ServerStatus.NoNetworkAddress; - yield break; + yield break; // Skip, if not neccessary } - UnityWebRequest request = UnityWebRequest.Get("http://" + domain + "/fact/list"); - yield return request.SendWebRequest(); + currentStatus = ServerStatus.checking; + ServerSlot myKey = ServerSlots.FirstOrDefault(x => x.Value == this).Key; - if (request.result == UnityWebRequest.Result.Success) + if (string.IsNullOrEmpty(domain)) { - currentStatus = ServerStatus.online; + currentStatus = ServerStatus.NoNetworkAddress; + UnityEngine.Debug.LogWarning("Server " + myKey.ToString() + " has no network adress."); } else { - UnityEngine.Debug.Log("Couldn't connect to Server " + domain + ": " + request.error + "\n"); - currentStatus = ServerStatus.offline; - - //try again - //request.Dispose(); - //request = pingMMTServer(NetwAddress); - //yield return request.SendWebRequest(); - //request.Dispose(); - + UnityWebRequest request = UnityWebRequest.Get("http://" + domain + "/fact/list"); + yield return request.SendWebRequest(); + + if (request.result == UnityWebRequest.Result.Success) + { + currentStatus = ServerStatus.online; + } + else + { + UnityEngine.Debug.Log("Couldn't connect to Server " + myKey.ToString() + " under " + domain + " : " + request.error + "\n"); + currentStatus = ServerStatus.offline; + + //try again + //request.Dispose(); + //request = pingMMTServer(NetwAddress); + //yield return request.SendWebRequest(); + //request.Dispose(); + + } + request.Dispose(); } - request.Dispose(); hasBeenChecked = true; - // To keep ServerRunningA updated, delete if you saved the world from that abomination - ServerSlot myKey = ServerSlots.FirstOrDefault(x => x.Value == this).Key; + // To keep ServerRunningA updated. Delete if you saved the world from that abomination ServerRunningA[(int)myKey] = (int)currentStatus; } @@ -145,6 +153,19 @@ public System.Collections.IEnumerator UpdateServerStatus() {ServerSlot.selecIP, new ServerSlotData("") } }; + /// <summary> + /// Iterate over all members of <see cref="ServerSlots"/> and have them update their <see cref="ServerSlotData.currentStatus"/><br/> + /// <br/> + /// Currently it is not possible to only load the domains via <see cref="StreamingAssetLoader.NetworkJSON_Load_x(string)"/>. If this changes, it might make sense to call the initial loading of the domains from in here. + /// </summary> + public static IEnumerator UpdateAllServers() + { + foreach (ServerSlotData server in ServerSlots.Values) + { + yield return server.UpdateServerStatus(); + } + } + //Enum.GetNames(typeof(KnownServers)).Length; //Number of known Server slots, to be able to add more later diff --git a/Assets/Scripts/UI/NetwMenu/StartMenu_mobile.cs b/Assets/Scripts/UI/NetwMenu/StartMenu_mobile.cs index 9c773644..16acfeb9 100644 --- a/Assets/Scripts/UI/NetwMenu/StartMenu_mobile.cs +++ b/Assets/Scripts/UI/NetwMenu/StartMenu_mobile.cs @@ -38,13 +38,7 @@ private void Awake() //GObj_text.text = "2: " + Application.streamingAssetsPath + " " + Application.persistentDataPath + " " + Application.dataPath; //Debug.Log(Application.streamingAssetsPath); - //Check for all stored Servers, whether they are online - foreach (ServerSlotData server in ServerSlots.Values) - { - StartCoroutine(server.UpdateServerStatus()); - } - - + StartCoroutine(UpdateAllServers()); } void Start() -- GitLab