Search in sources :

Example 1 with MessageForgeHandshakeOutRegistryData

use of org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeOutRegistryData in project LanternServer by LanternPowered.

the class HandlerForgeHandshakeInAck method handle.

@Override
public void handle(NetworkContext context, MessageForgeHandshakeInOutAck message) {
    final NetworkSession session = context.getSession();
    final Attribute<ForgeServerHandshakePhase> phase = context.getChannel().attr(ForgeHandshakePhase.PHASE);
    switch(phase.get()) {
        case WAITING_ACK:
            if (!message.getPhase().equals(ForgeClientHandshakePhase.WAITING_SERVER_DATA)) {
                session.disconnect(t("Retrieved unexpected forge handshake ack message. (Got %s, expected %s)", message.getPhase(), ForgeClientHandshakePhase.WAITING_SERVER_DATA));
            } else {
                final List<MessageForgeHandshakeOutRegistryData.Entry> entries = new ArrayList<>();
                entries.add(new MessageForgeHandshakeOutRegistryData.Entry("minecraft:items", new HashMap<>(), new ArrayList<>()));
                entries.add(new MessageForgeHandshakeOutRegistryData.Entry("minecraft:blocks", new HashMap<>(), new ArrayList<>()));
                session.send(new MessageForgeHandshakeOutRegistryData(entries));
                session.send(new MessageForgeHandshakeInOutAck(ForgeServerHandshakePhase.WAITING_ACK));
                phase.set(ForgeServerHandshakePhase.COMPLETE);
            }
            Lantern.getLogger().info("{}: Forge handshake -> Received ack (waitingServerData) message.", session.getGameProfile().getName().get());
            break;
        case COMPLETE:
            if (!message.getPhase().equals(ForgeClientHandshakePhase.WAITING_SERVER_COMPLETE)) {
                session.disconnect(t("Retrieved unexpected forge handshake ack message. (Got %s, expected %s)", message.getPhase(), ForgeClientHandshakePhase.WAITING_SERVER_COMPLETE));
            } else {
                session.send(new MessageForgeHandshakeInOutAck(ForgeServerHandshakePhase.COMPLETE));
                phase.set(ForgeServerHandshakePhase.DONE);
            }
            Lantern.getLogger().info("{}: Forge handshake -> Received ack (waitingServerComplete) message.", session.getGameProfile().getName().get());
            break;
        case DONE:
            if (!message.getPhase().equals(ForgeClientHandshakePhase.PENDING_COMPLETE) && !message.getPhase().equals(ForgeClientHandshakePhase.COMPLETE)) {
                session.disconnect(t("Retrieved unexpected forge handshake ack message. (Got %s, expected %s or %s)", message.getPhase(), ForgeClientHandshakePhase.PENDING_COMPLETE, ForgeClientHandshakePhase.COMPLETE));
            } else {
                if (message.getPhase().equals(ForgeClientHandshakePhase.PENDING_COMPLETE)) {
                    session.send(new MessageForgeHandshakeInOutAck(ForgeServerHandshakePhase.DONE));
                    Lantern.getLogger().info("{}: Forge handshake -> Received ack (pendingComplete) message.", session.getGameProfile().getName().get());
                } else {
                    session.setProtocolState(ProtocolState.PLAY);
                    session.initPlayer();
                    Lantern.getLogger().info("{}: Forge handshake -> Received ack (complete) message.", session.getGameProfile().getName().get());
                }
            }
            break;
        case ERROR:
            break;
        default:
            session.disconnect(t("Retrieved unexpected forge handshake ack message. (Got %s)", message.getPhase()));
    }
}
Also used : ForgeServerHandshakePhase(org.lanternpowered.server.network.forge.handshake.ForgeServerHandshakePhase) NetworkSession(org.lanternpowered.server.network.NetworkSession) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MessageForgeHandshakeOutRegistryData(org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeOutRegistryData) MessageForgeHandshakeInOutAck(org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeInOutAck)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 NetworkSession (org.lanternpowered.server.network.NetworkSession)1 ForgeServerHandshakePhase (org.lanternpowered.server.network.forge.handshake.ForgeServerHandshakePhase)1 MessageForgeHandshakeInOutAck (org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeInOutAck)1 MessageForgeHandshakeOutRegistryData (org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeOutRegistryData)1