Search in sources :

Example 1 with IceMessage

use of com.faforever.server.ice.IceMessage 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 IceMessage

use of com.faforever.server.ice.IceMessage in project faf-java-server by FAForever.

the class LegacyRequestTransformerTest method iceMessage.

@Test
public void iceMessage() throws Exception {
    IceMessage iceMessage = (IceMessage) instance.transform(ImmutableMap.of(KEY_COMMAND, "IceMsg", KEY_ARGS, Arrays.asList(1, "someObject")));
    assertThat(iceMessage.getReceiverId(), is(1));
    assertThat(iceMessage.getContent(), is("someObject"));
}
Also used : IceMessage(com.faforever.server.ice.IceMessage) Test(org.junit.Test)

Example 3 with IceMessage

use of com.faforever.server.ice.IceMessage in project faf-java-server by FAForever.

the class V2ClientMessageTransformerTest method iceClient.

@Test
public void iceClient() throws Exception {
    ClientMessage result = instance.transform(write(new IceClientMessage(12, "foobar")));
    assertThat(result, is(new IceMessage(12, "foobar")));
}
Also used : ClientMessage(com.faforever.server.common.ClientMessage) IceMessage(com.faforever.server.ice.IceMessage) Test(org.junit.Test)

Example 4 with IceMessage

use of com.faforever.server.ice.IceMessage in project faf-java-server by FAForever.

the class IceServiceActivatorsTest method forwardIceMessage.

@Test
public void forwardIceMessage() throws Exception {
    Object payload = new Object();
    instance.forwardIceMessage(new IceMessage(42, payload), clientConnection.getAuthentication());
    verify(iceService).forwardIceMessage(player, 42, payload);
}
Also used : IceMessage(com.faforever.server.ice.IceMessage) Test(org.junit.Test)

Aggregations

IceMessage (com.faforever.server.ice.IceMessage)4 Test (org.junit.Test)3 ClientMessage (com.faforever.server.common.ClientMessage)1 ProgrammingError (com.faforever.server.error.ProgrammingError)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 LegacyClientMessageType (com.faforever.server.integration.legacy.LegacyClientMessageType)1