コード例 #1
0
        private static void ProcessJsonResponse(CallRequestContainer reqContainer)
        {
            try {
                var serializer = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer);
                var httpResult = serializer.DeserializeObject <HttpResponseObject>(reqContainer.JsonResponse);

#if PLAYFAB_REQUEST_TIMING
                reqContainer.Timing.WorkerRequestMs = (int)reqContainer.Stopwatch.ElapsedMilliseconds;
#endif

                //This would happen if playfab returned a 500 internal server error or a bad json response.
                if (httpResult == null || httpResult.code != 200)
                {
                    QueueRequestError(reqContainer);
                    return;
                }

                reqContainer.JsonResponse = serializer.SerializeObject(httpResult.data);
                reqContainer.DeserializeResultJson(); // Assigns Result with a properly typed object
                reqContainer.ApiResult.Request    = reqContainer.ApiRequest;
                reqContainer.ApiResult.CustomData = reqContainer.CustomData;

                PlayFabHttp.instance.OnPlayFabApiResult(reqContainer);

#if !DISABLE_PLAYFABCLIENT_API
                lock (ResultQueueTransferThread) {
                    ResultQueueTransferThread.Enqueue(() => {
                        PlayFabDeviceUtil.OnPlayFabLogin(reqContainer.ApiResult, reqContainer.settings, reqContainer.instanceApi);
                    });
                }
#endif
                lock (ResultQueueTransferThread) {
                    //Queue The result callbacks to run on the main thread.
                    ResultQueueTransferThread.Enqueue(() => {
#if PLAYFAB_REQUEST_TIMING
                        reqContainer.Stopwatch.Stop();
                        reqContainer.Timing.MainThreadRequestMs = (int)reqContainer.Stopwatch.ElapsedMilliseconds;
                        PlayFabHttp.SendRequestTiming(reqContainer.Timing);
#endif
                        try {
                            PlayFabHttp.SendEvent(reqContainer.ApiEndpoint, reqContainer.ApiRequest, reqContainer.ApiResult,
                                                  ApiProcessingEventType.Post);
                            reqContainer.InvokeSuccessCallback();
                        }
                        catch (Exception e) {
                            Debug.LogException(e); // Log the user's callback exception back to them without halting PlayFabHttp
                        }
                    });
                }
            }
            catch (Exception e) {
                var msg = "Unhandled exception in ProcessJsonResponse : " + reqContainer.FullUrl;
                reqContainer.JsonResponse = reqContainer.JsonResponse ?? msg;
                var enhancedError = new Exception(msg, e);
                Debug.LogException(enhancedError);
                QueueRequestError(reqContainer);
            }
        }
コード例 #2
0
        public void OnResponse(string response, CallRequestContainer reqContainer)
        {
            try
            {
#if PLAYFAB_REQUEST_TIMING
                var startTime = DateTime.UtcNow;
#endif
                var serializer = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer);
                var httpResult = serializer.DeserializeObject <HttpResponseObject>(response);

                if (httpResult.code == 200)
                {
                    // We have a good response from the server
                    reqContainer.JsonResponse = serializer.SerializeObject(httpResult.data);
                    reqContainer.DeserializeResultJson();
                    reqContainer.ApiResult.Request    = reqContainer.ApiRequest;
                    reqContainer.ApiResult.CustomData = reqContainer.CustomData;

                    PlayFabHttp.instance.OnPlayFabApiResult(reqContainer.ApiResult);
#if !DISABLE_PLAYFABCLIENT_API
                    PlayFabDeviceUtil.OnPlayFabLogin(reqContainer.ApiResult);
#endif
                    try
                    {
                        PlayFabHttp.SendEvent(reqContainer.ApiEndpoint, reqContainer.ApiRequest, reqContainer.ApiResult,
                                              ApiProcessingEventType.Post);
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e);
                    }

                    try
                    {
                        reqContainer.InvokeSuccessCallback();
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e);
                    }
                }
                else
                {
                    if (reqContainer.ErrorCallback != null)
                    {
                        reqContainer.Error = PlayFabHttp.GeneratePlayFabError(reqContainer.ApiEndpoint, response, reqContainer.CustomData);
                        PlayFabHttp.SendErrorEvent(reqContainer.ApiRequest, reqContainer.Error);
                        reqContainer.ErrorCallback(reqContainer.Error);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }
コード例 #3
0
 private static void GetAdvertIdFromUnity()
 {
     Application.RequestAdvertisingIdentifierAsync(delegate(string advertisingId, bool trackingEnabled, string error)
     {
         PlayFabSettings.DisableAdvertising = !trackingEnabled;
         if (!trackingEnabled)
         {
             return;
         }
         PlayFabSettings.AdvertisingIdType  = "Adid";
         PlayFabSettings.AdvertisingIdValue = advertisingId;
         PlayFabDeviceUtil.DoAttributeInstall();
     });
 }
コード例 #4
0
ファイル: PlayFabWebRequest.cs プロジェクト: mrdivdiz/bpvita
        private static void ProcessJsonResponse(CallRequestContainer reqContainer)
        {
            try
            {
                HttpResponseObject httpResponseObject = JsonWrapper.DeserializeObject <HttpResponseObject>(reqContainer.JsonResponse);
                if (httpResponseObject == null || httpResponseObject.code != 200)
                {
                    PlayFabWebRequest.QueueRequestError(reqContainer);
                }
                else
                {
                    reqContainer.JsonResponse = JsonWrapper.SerializeObject(httpResponseObject.data);
                    reqContainer.DeserializeResultJson();
                    reqContainer.ApiResult.Request    = reqContainer.ApiRequest;
                    reqContainer.ApiResult.CustomData = reqContainer.CustomData;
                    SingletonMonoBehaviour <PlayFabHttp> .instance.OnPlayFabApiResult(reqContainer.ApiResult);

                    object resultQueue = PlayFabWebRequest.ResultQueue;
                    lock (resultQueue)
                    {
                        PlayFabWebRequest.ResultQueue.Enqueue(delegate
                        {
                            PlayFabDeviceUtil.OnPlayFabLogin(reqContainer.ApiResult);
                        });
                    }
                    object resultQueue2 = PlayFabWebRequest.ResultQueue;
                    lock (resultQueue2)
                    {
                        PlayFabWebRequest.ResultQueue.Enqueue(delegate
                        {
                            try
                            {
                                PlayFabHttp.SendEvent(reqContainer.ApiEndpoint, reqContainer.ApiRequest, reqContainer.ApiResult, ApiProcessingEventType.Post);
                                reqContainer.InvokeSuccessCallback();
                            }
                            catch (Exception ex2)
                            {
                            }
                        });
                    }
                }
            }
            catch (Exception innerException)
            {
                string text = "Unhandled exception in ProcessJsonResponse : " + reqContainer.FullUrl;
                reqContainer.JsonResponse = (reqContainer.JsonResponse ?? text);
                Exception ex = new Exception(text, innerException);
                PlayFabWebRequest.QueueRequestError(reqContainer);
            }
        }
コード例 #5
0
ファイル: PlayFabUnityHttp.cs プロジェクト: mrdivdiz/bpvita
        public void OnResponse(string response, CallRequestContainer reqContainer)
        {
            try
            {
                HttpResponseObject httpResponseObject = JsonWrapper.DeserializeObject <HttpResponseObject>(response);
                if (httpResponseObject.code == 200)
                {
                    reqContainer.JsonResponse = JsonWrapper.SerializeObject(httpResponseObject.data);
                    reqContainer.DeserializeResultJson();
                    reqContainer.ApiResult.Request    = reqContainer.ApiRequest;
                    reqContainer.ApiResult.CustomData = reqContainer.CustomData;
                    SingletonMonoBehaviour <PlayFabHttp> .instance.OnPlayFabApiResult(reqContainer.ApiResult);

                    PlayFabDeviceUtil.OnPlayFabLogin(reqContainer.ApiResult);
                    try
                    {
                        PlayFabHttp.SendEvent(reqContainer.ApiEndpoint, reqContainer.ApiRequest, reqContainer.ApiResult, ApiProcessingEventType.Post);
                    }
                    catch (Exception ex)
                    {
                    }
                    try
                    {
                        reqContainer.InvokeSuccessCallback();
                    }
                    catch (Exception ex2)
                    {
                    }
                }
                else if (reqContainer.ErrorCallback != null)
                {
                    reqContainer.Error = PlayFabHttp.GeneratePlayFabError(reqContainer.ApiEndpoint, response, reqContainer.CustomData);
                    PlayFabHttp.SendErrorEvent(reqContainer.ApiRequest, reqContainer.Error);
                    reqContainer.ErrorCallback(reqContainer.Error);
                }
            }
            catch (Exception ex3)
            {
            }
        }
コード例 #6
0
        public static void OnPlayFabLogin(PlayFabResultCommon result)
        {
            LoginResult loginResult = result as LoginResult;
            RegisterPlayFabUserResult registerPlayFabUserResult = result as RegisterPlayFabUserResult;

            if (loginResult == null && registerPlayFabUserResult == null)
            {
                return;
            }
            PlayFabDeviceUtil._needsAttribution = false;
            PlayFabDeviceUtil._gatherInfo       = false;
            if (loginResult != null && loginResult.SettingsForUser != null)
            {
                PlayFabDeviceUtil._needsAttribution = loginResult.SettingsForUser.NeedsAttribution;
            }
            else if (registerPlayFabUserResult != null && registerPlayFabUserResult.SettingsForUser != null)
            {
                PlayFabDeviceUtil._needsAttribution = registerPlayFabUserResult.SettingsForUser.NeedsAttribution;
            }
            if (loginResult != null && loginResult.SettingsForUser != null)
            {
                PlayFabDeviceUtil._gatherInfo = loginResult.SettingsForUser.GatherDeviceInfo;
            }
            else if (registerPlayFabUserResult != null && registerPlayFabUserResult.SettingsForUser != null)
            {
                PlayFabDeviceUtil._gatherInfo = registerPlayFabUserResult.SettingsForUser.GatherDeviceInfo;
            }
            if (PlayFabSettings.AdvertisingIdType != null && PlayFabSettings.AdvertisingIdValue != null)
            {
                PlayFabDeviceUtil.DoAttributeInstall();
            }
            else
            {
                PlayFabDeviceUtil.GetAdvertIdFromUnity();
            }
            PlayFabDeviceUtil.SendDeviceInfoToPlayFab();
        }
コード例 #7
0
ファイル: PlayFabWWW.cs プロジェクト: Feras94/WarZone-2.0
        public void MakeApiCall(CallRequestContainer reqContainer)
        {
            reqContainer.RequestHeaders["Content-Type"] = "application/json";

#if !UNITY_WSA && !UNITY_WP8 && !UNITY_WEBGL
            if (PlayFabSettings.CompressApiData)
            {
                reqContainer.RequestHeaders["Content-Encoding"] = "GZIP";
                reqContainer.RequestHeaders["Accept-Encoding"]  = "GZIP";

                using (var stream = new MemoryStream())
                {
                    using (var zipstream = new GZipStream(stream, CompressionMode.Compress, CompressionLevel.BestCompression))
                    {
                        zipstream.Write(reqContainer.Payload, 0, reqContainer.Payload.Length);
                    }
                    reqContainer.Payload = stream.ToArray();
                }
            }
#endif

            //Debug.LogFormat("Posting {0} to Url: {1}", req.Trim(), url);
            var www = new WWW(reqContainer.FullUrl, reqContainer.Payload, reqContainer.RequestHeaders);

#if PLAYFAB_REQUEST_TIMING
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();
#endif

            // Start the www corouting to Post, and get a response or error which is then passed to the callbacks.
            Action <string> wwwSuccessCallback = (response) =>
            {
                try
                {
#if PLAYFAB_REQUEST_TIMING
                    var startTime = DateTime.UtcNow;
#endif
                    var httpResult = JsonWrapper.DeserializeObject <HttpResponseObject>(response);

                    if (httpResult.code == 200)
                    {
                        // We have a good response from the server
                        reqContainer.JsonResponse = JsonWrapper.SerializeObject(httpResult.data);
                        reqContainer.DeserializeResultJson();
                        reqContainer.ApiResult.Request    = reqContainer.ApiRequest;
                        reqContainer.ApiResult.CustomData = reqContainer.CustomData;

                        PlayFabHttp.instance.OnPlayFabApiResult(reqContainer.ApiResult);
#if !DISABLE_PLAYFABCLIENT_API
                        PlayFabDeviceUtil.OnPlayFabLogin(reqContainer.ApiResult);
#endif

                        try
                        {
                            PlayFabHttp.SendEvent(reqContainer.ApiEndpoint, reqContainer.ApiRequest, reqContainer.ApiResult, ApiProcessingEventType.Post);
                        }
                        catch (Exception e)
                        {
                            Debug.LogException(e);
                        }

#if PLAYFAB_REQUEST_TIMING
                        stopwatch.Stop();
                        var timing = new PlayFabHttp.RequestTiming {
                            StartTimeUtc        = startTime,
                            ApiEndpoint         = reqContainer.ApiEndpoint,
                            WorkerRequestMs     = (int)stopwatch.ElapsedMilliseconds,
                            MainThreadRequestMs = (int)stopwatch.ElapsedMilliseconds
                        };
                        PlayFabHttp.SendRequestTiming(timing);
#endif
                        try
                        {
                            reqContainer.InvokeSuccessCallback();
                        }
                        catch (Exception e)
                        {
                            Debug.LogException(e);
                        }
                    }
                    else
                    {
                        if (reqContainer.ErrorCallback != null)
                        {
                            reqContainer.Error = PlayFabHttp.GeneratePlayFabError(reqContainer.ApiEndpoint, response, reqContainer.CustomData);
                            PlayFabHttp.SendErrorEvent(reqContainer.ApiRequest, reqContainer.Error);
                            reqContainer.ErrorCallback(reqContainer.Error);
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
            };

            Action <string> wwwErrorCallback = (errorCb) =>
            {
                reqContainer.JsonResponse = errorCb;
                if (reqContainer.ErrorCallback != null)
                {
                    reqContainer.Error = PlayFabHttp.GeneratePlayFabError(reqContainer.ApiEndpoint, reqContainer.JsonResponse, reqContainer.CustomData);
                    PlayFabHttp.SendErrorEvent(reqContainer.ApiRequest, reqContainer.Error);
                    reqContainer.ErrorCallback(reqContainer.Error);
                }
            };

            PlayFabHttp.instance.StartCoroutine(PostPlayFabApiCall(www, wwwSuccessCallback, wwwErrorCallback));
        }
コード例 #8
0
ファイル: PlayFabWww.cs プロジェクト: mrdivdiz/bpvita
        public void MakeApiCall(CallRequestContainer reqContainer)
        {
            reqContainer.RequestHeaders["Content-Type"] = "application/json";
            if (PlayFabSettings.CompressApiData)
            {
                reqContainer.RequestHeaders["Content-Encoding"] = "GZIP";
                reqContainer.RequestHeaders["Accept-Encoding"]  = "GZIP";
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    using (GZipStream gzipStream = new GZipStream(memoryStream, CompressionMode.Compress, Ionic.Zlib.CompressionLevel.BestCompression))
                    {
                        gzipStream.Write(reqContainer.Payload, 0, reqContainer.Payload.Length);
                    }
                    reqContainer.Payload = memoryStream.ToArray();
                }
            }
            WWW             www = new WWW(reqContainer.FullUrl, reqContainer.Payload, reqContainer.RequestHeaders);
            Action <string> wwwSuccessCallback = delegate(string response)
            {
                try
                {
                    HttpResponseObject httpResponseObject = JsonWrapper.DeserializeObject <HttpResponseObject>(response);
                    if (httpResponseObject.code == 200)
                    {
                        reqContainer.JsonResponse = JsonWrapper.SerializeObject(httpResponseObject.data);
                        reqContainer.DeserializeResultJson();
                        reqContainer.ApiResult.Request    = reqContainer.ApiRequest;
                        reqContainer.ApiResult.CustomData = reqContainer.CustomData;
                        SingletonMonoBehaviour <PlayFabHttp> .instance.OnPlayFabApiResult(reqContainer.ApiResult);

                        PlayFabDeviceUtil.OnPlayFabLogin(reqContainer.ApiResult);
                        try
                        {
                            PlayFabHttp.SendEvent(reqContainer.ApiEndpoint, reqContainer.ApiRequest, reqContainer.ApiResult, ApiProcessingEventType.Post);
                        }
                        catch (Exception ex)
                        {
                        }
                        try
                        {
                            reqContainer.InvokeSuccessCallback();
                        }
                        catch (Exception ex2)
                        {
                        }
                    }
                    else if (reqContainer.ErrorCallback != null)
                    {
                        reqContainer.Error = PlayFabHttp.GeneratePlayFabError(reqContainer.ApiEndpoint, response, reqContainer.CustomData);
                        PlayFabHttp.SendErrorEvent(reqContainer.ApiRequest, reqContainer.Error);
                        reqContainer.ErrorCallback(reqContainer.Error);
                    }
                }
                catch (Exception ex3)
                {
                }
            };
            Action <string> wwwErrorCallback = delegate(string errorCb)
            {
                reqContainer.JsonResponse = errorCb;
                if (reqContainer.ErrorCallback != null)
                {
                    reqContainer.Error = PlayFabHttp.GeneratePlayFabError(reqContainer.ApiEndpoint, reqContainer.JsonResponse, reqContainer.CustomData);
                    PlayFabHttp.SendErrorEvent(reqContainer.ApiRequest, reqContainer.Error);
                    reqContainer.ErrorCallback(reqContainer.Error);
                }
            };

            SingletonMonoBehaviour <PlayFabHttp> .instance.StartCoroutine(this.PostPlayFabApiCall(www, wwwSuccessCallback, wwwErrorCallback));
        }
コード例 #9
0
ファイル: PlayFabWWW.cs プロジェクト: MizunagiKB/SDKGenerator
        public void MakeApiCall(object reqContainerObj)
        {
            CallRequestContainer reqContainer = (CallRequestContainer)reqContainerObj;

            reqContainer.RequestHeaders["Content-Type"] = "application/json";

            //Debug.LogFormat("Posting {0} to Url: {1}", req.Trim(), url);
            var www = new WWW(reqContainer.FullUrl, reqContainer.Payload, reqContainer.RequestHeaders);

#if PLAYFAB_REQUEST_TIMING
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();
#endif

            // Start the www corouting to Post, and get a response or error which is then passed to the callbacks.
            Action <string> wwwSuccessCallback = (response) =>
            {
                try
                {
#if PLAYFAB_REQUEST_TIMING
                    var startTime = DateTime.UtcNow;
#endif
                    var serializer = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer);
                    var httpResult = serializer.DeserializeObject <HttpResponseObject>(response);

                    if (httpResult.code == 200)
                    {
                        // We have a good response from the server
                        reqContainer.JsonResponse = serializer.SerializeObject(httpResult.data);
                        reqContainer.DeserializeResultJson();
                        reqContainer.ApiResult.Request    = reqContainer.ApiRequest;
                        reqContainer.ApiResult.CustomData = reqContainer.CustomData;

                        PlayFabHttp.instance.OnPlayFabApiResult(reqContainer);
#if !DISABLE_PLAYFABCLIENT_API
                        PlayFabDeviceUtil.OnPlayFabLogin(reqContainer.ApiResult, reqContainer.settings, reqContainer.instanceApi);
#endif

                        try
                        {
                            PlayFabHttp.SendEvent(reqContainer.ApiEndpoint, reqContainer.ApiRequest, reqContainer.ApiResult, ApiProcessingEventType.Post);
                        }
                        catch (Exception e)
                        {
                            Debug.LogException(e);
                        }

#if PLAYFAB_REQUEST_TIMING
                        stopwatch.Stop();
                        var timing = new PlayFabHttp.RequestTiming {
                            StartTimeUtc        = startTime,
                            ApiEndpoint         = reqContainer.ApiEndpoint,
                            WorkerRequestMs     = (int)stopwatch.ElapsedMilliseconds,
                            MainThreadRequestMs = (int)stopwatch.ElapsedMilliseconds
                        };
                        PlayFabHttp.SendRequestTiming(timing);
#endif
                        try
                        {
                            reqContainer.InvokeSuccessCallback();
                        }
                        catch (Exception e)
                        {
                            Debug.LogException(e);
                        }
                    }
                    else
                    {
                        if (reqContainer.ErrorCallback != null)
                        {
                            reqContainer.Error = PlayFabHttp.GeneratePlayFabError(reqContainer.ApiEndpoint, response, reqContainer.CustomData);
                            PlayFabHttp.SendErrorEvent(reqContainer.ApiRequest, reqContainer.Error);
                            reqContainer.ErrorCallback(reqContainer.Error);
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
            };

            Action <string> wwwErrorCallback = (errorCb) =>
            {
                reqContainer.JsonResponse = errorCb;
                if (reqContainer.ErrorCallback != null)
                {
                    reqContainer.Error = PlayFabHttp.GeneratePlayFabError(reqContainer.ApiEndpoint, reqContainer.JsonResponse, reqContainer.CustomData);
                    PlayFabHttp.SendErrorEvent(reqContainer.ApiRequest, reqContainer.Error);
                    reqContainer.ErrorCallback(reqContainer.Error);
                }
            };

            PlayFabHttp.instance.StartCoroutine(PostPlayFabApiCall(www, wwwSuccessCallback, wwwErrorCallback));
        }