예제 #1
0
        private async void SignIn()
        {
            IServerChanger window = (IServerChanger)Window.GetWindow(View);

            if (Username == null || Username.Length == 0)
            {
                MessageBox.Show("Username is empty!", "Hanksite", MessageBoxButton.OK);
                return;
            }

            string password = ((IPasswordProvider)View).GetPassword();

            if (password == null || password.Length == 0)
            {
                MessageBox.Show("Password is empty!", "Hanksite", MessageBoxButton.OK);
                return;
            }

            IsPageEnabled = false;
            window.Disable();

            bool success;

            try
            {
                success = await Accounts.IsAccountValid(window.GetServer(), Username, password);
            }
            catch (System.Exception e)
            {
                MessageBox.Show("An error has occured while connecting to the server.\n" + e.Message, "Hanksite", MessageBoxButton.OK);
                IsPageEnabled = true;
                window.Enable();
                return;
            }

            if (success)
            {
                GameStateForDisconnected[] games = await gameServer.GetRunningGames();

                if (games.Length == 0)
                {
                    NavigationService.GetNavigationService(View).Navigate(new MainMenu());
                }
                else
                {
                    ReconnectDialog dialog = new ReconnectDialog(Window.GetWindow(View), games);
                    if (dialog.ShowDialog() == true)
                    {
                        NavigationService.GetNavigationService(View).Navigate(new GameView(dialog.GetConnectedGameState()));
                    }
                    else
                    {
                        NavigationService.GetNavigationService(View).Navigate(new MainMenu());
                    }
                }

                window.HideChangeServerButton();
                window.HideQuitButton();

                LoginData loginData = new LoginData(window.GetServer(), Username);
                loginDataManager.SaveLastLogin(loginData);
                window.Enable();
            }
            else
            {
                IsPageEnabled = true;
                window.Enable();
                MessageBox.Show("Wrong username or password!", "Hanksite", MessageBoxButton.OK);
            }
        }