Search in sources :

Example 1 with ProgrammingError

use of com.faforever.server.error.ProgrammingError in project faf-java-server by FAForever.

the class LegacyRequestTransformer method transform.

@Override
public ClientMessage transform(Map<String, Object> source) {
    String command = (String) source.get("command");
    LegacyClientMessageType messageType = LegacyClientMessageType.fromString(command);
    Requests.verify(messageType != null, ErrorCode.INVALID_COMMAND, command);
    switch(messageType) {
        case HOST_GAME:
            return handleHostGame(source);
        case JOIN_GAME:
            return new JoinGameRequest(((Number) source.get("uid")).intValue(), (String) source.get("password"));
        case ASK_SESSION:
            String userAgent = (String) source.get("user_agent");
            return LegacySessionRequest.forUserAgent(userAgent);
        case SOCIAL_ADD:
            return handleSocialAdd(source);
        case SOCIAL_REMOVE:
            return handleSocialRemove(source);
        case LOGIN:
            return handleLogin(source);
        case GAME_MATCH_MAKING:
            return handleMatchMaking(source);
        case AVATAR:
            return handleAvatar(source);
        case GAME_STATE:
            return handleGameState(source);
        case GAME_OPTION:
            List<Object> args = getArgs(source);
            return new GameOptionReport((String) args.get(0), args.get(1));
        case PLAYER_OPTION:
            args = getArgs(source);
            return new PlayerOptionReport(Integer.parseInt((String) args.get(0)), (String) args.get(1), args.get(2));
        case CLEAR_SLOT:
            args = getArgs(source);
            return ClearSlotRequest.valueOf((int) args.get(0));
        case DESYNC:
            return DesyncReport.INSTANCE;
        case GAME_MODS:
            return handleGameMods(source);
        case GAME_RESULT:
            return handleGameResult(source);
        case OPERATION_COMPLETE:
            return handleOperationComplete(source);
        case JSON_STATS:
            return handleJsonStats(source);
        case ENFORCE_RATING:
            return PlayerDefeatedReport.INSTANCE;
        case TEAMKILL_REPORT:
            return handleTeamKillReport(source);
        case MUTUAL_DRAW:
            return MutuallyAgreedDrawRequest.INSTANCE;
        case AI_OPTION:
            return handleAiOption(source);
        case INITIATE_TEST:
            throw new RequestException(ErrorCode.UNSUPPORTED_REQUEST, source);
        case ICE_SERVERS:
            return IceServersRequest.INSTANCE;
        case ICE_MESSAGE:
            args = getArgs(source);
            return new IceMessage((int) args.get(0), args.get(1));
        case RESTORE_GAME_SESSION:
            return new RestoreGameSessionRequest((int) source.get("game_id"));
        case CREATE_ACCOUNT:
            throw new RequestException(ErrorCode.CREATE_ACCOUNT_IS_DEPRECATED);
        case ADMIN:
            return handleAdminAction(source);
        case DISCONNECTED:
            return DisconnectedReport.INSTANCE;
        case BOTTLENECK:
            return BottleneckReport.INSTANCE;
        case CHAT:
            return handleGameChatMessage((String) getArgs(source).get(0));
        case BOTTLENECK_CLEARED:
            return BottleneckClearedReport.INSTANCE;
        default:
            throw new ProgrammingError("Uncovered message type: " + messageType);
    }
}
Also used : LegacyClientMessageType(com.faforever.server.integration.legacy.LegacyClientMessageType) PlayerOptionReport(com.faforever.server.game.PlayerOptionReport) GameOptionReport(com.faforever.server.game.GameOptionReport) ProgrammingError(com.faforever.server.error.ProgrammingError) RequestException(com.faforever.server.error.RequestException) IceMessage(com.faforever.server.ice.IceMessage) JoinGameRequest(com.faforever.server.game.JoinGameRequest)

Example 2 with ProgrammingError

use of com.faforever.server.error.ProgrammingError in project faf-java-server by FAForever.

the class V2ServerMessageTransformer method transform.

@Override
@SneakyThrows
public String transform(ServerMessage message) {
    Class<? extends ServerMessage> messageClass = message.getClass();
    Method method = Optional.ofNullable(mapperMethods.get(messageClass)).orElseThrow(() -> new ProgrammingError("No message mapping method is available for '" + messageClass + "' in '" + V2ServerMessageMapper.class + "'"));
    V2ServerMessage v2ServerMessage = (V2ServerMessage) method.invoke(v2ServerMessageMapper, message);
    return objectMapper.writeValueAsString(new V2ServerMessageWrapper(v2ServerMessage));
}
Also used : ProgrammingError(com.faforever.server.error.ProgrammingError) Method(java.lang.reflect.Method) SneakyThrows(lombok.SneakyThrows)

Example 3 with ProgrammingError

use of com.faforever.server.error.ProgrammingError in project faf-java-server by FAForever.

the class GameService method updatePlayerGameState.

/**
 * Updates the game state of a player's game.
 */
@Transactional
public void updatePlayerGameState(PlayerGameState newState, Player player) {
    Game game = player.getCurrentGame();
    Requests.verify(game != null, ErrorCode.NOT_IN_A_GAME);
    PlayerGameState oldState = player.getGameState();
    log.debug("Player '{}' updated his game state from '{}' to '{}' (game: '{}')", player, oldState, newState, game);
    Requests.verify(PlayerGameState.canTransition(oldState, newState), ErrorCode.INVALID_PLAYER_GAME_STATE_TRANSITION, oldState, newState);
    changePlayerGameState(player, newState);
    switch(newState) {
        case LOBBY:
            onLobbyEntered(player, game);
            break;
        case LAUNCHING:
            onGameLaunching(player, game);
            break;
        case ENDED:
            onPlayerGameEnded(player, game);
            break;
        case CLOSED:
            onPlayerGameClosed(player, game);
            break;
        case IDLE:
            log.warn("Ignoring state '{}' from player '{}' for game '{}' (should be handled by the client)", newState, player, game);
            break;
        default:
            throw new ProgrammingError("Uncovered state: " + newState);
    }
}
Also used : Game(com.faforever.server.entity.Game) ProgrammingError(com.faforever.server.error.ProgrammingError) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with ProgrammingError

use of com.faforever.server.error.ProgrammingError in project faf-java-server by FAForever.

the class ChatService method onPlayerOnlineEvent.

@EventListener
public void onPlayerOnlineEvent(PlayerOnlineEvent event) {
    Chat chat = properties.getChat();
    Set<String> channels = new HashSet<>(3, 1);
    channels.addAll(chat.getDefaultChannels());
    Optional.ofNullable(event.getPlayer().getClan()).map(clan -> (String.format(chat.getClanChannelFormat(), clan.getTag()))).ifPresent(channels::add);
    User user = event.getPlayer().getUser();
    GroupAssociation groupAssociation = user.getGroupAssociation();
    if (groupAssociation != null) {
        switch(groupAssociation.getGroup()) {
            case ADMIN:
                channels.addAll(chat.getAdminChannels());
                break;
            case MODERATOR:
                channels.addAll(chat.getModeratorChannels());
                break;
            default:
                throw new ProgrammingError("Uncovered group: " + groupAssociation.getGroup());
        }
    }
    clientService.sendChatChannels(channels, event.getPlayer());
}
Also used : Chat(com.faforever.server.config.ServerProperties.Chat) ProgrammingError(com.faforever.server.error.ProgrammingError) User(com.faforever.server.entity.User) EventListener(org.springframework.context.event.EventListener) Set(java.util.Set) Hashing(com.google.common.hash.Hashing) GroupAssociation(com.faforever.server.entity.GroupAssociation) BadSqlGrammarException(org.springframework.jdbc.BadSqlGrammarException) StandardCharsets(java.nio.charset.StandardCharsets) HashSet(java.util.HashSet) Slf4j(lombok.extern.slf4j.Slf4j) Service(org.springframework.stereotype.Service) ServerProperties(com.faforever.server.config.ServerProperties) PlayerOnlineEvent(com.faforever.server.player.PlayerOnlineEvent) Optional(java.util.Optional) ClientService(com.faforever.server.client.ClientService) User(com.faforever.server.entity.User) GroupAssociation(com.faforever.server.entity.GroupAssociation) Chat(com.faforever.server.config.ServerProperties.Chat) ProgrammingError(com.faforever.server.error.ProgrammingError) HashSet(java.util.HashSet) EventListener(org.springframework.context.event.EventListener)

Example 5 with ProgrammingError

use of com.faforever.server.error.ProgrammingError in project faf-java-server by FAForever.

the class RatingService method updateRating.

private void updateRating(RatingType ratingType, GamePlayerStats stats) {
    Rating rating;
    switch(ratingType) {
        case GLOBAL:
            rating = ofNullable(stats.getPlayer().getGlobalRating()).orElseGet(() -> {
                GlobalRating initial = new GlobalRating();
                stats.getPlayer().setGlobalRating(initial);
                return initial;
            });
            break;
        case LADDER_1V1:
            rating = ofNullable(stats.getPlayer().getLadder1v1Rating()).orElseGet(() -> {
                Ladder1v1Rating initial = new Ladder1v1Rating();
                stats.getPlayer().setLadder1v1Rating(initial);
                return initial;
            });
            break;
        default:
            throw new ProgrammingError("Uncovered rating type: " + ratingType);
    }
    rating.setMean(stats.getAfterMean());
    rating.setDeviation(stats.getAfterDeviation());
    log.debug("New '{}' rating for player '{}' is: {}", ratingType, stats.getPlayer(), rating);
}
Also used : Rating(com.faforever.server.entity.Rating) Ladder1v1Rating(com.faforever.server.entity.Ladder1v1Rating) GlobalRating(com.faforever.server.entity.GlobalRating) GlobalRating(com.faforever.server.entity.GlobalRating) Ladder1v1Rating(com.faforever.server.entity.Ladder1v1Rating) ProgrammingError(com.faforever.server.error.ProgrammingError)

Aggregations

ProgrammingError (com.faforever.server.error.ProgrammingError)5 ClientService (com.faforever.server.client.ClientService)1 ServerProperties (com.faforever.server.config.ServerProperties)1 Chat (com.faforever.server.config.ServerProperties.Chat)1 Game (com.faforever.server.entity.Game)1 GlobalRating (com.faforever.server.entity.GlobalRating)1 GroupAssociation (com.faforever.server.entity.GroupAssociation)1 Ladder1v1Rating (com.faforever.server.entity.Ladder1v1Rating)1 Rating (com.faforever.server.entity.Rating)1 User (com.faforever.server.entity.User)1 RequestException (com.faforever.server.error.RequestException)1 GameOptionReport (com.faforever.server.game.GameOptionReport)1 JoinGameRequest (com.faforever.server.game.JoinGameRequest)1 PlayerOptionReport (com.faforever.server.game.PlayerOptionReport)1 IceMessage (com.faforever.server.ice.IceMessage)1 LegacyClientMessageType (com.faforever.server.integration.legacy.LegacyClientMessageType)1 PlayerOnlineEvent (com.faforever.server.player.PlayerOnlineEvent)1 Hashing (com.google.common.hash.Hashing)1 Method (java.lang.reflect.Method)1 StandardCharsets (java.nio.charset.StandardCharsets)1