Exemplo n.º 1
0
        private void Back()
        {
            NavigationService.GetNavigationService(View).GoBack();
            IServerChanger window = (IServerChanger)Window.GetWindow(View);

            window.UnhideQuitButton();
        }
Exemplo n.º 2
0
        private void CreateAccount()
        {
            NavigationService.GetNavigationService(View).Navigate(new Registration());
            IServerChanger window = (IServerChanger)Window.GetWindow(View);

            window.HideQuitButton();
        }
Exemplo n.º 3
0
        private async void CreateAccount()
        {
            IServerChanger window = (IServerChanger)Window.GetWindow(View);

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

            IConfirmedPasswordProvider passwordProvider = (IConfirmedPasswordProvider)View;
            string password          = passwordProvider.GetPassword();
            string confirmedPassword = passwordProvider.GetConfirmedPassword();

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

            if (password != confirmedPassword)
            {
                MessageBox.Show("Password differs from confirmed password!", "Hanksite", MessageBoxButton.OK);
                return;
            }

            IsPageEnabled = false;
            window.Disable();

            bool success;

            try
            {
                success = await accounts.CreateAccount(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)
            {
                IsPageEnabled = true;
                window.Enable();
                MessageBox.Show("The given username already exists!", "Hanksite", MessageBoxButton.OK);
                return;
            }

            window.Enable();
            NavigationService.GetNavigationService(View).Navigate(new MainMenu());
            window.HideChangeServerButton();
        }
Exemplo n.º 4
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);
            }
        }