예제 #1
0
 /// <summary>
 /// Reads the Json response and applies it to local properties.
 /// </summary>
 /// <param name="result"></param>
 private AccountServiceResponse ParseResult(string result)
 {
     try
     {
         AccountServiceResponse res = JsonUtility.FromJson <AccountServiceResponse>(result);
         // Unity's JsonUtility does not support deserializing Dictionary, we manually parse it, dirty & ugly af, better then using a 3rd party lib
         if (res.ReturnCode == AccountServiceReturnCodes.Success)
         {
             string[] parts = result.Split(new[] { "\"ApplicationIds\":{" }, StringSplitOptions.RemoveEmptyEntries);
             parts = parts[1].Split('}');
             string applicationIds = parts[0];
             if (!string.IsNullOrEmpty(applicationIds))
             {
                 parts = applicationIds.Split(new[] { ',', '"', ':' }, StringSplitOptions.RemoveEmptyEntries);
                 res.ApplicationIds = new Dictionary <string, string>(parts.Length / 2);
                 for (int i = 0; i < parts.Length; i = i + 2)
                 {
                     res.ApplicationIds.Add(parts[i], parts[i + 1]);
                 }
             }
         }
         return(res);
     }
     catch (Exception ex) // probably JSON parsing exception, check if returned string is valid JSON
     {
         Debug.LogException(ex);
         return(null);
     }
 }
예제 #2
0
 public bool RegisterByEmail(AccountServiceRequest request, Action <AccountServiceResponse> callback = null, Action <string> errorCallback = null)
 {
     if (request == null)
     {
         Debug.LogError("Registration request is null");
         return(false);
     }
     PhotonEditorUtils.StartCoroutine(
         PhotonEditorUtils.HttpPost(GetUrlWithQueryStringEscaped(request),
                                    RequestHeaders,
                                    null,
                                    s =>
     {
         if (string.IsNullOrEmpty(s))
         {
             if (errorCallback != null)
             {
                 errorCallback("Server's response was empty. Please register through account website during this service interruption.");
             }
         }
         else
         {
             AccountServiceResponse ase = this.ParseResult(s);
             if (ase == null)
             {
                 if (errorCallback != null)
                 {
                     errorCallback("Error parsing registration response. Please try registering from account website");
                 }
             }
             else if (callback != null)
             {
                 callback(ase);
             }
         }
     },
                                    e =>
     {
         if (errorCallback != null)
         {
             errorCallback(e);
         }
     })
         );
     return(true);
 }
예제 #3
0
        /// <summary>
        /// Reads the Json response and applies it to local properties.
        /// </summary>
        /// <param name="result"></param>
        private void ParseResult(string result)
        {
            if (string.IsNullOrEmpty(result))
            {
                this.Message = "Server's response was empty. Please register through account website during this service interruption.";
                return;
            }

            try
            {
                AccountServiceResponse res = UnityEngine.JsonUtility.FromJson <AccountServiceResponse>(result);
                this.ReturnCode = res.ReturnCode;
                this.Message    = res.Message;
                if (this.ReturnCode == 0)
                {
                    // returnCode == 0 means: all ok. message is new AppId
                    this.AppId = this.Message;
                    if (PhotonEditorUtils.HasVoice)
                    {
                        this.AppId2 = res.MessageDetailed;
                    }
                }
                else
                {
                    // any error gives returnCode != 0
                    this.AppId = string.Empty;
                    if (PhotonEditorUtils.HasVoice)
                    {
                        this.AppId2 = string.Empty;
                    }
                }
            }
            catch (Exception ex) // probably JSON parsing exception, check if returned string is valid JSON
            {
                this.ReturnCode = -1;
                this.Message    = ex.Message;
            }
        }