Search in sources :

Example 11 with Player

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);
}
Also used : Player(com.faforever.server.entity.Player) GamePlayerStats(com.faforever.server.entity.GamePlayerStats)

Example 12 with Player

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);
}
Also used : Arrays(java.util.Arrays) ProgrammingError(com.faforever.server.error.ProgrammingError) ModVersion(com.faforever.server.entity.ModVersion) BiFunction(java.util.function.BiFunction) ArmyResult(com.faforever.server.entity.ArmyResult) PlayerOfflineEvent(com.faforever.server.player.PlayerOfflineEvent) PlayerService(com.faforever.server.player.PlayerService) Metrics(com.faforever.server.stats.Metrics) Player(com.faforever.server.entity.Player) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Map(java.util.Map) Pair(org.springframework.data.util.Pair) ArmyStatistics(com.faforever.server.stats.ArmyStatistics) ClientService(com.faforever.server.client.ClientService) CounterService(org.springframework.boot.actuate.metrics.CounterService) ConnectionAware(com.faforever.server.client.ConnectionAware) RatingService(com.faforever.server.rating.RatingService) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EventListener(org.springframework.context.event.EventListener) ErrorCode(com.faforever.server.error.ErrorCode) Streams(com.google.common.collect.Streams) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) GameState(com.faforever.server.entity.GameState) MapService(com.faforever.server.map.MapService) Ladder1v1Rating(com.faforever.server.entity.Ladder1v1Rating) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Requests(com.faforever.server.error.Requests) Stream(java.util.stream.Stream) DivisionService(com.faforever.server.ladder1v1.DivisionService) RatingType(com.faforever.server.rating.RatingType) Game(com.faforever.server.entity.Game) GlobalRating(com.faforever.server.entity.GlobalRating) Entry(java.util.Map.Entry) Optional(java.util.Optional) RequestException(com.faforever.server.error.RequestException) Joiner(com.google.common.base.Joiner) ModService(com.faforever.server.mod.ModService) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) FeaturedMod(com.faforever.server.entity.FeaturedMod) Validity(com.faforever.server.entity.Validity) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) VictoryCondition(com.faforever.server.entity.VictoryCondition) GameResponses(com.faforever.server.client.GameResponses) Service(org.springframework.stereotype.Service) ServerProperties(com.faforever.server.config.ServerProperties) Iterator(java.util.Iterator) FeaturedModFileVersion(com.faforever.server.game.GameResponse.FeaturedModFileVersion) EntityManager(javax.persistence.EntityManager) Consumer(java.util.function.Consumer) SimMod(com.faforever.server.game.GameResponse.SimMod) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) ArmyStatisticsService(com.faforever.server.stats.ArmyStatisticsService) PlayerOnlineEvent(com.faforever.server.player.PlayerOnlineEvent) GamePlayerStats(com.faforever.server.entity.GamePlayerStats) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) Game(com.faforever.server.entity.Game) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 13 with Player

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());
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Player(com.faforever.server.entity.Player)

Example 14 with Player

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);
}
Also used : Player(com.faforever.server.entity.Player) Before(org.junit.Before)

Example 15 with Player

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);
}
Also used : Player(com.faforever.server.entity.Player) HardwareInformation(com.faforever.server.entity.HardwareInformation)

Aggregations

Player (com.faforever.server.entity.Player)73 Test (org.junit.Test)38 Game (com.faforever.server.entity.Game)25 Before (org.junit.Before)13 ServerProperties (com.faforever.server.config.ServerProperties)11 GamePlayerStats (com.faforever.server.entity.GamePlayerStats)11 PlayerOnlineEvent (com.faforever.server.player.PlayerOnlineEvent)11 List (java.util.List)11 Slf4j (lombok.extern.slf4j.Slf4j)11 Service (org.springframework.stereotype.Service)11 ClientService (com.faforever.server.client.ClientService)10 ConnectionAware (com.faforever.server.client.ConnectionAware)10 FeaturedMod (com.faforever.server.entity.FeaturedMod)10 Ladder1v1Rating (com.faforever.server.entity.Ladder1v1Rating)10 Optional (java.util.Optional)10 GlobalRating (com.faforever.server.entity.GlobalRating)9 ModService (com.faforever.server.mod.ModService)9 VisibleForTesting (com.google.common.annotations.VisibleForTesting)9 Duration (java.time.Duration)9 Map (java.util.Map)9