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

Checking for the local Server also uses CommunicationEvents.ServerSlots

parent fa688508
No related branches found
No related tags found
No related merge requests found
...@@ -34,11 +34,9 @@ public static class CommunicationEvents ...@@ -34,11 +34,9 @@ public static class CommunicationEvents
public static bool ServerRunning = true; public static bool ServerRunning = true;
//CHANGE HERE PORT OF SERVER //CHANGE HERE PORT OF SERVER
public static string ServerPortDefault = "8085"; //used for Local 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 ServerAddressLocalhost = "http://localhost"; //Without Port //Kann das weg? public static string ServerAdress = "http://localhost:8085"; //need "http://" //used by displayScrolls.cs //http://10.231.4.95:8085"; //IMPORTANT for MAINMENU
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 Process process_mmt_frameIT_server; public static Process process_mmt_frameIT_server;
...@@ -55,14 +53,15 @@ public static class CommunicationEvents ...@@ -55,14 +53,15 @@ public static class CommunicationEvents
[System.Serializable] [System.Serializable]
public enum ServerSlot public enum ServerSlot
{// The numbers are due to legacy code, specifically ServerRunningA indices {// The numbers are due to legacy code, specifically ServerRunningA indices
last =1, last = 1,
newIP =2, newIP = 2,
slot1 =3, slot1 = 3,
slot2 =4, slot2 = 4,
slot3 =5, slot3 = 5,
slot4 =7, selecIP = 6,
slot5 =8, slot4 = 7,
selecIP=6 slot5 = 8,
localServer
} }
/// <summary> /// <summary>
...@@ -151,6 +150,8 @@ public IEnumerator UpdateServerStatus(bool skipIfAlreadyChecked = false) ...@@ -151,6 +150,8 @@ public IEnumerator UpdateServerStatus(bool skipIfAlreadyChecked = false)
{ServerSlot.slot4, new ServerSlotData("- -> 'Reset Options'") }, {ServerSlot.slot4, new ServerSlotData("- -> 'Reset Options'") },
{ServerSlot.slot5, new ServerSlotData("- -> PRESS: 'Reset Configurations'") }, {ServerSlot.slot5, new ServerSlotData("- -> PRESS: 'Reset Configurations'") },
{ServerSlot.selecIP, new ServerSlotData("") } {ServerSlot.selecIP, new ServerSlotData("") }
{ ServerSlot.selecIP, new ServerSlotData("") },
{ ServerSlot.localServer, new ServerSlotData(ServerAddressLocal) }
}; };
/// <summary> /// <summary>
......
...@@ -97,16 +97,14 @@ IEnumerator ServerRoutine1() ...@@ -97,16 +97,14 @@ IEnumerator ServerRoutine1()
IEnumerator ServerRoutine() IEnumerator ServerRoutine()
{ {
CommunicationEvents.ServerAddressLocal = ServerAddressLocalhost + ":" + ServerPortDefault; // Checking the Server status got unified in CommunicationEvents
//print(ServerAdress); // UnityWebRequest request = UnityWebRequest.Get(CommunicationEvents.ServerAddressLocal + "/fact/list");
//UnityWebRequest request = UnityWebRequest.Get(CommunicationEvents.ServerAddressLocal + "/scroll/list"); // yield return request.SendWebRequest();
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 (request.result == UnityWebRequest.Result.ConnectionError if (ServerSlots[ServerSlot.localServer].currentStatus == ServerStatus.offline)
|| request.result == UnityWebRequest.Result.ProtocolError)
{ {
UnityEngine.Debug.Log("no running server " + request.error);
#if !UNITY_WEBGL #if !UNITY_WEBGL
...@@ -137,15 +135,11 @@ IEnumerator ServerRoutine() ...@@ -137,15 +135,11 @@ IEnumerator ServerRoutine()
yield return new WaitForSecondsRealtime(2f); yield return new WaitForSecondsRealtime(2f);
print("waiting"); print("waiting");
//request = UnityWebRequest.Get(CommunicationEvents.ServerAddressLocal + "/scroll/list"); yield return ServerSlots[ServerSlot.localServer].UpdateServerStatus(skipIfAlreadyChecked: false);
request = UnityWebRequest.Get(CommunicationEvents.ServerAddressLocal + "/fact/list");
yield return request.SendWebRequest(); // The address of the localServer currently cannot change, so it is never empty/illegal
if (request.result == UnityWebRequest.Result.ConnectionError // If this can happen in the future, this condition may not suffice
|| request.result == UnityWebRequest.Result.ProtocolError) if (ServerSlots[ServerSlot.localServer].currentStatus == ServerStatus.online)
{
// UnityEngine.Debug.Log("no running server");
}
else
{ {
break; break;
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using UnityEngine; using UnityEngine;
using UnityEngine.Networking; using UnityEngine.Networking;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using static CommunicationEvents;
public class WaitingForLocalMMT : MonoBehaviour public class WaitingForLocalMMT : MonoBehaviour
{ {
...@@ -33,51 +34,32 @@ private void OnDisable() ...@@ -33,51 +34,32 @@ private void OnDisable()
void PrepareGame() 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.ServerAdress = "http://" + CommunicationEvents.ServerAddressLocal; //ServerAddress needs the "http://"
CommunicationEvents.ServerRunning = true;
//UnityEngine.Debug.Log("set server runs");
}
if (CommunicationEvents.ServerRunning == true)
{
CommunicationEvents.ServerAdress = CommunicationEvents.ServerAddressLocal;
//UnityEngine.Debug.Log("StartMainMenu"); //UnityEngine.Debug.Log("StartMainMenu");
SceneManager.LoadScene("MainMenu"); SceneManager.LoadScene("MainMenu");
} }
} }
IEnumerator ServerRoutine() IEnumerator ServerRoutine()
{ {
while (true) while (true)
{ {
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
using UnityWebRequest request = pingL(); if (ServerSlots[ServerSlot.localServer].currentStatus == ServerStatus.online)
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.ConnectionError
|| request.result == UnityWebRequest.Result.ProtocolError)
{ {
// UnityEngine.Debug.Log("no running server"); CommunicationEvents.ServerRunning = true;
}
else
{
//break;
PrepareGame(); PrepareGame();
} }
//Wait for 2 seconds //Wait for 2 seconds
yield return new WaitForSecondsRealtime(2f); yield return new WaitForSecondsRealtime(2f);
print("waiting"); print("waiting");
yield return null;
} }
...@@ -87,7 +69,7 @@ public UnityWebRequest pingL() ...@@ -87,7 +69,7 @@ public UnityWebRequest pingL()
{ {
//UnityWebRequest request = UnityWebRequest.Get("http://" + NetwAddress + "/scroll/list"); //UnityWebRequest request = UnityWebRequest.Get("http://" + NetwAddress + "/scroll/list");
//using UnityWebRequest request = UnityWebRequest.Get(CommunicationEvents.ServerAddressLocal + "/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; return request;
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment