Search in sources :

Example 1 with ServerMessage

use of com.faforever.client.remote.domain.ServerMessage in project downlords-faf-client by FAForever.

the class FafServerAccessorImpl method parseServerObject.

private void parseServerObject(String jsonString) {
    try {
        ServerMessage serverMessage = gson.fromJson(jsonString, ServerMessage.class);
        if (serverMessage == null) {
            logger.debug("Discarding unimplemented server message: {}", jsonString);
            return;
        }
        Class<?> messageClass = serverMessage.getClass();
        while (messageClass != Object.class) {
            messageListeners.getOrDefault(messageClass, Collections.emptyList()).forEach(consumer -> consumer.accept(serverMessage));
            messageClass = messageClass.getSuperclass();
        }
        for (Class<?> type : ClassUtils.getAllInterfacesForClassAsSet(messageClass)) {
            messageListeners.getOrDefault(messageClass, Collections.emptyList()).forEach(consumer -> consumer.accept(serverMessage));
        }
    } catch (JsonSyntaxException e) {
        logger.warn("Could not deserialize message: " + jsonString, e);
    }
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) ServerMessage(com.faforever.client.remote.domain.ServerMessage) IceServersServerMessage(com.faforever.client.remote.domain.IceServersServerMessage)

Aggregations

IceServersServerMessage (com.faforever.client.remote.domain.IceServersServerMessage)1 ServerMessage (com.faforever.client.remote.domain.ServerMessage)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1