コード例 #1
0
 public void Update(object data)
 {
     UserId    = new Id(Dot.Find <object>("uid", data));
     FirstName = Dot.String("first_name", data, FirstName);
     LastName  = Dot.String("last_name", data, LastName);
     IsAppUser = Dot.Bool("is_app_user", data, IsAppUser);
     Email     = Dot.String("email", data, string.Empty);
     Locale    = Dot.String("locale", data, string.Empty);
 }
コード例 #2
0
 public GameWorld(object world)
 {
     Id       = Dot.Integer("WID", world, Id);
     State    = (eState)EB.Dot.Integer("State", world, (int)State);
     Name     = Dot.String("WName", world, Name);
     Default  = Dot.Bool("Default", world, Default);
     P1       = Dot.Integer("P1", world, P1);
     OpenTime = Dot.Integer("openTime", world, OpenTime);
 }
コード例 #3
0
        IEnumerator Fetch(Request req)
        {
            var res = new Response(req);

            // check memory
            if ((System.DateTime.Now - _lastMemoryCheck).TotalSeconds > 2)
            {
                EB.Memory.Update(10000);
                _lastMemoryCheck = System.DateTime.Now;
            }

            int kNumRetries = Mathf.Max(req.numRetries, 0);

            for (int i = 0; i <= kNumRetries; ++i)
            {
                // wait and try again
                if (i > 0)
                {
                    yield return(new WaitForSeconds(Mathf.Pow(2.0f, i)));
                }

                if (HasInternetConnectivity == false)
                {
                    EB.Debug.Log("No internet connectivity");
                    res.error = "ID_SPARX_ERROR_NOT_CONNECTED";
                    res.fatal = true;
                    break;
                }

                // check for hacks
                if (SafeValue.Breach || Memory.Breach)
                {
                    res.fatal = true;
                    res.error = "ID_SPARX_ERROR_UNKNOWN";
                    break;
                }

                //EB.Debug.Log("Fetch: start {0}", req.url);
                Net.WebRequest www = Generate(req, i);
                //EB.Debug.Log("Fetch: generate {0}", req.url);
                while (!www.isDone)
                {
                    //EB.Debug.Log("Fetch: wait {0}", req.url);
                    yield return(null);
                }


                System.DateTime parseStartTime = System.DateTime.Now;

                res.timeTaken = www.responseTime;
                string error = www.error;

                // suspend request
                if (req.suspend)
                {
                    req.suspend = false;

                    if (req.suspendMethod == Request.eSuspendMethod.Retry)
                    {
                        if (!string.IsNullOrEmpty(error))
                        {
                            EB.Debug.LogWarning("Fetch: retry suspend request {0}, error = {1}", req.url, error);
                            ++kNumRetries;
                            continue;
                        }
                        else
                        {
                            EB.Debug.LogWarning("Fetch: suspend request was done {0}, (ziped)length = {1}", req.url, www.bytesRecieved);
                        }
                    }
                    else
                    {
                        EB.Debug.LogWarning("Fetch: ignore suspend request {0}", req.url);
                        _doneId  = req.id;
                        _current = null;
                        ServiceNext();
                        yield break;
                    }
                }

                if (string.IsNullOrEmpty(error) && req.dataCallback != null)
                {
                    res.sucessful    = true;
                    res.fatal        = false;
                    res.sessionError = false;
                    break;
                }
                else if (string.IsNullOrEmpty(error) && www.bytesRecieved > 0)
                {
                    res.result = null;
                    res.error  = null;

                    string cookie = www.GetResponseHeader("set-cookie");
                    if (!string.IsNullOrEmpty(cookie))
                    {
                        _cookie = cookie;
                    }

                    string contentType = www.GetResponseHeader("Content-Type");
                    if (contentType.IndexOf("application/json") != -1)
                    {
                        yield return(null);

                        string text = www.text;
                        res.text = text ?? string.Empty;
                        if (res.text.Length > 1024 * 100)
                        {
                            EB.Debug.LogWarning("Package size is bigger than 100K!");
                        }
                        else
                        {
                            EB.Debug.Log("<color=#ff6699>[Result]</color>: {0}", res.text);
                        }

                        try
                        {
                            object obj = JSON.Parse(res.text);
                            if (obj == null)
                            {
                                res.error = "Failed to decode json: " + res.text;
                            }
                            else
                            {
                                if (obj is Hashtable)
                                {
                                    Hashtable response = obj as Hashtable;
                                    res.result = response["result"];
                                    res.error  = response["err"] as string;
                                    res.async  = response["async"];
                                    res.msg    = response["msg"] as string;
                                    // update time
                                    Time.Now = Dot.Integer("ts", response, Time.Now);

                                    _lastActivity = Time.Now;
                                }
                                else
                                {
                                    res.error = "Obj is " + obj.ToString();
                                }
                            }
                        }
                        catch (System.Exception ex)
                        {
                            EB.Debug.LogWarning("failed to decode www " + ex);
                            res.error = ex.ToString();
                        }

                        if (res.result != null)
                        {
                            if (res.result is Hashtable)
                            {
                                res.hashtable = res.result as Hashtable;
                            }
                            else if (res.result is ArrayList)
                            {
                                res.arrayList = res.result as ArrayList;
                            }
                            else if (res.result is double)
                            {
                                res.number = (double)res.result;
                            }
                            else if (res.result is string)
                            {
                                res.str = res.result as string;
                            }
                        }
                    }
                    else if (contentType.IndexOf("application/octet-stream") != -1)
                    {
                        res.bytes = www.bytes;
                    }


                    var parseDelta = System.DateTime.Now - parseStartTime;
                    EB.Debug.LogIf(www.overallElapsed > 100 || parseDelta.TotalMilliseconds > 30,
                                   "Fetch: request {0} responseTime = {1} overallElapsed = {2} parse = {3} milliseconds",
                                   req.url,
                                   www.responseTime,
                                   www.overallElapsed,
                                   parseDelta.TotalMilliseconds);


                    if (res.error == null)
                    {
                        res.sucessful    = true;
                        res.fatal        = false;
                        res.sessionError = false;
                        break;
                    }

                    res.fatal        = Dot.Bool("fatal", res.hashtable, true);
                    res.sessionError = Dot.Bool("invalid_session", res.hashtable, false);
                    bool retry = Dot.Bool("retry", res.hashtable, true);
                    if (!retry)
                    {
                        // EB.Debug.LogWarning("skipping retry");
                        break;
                    }
                }
                // JEH - moved what was here, up there
                else
                {
                    if (www.statusCode != 0)
                    {
                        PrintError(req, www);
                    }

                    if (string.IsNullOrEmpty(error))
                    {
                        res.error = "unknown";
                    }
                    else
                    {
#if DEBUG
                        res.error = string.Format("^{0}\nError: {1}", Localizer.GetString("ID_SPARX_NETWORK_ERROR"), error);
#else
                        res.error = "ID_SPARX_NETWORK_ERROR";
#endif
                    }
                    res.fatal = true;

                    // if this is a client error, then don't retry
                    if (www.statusCode >= 400 && www.statusCode <= 499 || www.error.Equals("EndWrite failure"))
                    {
                        break;
                    }
                }
            }

            OnComplete(res);
        }