use of com.faforever.server.entity.Player in project faf-java-server by FAForever.
the class GameService method updateDivisionScoresIfValid.
private void updateDivisionScoresIfValid(Game game) {
if (game.getValidity() != Validity.VALID && !game.isRatingEnforced()) {
log.trace("Skipping update of division scores for invalid game: {}", game);
return;
}
if (!modService.isLadder1v1(game.getFeaturedMod())) {
log.trace("Skipping update of division scores for non-ladder1v1 game: {}", game);
return;
}
log.trace("Updating division scores for game: {}", game);
Assert.state(game.getConnectedPlayers().size() == 2, "A ladder1v1 game must have exactly 2 players");
Iterator<Player> playerIterator = game.getConnectedPlayers().values().iterator();
Player playerOne = playerIterator.next();
Player playerTwo = playerIterator.next();
Player winner = null;
if (!game.isMutuallyAgreedDraw()) {
winner = game.getPlayerStats().values().stream().filter(gamePlayerStats -> gamePlayerStats.getScore() != null).max(Comparator.comparingInt(GamePlayerStats::getScore)).map(GamePlayerStats::getPlayer).orElse(null);
log.trace("Game '{}' did not end with mutual draw, winner is: {}", game, winner);
} else {
log.trace("Game '{}' ended with mutual draw", game);
}
log.debug("Posting results for game '{}', playerOne: '{}', playerTwo: '{}', winner: '{}'", game, playerOne, playerTwo, winner);
divisionService.postResult(playerOne, playerTwo, winner);
}
use of com.faforever.server.entity.Player in project faf-java-server by FAForever.
the class GameService method reportArmyScore.
public void reportArmyScore(Player reporter, int armyId, int score) {
Game game = reporter.getCurrentGame();
if (game == null) {
log.warn("Army result reported by player w/o game: {}", reporter);
return;
}
if (!hasArmy(game, armyId)) {
log.warn("Player '{}' reported score '{}' for unknown army '{}' in game '{}'", reporter, score, armyId, game);
return;
}
log.debug("Player '{}' reported score '{}' for army '{}' in game '{}'", reporter, score, armyId, game);
game.getReportedArmyResults().computeIfAbsent(reporter.getId(), playerId -> new HashMap<>()).compute(armyId, (integer, armyResult) -> {
if (armyResult == null) {
return ArmyResult.of(armyId, Outcome.UNKNOWN, score);
}
return ArmyResult.of(armyId, armyResult.getOutcome(), score);
});
endGameIfArmyResultsComplete(game);
}
use of com.faforever.server.entity.Player in project faf-java-server by FAForever.
the class GameService method updateGamePlayerStatsFromOptions.
private void updateGamePlayerStatsFromOptions(GamePlayerStats gamePlayerStats, Map<String, Object> options) {
Arrays.asList(Pair.of(OPTION_TEAM, (Consumer<Integer>) gamePlayerStats::setTeam), Pair.of(OPTION_FACTION, (Consumer<Integer>) gamePlayerStats::setFaction), Pair.of(OPTION_COLOR, (Consumer<Integer>) gamePlayerStats::setColor), Pair.of(OPTION_START_SPOT, (Consumer<Integer>) gamePlayerStats::setStartSpot)).forEach(pair -> {
String key = pair.getFirst();
Optional<Integer> value = Optional.ofNullable((Integer) options.get(key));
if (value.isPresent()) {
pair.getSecond().accept(value.get());
} else {
Player player = gamePlayerStats.getPlayer();
log.warn("Missing option '{}' for player '{}' in game '{}'", key, player, player.getCurrentGame());
}
});
}
use of com.faforever.server.entity.Player in project faf-java-server by FAForever.
the class AvatarServiceTest method setUp.
@Before
public void setUp() throws Exception {
player = (Player) new Player().setId(1);
instance = new AvatarService(avatarAssociationRepository, clientService);
}
use of com.faforever.server.entity.Player in project faf-java-server by FAForever.
the class UniqueIdService method verify.
public void verify(Player player, String uid) {
if (!enabled) {
log.debug("Skipping unique ID check for player '{}' because it is disabled", player);
return;
}
if (player.getUniqueIdExempt() != null) {
log.debug("Skipping unique ID check for player '{}' because: {}", player, player.getUniqueIdExempt().getReason());
return;
}
if (player.getSteamId() != null) {
log.debug("Skipping unique ID check for player '{}' because of steam ID: {}", player, player.getSteamId());
return;
}
UidPayload uidPayload = noCatch(() -> extractPayload(uid));
String hash = Hashing.md5().hashString(uidPayload.getMachine().getUuid() + uidPayload.getMachine().getMemory().getSerial0() + uidPayload.getMachine().getDisks().getControllerId() + uidPayload.getMachine().getBios().getManufacturer() + uidPayload.getMachine().getProcessor().getName() + uidPayload.getMachine().getProcessor().getId() + uidPayload.getMachine().getBios().getSmbbVersion() + uidPayload.getMachine().getBios().getSerial() + uidPayload.getMachine().getDisks().getVSerial(), UTF_8).toString();
HardwareInformation information = hardwareInformationRepository.findOneByHash(hash).orElseGet(() -> hardwareInformationRepository.save(new HardwareInformation(0, hash, uidPayload.getMachine().getUuid(), uidPayload.getMachine().getMemory().getSerial0(), uidPayload.getMachine().getDisks().getControllerId(), uidPayload.getMachine().getBios().getManufacturer(), uidPayload.getMachine().getProcessor().getName(), uidPayload.getMachine().getProcessor().getId(), uidPayload.getMachine().getBios().getSmbbVersion(), uidPayload.getMachine().getBios().getSerial(), uidPayload.getMachine().getDisks().getVSerial(), Sets.newHashSet(player))));
player.getHardwareInformations().add(information);
Set<Player> players = information.getPlayers();
int count = players.size();
Requests.verify(count < 2, ErrorCode.UID_USED_BY_MULTIPLE_USERS, linkToSteamUrl);
Requests.verify(count == 0 || Objects.equals(players.iterator().next().getId(), player.getId()), ErrorCode.UID_USED_BY_ANOTHER_USER, linkToSteamUrl);
if (count == 0) {
// This happens if hardware information is already present but the user associations have been deleted.
information.getPlayers().add(player);
hardwareInformationRepository.save(information);
}
log.debug("Player '{}' passed unique ID check", player);
}
Aggregations