Search in sources :

Example 1 with ForgeClientHandshakePhase

use of org.lanternpowered.server.network.forge.handshake.ForgeClientHandshakePhase in project LanternServer by LanternPowered.

the class CodecPlayInOutCustomPayload method decode0.

@Override
protected Message decode0(CodecContext context, String channel, ByteBuffer content) throws CodecException {
    if ("FML|HS".equals(channel)) {
        int type = content.readByte();
        switch(type) {
            case FML_HANDSHAKE_RESET:
                // server -> client message: ignore
                break;
            case FML_HANDSHAKE_ACK:
                ForgeClientHandshakePhase phase = ForgeClientHandshakePhase.values()[content.readByte()];
                return new MessageForgeHandshakeInOutAck(phase);
            case FML_HANDSHAKE_SERVER_HELLO:
                // server -> client message: ignore
                break;
            case FML_HANDSHAKE_CLIENT_HELLO:
                // The forge protocol version on the client
                content.readByte();
                return new MessageForgeHandshakeInOutHello();
            case FML_HANDSHAKE_MOD_LIST:
                int size = content.readVarInt();
                Map<String, String> entries = Maps.newHashMapWithExpectedSize(size);
                for (int i = 0; i < size; i++) {
                    entries.put(content.readString(), content.readString());
                }
                return new MessageForgeHandshakeInOutModList(entries);
            case FML_HANDSHAKE_REGISTRY_DATA:
                // server -> client message: ignore
                break;
            default:
                throw new DecoderException("Unknown forge handshake message with opcode: " + type);
        }
        throw new DecoderException("Received an unexpected forge message with opcode: " + type);
    } else {
        throw new DecoderException("Received an unexpected message with channel: " + channel);
    }
}
Also used : MessageForgeHandshakeInOutHello(org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeInOutHello) DecoderException(io.netty.handler.codec.DecoderException) MessageForgeHandshakeInOutModList(org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeInOutModList) MessageForgeHandshakeInOutAck(org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeInOutAck) ForgeClientHandshakePhase(org.lanternpowered.server.network.forge.handshake.ForgeClientHandshakePhase)

Aggregations

DecoderException (io.netty.handler.codec.DecoderException)1 ForgeClientHandshakePhase (org.lanternpowered.server.network.forge.handshake.ForgeClientHandshakePhase)1 MessageForgeHandshakeInOutAck (org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeInOutAck)1 MessageForgeHandshakeInOutHello (org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeInOutHello)1 MessageForgeHandshakeInOutModList (org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeInOutModList)1