Пример #1
0
    IEnumerator FetchTile(Vector2 index)
    {
        Vector3 pos = indexToPosition(index);

        // Temporal Placeholder
        GameObject plane  = Instantiate(baseTile, pos, Quaternion.identity);
        GameObject loader = Instantiate(loading, pos, Quaternion.identity);

        loader.transform.position = new Vector3(pos.x, pos.y + 2, pos.z);
        string fileName = "" + index[0] + "." + index[1] + ".lnd";
        WWW    www      = new WWW("https://decentraland.org/content/" + fileName);

        yield return(www);

        if (!string.IsNullOrEmpty(www.error))
        {
            Debug.Log("Can't fetch tile content! " + index + " " + www.error);
            names.Add(index, "Unclaimed Land");
            Destroy(loader);
        }
        else
        {
            Debug.Log("Downloaded content for tile (" + index[0] + "," + index[1] + ")");
            try
            {
                STile t = STile.FromBytes(www.bytes);
                t.ToInstance(pos);
                names.Add(index, t.GetName());
            }
            catch (EndOfStreamException e)
            {
                Debug.Log("Invalid" + index + e.ToString());
            }
            catch (SerializationException e)
            {
                Debug.Log("Invalid" + index + e.ToString());
            }
            catch (Exception e)
            {
                Debug.Log("Exception found in " + index + e.ToString());
            }
            finally
            {
                Destroy(loader);
            }
        }
    }
Пример #2
0
    IEnumerator FetchTile(Vector2 index)
    {
        Vector3 pos = indexToPosition(index);

        // Temporal Placeholder
        GameObject plane  = Instantiate(baseTile, pos, Quaternion.identity);
        GameObject loader = Instantiate(loading, pos, Quaternion.identity);

        loader.transform.position = new Vector3(pos.x, pos.y + 2, pos.z);

        // Basic Auth
        Dictionary <string, string> headers = new Dictionary <string, string>();

        headers["Authorization"] = "Basic " + System.Convert.ToBase64String(
            System.Text.Encoding.ASCII.GetBytes("bitcoinrpc:38Dpwnjsj1zn3QETJ6GKv8YkHomA"));

        // JSON Data
        string json = "{\"method\":\"gettile\",\"params\":[" + index [0] + "," + index [1] + "],\"id\":0}";

        byte[] data = System.Text.Encoding.ASCII.GetBytes(json.ToCharArray());

        WWW www = new WWW("http://s1.decentraland.org:8301", data, headers);

        yield return(www);

        if (string.IsNullOrEmpty(www.error))
        {
            RPCResponse response = JsonUtility.FromJson <RPCResponse>(www.text);
            Destroy(loader);
            if (response.IsEmpty())
            {
                // TODO: do empty behavior
            }
            else if (response.IsUnmined())
            {
                names.Add(index, "Unclaimed Land");
            }
            else if (response.HasData())
            {
                // Download tile content
                string fileName = "" + index [0] + "." + index [1] + ".lnd";
                www = new WWW("http://s1.decentraland.org:9301/tile/" + fileName);
                yield return(www);

                if (string.IsNullOrEmpty(www.error))
                {
                    Debug.Log("Downloaded content for tile (" + index[0] + "," + index[1] + ")");
                    STile t = STile.FromBytes(www.bytes);
                    t.ToInstance(pos);
                    names.Add(index, t.GetName());
                }
                else
                {
                    Debug.Log("Can't fetch tile content! " + index + " " + www.error);
                }
            }
        }
        else
        {
            Debug.Log("Error on RPC call 'gettile': " + www.error);
        }
    }