use of org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeInOutModList 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);
}
}
use of org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeInOutModList in project LanternServer by LanternPowered.
the class CodecPlayInOutCustomPayload method encode0.
@Override
protected MessageResult encode0(CodecContext context, Message message) throws CodecException {
if (message instanceof MessageForgeHandshakeInOutAck) {
return new MessageResult("FML|HS", context.byteBufAlloc().buffer(2).writeByte((byte) FML_HANDSHAKE_ACK).writeByte((byte) ((ForgeServerHandshakePhase) ((MessageForgeHandshakeInOutAck) message).getPhase()).ordinal()));
} else if (message instanceof MessageForgeHandshakeInOutHello) {
return new MessageResult("FML|HS", context.byteBufAlloc().buffer(2).writeByte((byte) FML_HANDSHAKE_SERVER_HELLO).writeByte((byte) FORGE_PROTOCOL));
} else if (message instanceof MessageForgeHandshakeInOutModList) {
Map<String, String> entries = ((MessageForgeHandshakeInOutModList) message).getEntries();
ByteBuffer buf = context.byteBufAlloc().buffer();
buf.writeByte((byte) FML_HANDSHAKE_MOD_LIST);
buf.writeVarInt(entries.size());
for (Map.Entry<String, String> en : entries.entrySet()) {
buf.writeString(en.getKey());
buf.writeString(en.getValue());
}
return new MessageResult("FML|HS", buf);
} else if (message instanceof MessageForgeHandshakeOutReset) {
return new MessageResult("FML|HS", context.byteBufAlloc().buffer(1).writeByte((byte) FML_HANDSHAKE_RESET));
}
throw new EncoderException("Unsupported message type: " + message);
}
use of org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeInOutModList 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