use of com.faforever.client.player.Player in project downlords-faf-client by FAForever.
the class Ladder1V1ControllerTest method setUp.
@Before
public void setUp() throws Exception {
instance = new Ladder1v1Controller(gameService, preferencesService, playerService, leaderboardService, i18n, new ClientProperties(), eventBus);
Player player = new Player(USERNAME);
player.setId(PLAYER_ID);
currentPlayerProperty = new SimpleObjectProperty<>(player);
factionList = FXCollections.observableArrayList();
LeaderboardEntry leaderboardEntry = new LeaderboardEntry();
leaderboardEntry.setRating(500);
leaderboardEntry.setWinLossRatio(12.23f);
leaderboardEntry.setRank(100);
leaderboardEntry.setGamesPlayed(412);
leaderboardEntry.setUsername(USERNAME);
when(leaderboardService.getLadder1v1Stats()).thenReturn(CompletableFuture.completedFuture(new ArrayList<>()));
when(leaderboardService.getEntryForPlayer(PLAYER_ID)).thenReturn(CompletableFuture.completedFuture(leaderboardEntry));
when(gameService.searching1v1Property()).thenReturn(searching1v1Property);
when(preferencesService.getPreferences()).thenReturn(preferences);
when(preferences.getLadder1v1Prefs()).thenReturn(ladder1V1Prefs);
when(ladder1V1Prefs.getFactions()).thenReturn(factionList);
when(preferences.getForgedAlliance()).thenReturn(forgedAlliancePrefs);
when(playerService.getCurrentPlayer()).thenReturn(Optional.ofNullable(currentPlayerProperty.get()));
when(playerService.currentPlayerProperty()).thenReturn(currentPlayerProperty);
loadFxml("theme/play/ranked_1v1.fxml", clazz -> instance);
}
use of com.faforever.client.player.Player in project downlords-faf-client by FAForever.
the class ReplayDetailControllerTest method onDownloadMoreInfoClicked.
@Test
public void onDownloadMoreInfoClicked() throws Exception {
when(replayService.getSize(anyInt())).thenReturn(CompletableFuture.completedFuture(1024));
Replay replay = new Replay();
Review review = new Review();
review.setPlayer(new Player("junit"));
replay.getReviews().setAll(FXCollections.observableArrayList(review));
replay.setValidity(Validity.VALID);
replay.setFeaturedMod(new FeaturedMod());
instance.setReplay(replay);
Path tmpPath = Paths.get("foo.tmp");
when(replayService.downloadReplay(replay.getId())).thenReturn(CompletableFuture.completedFuture(tmpPath));
instance.onDownloadMoreInfoClicked();
verify(replayService).enrich(replay, tmpPath);
assertThat(instance.optionsTable.isVisible(), is(true));
assertThat(instance.chatTable.isVisible(), is(true));
}
use of com.faforever.client.player.Player in project downlords-faf-client by FAForever.
the class GameServiceImpl method onGameInfo.
private void onGameInfo(GameInfoMessage gameInfoMessage) {
// Since all game updates are usually reflected on the UI and to prevent deadlocks
JavaFxUtil.assertApplicationThread();
if (gameInfoMessage.getGames() != null) {
gameInfoMessage.getGames().forEach(this::onGameInfo);
return;
}
Player currentPlayer = playerService.getCurrentPlayer().orElseThrow(() -> new IllegalStateException("Player has not been set"));
Game game = createOrUpdateGame(gameInfoMessage);
if (GameStatus.CLOSED == game.getStatus()) {
if (currentPlayer.getGame() == game) {
// Don't remove the game until the current player closed it. TODO: Why?
currentPlayer.gameProperty().addListener((observable, oldValue, newValue) -> {
if (newValue == null && oldValue.getStatus() == GameStatus.CLOSED) {
removeGame(gameInfoMessage);
}
});
} else {
removeGame(gameInfoMessage);
}
return;
}
// TODO the following can be removed as soon as the server tells us which game a player is in.
boolean currentPlayerInGame = gameInfoMessage.getTeams().values().stream().anyMatch(team -> team.contains(currentPlayer.getUsername()));
if (currentPlayerInGame && GameStatus.OPEN == gameInfoMessage.getState()) {
synchronized (currentGame) {
currentGame.set(game);
}
}
game.statusProperty().addListener((observable, oldValue, newValue) -> {
if (oldValue == GameStatus.OPEN && newValue == GameStatus.PLAYING && game.getTeams().values().stream().anyMatch(team -> team.contains(currentPlayer.getUsername())) && !platformService.isWindowFocused(faWindowTitle)) {
platformService.focusWindow(faWindowTitle);
}
});
}
use of com.faforever.client.player.Player in project downlords-faf-client by FAForever.
the class IceAdapterImpl method start.
@Override
public CompletableFuture<Integer> start() {
iceAdapterClientFuture = new CompletableFuture<>();
Thread thread = new Thread(() -> {
String nativeDir = System.getProperty("nativeDir", "lib");
int adapterPort = SocketUtils.findAvailableTcpPort();
int gpgPort = SocketUtils.findAvailableTcpPort();
Player currentPlayer = playerService.getCurrentPlayer().orElseThrow(() -> new IllegalStateException("Player has not been set"));
Path workDirectory = Paths.get(nativeDir);
String[] cmd = new String[] { // FIXME make linux compatible
workDirectory.resolve("faf-ice-adapter.exe").toString(), "--id", String.valueOf(currentPlayer.getId()), "--login", currentPlayer.getUsername(), "--rpc-port", String.valueOf(adapterPort), "--gpgnet-port", String.valueOf(gpgPort) };
try {
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.directory(workDirectory.toFile());
processBuilder.command(cmd);
log.debug("Starting ICE adapter with command: {}", asList(cmd));
process = processBuilder.start();
Logger logger = LoggerFactory.getLogger("faf-ice-adapter");
gobbleLines(process.getInputStream(), logger::debug);
gobbleLines(process.getErrorStream(), logger::error);
IceAdapterCallbacks iceAdapterCallbacks = applicationContext.getBean(IceAdapterCallbacks.class);
for (int attempt = 0; attempt < CONNECTION_ATTEMPTS; attempt++) {
try {
TcpClient tcpClient = new TcpClient("localhost", adapterPort, iceAdapterCallbacks);
peer = tcpClient.getPeer();
setIceServers();
setLobbyInitMode();
break;
} catch (ConnectException e) {
logger.debug("Could not connect to ICE adapter (attempt {}/{})", attempt, CONNECTION_ATTEMPTS);
}
}
iceAdapterClientFuture.complete(gpgPort);
int exitCode = process.waitFor();
if (exitCode == 0) {
logger.debug("ICE adapter terminated normally");
} else {
logger.warn("ICE adapter terminated with exit code: {}", exitCode);
}
} catch (Exception e) {
iceAdapterClientFuture.completeExceptionally(e);
}
});
thread.setDaemon(true);
thread.start();
return iceAdapterClientFuture;
}
use of com.faforever.client.player.Player in project downlords-faf-client by FAForever.
the class ReviewsControllerTest method setUp.
@Before
public void setUp() throws Exception {
instance = new ReviewsController(i18n, uiService, playerService);
when(reviewController.getRoot()).thenReturn(new Pane());
when(playerService.getCurrentPlayer()).thenReturn(Optional.of(new Player("junit")));
loadFxml("theme/vault/review/reviews.fxml", param -> {
if (param == ReviewController.class) {
return reviewController;
}
if (param == StarsController.class) {
return starsController;
}
if (param == StarController.class) {
return starController;
}
return instance;
});
}
Aggregations