Ejemplo n.º 1
0
        private IEnumerator Send()
        {
            EB.Debug.Log("Downloading asset bundle {0} from {1}", mName, mUrl);

            if (mLocal)
            {
                mWebRequest = UnityWebRequest.Get(mUrl);
                yield return(mWebRequest.SendWebRequest());

                mDone = true;
                if (mWebRequest.isHttpError || mWebRequest.isNetworkError)
                {
                    EB.Debug.LogWarning("Failed to download asset bundle {0} from {1}, error: {2}", mName, mUrl, mWebRequest.error);
                    mError = mWebRequest.error;
                    yield break;
                }
                else
                {
                    mBytes = mWebRequest.downloadHandler.data;
                    EB.Debug.Log("Downloaded asset bundle {0} from {1}, {2}", mName, mUrl, mWebRequest.downloadedBytes);
                }
            }
            else
            {
                mRquest                  = new HTTP.Request("GET", mUrl);
                mRquest.acceptGzip       = false;
                mRquest.useCache         = false;
                mRquest.maximumRedirects = 2;
                yield return(mRquest.Send());

                mDone = true;
                if (mRquest.exception != null)
                {
                    mError = mRquest.exception.Message;
                    EB.Debug.LogWarning("Failed to download asset bundle {0} from {1}, error: {2}", mName, mUrl, mRquest.exception.Message);
                    yield break;
                }
                else
                {
                    if (mRquest.response.status != 200)
                    {
                        mError = "Not 200 status error(" + mRquest.response.status + ")";
                        EB.Debug.LogWarning("HTTP 404 error when download asset bundle {0} from {1}", mName, mUrl);
                        yield break;
                    }
                    else
                    {
                        mBytes = mRquest.response.Bytes;
                        EB.Debug.Log("Downloaded asset bundle {0} from {1}, {2}", mName, mUrl, mBytes.Length);
                    }
                }
            }

            if (mBytes == null || mBytes.Length == 0)
            {
                mError = "Invalid response data";
                EB.Debug.LogError("Downloaded asset bundle {0} error, invalid response data", mName);
            }
        }
Ejemplo n.º 2
0
        /**
         * GET with plain request as callback
         */
        public void GET(string endPoint, GETCallback cb)
        {
            HTTP.Request req = new HTTP.Request( "get", this.baseURL + endPoint );

            // Add headers
            foreach (DictionaryEntry h in headers) {
                req.AddHeader((string) h.Key, (string) h.Value);
            }

            req.Send( ( request ) => { cb(request); });
        }
Ejemplo n.º 3
0
        /**
         * GET with result parsed as list
         */
        public void GET(string endPoint, GETListCallback cb)
        {
            HTTP.Request req = new HTTP.Request( "get", this.baseURL + endPoint );

            // Add headers
            foreach (DictionaryEntry h in headers) {
                req.AddHeader((string) h.Key, (string) h.Value);
            }

            req.Send( ( request ) => {
                var resList = Json.Deserialize(request.response.Text) as List<object>;
                cb(resList);
            });
        }
Ejemplo n.º 4
0
        static StackObject *Send_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            HTTP.Request instance_of_this_method = (HTTP.Request) typeof(HTTP.Request).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.Send();

            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Ejemplo n.º 5
0
        IEnumerator _InnerLoadRemoteImage()
        {
            while (LoadingList.Count > 0)
            {
                var data = LoadingList.Dequeue();

                Texture2D t;
                if (textureCache.TryGetValue(data.Key, out t))
                {
                    if (data.Value != null)
                    {
                        data.Value.SetTexture(t);
                    }
                    continue;
                }

                int retries = 0;

                while (retries < 3)
                {
                    HTTP.Request req = new HTTP.Request("GET", data.Key);
                    yield return(req.Send());

                    if (req.exception != null)
                    {
                        retries++;
                        yield return(new WaitForSecondsRealtime(0.5f));

                        continue;
                    }

                    Texture2D texture = new Texture2D(1, 1, TextureFormat.RGBA32, false);
                    texture.LoadImage(req.response.Bytes);
                    textureCache.Add(data.Key, texture);
                    if (data.Value != null)
                    {
                        data.Value.SetTexture(texture);
                    }
                    break;
                }

                if (retries >= 3)
                {
                    EB.Debug.LogError("Cannot load remote image: {0}", data.Key);
                }
            }
            RemoteLoadingCoroutine = null;
        }
Ejemplo n.º 6
0
        void BoardSetup()
        {
            Hashtable data = new Hashtable();

            data.Add("username", SystemInfo.deviceUniqueIdentifier);

            string      strHostName = Dns.GetHostName();
            IPHostEntry ipEntry     = Dns.GetHostEntry(strHostName);

            IPAddress[] addr = ipEntry.AddressList;
            data.Add("ip", addr[addr.Length - 1].ToString());

            Debug.Log("Send:");
            foreach (string str in data.Keys)
            {
                Debug.Log(str + ": " + data[str]);
            }

            HTTP.Request req = new HTTP.Request("post", "http://143.248.139.70:8000/login", data);
            req.Send((request) =>
            {
                Hashtable result = request.response.Object;
                Debug.Log("Result");
                foreach (string str in result.Keys)
                {
                    Debug.Log(str + ": " + result[str]);
                    if ((string)(result[str].ToString()) == "System.Collections.Hashtable")
                    {
                        Hashtable rr = result[str] as Hashtable;
                        foreach (string strstr in rr.Keys)
                        {
                            Debug.Log(strstr + ": " + rr[strstr]);
                        }
                    }
                }
                if (result == null)
                {
                    Debug.LogWarning("Could not parse JSON response!");
                    return;
                }
                else
                {
                    // Receive String from server and generate room
                    Hashtable hashmap = (Hashtable)JSON.JsonDecode(request.response.Text);
                    generateMapAndPlayer(hashmap, PlayerSpawnDir.SPAWN_NONE);
                }
            });
        }
Ejemplo n.º 7
0
        public void Download(string filename, string url)
        {
            var req = new HTTP.Request("HEAD", url);

            req.Send(delegate(Request headreq) {
                if (headreq.exception == null)
                {
                    if (headreq.response.status == 200)
                    {
                        Debug.Log(headreq.response.headers.Get("Content-Length"));
                    }
                }
                else
                {
                    Debug.Log(headreq.exception);
                }
            });
        }
Ejemplo n.º 8
0
        protected static IEnumerator DownloadFromUrl(Collection <TRecordType> collection, string url)
        {
            var request = new HTTP.Request("GET", url, true);

            var icollection = collection as ICollection;

            request.Send();
            yield return(request.Wait());

            // Deserialize the collection
            var result = request.response.Text.Deserialize <Collection <TRecordType> > ();

            // Iterate through and update from the result. Remove old stuff
            foreach (var kv in result)
            {
                if (collection.Contains(kv))
                {
                    icollection.Changed(kv._id, null, kv.Coerce <Hashtable> ());
                }
            }
        }
Ejemplo n.º 9
0
        static IEnumerator SendBugReport(string crash)
        {
            if (Application.isEditor)
            {
                yield break;
            }

            var bytes = Encoding.GetBytes(crash);

            if (_url.StartsWith("http://"))
            {
                //Dictionary<string, string> headers = new Dictionary<string, string>();
                //headers.Add("Content-Type", "application/json");


                UnityWebRequest uwr = new UnityWebRequest(_url, UnityWebRequest.kHttpVerbPOST);
                uwr.uploadHandler   = new UploadHandlerRaw(bytes);
                uwr.downloadHandler = new DownloadHandlerBuffer();
                uwr.SetRequestHeader("Content-Type", "application/json");

                //var www = new WWW( _url, bytes, headers );
                yield return(uwr.SendWebRequest());

                if (uwr.isHttpError || uwr.isNetworkError)
                {
                    UnityEngine.Debug.LogWarning(uwr.error);
                }
            }
            else
            {
                HTTP.Request r = new HTTP.Request("POST", _url, bytes);
                r.headers.Add("Content-Type", "application/json");
                yield return(r.Send());

                if (r.exception != null)
                {
                    UnityEngine.Debug.LogWarning(r.exception.Message);
                }
            }
        }
Ejemplo n.º 10
0
        private static IEnumerator GetRequest(string url, System.Action <bool, string> callback)
        {
            var webService = new HTTP.Request("GET", url);

            yield return(webService.Send());

            if (webService.exception != null)
            {
                Debug.Log(webService.exception);
                if (callback != null)
                {
                    callback(false, webService.exception.Message);
                }
            }
            else
            {
                if (callback != null)
                {
                    callback(true, webService.response.Text);
                }
            }
        }
Ejemplo n.º 11
0
        public static void Upload(ContentMoment moment)
        {
            WWWForm form = moment.ToWWWForm();

            HTTP.Request postRequest = new HTTP.Request("post", GetUrl("/moments"), form);
            postRequest.AddHeader("Authorization", accessToken);

            postRequest.Send((request) => {
                bool result = false;
                try {
                    Hashtable thing = (Hashtable)JSON.JsonDecode(request.response.Text, ref result);
                } catch (NullReferenceException e) {
                    Debug.Log(e.ToString());
                    return;
                }

                if (!result) {
                    Debug.LogWarning("There is something wrong");
                    return;
                }
                Debug.Log("Moment uploaded");
            });
        }
Ejemplo n.º 12
0
        //cacheKey 需要缓存传对应URL 默认为空
        private static void GetData(string cacheKey, string url, JsonData para, Action <string, bool> callback, bool encrypt)
        {
            if (cacheKey != null)
            {
                if (!Cache.CanUpdate(cacheKey) && Cache.getResult(cacheKey) != null)
                {
                    callback(Cache.getResult(cacheKey).ResponseText, true);
                    return;
                }
            }

            if (para == null)
            {
                para = new JsonData();
            }
            url = GetURL(url, para, encrypt);

            HTTP.Request someRequest = new HTTP.Request("get", url);
            someRequest.Send(delegate(HTTP.Request req)
            {
                if (callback != null)
                {
                    if (req.response != null)
                    {
                        callback(new MyHttpResult(req.response.bytes, req.response.status).ResponseText, req.response.status == 200);
                        if (cacheKey != null)
                        {
                            Cache.UpdateRequestCache(cacheKey, new MyHttpResult(req.response.bytes, req.response.status));
                        }
                    }
                    else
                    {
                        callback(new MyHttpResult(null, -1).ResponseText, false);
                    }
                }
            });
        }
Ejemplo n.º 13
0
        /**
         * POST with result parsed as Dictionary<string,object>
         */
        public void POST(string endPoint, Hashtable body, GETDictCallback cb)
        {
            Console.WriteLine(this.baseURL + endPoint);
            HTTP.Request req = new HTTP.Request( "post", this.baseURL + endPoint, body );

            // Add headers
            foreach (DictionaryEntry h in headers) {
                req.AddHeader((string) h.Key, (string) h.Value);
            }

            req.Send( ( request ) => {
                var resObj = Json.Deserialize(request.response.Text) as Dictionary<string, object>;
                cb(resObj);
            });
        }
Ejemplo n.º 14
0
        public void gotoNextStage(Player.Direction dir)
        {
            switch (dir)
            {
            case Player.Direction.EAST:
                nextSpawnDir = PlayerSpawnDir.SPAWN_WEST;
                break;

            case Player.Direction.WEST:
                nextSpawnDir = PlayerSpawnDir.SPAWN_EAST;
                break;

            case Player.Direction.SOUTH:
                nextSpawnDir = PlayerSpawnDir.SPAWN_NORTH;
                break;

            case Player.Direction.NORTH:
                nextSpawnDir = PlayerSpawnDir.SPAWN_SOUTH;
                break;
            }

            Hashtable data = new Hashtable();

            data.Add("entrance", ((int)dir).ToString());
            data.Add("hash", currentStageHash);
            data.Add("username", SystemInfo.deviceUniqueIdentifier);

            string      strHostName = Dns.GetHostName();
            IPHostEntry ipEntry     = Dns.GetHostEntry(strHostName);

            IPAddress[] addr = ipEntry.AddressList;
            data.Add("ip", addr[addr.Length - 1].ToString());

            Debug.Log("Send:");
            foreach (string str in data.Keys)
            {
                Debug.Log(str + ": " + data[str]);
            }

            HTTP.Request req = new HTTP.Request("post", "http://143.248.139.70:8000/randomMapGenerator", data);
            req.Send((request) =>
            {
                Hashtable result = request.response.Object;
                Debug.Log("Result");
                foreach (string str in result.Keys)
                {
                    Debug.Log(str + ": " + result[str]);
                    if ((string)(result[str].ToString()) == "System.Collections.Hashtable")
                    {
                        Hashtable rr = result[str] as Hashtable;
                        foreach (string strstr in rr.Keys)
                        {
                            Debug.Log(strstr + ": " + rr[strstr]);
                        }
                    }
                }
                if (result == null)
                {
                    Debug.LogWarning("Could not parse JSON response!");
                    return;
                }
                else
                {
                    // Receive String from server and generate room
                    Hashtable hashmap = (Hashtable)JSON.JsonDecode(request.response.Text);
                    BoardHolderClear();
                    BoardHolderInit();
                    generateMapAndPlayer(hashmap, nextSpawnDir);
                }
            });
        }
Ejemplo n.º 15
0
        public static IEnumerator PostImageTweet(string text, byte[] image, string consumerKey, string consumerSecret, AccessTokenResponse response, PostTweetCallback callback) {
            if (string.IsNullOrEmpty(text) || text.Length > 140) {
                Debug.Log(string.Format("PostTweet - text[{0}] is empty or too long.", text));

                callback(false);
            } else if (image == null || image.Length == 0) {
                Debug.Log("Missing image.");

                callback(false);
            } else {
                Dictionary<string, string> parameters = new Dictionary<string, string>();
                
                var form = new WWWForm();
                form.AddBinaryData("status", UTF8Encoding.UTF8.GetBytes(text));
                form.AddBinaryData("media[]", image, "anuki.jpg", "application/octet-stream");
                var request = new HTTP.Request(PostImageTweetURL, form);
                request.headers.Add("Authorization", GetHeaderWithAccessToken("POST", PostImageTweetURL, consumerKey, consumerSecret, response, parameters));
                yield return request.Send();
                
                if (request.exception != null) {
                    
                    Debug.Log(string.Format("PostImageTweet - failed:\n" + request.exception.Message));
                    callback(false);
                } else {
                    var txt = request.response.Text;

                    if (txt.Contains("\"errors\":")) {
                        Debug.Log(string.Format("PostImageTweet - failed. {0}", txt));
                        callback(false);
                    } else {
                        Debug.Log("Response: " + txt);
                        callback(true);
                    }
                }
            }
        }
Ejemplo n.º 16
0
        public void gotoNextStage(Player.Direction dir)
        {
            switch (dir)
            {
                case Player.Direction.EAST:
                    nextSpawnDir = PlayerSpawnDir.SPAWN_WEST;
                    break;
                case Player.Direction.WEST:
                    nextSpawnDir = PlayerSpawnDir.SPAWN_EAST;
                    break;
                case Player.Direction.SOUTH:
                    nextSpawnDir = PlayerSpawnDir.SPAWN_NORTH;
                    break;
                case Player.Direction.NORTH:
                    nextSpawnDir = PlayerSpawnDir.SPAWN_SOUTH;
                    break;
            }

            Hashtable data = new Hashtable();
            data.Add("entrance", ((int)dir).ToString());
            data.Add("hash", currentStageHash);
            data.Add("username", SystemInfo.deviceUniqueIdentifier);

            string strHostName = Dns.GetHostName();
            IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
            IPAddress[] addr = ipEntry.AddressList;
            data.Add("ip", addr[addr.Length - 1].ToString());

            Debug.Log("Send:");
            foreach (string str in data.Keys)
            {
                Debug.Log(str + ": " + data[str]);
            }

            HTTP.Request req = new HTTP.Request("post", "http://143.248.139.70:8000/randomMapGenerator", data);
            req.Send((request) =>
            {
                Hashtable result = request.response.Object;
                Debug.Log("Result");
                foreach (string str in result.Keys)
                {
                    Debug.Log(str + ": " + result[str]);
                    if ((string)(result[str].ToString()) == "System.Collections.Hashtable")
                    {
                        Hashtable rr = result[str] as Hashtable;
                        foreach (string strstr in rr.Keys)
                        {
                            Debug.Log(strstr + ": " + rr[strstr]);
                        }
                    }
                }
                if (result == null)
                {
                    Debug.LogWarning("Could not parse JSON response!");
                    return;
                }
                else
                {
                    // Receive String from server and generate room
                    Hashtable hashmap = (Hashtable)JSON.JsonDecode(request.response.Text);
                    BoardHolderClear();
                    BoardHolderInit();
                    generateMapAndPlayer(hashmap, nextSpawnDir);
                }
            });
        }
Ejemplo n.º 17
0
        void BoardSetup()
        {
            Hashtable data = new Hashtable();
            data.Add("username", SystemInfo.deviceUniqueIdentifier);

            string strHostName = Dns.GetHostName();
            IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
            IPAddress[] addr = ipEntry.AddressList;
            data.Add("ip", addr[addr.Length - 1].ToString());

            Debug.Log("Send:");
            foreach (string str in data.Keys)
            {
                Debug.Log(str + ": " + data[str]);
            }

            HTTP.Request req = new HTTP.Request("post", "http://143.248.139.70:8000/login", data);
            req.Send((request) =>
            {
                Hashtable result = request.response.Object;
                Debug.Log("Result");
                foreach (string str in result.Keys)
                {
                    Debug.Log(str + ": " + result[str]);
                    if ((string)(result[str].ToString()) == "System.Collections.Hashtable")
                    {
                        Hashtable rr = result[str] as Hashtable;
                        foreach (string strstr in rr.Keys)
                        {
                            Debug.Log(strstr + ": " + rr[strstr]);
                        }
                    }
                }
                if (result == null)
                {
                    Debug.LogWarning("Could not parse JSON response!");
                    return;
                }
                else
                {
                    // Receive String from server and generate room
                    Hashtable hashmap = (Hashtable)JSON.JsonDecode(request.response.Text);
                    generateMapAndPlayer(hashmap, PlayerSpawnDir.SPAWN_NONE);
                }
            });
        }
Ejemplo n.º 18
0
 public void SendPackage(PackageOut pkg)
 {
     var r = new HTTP.Request("GET", _url, pkg.ToByteArray());
     r.Send(_OnResponse);
     Log.Debug("Socket SendPackage: [" + pkg.code.ToString() + "," + BitConverter.ToString(pkg.GetByteArray(0, pkg.length)) + "]");
 }
Ejemplo n.º 19
0
        public bool sendApiRequest(string request_str, ref JSONNode jsonRes)
        {
            Debug.Log("Request = " + request_str);

            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            data = encoding.GetBytes(request_str);

            Debug.Log("m_url = " + m_url);
            Debug.Log("data = " + data);

            HTTP.Request theRequest = new HTTP.Request("post", m_url, data);
            theRequest.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            theRequest.synchronous = true;
            theRequest.Send();

            Debug.Log("theRequest = " + theRequest);
            if (theRequest.response == null)
            {
                Debug.Log("RESPONSE IS NULL!!!!");
                return(false);
            }
            Debug.Log("theRequest.response = " + theRequest.response);


            string strResp = theRequest.response.Text;

            Debug.Log("Response: (" + theRequest.response.status + "): " + strResp);

            if (theRequest.response.status != 200)
            {
                return(false);
            }

            try {
                jsonRes = JSON.Parse(strResp);
                if (jsonRes == null)
                {
                    Debug.Log("json parse failed");
                    return(false);
                }
            } catch (Exception e) {
                Debug.Log("Json parse Exception: " + e);
                return(false);
            }

            if (jsonRes["error"] == null)
            {
                Debug.Log("No error node!");
                return(false);
            }
            JSONNode error = jsonRes["error"];

            if ((error["success"] == null) || (error["success"].AsBool == false))
            {
                Debug.Log("json success is false");
                m_errorMsg = error["message"].Value;
                return(false);
            }

            return(true);
        }
Ejemplo n.º 20
0
        IEnumerator _GetRemoteBundlesInfoFileCoroutine(string url, System.Action <bool> action, GameObject target)
        {
#if USE_LOCAL_ABINFO //使用本地AB依赖包的配制信息表
            string    textPath  = "BundleShipInfo";
            TextAsset textAsset = Resources.Load <TextAsset>(textPath);
            if (textAsset == null)
            {
                EB.Debug.LogErrorFormat("使用读取本地依赖AB包信息表,发现指定不存在相应的文件textPath:{0}", textPath);
                yield break;
            }
            else
            {
                EB.Debug.LogFormat("使用本地AB依赖包的配制信息表,相应的文件textPath:{0}", textPath);
            }
            ParseRemoteBundlesInfoFile(textAsset.text);
            isReady   = true;
            isGetting = false;
            AssetUtils.DoAction(action, true, target);
            yield break;
#endif
            yield return(null);

            if (!AssetUtils.LoadFromLocalFile(url))
            {
                HTTP.Request r = new HTTP.Request("GET", url);
                r.acceptGzip       = true;
                r.useCache         = false;
                r.maximumRedirects = 2;

                EB.Debug.Log("Getting Remote Bundles Info File from: {0}", url);

                yield return(r.Send());

                if (r.exception != null)
                {
                    isReady   = false;
                    isGetting = false;
                    EB.Debug.LogWarning("CAN NOT fetch scene description file from {0}, error = {1}", url, r.exception.Message);
                    AssetUtils.DoAction(action, false, target);
                }
                else
                {
                    if (r.response.status == 404)
                    {
                        EB.Debug.LogError("HTTP 404 error when gettings file from url: {0}", url);
                    }
                    else
                    {
                        EB.Debug.Log("_GetRemoteBundlesInfoFileCoroutine: success, length = {0}", r.response.Text.Length);
#if UNITY_EDITOR || UNITY_IOS
                        byte[] data = r.response.Bytes;
                        ParseRemoteBundlesInfoFile(data);
#else
                        string data = r.response.Text;
                        ParseRemoteBundlesInfoFile(data);
#endif
                        GM.AssetManager.ResetDownloaBundleSize();
                        isReady   = true;
                        isGetting = false;
                        if (data != null)
                        {
                            int gid = System.GC.GetGeneration(data);
                            data = null;
                            System.GC.Collect(gid);
                        }
                        AssetUtils.DoAction(action, true, target);
                    }
                }
            }
            else
            {
                UnityWebRequest request = UnityWebRequest.Get(url);
                EB.Debug.Log("Getting Remote Bundles Info File from: {0}", url);
                yield return(request.SendWebRequest());

                if (request.isHttpError || request.isNetworkError)
                {
                    isReady   = false;
                    isGetting = false;
                    EB.Debug.LogError("CAN NOT fetch scene description file from {0}, error = {1}", url, request.error);
                    AssetUtils.DoAction(action, false, target);
                }
                else
                {
                    //EB.Debug.Log("_GetRemoteBundlesInfoFileCoroutine: success, length = {0}", request.downloadHandler.text.Length);
#if UNITY_EDITOR || UNITY_IOS
                    byte[] data = request.downloadHandler.data;
                    ParseRemoteBundlesInfoFile(data);
#else
                    string data = request.downloadHandler.text;
                    ParseRemoteBundlesInfoFile(data);
#endif
                    GM.AssetManager.ResetDownloaBundleSize();
                    isReady   = true;
                    isGetting = false;
                    if (data != null)
                    {
                        int gid = System.GC.GetGeneration(data);
                        data = null;
                        System.GC.Collect(gid);
                    }
                    AssetUtils.DoAction(action, true, target);
                }
                request.Dispose();
                request = null;
                yield return(true);
            }
        }