IEnumerator WaitForResponse()
        {
            yield return(WaitForDoneProcess(5f));

            if (_serverHubConnection.Available <= 0)
            {
                try
                {
                    TextMeshProUGUI _errorText = ui.CreateText(rectTransform, "Can't connect to ServerHub!", new Vector2(0f, -48f));
                    _errorText.alignment = TextAlignmentOptions.Center;
                    Destroy(_errorText.gameObject, 4f);
                    _serverHubConnection.Close();
                    _loading = false;
                }catch (Exception e)
                {
                    Console.WriteLine($"ServerHub Exception: {e}");
                }
                yield break;
            }

            byte[]           bytes  = new byte[Packet.MAX_BYTE_LENGTH];
            ClientDataPacket packet = null;

            if (_serverHubConnection.GetStream().Read(bytes, 0, bytes.Length) != 0)
            {
                packet = Packet.ToClientDataPacket(bytes);
            }

            _serverHubConnection.Close();
            _loading = false;

            _multiplayerServerList.SetServers((packet as ClientDataPacket).Servers);
        }
Beispiel #2
0
        internal void GetServers()
        {
            if (!_loading)
            {
                Console.WriteLine($"Get servers from ServerHubs");
                try
                {
                    _loading = true;

                    _multiplayerServerList.SetServers(new List <Data.Data>());
                    _serverHubs.ForEach(x => x.RequestServers());

                    Console.WriteLine("Waiting for response...");
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Exception: {e}");
                    _loading = false;
                    TextMeshProUGUI _errorText = ui.CreateText(rectTransform, "Can't connect to ServerHub!", new Vector2(0f, -48f));
                    _errorText.alignment = TextAlignmentOptions.Center;
                    Destroy(_errorText.gameObject, 4f);
                }
            }
        }