use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutRegisterChannels in project LanternServer by LanternPowered.
the class AbstractCodecPlayInOutCustomPayload method decode0.
private Message decode0(CodecContext context, ByteBuffer content, String channel) {
if ("REGISTER".equals(channel)) {
Set<String> channels = decodeChannels(content);
Iterator<String> it = channels.iterator();
while (it.hasNext()) {
String channel0 = it.next();
if (channel0.startsWith("FML")) {
it.remove();
}
}
if (!channels.isEmpty()) {
return new MessagePlayInOutRegisterChannels(channels);
}
} else if ("UNREGISTER".equals(channel)) {
Set<String> channels = decodeChannels(content);
Iterator<String> it = channels.iterator();
while (it.hasNext()) {
String channel0 = it.next();
if (channel0.startsWith("FML")) {
it.remove();
}
}
if (!channels.isEmpty()) {
return new MessagePlayInOutUnregisterChannels(channels);
}
} else if ("FML|MP".equals(channel)) {
Attribute<MultiPartMessage> attribute = context.getChannel().attr(FML_MULTI_PART_MESSAGE);
MultiPartMessage message0 = attribute.get();
if (message0 == null) {
String channel0 = content.readString();
int parts = content.readByte() & 0xff;
int size = content.readInteger();
if (size <= 0 || size >= -16797616) {
throw new CodecException("Received FML MultiPart packet outside of valid length bounds, Max: -16797616, Received: " + size);
}
attribute.set(new MultiPartMessage(channel0, context.byteBufAlloc().buffer(size), parts));
} else {
int part = content.readByte() & 0xff;
if (part != message0.index) {
throw new CodecException("Received FML MultiPart packet out of order, Expected: " + message0.index + ", Got: " + part);
}
int len = content.available() - 1;
content.readBytes(message0.buffer, message0.offset, len);
message0.offset += len;
message0.index++;
if (message0.index >= message0.parts) {
final Message message = decode0(context, message0.channel, message0.buffer);
attribute.set(null);
return message;
}
}
} else {
return decode0(context, channel, content);
}
return NullMessage.INSTANCE;
}
use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutRegisterChannels 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.vanilla.message.type.play.MessagePlayInOutRegisterChannels in project LanternServer by LanternPowered.
the class LanternChannelRegistrar method create.
private LanternChannelBinding create(Object plugin, String channel, boolean rawChannel) throws ChannelRegistrationException {
final PluginContainer container = checkPlugin(plugin, "plugin");
checkNotNullOrEmpty(channel, "channel");
checkArgument(channel.length() <= MAX_NAME_LENGTH, "channel length may not be longer then 20");
if (!isChannelAvailable(channel)) {
throw new ChannelRegistrationException("Channel with name \"" + channel + "\" is already registered!");
}
final LanternChannelBinding binding;
if (rawChannel) {
binding = new LanternRawDataChannel(this, channel, container);
} else {
binding = new LanternIndexedMessageChannel(this, channel, container);
}
binding.bound = true;
final MessagePlayInOutRegisterChannels message = new MessagePlayInOutRegisterChannels(Sets.newHashSet(channel));
for (Player player : this.server.getOnlinePlayers()) {
((NetworkSession) player.getConnection()).send(message);
}
return binding;
}
use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutRegisterChannels in project LanternServer by LanternPowered.
the class AbstractCodecPlayInOutCustomPayload method encode.
@Override
public ByteBuffer encode(CodecContext context, Message message) throws CodecException {
final ByteBuffer buf = context.byteBufAlloc().buffer();
final String channel;
final ByteBuffer content;
if (message instanceof MessagePlayInOutChannelPayload) {
final MessagePlayInOutChannelPayload message1 = (MessagePlayInOutChannelPayload) message;
content = message1.getContent();
channel = message1.getChannel();
} else if (message instanceof MessagePlayInOutRegisterChannels) {
content = encodeChannels(((MessagePlayInOutRegisterChannels) message).getChannels());
channel = "REGISTER";
} else if (message instanceof MessagePlayInOutUnregisterChannels) {
content = encodeChannels(((MessagePlayInOutUnregisterChannels) message).getChannels());
channel = "UNREGISTER";
} else {
final MessageResult result = encode0(context, message);
channel = result.channel;
content = result.byteBuf;
}
buf.writeString(channel);
buf.writeBytes(content);
return buf;
}
Aggregations