Search in sources :

Example 16 with Player

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

the class SocialService method onPlayerOnlineEvent.

@EventListener
public void onPlayerOnlineEvent(PlayerOnlineEvent event) {
    Player player = event.getPlayer();
    List<SocialRelation> socialRelations = player.getSocialRelations();
    if (socialRelations == null) {
        return;
    }
    clientService.sendSocialRelations(new SocialRelationListResponse(socialRelations.stream().map(socialRelation -> new SocialRelationResponse(socialRelation.getSubjectId(), RelationType.valueOf(socialRelation.getStatus().toString()))).collect(Collectors.toList())), player);
}
Also used : SocialRelation(com.faforever.server.entity.SocialRelation) SocialRelationStatus(com.faforever.server.entity.SocialRelationStatus) EventListener(org.springframework.context.event.EventListener) RelationType(com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse.RelationType) Collectors(java.util.stream.Collectors) Player(com.faforever.server.entity.Player) SocialRelationResponse(com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SocialRelation(com.faforever.server.entity.SocialRelation) Service(org.springframework.stereotype.Service) PlayerOnlineEvent(com.faforever.server.player.PlayerOnlineEvent) ClientService(com.faforever.server.client.ClientService) Transactional(org.springframework.transaction.annotation.Transactional) Player(com.faforever.server.entity.Player) SocialRelationResponse(com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse) EventListener(org.springframework.context.event.EventListener)

Example 17 with Player

use of com.faforever.server.entity.Player 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)

Example 18 with Player

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

the class MatchMakerService method processPool.

private void processPool(String poolName, Map<Integer, MatchMakerSearch> pool) {
    Set<MatchMakerSearch> processedSearches = new HashSet<>();
    log.trace("Processing '{}' entries of pool '{}'", pool.size(), poolName);
    pool.values().stream().sorted(Comparator.comparingInt(search -> search.player.getId())).map((search) -> {
        processedSearches.add(search);
        return findMatch(search, processedSearches);
    }).filter(Optional::isPresent).forEach(optional -> {
        Match match = optional.get();
        MatchMakerSearch leftSearch = match.leftSearch;
        MatchMakerSearch rightSearch = match.rightSearch;
        Player leftPlayer = leftSearch.player;
        Player rightPlayer = rightSearch.player;
        log.debug("Player '{}' was matched against '{}' with game quality '{}'", leftPlayer, rightPlayer, match.quality);
        pool.remove(leftSearch.player.getId());
        pool.remove(rightSearch.player.getId());
        String technicalModName = modByPoolName.get(leftSearch.poolName).getTechnicalName();
        startGame(technicalModName, leftPlayer, leftSearch.faction, rightPlayer, rightSearch.faction);
    });
}
Also used : Player(com.faforever.server.entity.Player) HashSet(java.util.HashSet)

Example 19 with Player

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

the class DivisionService method getCurrentPlayerDivision.

public Optional<Division> getCurrentPlayerDivision(Player player) {
    int season = properties.getLadder1v1().getSeason();
    PlayerDivisionInfo info = playerDivisionInfoRepository.findByPlayerAndSeason(player, season);
    if (info == null) {
        return Optional.empty();
    }
    return Optional.of(divisions.stream().filter(division -> Objects.equals(division.getLeague(), info.getLeague())).filter(division -> info.getScore() <= division.getThreshold()).findFirst().orElseThrow(() -> new IllegalStateException(MessageFormat.format("Could not determine division for PlayerDivisionInfo {0}", info))));
}
Also used : Getter(lombok.Getter) Transactional(javax.transaction.Transactional) PlayerDivisionInfo(com.faforever.server.entity.PlayerDivisionInfo) MessageFormat(java.text.MessageFormat) Player(com.faforever.server.entity.Player) Inject(javax.inject.Inject) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) Slf4j(lombok.extern.slf4j.Slf4j) ImmutableList(com.google.common.collect.ImmutableList) Service(org.springframework.stereotype.Service) ServerProperties(com.faforever.server.config.ServerProperties) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) Division(com.faforever.server.entity.Division) NotNull(org.jetbrains.annotations.NotNull) PlayerDivisionInfo(com.faforever.server.entity.PlayerDivisionInfo)

Example 20 with Player

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

the class SocialServiceActivatorsTest method setUp.

@Before
public void setUp() throws Exception {
    player = (Player) new Player().setId(1);
    clientConnection = new ClientConnection("1", Protocol.V1_LEGACY_UTF_16, mock(InetAddress.class));
    clientConnection.setAuthentication(new TestingAuthenticationToken(new FafUserDetails((User) new User().setPlayer(player).setPassword("pw").setLogin("JUnit")), null));
    instance = new SocialServiceActivators(socialService);
}
Also used : Player(com.faforever.server.entity.Player) User(com.faforever.server.entity.User) ClientConnection(com.faforever.server.client.ClientConnection) FafUserDetails(com.faforever.server.security.FafUserDetails) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Before(org.junit.Before)

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