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()));
}
}
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());
}
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();
}
}
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());
}
Aggregations