Skip to content
Snippets Groups Projects
Commit fa688508 authored by baletiballo's avatar baletiballo
Browse files

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
parent 8eda2c77
No related branches found
No related tags found
No related merge requests found
......@@ -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}
......
......@@ -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}
......
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());
}
}
}
fileFormatVersion: 2
guid: baada65e49c925541b0fa8823b27a801
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -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)
......
......@@ -92,15 +92,23 @@ 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)
{
if (skipIfAlreadyChecked && hasBeenChecked)
{
yield break; // Skip, if not neccessary
}
currentStatus = ServerStatus.checking;
ServerSlot myKey = ServerSlots.FirstOrDefault(x => x.Value == this).Key;
if (string.IsNullOrEmpty(domain))
{
currentStatus = CommunicationEvents.ServerStatus.NoNetworkAddress;
yield break;
currentStatus = ServerStatus.NoNetworkAddress;
UnityEngine.Debug.LogWarning("Server " + myKey.ToString() + " has no network adress.");
}
else
{
UnityWebRequest request = UnityWebRequest.Get("http://" + domain + "/fact/list");
yield return request.SendWebRequest();
......@@ -110,7 +118,7 @@ public System.Collections.IEnumerator UpdateServerStatus()
}
else
{
UnityEngine.Debug.Log("Couldn't connect to Server " + domain + ": " + request.error + "\n");
UnityEngine.Debug.Log("Couldn't connect to Server " + myKey.ToString() + " under " + domain + " : " + request.error + "\n");
currentStatus = ServerStatus.offline;
//try again
......@@ -121,10 +129,10 @@ public System.Collections.IEnumerator UpdateServerStatus()
}
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
......
......@@ -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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment