Example #1
0
    public void UpdateServers()
    {
        IEnumerable <ServerInfo> servers = ServerRegistry.GetServers();

        foreach (ServerInfo server in servers)
        {
            int index = allServerslots.FindIndex(item => item.GetComponent <ServerListObj>().server.host == server.host);
            if (index > 0)
            {
                Debug.Log("Server exist");
                // element exists, do what you need
            }
            else
            {
                Debug.Log("Server dont exist");
                GameObject    newServerBox     = Instantiate(ServerBoxPrefab) as GameObject;
                RectTransform newServerBoxRect = newServerBox.GetComponent <RectTransform>();
                ServerListObj serverListScript = newServerBox.GetComponent <ServerListObj>();
                serverListScript.server = server;
                newServerBox.transform.SetParent(ServerRect.transform);
                newServerBoxRect.localPosition = new Vector3(0, (-serverRow * 50), 0);
                newServerBoxRect.localScale    = Vector3.one;
                allServerslots.Add(newServerBox);
                serverRow++;
                serverRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 50 * serverRow);
            }
        }
        Invoke("UpdateServers", 10);
    }
Example #2
0
    public void ConnectToServer()
    {
        IEnumerable <ServerInfo> servers = ServerRegistry.GetServers();

        foreach (ServerInfo server in servers)
        {
            uLink.BitStream dataCopy = server.data;
            //int numPlayers = dataCopy.ReadInt32();
            //int maxPlayers = dataCopy.ReadInt32();
            string name = dataCopy.ReadString();

            if (serverName == name)
            {
                attempts = 0;
                Debug.Log("CONNECTING TO SERVER" + server.host + " " + server.port);
                ConnectToIp(server.host, server.port);
            }
        }

        if (!uLink.Network.isServer && !uLink.Network.isClient)
        {
            if (attempts < 3)
            {
                attempts++;
                Invoke("ConnectToServer", 3);
            }
            else
            {
                attempts = 0;
                windowServerCreation.GetComponent <Menu>().errorDialogText.color = Color.red;
                windowServerCreation.GetComponent <Menu>().errorDialogText.text  = "Error creating a custom match";
                mainMenuManager.loadingScreenObj.SetActive(false);
            }
        }
    }
Example #3
0
    public void ShowServers()
    {
        for (int i = 0; i < allServerslots.Count; i++)
        {
            Destroy(allServerslots[i]);
            allServerslots.Remove(allServerslots[i]);
        }


        IEnumerable <ServerInfo> servers = ServerRegistry.GetServers();


        foreach (ServerInfo server in servers)
        {
            GameObject    newServerBox     = Instantiate(ServerBoxPrefab) as GameObject;
            RectTransform newServerBoxRect = newServerBox.GetComponent <RectTransform>();
            ServerListObj serverListScript = newServerBox.GetComponent <ServerListObj>();
            serverListScript.server = server;


            newServerBox.transform.SetParent(ServerRect.transform);

            newServerBoxRect.localPosition = new Vector3(0, (-serverRow * 50), 0);
            newServerBoxRect.localScale    = Vector3.one;

            allServerslots.Add(newServerBox);
            serverRow++;
            serverRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 50 * serverRow);
        }
        serverRow = 0;
        Invoke("ShowServers", 15);
    }