use of com.faforever.server.entity.Player in project faf-java-server by FAForever.
the class GameService method updateAiOption.
/**
* Updates an option value of a specific AI player. Only the host of a game is allowed to report such options,
* otherwise an exception will be thrown.
*
* @throws RequestException if the reporting player is not the host
*/
public void updateAiOption(Player reporter, String aiName, String key, Object value) {
Game game = reporter.getCurrentGame();
if (game == null) {
// Since this is called repeatedly, throwing exceptions here would not be a good idea. Happens after restarts.
log.warn("Received AI option for player w/o game: {}", reporter);
return;
}
Requests.verify(Objects.equals(reporter.getCurrentGame().getHost(), reporter), ErrorCode.HOST_ONLY_OPTION, key);
if (!OPTION_ARMY.equals(key)) {
log.trace("Ignoring option '{}' = '{}' for AI '{}' in game '{}' because only the option 'Army' is currently sent with the correct, final AI name", key, value, aiName, game.getId());
return;
}
log.trace("Updating option for AI '{}' in game '{}': '{}' = '{}'", aiName, game.getId(), key, value);
game.getAiOptions().computeIfAbsent(aiName, s -> new HashMap<>()).put(key, value);
markDirty(game, DEFAULT_MIN_DELAY, DEFAULT_MAX_DELAY);
}
use of com.faforever.server.entity.Player in project faf-java-server by FAForever.
the class GameService method reportArmyOutcome.
public void reportArmyOutcome(Player reporter, int armyId, Outcome outcome) {
Game game = reporter.getCurrentGame();
if (game == null) {
log.warn("Army score reported by player w/o game: {}", reporter);
return;
}
if (!hasArmy(game, armyId)) {
log.warn("Player '{}' reported outcome '{}' for unknown army '{}' in game '{}'", reporter, outcome, armyId, game);
return;
}
log.debug("Player '{}' reported result for army '{}' in game '{}': {}", reporter, armyId, game, outcome);
game.getReportedArmyResults().computeIfAbsent(reporter.getId(), playerId -> new HashMap<>()).compute(armyId, (integer, armyResult) -> {
if (armyResult == null) {
return ArmyResult.of(armyId, outcome, null);
}
return ArmyResult.of(armyId, outcome, armyResult.getScore());
});
endGameIfArmyResultsComplete(game);
}
use of com.faforever.server.entity.Player in project faf-java-server by FAForever.
the class GameService method mutuallyAgreeDraw.
public void mutuallyAgreeDraw(Player player) {
Requests.verify(player.getCurrentGame() != null, ErrorCode.NOT_IN_A_GAME);
Game game = player.getCurrentGame();
GameState gameState = game.getState();
Requests.verify(gameState == GameState.PLAYING, ErrorCode.INVALID_GAME_STATE, GameState.PLAYING);
getPlayerTeamId(player).filter(teamId -> OBSERVERS_TEAM_ID != teamId).ifPresent(teamId -> {
log.debug("Adding player '{}' to mutually accepted draw list in game '{}'", player, game);
game.getMutuallyAcceptedDrawPlayerIds().add(player.getId());
final boolean allConnectedNonObserverPlayersAgreedOnMutualDraw = game.getConnectedPlayers().values().stream().filter(connectedPlayer -> !getPlayerTeamId(connectedPlayer).equals(Optional.of(OBSERVERS_TEAM_ID)) && !getPlayerTeamId(connectedPlayer).equals(Optional.empty())).allMatch(connectedPlayer -> game.getMutuallyAcceptedDrawPlayerIds().contains(connectedPlayer.getId()));
if (allConnectedNonObserverPlayersAgreedOnMutualDraw) {
log.debug("All in-game players agreed on mutual draw. Setting mutually agreed draw state in game '{}'", game);
game.setMutuallyAgreedDraw(true);
}
});
}
use of com.faforever.server.entity.Player in project faf-java-server by FAForever.
the class ClientConnectionService method disconnectClient.
/**
* Fires a {@link CloseConnectionEvent} in order to disconnect the client of the user with the specified ID.
*/
void disconnectClient(Authentication requester, int userId) {
// TODO actually there should be a user service, returning a User
Optional<Player> optional = playerService.getOnlinePlayer(userId);
if (!optional.isPresent()) {
log.warn("User '{}' requested disconnection of unknown user '{}'", requester, userId);
return;
}
Player player = optional.get();
eventPublisher.publishEvent(new CloseConnectionEvent(this, player.getClientConnection()));
log.info("User '{}' closed connection of user '{}'", requester, player);
}
use of com.faforever.server.entity.Player in project faf-java-server by FAForever.
the class ClientService method connectToHost.
/**
* Tells the client to connect to a host. The game process must have been started before.
*
* @param player the player to send the message to
* @param game the game to whose host to connect to
*/
public void connectToHost(Player player, Game game) {
Player host = game.getHost();
log.debug("Telling '{}' to connect to host '{}'", player, host);
send(new ConnectToHostResponse(host.getLogin(), host.getId()), player);
}
Aggregations