/// <summary>
        /// Sends a login request to the server
        /// </summary>
        public static string[] LoginServer(string Username, string Password)
        {
            string url = CurrentUrl;

            IStatus.LoginResponseObject payload;
            IStatus.LoginRequestObject  request = new IStatus.LoginRequestObject();
            request.Username     = Username;
            request.PasswordHash = Password;

            string msg;

            switch (AccountServer.LoginAccount(request, CurrentUrl, out payload))
            {
            case IStatus.LoginStatusCode.Ok:
                string[] getPayload = { payload.TicketId.ToString(), payload.Username };
                return(getPayload);

            case IStatus.LoginStatusCode.InvalidCredentials:
                msg = "Error: Invalid username/password";
                MessageBox.Show(string.IsNullOrWhiteSpace(AccountServer.Reason) ? msg : "Error: " + AccountServer.Reason, "Login Request");
                if (passwordCount++ >= 3)
                {
                    if (ShowReminder != null)
                    {
                        ShowReminder(passwordCount);
                    }
                }
                break;

            case IStatus.LoginStatusCode.MalformedData:
                msg = "Error: malformed username/password";
                MessageBox.Show(string.IsNullOrWhiteSpace(AccountServer.Reason) ? msg : "Error: " + AccountServer.Reason, "Login Request");
                if (passwordCount++ >= 3)
                {
                    if (ShowReminder != null)
                    {
                        ShowReminder(passwordCount);
                    }
                }
                break;

            case IStatus.LoginStatusCode.ServerError:
                msg = "Server error, could not connect.\r\n Is your firewall enabled?";
                MessageBox.Show(string.IsNullOrWhiteSpace(AccountServer.Reason) ? msg : AccountServer.Reason, "Login Request");
                break;

            case IStatus.LoginStatusCode.NoResponse:
                msg = "Server error, received no response from the server.";
                MessageBox.Show(string.IsNullOrWhiteSpace(AccountServer.Reason) ? msg : AccountServer.Reason, "Login Request");
                break;
            }

            return(null);
        }
Ejemplo n.º 2
0
        private void btnPlay_Click(object sender, EventArgs e)
        {
            this.accountServer = this.settings["Launcher"]["Accounts"];
            this.SetCurrentTask("Checking server status...");

            //Lets ping first
            AccountServer.PingRequestStatusCode ping = PingServer(this.settings["Launcher"]["Accounts"]);
            if (ping != AccountServer.PingRequestStatusCode.Ok)
            {
                //Try the backup
                if ((ping = PingServer(this.settings["Launcher"]["AccountsBackup"])) != AccountServer.PingRequestStatusCode.Ok)
                {
                    int num3 = (int)MessageBox.Show("Server error, could not connect. Is your firewall enabled?");
                    return;
                }
                this.accountServer = this.settings["Launcher"]["AccountsBackup"];
            }

            this.SetCurrentTask("Trying credentials...");
            AccountServer.LoginResponseObject payload;
            switch (AccountServer.LoginAccount(new AccountServer.LoginRequestObject()
            {
                Username = this.txtUsername.Text.Trim(),
                PasswordHash = this.txtPassword.Text == "*****" ? this.settings["Credentials"]["Password"] : Md5.Hash(this.txtPassword.Text.Trim())
            }, this.accountServer, out payload))
            {
            case AccountServer.LoginStatusCode.Ok:
                this.LaunchGame(payload.TicketId.ToString(), ((object)payload.Username).ToString());
                break;

            case AccountServer.LoginStatusCode.MalformedData:
                string msg  = "Error: malformed username/password";
                int    num1 = (int)MessageBox.Show((AccountServer.Reason != null ? "Error: " + AccountServer.Reason : msg));
                break;

            case AccountServer.LoginStatusCode.InvalidCredentials:
                int num2 = (int)MessageBox.Show("Invalid username/password");
                break;

            case AccountServer.LoginStatusCode.ServerError:
                int num3 = (int)MessageBox.Show("Server error, could not connect. Is your firewall enabled?");
                break;
            }
        }