Ejemplo n.º 1
0
        public void OnLoginCallback(IAsyncResult iAr)
        {
            LoginAnimation.Stop();
            HSession HS = (HSession)iAr.AsyncState;

            if (HS.EndLogin(iAr))
            {
                Invoke(new Action(() =>
                {
                    LoginBtn.Text = "Login Successful!";
                    foreach (Control C in Controls)
                    {
                        C.Enabled = true;
                    }
                    Cursor          = Cursors.Default;
                    Program.Account = HS;
                    Close();
                }));
            }
            else
            {
                Invoke(new Action(() =>
                {
                    LoginBtn.Text = "Login Failed!";
                    foreach (Control C in Controls)
                    {
                        C.Enabled = true;
                    }
                    Cursor = Cursors.Default;
                    MessageBox.Show("Unable to authenticate the account, please try again.", "iKBenPeanut ~ Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    LoginBtn.Text = "Login/Connect";
                }));
            }
        }
Ejemplo n.º 2
0
        private void LoginBtn_Click(object sender, EventArgs e)
        {
            LoggingIn = true;
            UpdateAccountUI(false);
            UpdateConnectionFeats(false);

            if (AllAccountsChckbx.Checked)
            {
                #region Account Login: Multiple
                int      LoginCount = 0;
                int      LoginFails = AccountTxt.Items.Count;
                string[] Accounts   = AccountTxt.Items.Cast <object>().Select(i => i.ToString()).ToArray();
                AnimationDisplay = string.Format("Logging In% | (1/{0})", Accounts.Length);
                AnimationTmr.Start();
                foreach (string Account in Accounts)
                {
                    if (Account.Contains('@'))
                    {
                        Program.Emails[Account].BeginLogin(new AsyncCallback((iAr) =>
                        {
                            HSession HS = (HSession)iAr.AsyncState;
                            if (HS.EndLogin(iAr))
                            {
                                LoginFails--;
                                Program.Accounts[HS.PlayerName] = HS;
                                Invoke(new Action(() =>
                                {
                                    AccountTxt.Items.Remove(HS.Email);
                                    AccountTxt.Items.Add(HS.PlayerName);
                                    AccountTxt.SelectedIndex = AccountTxt.Items.IndexOf(HS.PlayerName);
                                }));
                            }
                            AnimationDisplay = string.Format("Logging In% | ({0}/{1})", LoginCount + 2, Accounts.Length);
                            if (++LoginCount == Accounts.Length)
                            {
                                DisplayFinish(string.Format("Login(s) Succeeded! | ({0}/{1})", Accounts.Length - LoginFails, Accounts.Length));
                            }
                        }), Program.Emails[Account]);
                    }
                    else
                    {
                        Program.Accounts[Account].BeginLogin(new AsyncCallback((iAr) =>
                        {
                            if ((iAr.AsyncState as HSession).EndLogin(iAr))
                            {
                                LoginFails--;
                            }
                            AnimationDisplay = string.Format("Logging In% | ({0}/{1})", LoginCount + 2, Accounts.Length);
                            if (++LoginCount == Accounts.Length)
                            {
                                DisplayFinish(string.Format("Login(s) Succeeded! | ({0}/{1})", Accounts.Length - LoginFails, Accounts.Length));
                            }
                        }), Program.Accounts[Account]);
                    }
                }
                #endregion
            }
            else
            {
                #region Account Login: Single
                string AN = AccountTxt.Text;
                AnimationDisplay = string.Format("Logging In% | {0}", AN);
                AnimationTmr.Start();
                if (AN.Contains("@"))
                {
                    Program.Emails[AN].BeginLogin(new AsyncCallback((iAr) =>
                    {
                        HSession HS = (HSession)iAr.AsyncState;
                        if (HS.EndLogin(iAr))
                        {
                            Program.Accounts[HS.PlayerName] = HS;
                            Invoke(new Action(() =>
                            {
                                AccountTxt.Items.Remove(HS.Email);
                                AccountTxt.Items.Add(HS.PlayerName);
                                AccountTxt.SelectedIndex = AccountTxt.Items.IndexOf(HS.PlayerName);
                            }));
                            DisplayFinish("Login Success! | " + AN);
                        }
                        else
                        {
                            DisplayFinish("Login Failed! | " + AN);
                        }
                    }), Program.Emails[AN]);
                }
                else
                {
                    Program.Accounts[AN].BeginLogin(new AsyncCallback((iAr) =>
                    {
                        DisplayFinish(string.Format("Login {0}! | {1}", (iAr.AsyncState as HSession).EndLogin(iAr) ? "Success" : "Failed", AN));
                    }), Program.Accounts[AN]);
                }
                #endregion
            }
        }