Search in sources :

Example 1 with ForgeServerHandshakePhase

use of org.lanternpowered.server.network.forge.handshake.ForgeServerHandshakePhase 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)

Example 2 with ForgeServerHandshakePhase

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

the class HandlerForgeHandshakeInHello method handle.

@Override
public void handle(NetworkContext context, MessageForgeHandshakeInOutHello message) {
    final NetworkSession session = context.getSession();
    final Attribute<ForgeServerHandshakePhase> phase = session.getChannel().attr(ForgeHandshakePhase.PHASE);
    if (phase.get() != ForgeServerHandshakePhase.HELLO) {
        session.disconnect(t("Retrieved unexpected forge handshake hello message."));
        return;
    }
    Lantern.getLogger().info("{}: Forge handshake -> Received hello message.", session.getGameProfile().getName().get());
}
Also used : ForgeServerHandshakePhase(org.lanternpowered.server.network.forge.handshake.ForgeServerHandshakePhase) NetworkSession(org.lanternpowered.server.network.NetworkSession)

Example 3 with ForgeServerHandshakePhase

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

the class HandlerForgeHandshakeInStart method handle.

@Override
public void handle(NetworkContext context, MessageForgeHandshakeInStart message) {
    final Attribute<ForgeServerHandshakePhase> phase = context.getChannel().attr(ForgeHandshakePhase.PHASE);
    final NetworkSession session = context.getSession();
    if (phase.get() != null && phase.get() != ForgeServerHandshakePhase.START) {
        session.disconnect(t("Retrieved unexpected forge handshake start message."));
        return;
    }
    final boolean fml = session.getChannel().attr(NetworkSession.FML_MARKER).get();
    final Set<String> channels = new HashSet<>(Sponge.getChannelRegistrar().getRegisteredChannels(Platform.Type.SERVER));
    if (fml) {
        channels.add("FML");
        channels.add("FML|HS");
        channels.add("FML|MP");
    }
    if (!channels.isEmpty()) {
        session.send(new MessagePlayInOutRegisterChannels(channels));
    }
    // future if sponge uses completely it's own protocol.
    if (false && fml) {
        phase.set(ForgeServerHandshakePhase.HELLO);
        session.send(new MessageForgeHandshakeInOutHello());
        Lantern.getLogger().info("{}: Start forge handshake.", session.getGameProfile().getName().get());
    } else {
        Lantern.getLogger().info("{}: Skip forge handshake.", session.getGameProfile().getName().get());
        phase.set(ForgeServerHandshakePhase.DONE);
        session.setProtocolState(ProtocolState.PLAY);
        session.initPlayer();
    }
}
Also used : MessageForgeHandshakeInOutHello(org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeInOutHello) ForgeServerHandshakePhase(org.lanternpowered.server.network.forge.handshake.ForgeServerHandshakePhase) MessagePlayInOutRegisterChannels(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutRegisterChannels) NetworkSession(org.lanternpowered.server.network.NetworkSession) HashSet(java.util.HashSet)

Example 4 with ForgeServerHandshakePhase

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

the class HandlerForgeHandshakeInModList method handle.

@Override
public void handle(NetworkContext context, MessageForgeHandshakeInOutModList message) {
    final NetworkSession session = context.getSession();
    final Attribute<ForgeServerHandshakePhase> phase = context.getChannel().attr(ForgeHandshakePhase.PHASE);
    if (phase.get() != ForgeServerHandshakePhase.HELLO) {
        session.disconnect(t("Retrieved unexpected forge handshake modList message."));
        return;
    }
    // We don't need to validate the mods for now, maybe in the future, just poke back
    session.getInstalledMods().addAll(message.getEntries().keySet());
    // Just use a empty map for now
    session.send(new MessageForgeHandshakeInOutModList(new HashMap<>()));
    phase.set(ForgeServerHandshakePhase.WAITING_ACK);
    Lantern.getLogger().info("{}: Forge handshake -> Received modList message.", session.getGameProfile().getName().get());
}
Also used : ForgeServerHandshakePhase(org.lanternpowered.server.network.forge.handshake.ForgeServerHandshakePhase) NetworkSession(org.lanternpowered.server.network.NetworkSession) HashMap(java.util.HashMap) MessageForgeHandshakeInOutModList(org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeInOutModList)

Aggregations

NetworkSession (org.lanternpowered.server.network.NetworkSession)4 ForgeServerHandshakePhase (org.lanternpowered.server.network.forge.handshake.ForgeServerHandshakePhase)4 HashMap (java.util.HashMap)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)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 MessageForgeHandshakeOutRegistryData (org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeOutRegistryData)1 MessagePlayInOutRegisterChannels (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutRegisterChannels)1