コード例 #1
0
        private async void activationCodeTextBox_TextChanged(object sender, EventArgs e)
        {
            if (activationCodeTextBox.TextLength != 6)
            {
                return;
            }

            string sessionId = Router.Params["sessionId"];

            try
            {
                await _forgameAuthProvider.SendActivationCode(
                    sessionId,
                    activationCodeTextBox.Text);

                string username = Router.Query["username"];
                string password = Router.Query["password"];

                Token token = await _forgameAuthProvider.Authorize(username, password);

                _launcherConfigProvider.AddOrUpdateAccount(new Account {
                    Username = username,
                    Token    = token
                });
                _launcherConfigProvider.UpdateLastUsedAccount(username);

                Router.SetLocation("/");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
        private async void startGameButton_Click(object sender, EventArgs e)
        {
            string username = (string)accountsListBox.SelectedItem;

            Account account = _launcherConfigProvider.GetAccounts().Find(
                acc => acc.Username == username);

            if (account == null)
            {
                MessageBox.Show("Select account.");
                return;
            }

            var jwt = new JwtSecurityToken(account.Token.AccessToken);

            try
            {
                long validTo = jwt.ValidTo.Ticks;

                if (DateTime.Now.Ticks > validTo)
                {
                    Token token = await _forgameAuthProvider.Refresh(account.Token.RefreshToken);

                    _launcherConfigProvider.AddOrUpdateAccount(new Account {
                        Username = username,
                        Token    = token
                    });

                    account.Token = token;
                }

                GameTokenCode gameTokenCode;

                try
                {
                    gameTokenCode = await _gameAuthProvider.GetGameTokenCode(
                        account.Token.AccessToken);
                }
                catch (Exception)
                {
                    MessageBox.Show("Something went wrong. Re-login to your account.");
                    return;
                }

                _gameManager.Launch("bns-ru", new GameLaunchData {
                    Login     = gameTokenCode.Login,
                    Password  = gameTokenCode.Password,
                    Version   = _launcherConfigProvider.GetGameVersion(),
                    Arguments = _launcherConfigProvider.GetGameArguments()
                });

                if (_launcherConfigProvider.GetAutoCloseLauncher())
                {
                    var mainForm = (MainForm)Parent;
                    mainForm.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }