Search in sources :

Example 6 with PlayerResponse

use of com.faforever.server.player.PlayerResponse in project faf-java-server by FAForever.

the class ClientService method toPlayerInformationResponse.

private PlayerResponse toPlayerInformationResponse(Player player) {
    Optional<PlayerResponse.Player.Avatar> avatar = player.getAvailableAvatars().stream().filter(AvatarAssociation::isSelected).findFirst().map(association -> {
        com.faforever.server.entity.Avatar avatarEntity = association.getAvatar();
        return new PlayerResponse.Player.Avatar(avatarEntity.getUrl(), avatarEntity.getDescription());
    });
    Optional<Rating> globalRating = Optional.ofNullable(player.getGlobalRating()).map(rating -> new Rating(rating.getMean(), rating.getDeviation()));
    Optional<Rating> ladder1v1Rating = Optional.ofNullable(player.getLadder1v1Rating()).map(rating -> new Rating(rating.getMean(), rating.getDeviation()));
    return new PlayerResponse(player.getId(), player.getLogin(), player.getCountry(), new PlayerResponse.Player(globalRating.orElse(null), ladder1v1Rating.orElse(null), Optional.ofNullable(player.getGlobalRating()).map(GlobalRating::getNumGames).orElse(0), avatar.orElse(null), Optional.ofNullable(player.getClan()).map(Clan::getTag).orElse(null)));
}
Also used : PlayerResponse(com.faforever.server.player.PlayerResponse) Rating(com.faforever.server.player.PlayerResponse.Player.Rating) GlobalRating(com.faforever.server.entity.GlobalRating) AvatarAssociation(com.faforever.server.entity.AvatarAssociation)

Example 7 with PlayerResponse

use of com.faforever.server.player.PlayerResponse in project faf-java-server by FAForever.

the class V2ServerMessageTransformerTest method player.

@Test
public void player() throws Exception {
    String response = instance.transform(new PlayerResponse(1, "A", "CH", new PlayerResponse.Player(new Rating(900, 120), new Rating(600, 50), 12, new Avatar("http://localhost/avatar.png", "Avatar"), "AA")));
    assertThat(response, is("{\"data\":{\"playerId\":1,\"username\":\"A\",\"country\":\"CH\",\"player\":{\"globalRating\":{\"mean\":900.0,\"deviation\":120.0},\"ladder1v1Rating\":{\"mean\":600.0,\"deviation\":50.0},\"numberOfGames\":12,\"avatar\":{\"url\":\"http://localhost/avatar.png\",\"description\":\"Avatar\"},\"clanTag\":\"AA\"}},\"type\":\"player\"}"));
}
Also used : PlayerResponse(com.faforever.server.player.PlayerResponse) Player(com.faforever.server.game.GameResponse.Player) Rating(com.faforever.server.player.PlayerResponse.Player.Rating) Avatar(com.faforever.server.player.PlayerResponse.Player.Avatar) Test(org.junit.Test)

Example 8 with PlayerResponse

use of com.faforever.server.player.PlayerResponse in project faf-java-server by FAForever.

the class V2ServerMessageTransformerTest method loginDetails.

@Test
public void loginDetails() throws Exception {
    String response = instance.transform(new LoginDetailsResponse(new PlayerResponse(1, "A", "CH", new PlayerResponse.Player(new Rating(900, 120), new Rating(600, 50), 12, new Avatar("http://localhost/avatar.png", "Avatar"), "AA"))));
    assertThat(response, is("{\"data\":{\"playerId\":1,\"username\":\"A\",\"country\":\"CH\",\"player\":{\"globalRating\":{\"mean\":900.0,\"deviation\":120.0},\"ladder1v1Rating\":{\"mean\":600.0,\"deviation\":50.0},\"numberOfGames\":12,\"avatar\":{\"url\":\"http://localhost/avatar.png\",\"description\":\"Avatar\"},\"clanTag\":\"AA\"}},\"type\":\"loginDetails\"}"));
}
Also used : PlayerResponse(com.faforever.server.player.PlayerResponse) Rating(com.faforever.server.player.PlayerResponse.Player.Rating) LoginDetailsResponse(com.faforever.server.player.LoginDetailsResponse) Avatar(com.faforever.server.player.PlayerResponse.Player.Avatar) Test(org.junit.Test)

Example 9 with PlayerResponse

use of com.faforever.server.player.PlayerResponse in project faf-java-server by FAForever.

the class LoginDetailsServerMessageTransformerTest method transformFull.

@Test
@SuppressWarnings("unchecked")
public void transformFull() throws Exception {
    Map<String, Serializable> result = LoginDetailsResponseTransformer.INSTANCE.transform(new LoginDetailsResponse(new PlayerResponse(1, TEST_USERNAME, "CH", new PlayerResponse.Player(new Rating(1200d, 200d), new Rating(900d, 100d), 12, new Avatar("http://example.com", "Tooltip"), "FOO"))));
    assertThat(result.get("command"), is("welcome"));
    assertThat(result.get("id"), is(1));
    assertThat(result.get("login"), is(TEST_USERNAME));
    Map<String, Object> me = (Map<String, Object>) result.get("me");
    assertThat(me.get("id"), is(1));
    assertThat(me.get("login"), is(TEST_USERNAME));
    assertThat(me.get("login"), is(TEST_USERNAME));
    assertThat(me.get("global_rating"), is(new double[] { 1200, 200 }));
    assertThat(me.get("ladder_rating"), is(new double[] { 900, 100 }));
    assertThat(me.get("number_of_games"), is(12));
    Map<String, Serializable> avatarMap = (Map<String, Serializable>) me.get("avatar");
    assertThat(avatarMap.get("url"), is("http://example.com"));
    assertThat(avatarMap.get("tooltip"), is("Tooltip"));
    assertThat(me.get("country"), is("CH"));
    assertThat(me.get("clan"), is("FOO"));
}
Also used : PlayerResponse(com.faforever.server.player.PlayerResponse) Serializable(java.io.Serializable) Rating(com.faforever.server.player.PlayerResponse.Player.Rating) LoginDetailsResponse(com.faforever.server.player.LoginDetailsResponse) Map(java.util.Map) Avatar(com.faforever.server.player.PlayerResponse.Player.Avatar) Test(org.junit.Test)

Example 10 with PlayerResponse

use of com.faforever.server.player.PlayerResponse in project faf-java-server by FAForever.

the class LoginDetailsServerMessageTransformerTest method transformHandleLadder1v1RatingNull.

@Test
@SuppressWarnings("unchecked")
public void transformHandleLadder1v1RatingNull() throws Exception {
    Map<String, Serializable> result = LoginDetailsResponseTransformer.INSTANCE.transform(new LoginDetailsResponse(new PlayerResponse(1, TEST_USERNAME, "CH", new PlayerResponse.Player(new Rating(900d, 100d), null, 12, new Avatar("http://example.com", "Tooltip"), "FOO"))));
    Map<String, Object> me = (Map<String, Object>) result.get("me");
    assertThat(me.get("ladder_rating"), is(new double[2]));
}
Also used : PlayerResponse(com.faforever.server.player.PlayerResponse) Serializable(java.io.Serializable) Rating(com.faforever.server.player.PlayerResponse.Player.Rating) LoginDetailsResponse(com.faforever.server.player.LoginDetailsResponse) Map(java.util.Map) Avatar(com.faforever.server.player.PlayerResponse.Player.Avatar) Test(org.junit.Test)

Aggregations

PlayerResponse (com.faforever.server.player.PlayerResponse)15 Test (org.junit.Test)14 Rating (com.faforever.server.player.PlayerResponse.Player.Rating)13 Serializable (java.io.Serializable)10 Map (java.util.Map)10 Avatar (com.faforever.server.player.PlayerResponse.Player.Avatar)8 LoginDetailsResponse (com.faforever.server.player.LoginDetailsResponse)6 PlayerResponses (com.faforever.server.client.PlayerResponses)5 List (java.util.List)5 AvatarAssociation (com.faforever.server.entity.AvatarAssociation)2 GlobalRating (com.faforever.server.entity.GlobalRating)2 Avatar (com.faforever.server.entity.Avatar)1 Clan (com.faforever.server.entity.Clan)1 ClanMembership (com.faforever.server.entity.ClanMembership)1 Ladder1v1Rating (com.faforever.server.entity.Ladder1v1Rating)1 Player (com.faforever.server.entity.Player)1 Player (com.faforever.server.game.GameResponse.Player)1 CompletableFuture (java.util.concurrent.CompletableFuture)1