Search in sources :

Example 1 with LoginSuccessEvent

use of com.faforever.client.user.event.LoginSuccessEvent in project downlords-faf-client by FAForever.

the class MainControllerTest method fakeLogin.

private void fakeLogin() throws InterruptedException {
    instance.onLoginSuccessEvent(new LoginSuccessEvent("junit", "", 1));
    assertTrue(mainControllerInitializedLatch.await(3000, TimeUnit.SECONDS));
}
Also used : LoginSuccessEvent(com.faforever.client.user.event.LoginSuccessEvent)

Example 2 with LoginSuccessEvent

use of com.faforever.client.user.event.LoginSuccessEvent in project downlords-faf-client by FAForever.

the class PlayerServiceImplTest method testGetCurrentPlayer.

@Test
public void testGetCurrentPlayer() throws Exception {
    LoginSuccessEvent event = new LoginSuccessEvent("junit", "", 1);
    instance.onLoginSuccess(event);
    Player currentPlayer = instance.getCurrentPlayer().orElseThrow(() -> new IllegalStateException("No player returned"));
    assertThat(currentPlayer.getUsername(), is("junit"));
    assertThat(currentPlayer.getId(), is(1));
}
Also used : LoginSuccessEvent(com.faforever.client.user.event.LoginSuccessEvent) Test(org.junit.Test)

Example 3 with LoginSuccessEvent

use of com.faforever.client.user.event.LoginSuccessEvent in project downlords-faf-client by FAForever.

the class UserServiceImpl method login.

@Override
public CompletableFuture<Void> login(String username, String password, boolean autoLogin) {
    this.password = password;
    preferencesService.getPreferences().getLogin().setUsername(username).setPassword(password).setAutoLogin(autoLogin);
    preferencesService.storeInBackground();
    loginFuture = fafService.connectAndLogIn(username, password).thenAccept(loginInfo -> {
        userId = loginInfo.getId();
        // Because of different case (upper/lower)
        String login = loginInfo.getLogin();
        UserServiceImpl.this.username.set(login);
        preferencesService.getPreferences().getLogin().setUsername(login);
        preferencesService.storeInBackground();
        eventBus.post(new LoginSuccessEvent(login, password, userId));
    }).whenComplete((aVoid, throwable) -> {
        if (throwable != null) {
            logger.warn("Error during login", throwable);
            fafService.disconnect();
        }
        loginFuture = null;
    });
    return loginFuture;
}
Also used : PreferencesService(com.faforever.client.preferences.PreferencesService) LoggedOutEvent(com.faforever.client.user.event.LoggedOutEvent) LoginSuccessEvent(com.faforever.client.user.event.LoginSuccessEvent) Logger(org.slf4j.Logger) CompletableTask(com.faforever.client.task.CompletableTask) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) LoginMessage(com.faforever.client.remote.domain.LoginMessage) MethodHandles(java.lang.invoke.MethodHandles) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) ApplicationContext(org.springframework.context.ApplicationContext) NoticeMessage(com.faforever.client.remote.domain.NoticeMessage) FafService(com.faforever.client.remote.FafService) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) LogOutRequestEvent(com.faforever.client.user.event.LogOutRequestEvent) Service(org.springframework.stereotype.Service) PostConstruct(javax.annotation.PostConstruct) Subscribe(com.google.common.eventbus.Subscribe) Lazy(org.springframework.context.annotation.Lazy) StringProperty(javafx.beans.property.StringProperty) TaskService(com.faforever.client.task.TaskService) LoginSuccessEvent(com.faforever.client.user.event.LoginSuccessEvent)

Example 4 with LoginSuccessEvent

use of com.faforever.client.user.event.LoginSuccessEvent in project downlords-faf-client by FAForever.

the class MockFafServerAccessor method connectAndLogIn.

@Override
public CompletableFuture<LoginMessage> connectAndLogIn(String username, String password) {
    return taskService.submitTask(new CompletableTask<LoginMessage>(HIGH) {

        @Override
        protected LoginMessage call() throws Exception {
            updateTitle(i18n.get("login.progress.message"));
            Player player = new Player();
            player.setId(4812);
            player.setLogin(USER_NAME);
            player.setClan("ABC");
            player.setCountry("A1");
            player.setGlobalRating(new float[] { 1500, 220 });
            player.setLadderRating(new float[] { 1500, 220 });
            player.setNumberOfGames(330);
            PlayersMessage playersMessage = new PlayersMessage();
            playersMessage.setPlayers(singletonList(player));
            eventBus.post(new LoginSuccessEvent(username, password, player.getId()));
            messageListeners.getOrDefault(playersMessage.getClass(), Collections.emptyList()).forEach(consumer -> consumer.accept(playersMessage));
            timer.schedule(new TimerTask() {

                @Override
                public void run() {
                    UpdatedAchievementsMessage updatedAchievementsMessage = new UpdatedAchievementsMessage();
                    UpdatedAchievement updatedAchievement = new UpdatedAchievement();
                    updatedAchievement.setAchievementId("50260d04-90ff-45c8-816b-4ad8d7b97ecd");
                    updatedAchievement.setNewlyUnlocked(true);
                    updatedAchievementsMessage.setUpdatedAchievements(Arrays.asList(updatedAchievement));
                    messageListeners.getOrDefault(updatedAchievementsMessage.getClass(), Collections.emptyList()).forEach(consumer -> consumer.accept(updatedAchievementsMessage));
                }
            }, 7000);
            timer.schedule(new TimerTask() {

                @Override
                public void run() {
                    MatchmakerMessage matchmakerServerMessage = new MatchmakerMessage();
                    matchmakerServerMessage.setQueues(singletonList(new MatchmakerQueue("ladder1v1", singletonList(new RatingRange(100, 200)), singletonList(new RatingRange(100, 200)))));
                    messageListeners.getOrDefault(matchmakerServerMessage.getClass(), Collections.emptyList()).forEach(consumer -> consumer.accept(matchmakerServerMessage));
                }
            }, 7000);
            List<GameInfoMessage> gameInfoMessages = Arrays.asList(createGameInfo(1, "Mock game 500 - 800", PUBLIC, "faf", "scmp_010", 1, 6, "Mock user"), createGameInfo(2, "Mock game 500+", PUBLIC, "faf", "scmp_011", 2, 6, "Mock user"), createGameInfo(3, "Mock game +500", PUBLIC, "faf", "scmp_012", 3, 6, "Mock user"), createGameInfo(4, "Mock game <1000", PUBLIC, "faf", "scmp_013", 4, 6, "Mock user"), createGameInfo(5, "Mock game >1000", PUBLIC, "faf", "scmp_014", 5, 6, "Mock user"), createGameInfo(6, "Mock game ~600", PASSWORD, "faf", "scmp_015", 6, 6, "Mock user"), createGameInfo(7, "Mock game 7", PASSWORD, "faf", "scmp_016", 7, 6, "Mock user"));
            gameInfoMessages.forEach(gameInfoMessage -> messageListeners.getOrDefault(gameInfoMessage.getClass(), Collections.emptyList()).forEach(consumer -> consumer.accept(gameInfoMessage)));
            notificationService.addNotification(new PersistentNotification("How about a long-running (7s) mock task?", Severity.INFO, Arrays.asList(new Action("Execute", event -> taskService.submitTask(new CompletableTask<Void>(HIGH) {

                @Override
                protected Void call() throws Exception {
                    updateTitle("Mock task");
                    Thread.sleep(2000);
                    for (int i = 0; i < 5; i++) {
                        updateProgress(i, 5);
                        Thread.sleep(1000);
                    }
                    return null;
                }
            })), new Action("Nope"))));
            LoginMessage sessionInfo = new LoginMessage();
            sessionInfo.setId(123);
            sessionInfo.setLogin(USER_NAME);
            return sessionInfo;
        }
    }).getFuture();
}
Also used : NewGameInfo(com.faforever.client.game.NewGameInfo) Arrays(java.util.Arrays) PUBLIC(com.faforever.client.remote.domain.GameAccess.PUBLIC) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) Timer(java.util.Timer) Faction(com.faforever.client.game.Faction) ConnectionState(com.faforever.client.net.ConnectionState) GameInfoMessage(com.faforever.client.remote.domain.GameInfoMessage) Collections.singletonList(java.util.Collections.singletonList) HIGH(com.faforever.client.task.CompletableTask.Priority.HIGH) IceServer(com.faforever.client.remote.domain.IceServersServerMessage.IceServer) GameStatus(com.faforever.client.remote.domain.GameStatus) TimerTask(java.util.TimerTask) FafClientApplication(com.faforever.client.FafClientApplication) Collections.emptyList(java.util.Collections.emptyList) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) PASSWORD(com.faforever.client.remote.domain.GameAccess.PASSWORD) PlayersMessage(com.faforever.client.remote.domain.PlayersMessage) List(java.util.List) Lazy(org.springframework.context.annotation.Lazy) TaskService(com.faforever.client.task.TaskService) Player(com.faforever.client.remote.domain.Player) LoginSuccessEvent(com.faforever.client.user.event.LoginSuccessEvent) MatchmakerQueue(com.faforever.client.rankedmatch.MatchmakerMessage.MatchmakerQueue) GameLaunchMessage(com.faforever.client.remote.domain.GameLaunchMessage) Avatar(com.faforever.client.remote.domain.Avatar) ReadOnlyObjectProperty(javafx.beans.property.ReadOnlyObjectProperty) CompletableTask(com.faforever.client.task.CompletableTask) LoginMessage(com.faforever.client.remote.domain.LoginMessage) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) GameAccess(com.faforever.client.remote.domain.GameAccess) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) NotificationService(com.faforever.client.notification.NotificationService) KnownFeaturedMod(com.faforever.client.game.KnownFeaturedMod) LinkedList(java.util.LinkedList) ObjectProperty(javafx.beans.property.ObjectProperty) Logger(org.slf4j.Logger) Action(com.faforever.client.notification.Action) MatchmakerMessage(com.faforever.client.rankedmatch.MatchmakerMessage) Profile(org.springframework.context.annotation.Profile) PersistentNotification(com.faforever.client.notification.PersistentNotification) Consumer(java.util.function.Consumer) ServerMessage(com.faforever.client.remote.domain.ServerMessage) Component(org.springframework.stereotype.Component) RatingRange(com.faforever.client.remote.domain.RatingRange) Severity(com.faforever.client.notification.Severity) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) I18n(com.faforever.client.i18n.I18n) Collections(java.util.Collections) GpgGameMessage(com.faforever.client.fa.relay.GpgGameMessage) Player(com.faforever.client.remote.domain.Player) Action(com.faforever.client.notification.Action) MatchmakerMessage(com.faforever.client.rankedmatch.MatchmakerMessage) CompletableTask(com.faforever.client.task.CompletableTask) PlayersMessage(com.faforever.client.remote.domain.PlayersMessage) MatchmakerQueue(com.faforever.client.rankedmatch.MatchmakerMessage.MatchmakerQueue) TimerTask(java.util.TimerTask) RatingRange(com.faforever.client.remote.domain.RatingRange) GameInfoMessage(com.faforever.client.remote.domain.GameInfoMessage) LoginMessage(com.faforever.client.remote.domain.LoginMessage) LoginSuccessEvent(com.faforever.client.user.event.LoginSuccessEvent) PersistentNotification(com.faforever.client.notification.PersistentNotification)

Aggregations

LoginSuccessEvent (com.faforever.client.user.event.LoginSuccessEvent)4 LoginMessage (com.faforever.client.remote.domain.LoginMessage)2 CompletableTask (com.faforever.client.task.CompletableTask)2 TaskService (com.faforever.client.task.TaskService)2 EventBus (com.google.common.eventbus.EventBus)2 MethodHandles (java.lang.invoke.MethodHandles)2 FafClientApplication (com.faforever.client.FafClientApplication)1 GpgGameMessage (com.faforever.client.fa.relay.GpgGameMessage)1 Faction (com.faforever.client.game.Faction)1 KnownFeaturedMod (com.faforever.client.game.KnownFeaturedMod)1 NewGameInfo (com.faforever.client.game.NewGameInfo)1 I18n (com.faforever.client.i18n.I18n)1 ConnectionState (com.faforever.client.net.ConnectionState)1 Action (com.faforever.client.notification.Action)1 NotificationService (com.faforever.client.notification.NotificationService)1 PersistentNotification (com.faforever.client.notification.PersistentNotification)1 Severity (com.faforever.client.notification.Severity)1 PreferencesService (com.faforever.client.preferences.PreferencesService)1 MatchmakerMessage (com.faforever.client.rankedmatch.MatchmakerMessage)1 MatchmakerQueue (com.faforever.client.rankedmatch.MatchmakerMessage.MatchmakerQueue)1