Skip to content

Commit

Permalink
Feature/v2 protocol geo (#11)
Browse files Browse the repository at this point in the history
* Also auto-complete chat-only users on Tab in regular chat tabs
Fixes #1092

* Remove AutoCompletion from all controller except ChannelTabController
Fixes #1092

* v2 protocol fix
  • Loading branch information
Geosearchef authored and 1-alex98 committed Mar 22, 2019
1 parent cc3a98d commit 4118fbd
Show file tree
Hide file tree
Showing 41 changed files with 181 additions and 199 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ apply plugin: 'jacoco'
apply plugin: 'com.github.kt3k.coveralls'
apply plugin: 'distribution'

sourceCompatibility = JavaVersion.VERSION_1_10
targetCompatibility = JavaVersion.VERSION_1_10
sourceCompatibility = 1.11
targetCompatibility = 1.11

allprojects {
repositories {
Expand Down
6 changes: 4 additions & 2 deletions service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ dependencies {
compile("org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:${springSecurityOauth2AutoconfigureVersion}")
compile("org.springframework:spring-web")

compileOnly("org.springframework.boot:spring-boot-configuration-processor")

compile("com.github.ben-manes.caffeine:caffeine")
compile("org.apache.httpcomponents:httpclient")

Expand Down Expand Up @@ -50,6 +52,6 @@ dependencies {
testCompile("com.natpryce.hamcrest:hamcrest-reflection:0.1-2")

// TODO remove after going public with the project
compile files("C:\\Users\\Downlord\\git\\sh-java-api\\sh-api-java-dto\\build\\libs\\sh-api-java-dto.jar")
compile files("C:\\Users\\Downlord\\git\\sh-server\\sh-server-protocol-v2\\build\\libs\\sh-server-protocol-v2-snapshot.jar")
compile files("/home/geosearchef/sh/sh-java-api/sh-api-java-dto/build/libs/sh-api-java-dto.jar")
compile files("/home/geosearchef/sh/sh-java-server/sh-server-protocol-v2/build/libs/sh-server-protocol-v2-snapshot.jar")
}
17 changes: 4 additions & 13 deletions service/src/main/java/com/faforever/client/api/ApiDtoMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.supcomhub.api.dto.ModReview;
import org.supcomhub.api.dto.ModReviewSummary;
import org.supcomhub.api.dto.ModVersionReview;
import org.supcomhub.api.dto.Rank;
import org.supcomhub.api.dto.ReviewScoreCount;

import java.time.LocalDateTime;
Expand All @@ -63,16 +62,10 @@ public interface ApiDtoMapper {
@Mapping(target = "idleSince", ignore = true)
@Mapping(target = "names", ignore = true)
@Mapping(target = "chatChannelUsers", ignore = true)
@Mapping(target = "rating", ignore = true)
//TODO: implement lazy fetching
Player map(Account dto);

default Integer map(Rank rank) {
return rank.getRank();
}

default ObservableMap<String, Integer> mapRanks(List<Rank> ranks) {
return FXCollections.observableMap(ranks.stream()
.collect(Collectors.toMap(o -> o.getFeaturedMod().getTechnicalName(), Rank::getRank)));
}

@Mapping(target = "selected", ignore = true)
@Mapping(target = "selectable", ignore = true)
Expand Down Expand Up @@ -142,10 +135,8 @@ default FaMap map(LadderMap ladderMap) {
@Mapping(target = "size", ignore = true)
FaMap map(org.supcomhub.api.dto.Map map);

@Mapping(target = "username", source = "account.displayName")
@Mapping(target = "position", source = "rank")
@Mapping(target = "gamesPlayed", ignore = true)
@Mapping(target = "winLossRatio", ignore = true)
// @Mapping(target = "totalGames", ignore = true) TODO: add ?, was ignored before
// @Mapping(target = "wonGames", ignore = true)
LeaderboardEntry map(org.supcomhub.api.dto.LeaderboardEntry leaderboardEntry);

Mod map(org.supcomhub.api.dto.Mod mod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ public void authorize(int playerId, String username, String password) {
public List<Mod> getMods() {
Account uploader = new Account();
return Arrays.asList(
new org.supcomhub.api.dto.Mod("1", "Mod Number One", "Mock", uploader, Collections.emptyList(), mod()),
new org.supcomhub.api.dto.Mod("2", "Mod Number Two", "Mock", uploader, Collections.emptyList(), mod()),
new org.supcomhub.api.dto.Mod("3", "Mod Number Three", "Mock", uploader, Collections.emptyList(), mod()),
new org.supcomhub.api.dto.Mod("4", "Mod Number Four", "Mock", uploader, Collections.emptyList(), mod()),
new org.supcomhub.api.dto.Mod("5", "Mod Number Five", "Mock", uploader, Collections.emptyList(), mod()),
new org.supcomhub.api.dto.Mod("6", "Mod Number Six", "Mock", uploader, Collections.emptyList(), mod()),
new org.supcomhub.api.dto.Mod("7", "Mod Number Seven", "Mock", uploader, Collections.emptyList(), mod()),
new org.supcomhub.api.dto.Mod("8", "Mod Number Eight", "Mock", uploader, Collections.emptyList(), mod())
new org.supcomhub.api.dto.Mod("1", "Mod Number One", uploader, Collections.emptyList(), mod()),
new org.supcomhub.api.dto.Mod("2", "Mod Number Two", uploader, Collections.emptyList(), mod()),
new org.supcomhub.api.dto.Mod("3", "Mod Number Three", uploader, Collections.emptyList(), mod()),
new org.supcomhub.api.dto.Mod("4", "Mod Number Four", uploader, Collections.emptyList(), mod()),
new org.supcomhub.api.dto.Mod("5", "Mod Number Five", uploader, Collections.emptyList(), mod()),
new org.supcomhub.api.dto.Mod("6", "Mod Number Six", uploader, Collections.emptyList(), mod()),
new org.supcomhub.api.dto.Mod("7", "Mod Number Seven", uploader, Collections.emptyList(), mod()),
new org.supcomhub.api.dto.Mod("8", "Mod Number Eight", uploader, Collections.emptyList(), mod())
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Process startGame(
.faction(faction)
.clan(currentPlayer.getClanTag())
.country(currentPlayer.getCountry())
.rank(currentPlayer.getRanks().get(leaderboardName))
.rank(currentPlayer.getRating().get(leaderboardName))
.username(currentPlayer.getDisplayName())
.logFile(preferencesService.getFafLogDirectory().resolve("game.log"))
.localGpgPort(gpgPort)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -132,7 +133,7 @@ public GameService(
GameUpdater gameUpdater,
NotificationService notificationService,
I18n i18n,
Executor executor,
@Qualifier("taskExecutor") Executor executor,
PlayerService playerService,
ReportingService reportingService,
EventBus eventBus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import com.faforever.client.remote.ClientMessage;
import org.springframework.integration.annotation.Gateway;
import org.springframework.integration.annotation.IntegrationComponentScan;
import org.springframework.integration.annotation.MessagingGateway;
import org.springframework.stereotype.Component;

/**
* A Spring Integration gateway to send messages to the server.
*/
@MessagingGateway
@IntegrationComponentScan
@Component
public interface ServerGateway {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
package com.faforever.client.leaderboard;

import javafx.beans.property.FloatProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleFloatProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import org.supcomhub.api.dto.Leaderboard;

public class LeaderboardEntry {

private StringProperty username;
private StringProperty playerName;
private IntegerProperty rating;
private IntegerProperty totalGames;
private IntegerProperty wonGames;
private ObjectProperty<Leaderboard> leaderboard;
private IntegerProperty position;
private IntegerProperty rank;
private IntegerProperty gamesPlayed;
private FloatProperty winLossRatio;

public LeaderboardEntry() {
username = new SimpleStringProperty();
playerName = new SimpleStringProperty();
rating = new SimpleIntegerProperty();
totalGames = new SimpleIntegerProperty();
wonGames = new SimpleIntegerProperty();
leaderboard = new SimpleObjectProperty<>();
position = new SimpleIntegerProperty();
rank = new SimpleIntegerProperty();
gamesPlayed = new SimpleIntegerProperty();
winLossRatio = new SimpleFloatProperty();
}

public String getUsername() {
return username.get();
public float getWinLossRatio() {
return (float) getWonGames() / (float) getTotalGames();
}

public String getPlayerName() {
return playerName.get();
}

public void setUsername(String username) {
this.username.set(username);
public void setPlayerName(String playerName) {
this.playerName.set(playerName);
}

public StringProperty usernameProperty() {
return username;
public StringProperty playerNameProperty() {
return playerName;
}

public int getPosition() {
Expand All @@ -47,45 +54,45 @@ public IntegerProperty positionProperty() {
return position;
}

public int getRank() {
return rank.get();
public int getRating() {
return rating.get();
}

public void setRank(int rank) {
this.rank.set(rank);
public void setRating(int rating) {
this.rating.set(rating);
}

public IntegerProperty rankProperty() {
return rank;
public IntegerProperty ratingProperty() {
return rating;
}

public int getGamesPlayed() {
return gamesPlayed.get();
public int getTotalGames() {
return totalGames.get();
}

public void setGamesPlayed(int gamesPlayed) {
this.gamesPlayed.set(gamesPlayed);
public void setTotalGames(int totalGames) {
this.totalGames.set(totalGames);
}

public IntegerProperty gamesPlayedProperty() {
return gamesPlayed;
public IntegerProperty totalGamesProperty() {
return totalGames;
}

public float getWinLossRatio() {
return winLossRatio.get();
public int getWonGames() {
return wonGames.get();
}

public void setWinLossRatio(float winLossRatio) {
this.winLossRatio.set(winLossRatio);
public void setWonGames(int wonGames) {
this.wonGames.set(wonGames);
}

public FloatProperty winLossRatioProperty() {
return winLossRatio;
public IntegerProperty wonGamesProperty() {
return wonGames;
}

@Override
public int hashCode() {
return username.get() != null ? username.get().hashCode() : 0;
return playerName.get() != null ? playerName.get().hashCode() : 0;
}

@Override
Expand All @@ -99,14 +106,14 @@ public boolean equals(Object o) {

LeaderboardEntry that = (LeaderboardEntry) o;

return !(username.get() != null ? !username.get().equalsIgnoreCase(that.username.get()) : that.username.get() != null);
return !(playerName.get() != null ? !playerName.get().equalsIgnoreCase(that.playerName.get()) : that.playerName.get() != null);

}

@Override
public String toString() {
return "Ranked1v1EntryBean{" +
"displayName=" + username.get() +
"displayName=" + playerName.get() +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public CompletableFuture<List<RatingStat>> getLeaderboardStats(String leaderboar
private List<RatingStat> toRankStats(List<LeaderboardEntry> entries) {
Map<Integer, Long> totalCount = countByRank(entries.stream());
Map<Integer, Long> countWithoutFewGames = countByRank(entries.stream()
.filter(entry -> entry.gamesPlayedProperty().get() >= MINIMUM_GAMES_PLAYED_TO_BE_SHOWN));
.filter(entry -> entry.totalGamesProperty().get() >= MINIMUM_GAMES_PLAYED_TO_BE_SHOWN));

return totalCount.entrySet().stream()
.map(entry -> new RatingStat(
Expand All @@ -43,7 +43,7 @@ private List<RatingStat> toRankStats(List<LeaderboardEntry> entries) {
}

private Map<Integer, Long> countByRank(Stream<LeaderboardEntry> entries) {
return entries.collect(Collectors.groupingBy(LeaderboardEntry::getRank, Collectors.counting()));
return entries.collect(Collectors.groupingBy(LeaderboardEntry::getRating, Collectors.counting()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public CompletableFuture<List<RatingStat>> getLeaderboardStats(String leaderboar

@Override
public CompletableFuture<LeaderboardEntry> getEntryForPlayer(int playerId, String leaderboardName) {
return CompletableFuture.completedFuture(createLeaderboardEntry("Player #" + playerId, 111, 222, 333, 55.55f));
return CompletableFuture.completedFuture(createLeaderboardEntry("Player #" + playerId, 111, 222, 333, 192));
}

@Override
Expand All @@ -51,21 +51,21 @@ protected List<LeaderboardEntry> call() {
int gamecount = (int) (Math.random() * 10000);
float winloss = (float) (Math.random() * 100);

list.add(createLeaderboardEntry(name, i, rating, gamecount, winloss));
list.add(createLeaderboardEntry(name, i, rating, gamecount, (int) (gamecount * winloss)));

}
return list;
}
}).getFuture();
}

private LeaderboardEntry createLeaderboardEntry(String name, int position, int rank, int gamesPlayed, float winLossRatio) {
private LeaderboardEntry createLeaderboardEntry(String name, int position, int rank, int totalGames, int wonGames) {
LeaderboardEntry leaderboardEntry = new LeaderboardEntry();
leaderboardEntry.setUsername(name);
leaderboardEntry.setPlayerName(name);
leaderboardEntry.setPosition(position);
leaderboardEntry.setRank(rank);
leaderboardEntry.setGamesPlayed(gamesPlayed);
leaderboardEntry.setWinLossRatio(winLossRatio);
leaderboardEntry.setRating(rank);
leaderboardEntry.setTotalGames(totalGames);
leaderboardEntry.setWonGames(wonGames);

return leaderboardEntry;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.faforever.client.mod;

import com.faforever.client.api.FxMapper;
import com.faforever.client.mapstruct.MapStructConfig;
import com.faforever.client.mod.ModVersion.ModType;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

import java.util.UUID;

@Mapper(uses = FxMapper.class)
@Mapper(config = MapStructConfig.class, uses = FxMapper.class)
public interface ModInfoMapper {

@Mapping(target = "displayName", source = "name")
Expand Down
12 changes: 6 additions & 6 deletions service/src/main/java/com/faforever/client/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Player {
private final StringProperty avatarTooltip;
private final ObjectProperty<SocialStatus> socialStatus;
/** Key is the leaderboard name. */
private final MapProperty<String, Integer> ranks;
private final MapProperty<String, Integer> rating;
private final ObjectProperty<Game> game;
private final ObjectProperty<PlayerStatus> status;
private final ObservableSet<ChatChannelUser> chatChannelUsers;
Expand All @@ -54,7 +54,7 @@ public Player() {
country = new SimpleStringProperty();
avatarUrl = new SimpleObjectProperty<>();
avatarTooltip = new SimpleStringProperty();
ranks = new SimpleMapProperty<>(FXCollections.observableHashMap());
rating = new SimpleMapProperty<>(FXCollections.observableHashMap());
status = new SimpleObjectProperty<>(PlayerStatus.IDLE);
chatChannelUsers = FXCollections.observableSet();
game = new SimpleObjectProperty<>();
Expand Down Expand Up @@ -242,12 +242,12 @@ public ObservableSet<ChatChannelUser> getChatChannelUsers() {
return chatChannelUsers;
}

public ObservableMap<String, Integer> getRanks() {
return ranks.get();
public ObservableMap<String, Integer> getRating() {
return rating.get();
}

public ReadOnlyMapProperty<String, Integer> ranksProperty() {
return ranks;
public ReadOnlyMapProperty<String, Integer> ratingProperty() {
return rating;
}

public void updateFrom(PlayerServerMessage player) {
Expand Down
Loading

0 comments on commit 4118fbd

Please sign in to comment.