示例#1
0
        public LoginResult Login(string userName, string password, string otp, bool isSteamServiceAccount, bool useCache, DirectoryInfo gamePath)
        {
            string uid;
            PatchListEntry[] pendingPatches = null;

            OauthLoginResult oauthLoginResult;

            LoginState loginState;

            Log.Information($"XivGame::Login(steamServiceAccount:{isSteamServiceAccount}, cache:{useCache})");

            if (!useCache || !UniqueIdCache.Instance.HasValidCache(userName))
            {
                Log.Information("Cache is invalid or disabled, logging in normally.");

                try
                {
                    oauthLoginResult = OauthLogin(userName, password, otp, isSteamServiceAccount, 3);

                    Log.Information($"OAuth login successful - playable:{oauthLoginResult.Playable} terms:{oauthLoginResult.TermsAccepted} region:{oauthLoginResult.Region} expack:{oauthLoginResult.MaxExpansion}");
                }
                catch (Exception ex)
                {
                    Log.Information(ex, "OAuth login failed.");
                    
                    return new LoginResult
                    {
                        State = LoginState.NoOAuth
                    };
                }

                if (!oauthLoginResult.Playable)
                {
                    return new LoginResult
                    {
                        State = LoginState.NoService
                    };
                }

                if (!oauthLoginResult.TermsAccepted)
                {
                    return new LoginResult
                    {
                        State = LoginState.NoTerms
                    };
                }

                (uid, loginState, pendingPatches) = Task.Run(() => RegisterSession(oauthLoginResult, gamePath)).Result;

                if (useCache)
                    Task.Run(() => UniqueIdCache.Instance.AddCachedUid(userName, uid, oauthLoginResult.Region, oauthLoginResult.MaxExpansion))
                        .Wait();
            }
            else
            {
                Log.Information("Cached UID found, using instead.");
                var (cachedUid, region, expansionLevel) = Task.Run(() => UniqueIdCache.Instance.GetCachedUid(userName)).Result;
                uid = cachedUid;
                loginState = LoginState.Ok;

                oauthLoginResult = new OauthLoginResult
                {
                    Playable = true,
                    Region = region,
                    TermsAccepted = true,
                    MaxExpansion = expansionLevel
                };
            }

            return new LoginResult
            {
                PendingPatches = pendingPatches,
                OauthLogin = oauthLoginResult,
                State = loginState,
                UniqueId = uid
            };
        }
示例#2
0
        public Process Login(string userName, string password, string otp, bool isSteam, string additionalArguments, bool useCache)
        {
            string uid;
            var    needsUpdate = false;

            OauthLoginResult loginResult;

            if (!useCache || !Cache.HasValidCache(userName))
            {
                Log.Information("Cache is invalid or disabled, logging in normally.");

                try
                {
                    loginResult = OauthLogin(userName, password, otp, isSteam);
                }
                catch (Exception ex)
                {
                    Log.Error("OAuth login failed.", ex);
                    MessageBox.Show(
                        "Could not login into your Square Enix account.\nThis could be caused by bad credentials or OTPs.\n\nPlease also check your email inbox for any messages from Square Enix - they might want you to reset your password due to \"suspicious activity\".\nThis is NOT caused by a security issue in XIVLauncher, it is merely a safety measure by Square Enix to prevent logins from new locations, in case your account is getting stolen.\nXIVLauncher and the official launcher will work fine again after resetting your password.",
                        "Login issue", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(null);
                }

                if (!loginResult.Playable)
                {
                    MessageBox.Show("This Square Enix account cannot play FINAL FANTASY XIV.\n\nIf you bought FINAL FANTASY XIV on Steam, make sure to enable Steam integration in Settings->Game.\nIf Auto-Login is enabled, hold shift while starting to access settings.", "Error",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                    return(null);
                }

                if (!loginResult.TermsAccepted)
                {
                    MessageBox.Show("Please accept the FINAL FANTASY XIV Terms of Use in the official launcher.",
                                    "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(null);
                }

                (uid, needsUpdate) = Task.Run(() => RegisterSession(loginResult)).Result;

                if (useCache)
                {
                    Task.Run(() => Cache.AddCachedUid(userName, uid, loginResult.Region, loginResult.MaxExpansion))
                    .Wait();
                }
            }
            else
            {
                Log.Information("Cached UID found, using instead.");
                var(cachedUid, region, expansionLevel) = Task.Run(() => Cache.GetCachedUid(userName)).Result;
                uid = cachedUid;

                loginResult = new OauthLoginResult
                {
                    Playable      = true,
                    Region        = region,
                    TermsAccepted = true,
                    MaxExpansion  = expansionLevel
                };
            }

            if (needsUpdate)
            {
                MessageBox.Show(
                    "Your game is out of date. Please start the official launcher and update it before trying to log in.",
                    "Out of date", MessageBoxButton.OK, MessageBoxImage.Error);

                return(null);
            }

            return(LaunchGame(uid, loginResult.Region, loginResult.MaxExpansion, isSteam, additionalArguments));
        }
示例#3
0
        private static (string Uid, LoginState result, PatchListEntry[] PendingGamePatches) RegisterSession(OauthLoginResult loginResult, DirectoryInfo gamePath)
        {
            using var client = new WebClient();

            client.Headers.Add("X-Hash-Check", "enabled");
            client.Headers.Add("User-Agent", "FFXIV PATCH CLIENT");
            //client.Headers.Add("Referer",
            //    $"https://ffxiv-login.square-enix.com/oauth/ffxivarr/login/top?lng=en&rgn={loginResult.Region}");
            client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

            var url =
                $"https://patch-gamever.ffxiv.com/http/win32/ffxivneo_release_game/{Repository.Ffxiv.GetVer(gamePath)}/{loginResult.SessionId}";

            try
            {
                var report = GetVersionReport(gamePath, loginResult.MaxExpansion);
                var result = client.UploadString(url, report);

                // Get the unique ID needed to authenticate with the lobby server
                if (client.ResponseHeaders.AllKeys.Contains("X-Patch-Unique-Id"))
                {
                    var sid = client.ResponseHeaders["X-Patch-Unique-Id"];

                    if (result == string.Empty)
                        return (sid, LoginState.Ok, null);

                    Log.Verbose("Patching is needed... List:\n" + result);

                    var pendingPatches = PatchListParser.Parse(result);

                    return (sid, LoginState.NeedsPatchGame, pendingPatches);
                }
            }
            catch (WebException exc)
            {
                if (exc.Status == WebExceptionStatus.ProtocolError)
                {
                    if (exc.Response is HttpWebResponse response)
                    {
                        // Conflict indicates that boot needs to update, we do not get a patch list or a unique ID to download patches with in this case
                        if (response.StatusCode == HttpStatusCode.Conflict)
                            return (null, LoginState.NeedsPatchBoot, null);
                    }
                    else
                    {
                        throw;
                    }
                }
                else
                {
                    throw;
                }
            }

            throw new Exception("Could not validate game version.");
        }
示例#4
0
        public LoginResult Login(string userName, string password, string otp, bool isSteamServiceAccount, bool useCache, DirectoryInfo gamePath)
        {
            string uid;

            PatchListEntry[] pendingPatches = null;

            OauthLoginResult oauthLoginResult;

            LoginState loginState;

            Log.Information($"XivGame::Login(steamServiceAccount:{isSteamServiceAccount}, cache:{useCache})");

            if (!useCache || !Cache.HasValidCache(userName))
            {
                Log.Information("Cache is invalid or disabled, logging in normally.");

                try
                {
                    oauthLoginResult = OauthLogin(userName, password, otp, isSteamServiceAccount, 3);

                    Log.Information($"OAuth login successful - playable:{oauthLoginResult.Playable} terms:{oauthLoginResult.TermsAccepted} region:{oauthLoginResult.Region} expack:{oauthLoginResult.MaxExpansion}");
                }
                catch (Exception ex)
                {
                    Log.Information(ex, "OAuth login failed.");
                    MessageBox.Show(
                        "Could not login into your Square Enix account.\nThis could be caused by bad credentials or OTPs.\n\nPlease also check your email inbox for any messages from Square Enix - they might want you to reset your password due to \"suspicious activity\".\nThis is NOT caused by a security issue in XIVLauncher, it is merely a safety measure by Square Enix to prevent logins from new locations, in case your account is getting stolen.\nXIVLauncher and the official launcher will work fine again after resetting your password.",
                        "Login issue", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(null);
                }

                if (!oauthLoginResult.Playable)
                {
                    MessageBox.Show("This Square Enix account cannot play FINAL FANTASY XIV.\n\nIf you bought FINAL FANTASY XIV on Steam, make sure to check the \"Use Steam service account\" checkbox while logging in.\nIf Auto-Login is enabled, hold shift while starting to access settings.", "Error",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                    return(null);
                }

                if (!oauthLoginResult.TermsAccepted)
                {
                    MessageBox.Show("Please accept the FINAL FANTASY XIV Terms of Use in the official launcher.",
                                    "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(null);
                }

                (uid, loginState, pendingPatches) = Task.Run(() => RegisterSession(oauthLoginResult, gamePath)).Result;

                if (useCache)
                {
                    Task.Run(() => Cache.AddCachedUid(userName, uid, oauthLoginResult.Region, oauthLoginResult.MaxExpansion))
                    .Wait();
                }
            }
            else
            {
                Log.Information("Cached UID found, using instead.");
                var(cachedUid, region, expansionLevel) = Task.Run(() => Cache.GetCachedUid(userName)).Result;
                uid        = cachedUid;
                loginState = LoginState.Ok;

                oauthLoginResult = new OauthLoginResult
                {
                    Playable      = true,
                    Region        = region,
                    TermsAccepted = true,
                    MaxExpansion  = expansionLevel
                };
            }

            return(new LoginResult
            {
                PendingPatches = pendingPatches,
                OauthLogin = oauthLoginResult,
                State = loginState,
                UniqueId = uid
            });
        }