Search in sources :

Example 1 with GameResponses

use of com.faforever.server.client.GameResponses in project faf-java-server by FAForever.

the class GameService method onPlayerOnlineEvent.

@EventListener
public void onPlayerOnlineEvent(PlayerOnlineEvent event) {
    counterService.increment(String.format(Metrics.PLAYER_GAMES_STATE_FORMAT, event.getPlayer().getGameState()));
    clientService.sendGameList(new GameResponses(activeGamesById.values().stream().map(this::toResponse).collect(Collectors.toList())), event.getPlayer());
}
Also used : GameResponses(com.faforever.server.client.GameResponses) EventListener(org.springframework.context.event.EventListener)

Example 2 with GameResponses

use of com.faforever.server.client.GameResponses in project faf-java-server by FAForever.

the class GameServiceTest method onAuthenticationSuccess.

@Test
@SuppressWarnings("unchecked")
public void onAuthenticationSuccess() throws Exception {
    player1.setCurrentGame(null);
    instance.createGame("Test game", FAF_TECHNICAL_NAME, MAP_NAME, null, GameVisibility.PUBLIC, GAME_MIN_RATING, GAME_MAX_RATING, player1);
    TestingAuthenticationToken authentication = new TestingAuthenticationToken("JUnit", "foo");
    authentication.setDetails(new TestingAuthenticationToken(new FafUserDetails((User) new User().setPlayer(player2).setPassword("pw").setLogin("JUnit")), null));
    instance.onPlayerOnlineEvent(new PlayerOnlineEvent(this, player2));
    ArgumentCaptor<GameResponses> captor = ArgumentCaptor.forClass((Class) Collection.class);
    verify(clientService).sendGameList(captor.capture(), eq(player2));
    GameResponses games = captor.getValue();
    assertThat(games.getResponses(), hasSize(1));
    assertThat(games.getResponses().iterator().next().getTitle(), is("Test game"));
}
Also used : User(com.faforever.server.entity.User) Collection(java.util.Collection) FafUserDetails(com.faforever.server.security.FafUserDetails) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) PlayerOnlineEvent(com.faforever.server.player.PlayerOnlineEvent) GameResponses(com.faforever.server.client.GameResponses) Test(org.junit.Test)

Aggregations

GameResponses (com.faforever.server.client.GameResponses)2 User (com.faforever.server.entity.User)1 PlayerOnlineEvent (com.faforever.server.player.PlayerOnlineEvent)1 FafUserDetails (com.faforever.server.security.FafUserDetails)1 Collection (java.util.Collection)1 Test (org.junit.Test)1 EventListener (org.springframework.context.event.EventListener)1 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)1