in UnityProject/Assets/Scripts/Server/Server.cs [164:193]
IEnumerator GetTaskMetadata(string uri)
{
using (UnityWebRequest webRequest = UnityWebRequest.Get(uri))
{
// Request and wait for the desired page.
yield return webRequest.SendWebRequest();
if (webRequest.isNetworkError)
{
Debug.Log("Task metadata Error: " + webRequest.error);
}
else
{
Debug.Log("Task metadata Received: " + webRequest.downloadHandler.text);
var taskData = JsonUtility.FromJson<TaskData>(webRequest.downloadHandler.text);
this.taskDataArn = taskData.TaskARN;
// Search for the host port, a bit hacky but it's always 5 numbers after "HostPort":
string afterHostport = webRequest.downloadHandler.text.Split(new string[] { "\"HostPort\":" }, StringSplitOptions.None)[1];
Server.port = int.Parse(afterHostport.Substring(0, 5));
Console.WriteLine("port: " + Server.port);
this.taskDataArnWithContainer = taskData.TaskARN + "-" + Environment.GetEnvironmentVariable("CONTAINERNAME"); //Including the container name as we run multiple containers in a Task
Debug.Log("TaskARN: " + this.taskDataArn);
Debug.Log("TaskARN with container: " + this.taskDataArnWithContainer);
// We will generate the game server name with the Task Arn id only to match the constraints
var splittedArn = this.taskDataArnWithContainer.Split('/');
this.gameServerId = splittedArn[splittedArn.Length - 1];
Debug.Log("Game Server ID: " + this.gameServerId);
}
}
}