Example #1
0
        /// <summary>
        /// Verifies that the input username and password are correct
        /// </summary>
        public static void LauncherSignIn(string username, string password, LauncherSignInCompleteDelegate finished)
        {
            bool updatePersistedCredentials = String.IsNullOrEmpty(username) == false && String.IsNullOrEmpty(password) == false;

            if (updatePersistedCredentials == true)
            {
                AuthenticatedData.SetLogin(username, password);
            }

            TaskHandler.RunTask(delegate() {
                LauncherSignInResult result = new LauncherSignInResult();

                try
                {
                    LoginResult blackBoxData = Service.GetBlackBoxForUser(new LoginData()
                    {
                        Alias              = AuthenticatedData.PersistedUser,
                        LobbyId            = null,
                        LobbyIdSpecified   = false,
                        Password           = AuthenticatedData.PersistedPass,
                        SessionId          = 0,
                        SessionIdSpecified = false,
                        Username           = AuthenticatedData.PersistedUser
                    });

                    if (blackBoxData.Status == LoginStatus.Authenticated)
                    {
                        Log.Write("ServiceHandler::LauncherSignIn() - Data received for: " + AuthenticatedData.PersistedUser + ", data length: " + blackBoxData.BlackboxData.Length);

                        string message    = null;
                        string ticket     = null;
                        var checkInStatus = SessionNegotiator.ValidateLogin(blackBoxData.BlackboxData, ref message, ref ticket);

                        if (checkInStatus != CheckInStatus.Ok && checkInStatus != CheckInStatus.AccountLinked)
                        {
                            result.Status          = checkInStatus;
                            result.StatusSpecified = true;
                            result.LinkedAccount   = String.Empty;
                        }
                        else
                        {
                            // Attempt to verify the login credentials
                            result = Service.LauncherSignIn(new LauncherSignInData());
                        }
                    }
                    else
                    {
                        switch (blackBoxData.Status)
                        {
                        case LoginStatus.AccountLocked:
                            result.Status = CheckInStatus.AccountLocked;
                            break;

                        case LoginStatus.InvalidCredentials:
                            result.Status = CheckInStatus.InvalidCredentials;
                            break;

                        case LoginStatus.PermissionDenied:
                            result.Status = CheckInStatus.PermissionDenied;
                            break;

                        default:
                            throw new NotSupportedException(blackBoxData.Status.ToString());
                        }

                        result.StatusSpecified = true;
                        result.LinkedAccount   = String.Empty;
                    }
                }
                catch (Exception error)
                {
                    result = new LauncherSignInResult()
                    {
                        Status          = CheckInStatus.Timeout,
                        StatusSpecified = false
                    };

                    Log.Write(error);
                }

                if (result.StatusSpecified == true && result.Status == CheckInStatus.Ok)
                {
                    DataStore.Callsigns = null;

                    if (updatePersistedCredentials == true)
                    {
                        AuthenticatedData.PersistLogin(username, AuthenticatedData.PersistedPass);
                    }
                }

                finished(result);
            });
        }