Exemplo n.º 1
0
 public void Initialise(ILoginDialog loginDialog)
 {
     view = loginDialog;
     view.UserManualMode=false;
     State = CreateFillingDomainState();
     attempter = new Attempter(this);      
 }
Exemplo n.º 2
0
        /// <summary>
        /// Builds the url of the authorization endpoint and navigates the WebView of the dialog to it.
        /// </summary>
        /// <param name="dialog">The dialog</param>
        public void Initialize(ILoginDialog dialog)
        {
            var url = new Url(_baseUrl)
                      .SetQueryParams(new
            {
                client_id     = _clientId,
                scope         = _scopes,
                response_type = "code",
                redirect_uri  = _callbackUrl
            });

            dialog.NavigateWebView(url.ToUri());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Opens a dialog that allows users to log in.
        /// </summary>
        /// <remarks>
        /// If the user fails to log in, this method will reopen the login dialog
        /// with an error message. The done delegate is not called until the user
        /// either logs in successfully or clicks cancel.
        /// </remarks>
        /// <param name="done">Delegate that is invoked when the user logs in
        /// successfully.</param>
        /// <param name="inst">The instance that is being launched.</param>
        /// <param name="message">An error message to be displayed on the login dialog.</param>
        /// <param name="canplayOffline">True if the user can play this instance offline.</param>
        private void DoLogin(LoginCompleteHandler done,
                             Instance inst,
                             string message      = "",
                             bool canplayOffline = false)
        {
            string username = "";
            string password = "";

            ReadUserInfo(out username, out password);

            ILoginDialog loginDlg = GUIManager.Main.LoginDialog(message);

            loginDlg.Parent          = (DirectLaunch ? null : MainWindow);
            loginDlg.DefaultPosition = DefWindowPosition.CenterParent;
            loginDlg.ShowInTaskbar   = DirectLaunch;

            if (!string.IsNullOrEmpty(username))
            {
                loginDlg.RememberUsername = true;
                loginDlg.Username         = username;
            }
            if (!string.IsNullOrEmpty(password))
            {
                loginDlg.RememberPassword = true;
                loginDlg.Password         = password;
            }
            loginDlg.Response += (o, args) =>
            {
                if (args.Response == DialogResponse.OK)
                {
                    string parameters = string.Format(
                        "user={0}&password={1}&version=1337",
                        Uri.EscapeDataString(loginDlg.Username),
                        Uri.EscapeDataString(loginDlg.Password), 13);

                    WriteUserInfo((loginDlg.RememberUsername ? loginDlg.Username : ""),
                                  (loginDlg.RememberPassword ? loginDlg.Password : ""));

                    // Start a new thread and post the login info to login.minecraft.net
                    SimpleTask loginTask = new SimpleTask(() =>
                    {
                        string reply    = "";
                        bool postFailed = false;
                        try
                        {
                            if (loggingIn)
                            {
                                return;
                            }
                            loggingIn = true;
                            reply     = AppUtils.ExecutePost("https://login.minecraft.net/",
                                                             parameters);
                        }
                        catch (System.Net.WebException e)
                        {
                            postFailed = true;
                            reply      = e.Message;
                        }
                        finally
                        {
                            loggingIn = false;
                        }

                        // If the login failed
                        if (!reply.Contains(":") || postFailed)
                        {
                            // Translate the error message to a more user friendly wording
                            string errorMessage = reply;
                            switch (reply.ToLower())
                            {
                            case "bad login":
                                errorMessage = "Invalid username or password.";
                                break;

                            case "old version":
                                errorMessage = "Invalid launcher version.";
                                break;

                            default:
                                errorMessage = "Login failed: " + reply;
                                break;
                            }

                            // Unable to resolve hostname.
                            if (reply.ToLower().Contains("name could not be resolved"))
                            {
                                errorMessage = string.Format(
                                    "Couldn't connect to login.minecraft.net, " +
                                    "please connect to the internet or use offline mode.");
                            }

                            // Error
                            MainWindow.Invoke((sender, e) =>
                                              DoLogin(done, inst, errorMessage));
                        }

                        // If the login succeeded
                        else
                        {
                            string[] responseValues = reply.Split(':');

                            // The response must have at least 4 values or it's invalid
                            if (responseValues.Length < 4)
                            {
                                // Error
                                MainWindow.Invoke((sender, e) =>
                                                  DoLogin(done, inst,
                                                          "Got an invalid response from server", canplayOffline));
                            }
                            // Now we can finally return our login info.
                            else
                            {
                                LoginInfo info = new LoginInfo(responseValues,
                                                               loginDlg.ForceUpdate);
                                done(info, inst);
                            }
                        }
                    }, "Logging in...");

                    if (!loggingIn)
                    {
                        MainWindow.Invoke((o2, args2) =>
                                          StartModalTask(loginTask));
                    }
                }
                else if (args.Response == DialogResponse.No)
                {
                    // Play offline
                    done(new LoginInfo(null, false, false), inst);
                }
                else
                {
                    // Login cancelled
                    done(new LoginInfo(), inst);
                }
            };
            loginDlg.Run();
        }