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
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;
......@@ -60,9 +58,10 @@ public enum ServerSlot
slot1 = 3,
slot2 = 4,
slot3 = 5,
selecIP = 6,
slot4 = 7,
slot5 = 8,
selecIP=6
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>
......
......@@ -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;
}
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment