예제 #1
0
        internal void NotifyFailed()
        {
            #if DEBUG
            if (GlobalSettings.LOG_ALL_WEBREQUESTS &&
                error != null)
            {
                WebRequestError.LogAsWarning(error);
            }
            #endif

            if (failed != null)
            {
                failed(this);
            }
        }
예제 #2
0
        private static void OnModBinaryRequestCompleted(ModfileIdPair idPair)
        {
            FileDownloadInfo downloadInfo = DownloadClient.modfileDownloadMap[idPair];
            UnityWebRequest  request      = downloadInfo.request;
            bool             succeeded    = false;

            downloadInfo.isDone         = true;
            downloadInfo.bytesPerSecond = 0;

            if (request.isNetworkError || request.isHttpError)
            {
                if (request.error.ToUpper() == "USER ABORTED" ||
                    request.error.ToUpper() == "REQUEST ABORTED")
                {
                    #if DEBUG
                    if (PluginSettings.data.logAllRequests)
                    {
                        Debug.Log("DOWNLOAD ABORTED"
                                  + "\nDownload aborted at: " + ServerTimeStamp.Now
                                  + "\nURL: " + request.url);
                    }
                    #endif

                    downloadInfo.wasAborted = true;
                }

                // NOTE(@jackson): This workaround addresses an issue in UnityWebRequests on the
                //  PS4 whereby redirects fail in specific cases. Special thanks to @Eamon of
                //  Spiderling Studios (http://spiderlinggames.co.uk/)
                #if UNITY_PS4
                else if (downloadInfo.error.responseCode == 302) // Redirect limit exceeded
                {
                    string headerLocation = string.Empty;
                    if (downloadInfo.error.responseHeaders.TryGetValue("location", out headerLocation) &&
                        !request.url.Equals(headerLocation))
                    {
                        if (PluginSettings.data.logAllRequests)
                        {
                            Debug.LogFormat("CAUGHT DOWNLOAD REDIRECTION\nURL: {0}", headerLocation);
                        }

                        downloadInfo.error  = null;
                        downloadInfo.isDone = false;
                        DownloadModBinary_Internal(idPair, headerLocation);
                        return;
                    }
                }
                #endif

                else
                {
                    downloadInfo.error = WebRequestError.GenerateFromWebRequest(request);

                    if (PluginSettings.data.logAllRequests)
                    {
                        WebRequestError.LogAsWarning(downloadInfo.error);
                    }

                    if (modfileDownloadFailed != null)
                    {
                        modfileDownloadFailed(idPair, downloadInfo.error);
                    }
                }
            }
            else
            {
                try
                {
                    if (File.Exists(downloadInfo.target))
                    {
                        File.Delete(downloadInfo.target);
                    }

                    File.Move(downloadInfo.target + ".download", downloadInfo.target);

                    succeeded = true;
                }
                catch (Exception e)
                {
                    string warningInfo = ("Failed to save mod binary."
                                          + "\nFile: " + downloadInfo.target + "\n\n");

                    Debug.LogWarning("[mod.io] " + warningInfo + Utility.GenerateExceptionDebugString(e));

                    downloadInfo.error = WebRequestError.GenerateLocal(warningInfo);

                    if (modfileDownloadFailed != null)
                    {
                        modfileDownloadFailed(idPair, downloadInfo.error);
                    }
                }
            }

            if (succeeded)
            {
                #if DEBUG
                if (PluginSettings.data.logAllRequests)
                {
                    var responseTimeStamp = ServerTimeStamp.Now;
                    Debug.Log("DOWNLOAD SUCEEDED"
                              + "\nDownload completed at: " + ServerTimeStamp.ToLocalDateTime(responseTimeStamp)
                              + "\nURL: " + request.url
                              + "\nFilePath: " + downloadInfo.target);
                }
                #endif

                if (modfileDownloadSucceeded != null)
                {
                    modfileDownloadSucceeded(idPair, downloadInfo);
                }
            }

            modfileDownloadMap.Remove(idPair);
            DownloadClient.modfileProgressMarkers.Remove(idPair);
        }
예제 #3
0
        /// <summary>Attempts to reauthenticate using the stored external auth ticket.</summary>
        public static void ReauthenticateWithStoredExternalAuthData(Action <UserProfile> onSuccess,
                                                                    Action <WebRequestError> onError)
        {
            ExternalAuthenticationData authData = LocalUser.ExternalAuthentication;

            Debug.Assert(!string.IsNullOrEmpty(authData.ticket));
            Debug.Assert(authData.provider != ExternalAuthenticationProvider.None);

            Action <string> onSuccessWrapper = (t) =>
            {
                LocalUser.OAuthToken       = t;
                LocalUser.WasTokenRejected = false;
                LocalUser.Save();

                if (onSuccess != null)
                {
                    UserAccountManagement.UpdateUserProfile(onSuccess, onError);
                }
            };

            switch (LocalUser.ExternalAuthentication.provider)
            {
            case ExternalAuthenticationProvider.Steam:
            {
                APIClient.RequestSteamAuthentication(authData.ticket,
                                                     onSuccessWrapper,
                                                     onError);
            }
            break;

            case ExternalAuthenticationProvider.GOG:
            {
                APIClient.RequestGOGAuthentication(authData.ticket,
                                                   onSuccessWrapper,
                                                   onError);
            }
            break;

            case ExternalAuthenticationProvider.ItchIO:
            {
                APIClient.RequestItchIOAuthentication(authData.ticket,
                                                      onSuccessWrapper,
                                                      onError);
            }
            break;

            case ExternalAuthenticationProvider.OculusRift:
            {
                string token = authData.ticket;
                string nonce;
                string userIdString;
                int    userId;

                if (authData.additionalData == null)
                {
                    var error = WebRequestError.GenerateLocal("Unable to authenticate using stored Oculus Rift user data."
                                                              + " The user id and nonce are missing.");
                    WebRequestError.LogAsWarning(error);

                    if (onError != null)
                    {
                        onError(error);
                    }

                    return;
                }
                else if (!authData.additionalData.TryGetValue(ExternalAuthenticationData.OculusRiftKeys.NONCE, out nonce) ||
                         string.IsNullOrEmpty(nonce))
                {
                    var error = WebRequestError.GenerateLocal("Unable to authenticate using stored Oculus Rift user data."
                                                              + " The nonce is missing.");
                    WebRequestError.LogAsWarning(error);

                    if (onError != null)
                    {
                        onError(error);
                    }

                    return;
                }
                else if (!authData.additionalData.TryGetValue(ExternalAuthenticationData.OculusRiftKeys.USER_ID, out userIdString) ||
                         string.IsNullOrEmpty(userIdString))
                {
                    var error = WebRequestError.GenerateLocal("Unable to authenticate using stored Oculus Rift user data."
                                                              + " The user id is missing.");
                    WebRequestError.LogAsWarning(error);

                    if (onError != null)
                    {
                        onError(error);
                    }

                    return;
                }
                else if (!int.TryParse(userIdString, out userId))
                {
                    var error = WebRequestError.GenerateLocal("Unable to authenticate using stored Oculus Rift user data."
                                                              + " The user id is not parseable as an integer.");
                    WebRequestError.LogAsWarning(error);

                    if (onError != null)
                    {
                        onError(error);
                    }

                    return;
                }
                else
                {
                    APIClient.RequestOculusRiftAuthentication(nonce, userId, token,
                                                              onSuccessWrapper,
                                                              onError);
                }
            }
            break;

            case ExternalAuthenticationProvider.XboxLive:
            {
                APIClient.RequestXboxLiveAuthentication(authData.ticket,
                                                        onSuccessWrapper,
                                                        onError);
            }
            break;

            default:
            {
                throw new System.NotImplementedException();
            }
            }
        }
예제 #4
0
        // ------[ INITIALIZATION ]------
        protected virtual void OnEnable()
        {
            // Grab Serialized Properties
            serializedObject.Update();
            modIdProperty = serializedObject.FindProperty("modId");
            editableModProfileProperty = serializedObject.FindProperty("editableModProfile");
            isModListLoading           = false;
            profileViewParts           = new IModProfileViewPart[]
            {
                new LoadingProfileViewPart()
            };

            // Profile Initialization
            if (modIdProperty.intValue == ScriptableModProfile.UNINITIALIZED_MOD_ID)
            {
                this.profile = null;

                string userAuthToken = CacheClient.LoadAuthenticatedUserToken();

                if (!String.IsNullOrEmpty(userAuthToken))
                {
                    APIClient.userAuthorizationToken = userAuthToken;

                    this.isModListLoading = true;
                    this.modOptions       = new string[] { "Loading..." };

                    Action <WebRequestError> onError = (e) =>
                    {
                        WebRequestError.LogAsWarning(e);
                        isModListLoading = false;
                    };

                    ModManager.GetAuthenticatedUserProfile((userProfile) =>
                    {
                        this.user = userProfile;

                        // - Find User Mods -
                        Action <List <ModProfile> > onGetUserMods = (profiles) =>
                        {
                            modInitializationOptionIndex = 0;
                            modList    = profiles.ToArray();
                            modOptions = new string[modList.Length];
                            for (int i = 0; i < modList.Length; ++i)
                            {
                                ModProfile mod = modList[i];
                                modOptions[i]  = mod.name;
                            }

                            isModListLoading = false;
                        };

                        ModManager.GetAuthenticatedUserMods(onGetUserMods, onError);
                    },
                                                           onError);
                }
                else
                {
                    this.modOptions = new string[0];
                }

                modInitializationOptionIndex = 0;
            }
            else
            {
                // Initialize View
                profile = null;

                System.Action <ModProfile> onGetProfile = (p) =>
                {
                    profile = p;

                    profileViewParts = CreateProfileViewParts();

                    foreach (IModProfileViewPart viewPart in profileViewParts)
                    {
                        viewPart.OnEnable(editableModProfileProperty, p, this.user);
                    }
                    ;

                    profileGetErrorMessage = string.Empty;
                };

                System.Action <WebRequestError> onGetProfileError = (e) =>
                {
                    profile = null;

                    profileViewParts = CreateProfileViewParts();

                    foreach (IModProfileViewPart viewPart in profileViewParts)
                    {
                        viewPart.OnEnable(editableModProfileProperty, null, this.user);
                    }
                    ;

                    profileGetErrorMessage = ("Unable to fetch the mod profile data on the server.\n"
                                              + e.message);
                };

                ModManager.GetModProfile(modIdProperty.intValue,
                                         onGetProfile,
                                         onGetProfileError);
            }

            scrollPos        = Vector2.zero;
            isProfileSyncing = false;

            // Events
            EditorApplication.update += OnUpdate;
            LoginWindow.userLoggedIn += OnUserLogin;
        }