diff --git a/Assets/Scripts/InteractionEngine/CommunicationEvents.cs b/Assets/Scripts/InteractionEngine/CommunicationEvents.cs index 6b493ec13259bab95ce0753358a9d73f0dff0c5f..f0f8233eb72f70ecd6691c8602d4e7dee1abf906 100644 --- a/Assets/Scripts/InteractionEngine/CommunicationEvents.cs +++ b/Assets/Scripts/InteractionEngine/CommunicationEvents.cs @@ -34,11 +34,9 @@ public static class CommunicationEvents public static bool ServerRunning = true; //CHANGE HERE PORT OF SERVER - public static string ServerPortDefault = "8085"; //used for Local - - public static string ServerAddressLocalhost = "http://localhost"; //Without Port //Kann das weg? - public static string ServerAddressLocal = "http://localhost:8085"; // "http://localhost:8085" //Kann das weg? - public static string ServerAdress = "http://localhost:8085"; //need "http://" //used by dispalyScrolls.cs //http://10.231.4.95:8085"; //IMPORTANT for MAINMENU + public static readonly string ServerPortDefault = "8085"; //used for Local + public static readonly string ServerAddressLocal = "localhost:" + ServerPortDefault; // there is currently never a reason to change this. + public static string ServerAdress = "http://localhost:8085"; //need "http://" //used by displayScrolls.cs //http://10.231.4.95:8085"; //IMPORTANT for MAINMENU public static Process process_mmt_frameIT_server; @@ -55,14 +53,15 @@ public static class CommunicationEvents [System.Serializable] public enum ServerSlot {// The numbers are due to legacy code, specifically ServerRunningA indices - last =1, - newIP =2, - slot1 =3, - slot2 =4, - slot3 =5, - slot4 =7, - slot5 =8, - selecIP=6 + last = 1, + newIP = 2, + slot1 = 3, + slot2 = 4, + slot3 = 5, + selecIP = 6, + slot4 = 7, + slot5 = 8, + localServer } /// <summary> @@ -151,6 +150,8 @@ public IEnumerator UpdateServerStatus(bool skipIfAlreadyChecked = false) {ServerSlot.slot4, new ServerSlotData("- -> 'Reset Options'") }, {ServerSlot.slot5, new ServerSlotData("- -> PRESS: 'Reset Configurations'") }, {ServerSlot.selecIP, new ServerSlotData("") } + { ServerSlot.selecIP, new ServerSlotData("") }, + { ServerSlot.localServer, new ServerSlotData(ServerAddressLocal) } }; /// <summary> diff --git a/Assets/Scripts/StartServer.cs b/Assets/Scripts/StartServer.cs index afb57aa8c6712136880b8105a2f71af6892ac348..bf5ad6afc3910b2773469b3a8e1f03e94e281786 100644 --- a/Assets/Scripts/StartServer.cs +++ b/Assets/Scripts/StartServer.cs @@ -97,16 +97,14 @@ IEnumerator ServerRoutine1() IEnumerator ServerRoutine() { - CommunicationEvents.ServerAddressLocal = ServerAddressLocalhost + ":" + ServerPortDefault; - //print(ServerAdress); - //UnityWebRequest request = UnityWebRequest.Get(CommunicationEvents.ServerAddressLocal + "/scroll/list"); - UnityWebRequest request = UnityWebRequest.Get(CommunicationEvents.ServerAddressLocal + "/fact/list"); - yield return request.SendWebRequest(); - - if (request.result == UnityWebRequest.Result.ConnectionError - || request.result == UnityWebRequest.Result.ProtocolError) + // Checking the Server status got unified in CommunicationEvents + // UnityWebRequest request = UnityWebRequest.Get(CommunicationEvents.ServerAddressLocal + "/fact/list"); + // yield return request.SendWebRequest(); + + // Make sure the server status has been checked + yield return ServerSlots[ServerSlot.localServer].UpdateServerStatus(skipIfAlreadyChecked: true); + if (ServerSlots[ServerSlot.localServer].currentStatus == ServerStatus.offline) { - UnityEngine.Debug.Log("no running server " + request.error); #if !UNITY_WEBGL @@ -137,15 +135,11 @@ IEnumerator ServerRoutine() yield return new WaitForSecondsRealtime(2f); print("waiting"); - //request = UnityWebRequest.Get(CommunicationEvents.ServerAddressLocal + "/scroll/list"); - request = UnityWebRequest.Get(CommunicationEvents.ServerAddressLocal + "/fact/list"); - yield return request.SendWebRequest(); - if (request.result == UnityWebRequest.Result.ConnectionError - || request.result == UnityWebRequest.Result.ProtocolError) - { - // UnityEngine.Debug.Log("no running server"); - } - else + yield return ServerSlots[ServerSlot.localServer].UpdateServerStatus(skipIfAlreadyChecked: false); + + // The address of the localServer currently cannot change, so it is never empty/illegal + // If this can happen in the future, this condition may not suffice + if (ServerSlots[ServerSlot.localServer].currentStatus == ServerStatus.online) { break; } diff --git a/Assets/Scripts/UI/NetwMenu/WaitingForLocalMMT.cs b/Assets/Scripts/UI/NetwMenu/WaitingForLocalMMT.cs index 36862caac78457e924d786f3555e02af128b76c9..4ad57bf52313e2a99c117ccaa596180752ea5f4d 100644 --- a/Assets/Scripts/UI/NetwMenu/WaitingForLocalMMT.cs +++ b/Assets/Scripts/UI/NetwMenu/WaitingForLocalMMT.cs @@ -2,6 +2,7 @@ using UnityEngine; using UnityEngine.Networking; using UnityEngine.SceneManagement; +using static CommunicationEvents; public class WaitingForLocalMMT : MonoBehaviour { @@ -33,51 +34,32 @@ private void OnDisable() void PrepareGame() { - if (true) + //This condition should always be true if PrepareGame gets called, but it never hurts to make sure. + if (CommunicationEvents.ServerRunning) { - - CommunicationEvents.ServerRunning = true; - //UnityEngine.Debug.Log("set server runs"); - } - if (CommunicationEvents.ServerRunning == true) - { - CommunicationEvents.ServerAdress = CommunicationEvents.ServerAddressLocal; + CommunicationEvents.ServerAdress = "http://" + CommunicationEvents.ServerAddressLocal; //ServerAddress needs the "http://" //UnityEngine.Debug.Log("StartMainMenu"); SceneManager.LoadScene("MainMenu"); } - - } IEnumerator ServerRoutine() { while (true) { + yield return ServerSlots[ServerSlot.localServer].UpdateServerStatus(skipIfAlreadyChecked: false); - - - using UnityWebRequest request = pingL(); - yield return request.SendWebRequest(); - if (request.result == UnityWebRequest.Result.ConnectionError - || request.result == UnityWebRequest.Result.ProtocolError) + // The address of the localServer currently cannot change, so it is never empty/illegal + // If this can happen in the future, this condition may not suffice + if (ServerSlots[ServerSlot.localServer].currentStatus == ServerStatus.online) { - // UnityEngine.Debug.Log("no running server"); - } - else - { - //break; + CommunicationEvents.ServerRunning = true; PrepareGame(); } - - - - //Wait for 2 seconds yield return new WaitForSecondsRealtime(2f); print("waiting"); - - yield return null; } @@ -87,7 +69,7 @@ public UnityWebRequest pingL() { //UnityWebRequest request = UnityWebRequest.Get("http://" + NetwAddress + "/scroll/list"); //using UnityWebRequest request = UnityWebRequest.Get(CommunicationEvents.ServerAddressLocal + "/scroll/list"); - UnityWebRequest request = UnityWebRequest.Get(CommunicationEvents.ServerAddressLocal + "/fact/list"); + UnityWebRequest request = UnityWebRequest.Get("http://" + CommunicationEvents.ServerAddressLocal + "/fact/list"); return request; } } \ No newline at end of file