Search in sources :

Example 1 with Game

use of com.faforever.server.entity.Game in project faf-java-server by FAForever.

the class MatchMakerServiceTest method startSearchAlreadyInGame.

@Test
public void startSearchAlreadyInGame() throws Exception {
    Player player = new Player();
    player.setCurrentGame(new Game());
    expectedException.expect(requestExceptionWithCode(ErrorCode.ALREADY_IN_GAME));
    instance.submitSearch(player, Faction.CYBRAN, QUEUE_NAME);
}
Also used : Player(com.faforever.server.entity.Player) Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Example 2 with Game

use of com.faforever.server.entity.Game in project faf-java-server by FAForever.

the class GameService method settlePlayerScores.

/**
 * Determines the final army results and updates the players' scores with them.
 */
private void settlePlayerScores(Game game) {
    Map<Integer, ArmyResult> armyIdToResult = findMostReportedCompleteArmyResultsReportedByConnectedPlayers(game);
    for (Entry<Integer, GamePlayerStats> entry : game.getPlayerStats().entrySet()) {
        Integer playerId = entry.getKey();
        Integer armyScore = Optional.ofNullable(game.getPlayerOptions()).map(playerOptions -> playerOptions.get(playerId)).map(options -> (Integer) options.get(OPTION_ARMY)).map(armyIdToResult::get).map(ArmyResult::getScore).orElse(null);
        entry.getValue().setScore(armyScore).setScoreTime(Instant.now());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) GamePlayerStats(com.faforever.server.entity.GamePlayerStats) ArmyResult(com.faforever.server.entity.ArmyResult)

Example 3 with Game

use of com.faforever.server.entity.Game in project faf-java-server by FAForever.

the class GameService method enforceRating.

/**
 * Enforce rating even though the minimum game time has not yet been reached.
 */
public void enforceRating(Player reporter) {
    Game game = reporter.getCurrentGame();
    if (game == null) {
        log.warn("Game statistics reported by player w/o game: {}", reporter);
        return;
    }
    log.debug("Player '{}' enforced rating for game '{}'", reporter, game);
    game.setRatingEnforced(true);
}
Also used : Game(com.faforever.server.entity.Game)

Example 4 with Game

use of com.faforever.server.entity.Game 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 5 with Game

use of com.faforever.server.entity.Game in project faf-java-server by FAForever.

the class ArmyStatisticsService method process.

public void process(Player player, Game game, List<ArmyStatistics> statistics) {
    int numberOfHumans = 0;
    float highestScore = 0;
    String highestScorerName = null;
    ArmyStatistics armyStats = null;
    int currentIndex = 0;
    int playerArmyId = -1;
    for (ArmyStatistics statsItem : statistics) {
        currentIndex++;
        if (statsItem.getType() == AI && !CIVILIAN_ARMY_NAME.equals(statsItem.getName())) {
            log.debug("AI game reported by '{}', aborting stats processing", player);
            return;
        }
        if (statsItem.getType() == HUMAN) {
            numberOfHumans += 1;
        }
        if (highestScore < statsItem.getGeneral().getScore()) {
            highestScore = statsItem.getGeneral().getScore();
            highestScorerName = statsItem.getName();
        }
        if (Objects.equals(statsItem.getName(), player.getLogin())) {
            armyStats = statsItem;
            playerArmyId = currentIndex;
        }
    }
    if (playerArmyId == -1) {
        log.warn("No army stats available for player '{}' in game '{}', aborting stats processing", player, game);
        return;
    }
    if (numberOfHumans < 2) {
        log.debug("Single player game '{}' reported by '{}', aborting stats processing", game, player);
        return;
    }
    int finalArmyId = playerArmyId;
    Optional<ArmyResult> armyOutcome = game.getReportedArmyResults().values().stream().flatMap(map -> map.values().stream()).filter(item -> item.getArmyId() == finalArmyId).findFirst();
    if (!armyOutcome.isPresent()) {
        log.warn("No outcome for army '{}ยด (player '{}') has been reported for game '{}', " + "aborting stats processing", playerArmyId, player, game);
        return;
    }
    Outcome outcome = armyOutcome.get().getOutcome();
    log.debug("Processing stats for army '{}' (player '{}') in game '{}'", playerArmyId, player, game);
    Faction faction = armyStats.getFaction();
    ArrayList<AchievementUpdate> achievementUpdates = new ArrayList<>();
    ArrayList<EventUpdate> eventUpdates = new ArrayList<>();
    boolean survived = outcome == Outcome.VICTORY;
    Map<String, ArmyStatistics.UnitStats> unitStats = firstNonNull(armyStats.getUnitStats(), Collections.emptyMap());
    ArmyStatistics.CategoryStats categoryStats = armyStats.getCategoryStats();
    boolean scoredHighest = Objects.equals(highestScorerName, player.getLogin());
    int playerId = player.getId();
    if (survived && modService.isLadder1v1(game.getFeaturedMod())) {
        unlock(AchievementId.ACH_FIRST_SUCCESS, achievementUpdates, playerId);
        if (Duration.between(game.getStartTime(), game.getEndTime()).compareTo(Duration.ofMinutes(RUSHER_MINUTE_LIMIT)) < 0) {
            unlock(AchievementId.ACH_RUSHER, achievementUpdates, playerId);
        }
    }
    increment(AchievementId.ACH_NOVICE, 1, achievementUpdates, playerId);
    increment(AchievementId.ACH_JUNIOR, 1, achievementUpdates, playerId);
    increment(AchievementId.ACH_SENIOR, 1, achievementUpdates, playerId);
    increment(AchievementId.ACH_VETERAN, 1, achievementUpdates, playerId);
    increment(AchievementId.ACH_ADDICT, 1, achievementUpdates, playerId);
    factionPlayed(faction, survived, achievementUpdates, eventUpdates, playerId);
    categoryStats(categoryStats, survived, achievementUpdates, eventUpdates, playerId);
    killedAcus(categoryStats, survived, achievementUpdates, playerId);
    builtMercies(countBuiltUnits(unitStats, Unit.MERCY), achievementUpdates, playerId);
    builtFireBeetles(countBuiltUnits(unitStats, Unit.FIRE_BEETLE), achievementUpdates, playerId);
    builtSalvations(countBuiltUnits(unitStats, Unit.SALVATION), survived, achievementUpdates, playerId);
    builtYolonaOss(countBuiltUnits(unitStats, Unit.YOLONA_OSS), survived, achievementUpdates, playerId);
    builtParagons(countBuiltUnits(unitStats, Unit.PARAGON), survived, achievementUpdates, playerId);
    builtAtlantis(countBuiltUnits(unitStats, Unit.ATLANTIS), achievementUpdates, playerId);
    builtTempests(countBuiltUnits(unitStats, Unit.TEMPEST), achievementUpdates, playerId);
    builtScathis(countBuiltUnits(unitStats, Unit.SCATHIS), survived, achievementUpdates, playerId);
    builtMavors(countBuiltUnits(unitStats, Unit.MAVOR), survived, achievementUpdates, playerId);
    builtCzars(countBuiltUnits(unitStats, Unit.CZAR), achievementUpdates, playerId);
    builtAhwassas(countBuiltUnits(unitStats, Unit.AHWASSA), achievementUpdates, playerId);
    builtYthothas(countBuiltUnits(unitStats, Unit.YTHOTHA), achievementUpdates, playerId);
    builtFatboys(countBuiltUnits(unitStats, Unit.FATBOY), achievementUpdates, playerId);
    builtMonkeylords(countBuiltUnits(unitStats, Unit.MONKEYLORD), achievementUpdates, playerId);
    builtGalacticColossus(countBuiltUnits(unitStats, Unit.GALACTIC_COLOSSUS), achievementUpdates, playerId);
    builtSoulRippers(countBuiltUnits(unitStats, Unit.SOUL_RIPPER), achievementUpdates, playerId);
    builtMegaliths(countBuiltUnits(unitStats, Unit.MEGALITH), achievementUpdates, playerId);
    builtAsfs(countBuiltUnits(unitStats, Unit.ASFS), achievementUpdates, playerId);
    builtTransports(categoryStats.getTransportation().getBuilt(), achievementUpdates, playerId);
    builtSacus(categoryStats.getSacu().getBuilt(), achievementUpdates, playerId);
    lowestAcuHealth(count(unitStats, ArmyStatistics.UnitStats::getLowestHealth, Unit.ACUS), survived, achievementUpdates, playerId);
    highscore(scoredHighest, numberOfHumans, achievementUpdates, playerId);
    eventService.executeBatchUpdate(eventUpdates).exceptionally(throwable -> {
        log.warn("Could not report '" + eventUpdates.size() + "' event updates for player '" + player + "'", throwable);
        return null;
    });
    achievementService.executeBatchUpdate(achievementUpdates).thenAccept(playerAchievements -> clientService.reportUpdatedAchievements(playerAchievements, player)).exceptionally(throwable -> {
        log.warn("Could not report '" + achievementUpdates.size() + "' achievement updates for player '" + player + "'", throwable);
        return null;
    });
}
Also used : Arrays(java.util.Arrays) ModService(com.faforever.server.mod.ModService) ArmyResult(com.faforever.server.entity.ArmyResult) Outcome(com.faforever.server.game.Outcome) CategoryStats(com.faforever.server.stats.ArmyStatistics.CategoryStats) ArrayList(java.util.ArrayList) Player(com.faforever.server.entity.Player) Service(org.springframework.stereotype.Service) Duration(java.time.Duration) Map(java.util.Map) ClientService(com.faforever.server.client.ClientService) AchievementUpdate(com.faforever.server.stats.achievements.AchievementUpdate) Unit(com.faforever.server.game.Unit) HUMAN(com.faforever.server.stats.ArmyStatistics.BrainType.HUMAN) ToIntFunction(java.util.function.ToIntFunction) Faction(com.faforever.server.game.Faction) AI(com.faforever.server.stats.ArmyStatistics.BrainType.AI) AchievementId(com.faforever.server.stats.achievements.AchievementId) EventId(com.faforever.server.stats.event.EventId) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Game(com.faforever.server.entity.Game) Optional(java.util.Optional) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) EventUpdate(com.faforever.server.stats.event.EventUpdate) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) AchievementService(com.faforever.server.stats.achievements.AchievementService) EventService(com.faforever.server.stats.event.EventService) ArrayList(java.util.ArrayList) AchievementUpdate(com.faforever.server.stats.achievements.AchievementUpdate) EventUpdate(com.faforever.server.stats.event.EventUpdate) Outcome(com.faforever.server.game.Outcome) ArmyResult(com.faforever.server.entity.ArmyResult) Faction(com.faforever.server.game.Faction) CategoryStats(com.faforever.server.stats.ArmyStatistics.CategoryStats)

Aggregations

Game (com.faforever.server.entity.Game)96 Test (org.junit.Test)71 Player (com.faforever.server.entity.Player)26 FeaturedMod (com.faforever.server.entity.FeaturedMod)15 ModVersion (com.faforever.server.entity.ModVersion)12 ConnectionAware (com.faforever.server.client.ConnectionAware)11 Ladder1v1Rating (com.faforever.server.entity.Ladder1v1Rating)11 List (java.util.List)11 ClientService (com.faforever.server.client.ClientService)10 ServerProperties (com.faforever.server.config.ServerProperties)10 RequestException (com.faforever.server.error.RequestException)10 ModService (com.faforever.server.mod.ModService)10 VisibleForTesting (com.google.common.annotations.VisibleForTesting)10 Duration (java.time.Duration)10 Map (java.util.Map)10 Optional (java.util.Optional)10 Slf4j (lombok.extern.slf4j.Slf4j)10 Service (org.springframework.stereotype.Service)10 ArmyResult (com.faforever.server.entity.ArmyResult)9 GamePlayerStats (com.faforever.server.entity.GamePlayerStats)9