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);
}
}
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));
}
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);
}
}
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());
}
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);
}
Aggregations