use of net.minecraftforge.fml.common.network.internal.FMLProxyPacket in project Railcraft by Railcraft.
the class RailcraftPacket method getPacket.
public FMLProxyPacket getPacket() {
ByteBuf byteBuf = Unpooled.buffer();
try (ByteBufOutputStream out = new ByteBufOutputStream(byteBuf);
RailcraftOutputStream data = new RailcraftOutputStream(out)) {
data.writeByte(getID());
writeData(data);
return new FMLProxyPacket(new PacketBuffer(byteBuf), CHANNEL_NAME);
} catch (IOException e) {
Game.logThrowable("Error constructing packet: {0}", e, getClass());
if (Game.DEVELOPMENT_ENVIRONMENT)
throw new RuntimeException(e);
}
PacketBuffer buffer = new PacketBuffer(byteBuf);
buffer.writeByte(-1);
return new FMLProxyPacket(buffer, CHANNEL_NAME);
}
use of net.minecraftforge.fml.common.network.internal.FMLProxyPacket in project MinecraftForge by MinecraftForge.
the class FMLHandshakeMessage method makeCustomChannelRegistration.
public static FMLProxyPacket makeCustomChannelRegistration(Set<String> channels) {
String salutation = Joiner.on('\0').join(Iterables.concat(Arrays.asList("FML|HS", "FML", "FML|MP"), channels));
FMLProxyPacket proxy = new FMLProxyPacket(new PacketBuffer(Unpooled.wrappedBuffer(salutation.getBytes(Charsets.UTF_8))), "REGISTER");
return proxy;
}
use of net.minecraftforge.fml.common.network.internal.FMLProxyPacket in project MinecraftForge by MinecraftForge.
the class NetworkDispatcher method handleClientSideCustomPacket.
private boolean handleClientSideCustomPacket(SPacketCustomPayload msg, ChannelHandlerContext context) {
String channelName = msg.getChannelName();
if ("FML|MP".equals(channelName)) {
try {
if (multipart == null) {
multipart = new MultiPartCustomPayload(msg.getBufferData());
} else {
multipart.processPart(msg.getBufferData());
}
} catch (IOException e) {
this.kickWithMessage(e.getMessage());
multipart = null;
return true;
}
if (multipart.isComplete()) {
msg = multipart;
channelName = msg.getChannelName();
multipart = null;
} else {
// Haven't received all so return till we have.
return true;
}
}
if ("FML|HS".equals(channelName) || "REGISTER".equals(channelName) || "UNREGISTER".equals(channelName)) {
FMLProxyPacket proxy = new FMLProxyPacket(msg);
proxy.setDispatcher(this);
handshakeChannel.writeInbound(proxy);
// forward any messages into the regular channel
for (Object push : handshakeChannel.inboundMessages()) {
List<FMLProxyPacket> messageResult = FMLNetworkHandler.forwardHandshake((FMLMessage.CompleteHandshake) push, this, Side.CLIENT);
for (FMLProxyPacket result : messageResult) {
result.setTarget(Side.CLIENT);
result.payload().resetReaderIndex();
context.fireChannelRead(result);
}
}
handshakeChannel.inboundMessages().clear();
return true;
} else if (NetworkRegistry.INSTANCE.hasChannel(channelName, Side.CLIENT)) {
FMLProxyPacket proxy = new FMLProxyPacket(msg);
proxy.setDispatcher(this);
context.fireChannelRead(proxy);
return true;
}
return false;
}
use of net.minecraftforge.fml.common.network.internal.FMLProxyPacket in project MinecraftForge by MinecraftForge.
the class ForgeNetworkTestMod method onPlayerLogin.
@SubscribeEvent
public void onPlayerLogin(PlayerLoggedInEvent e) {
if (channel == null)
return;
PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
buffer.writeByte(0);
// disconnects vanilla clients in 1.11
channel.sendTo(new FMLProxyPacket(buffer, MOD_ID), (EntityPlayerMP) e.player);
}
Aggregations