diff --git a/fml/src/main/java/cpw/mods/fml/common/FMLDummyContainer.java b/fml/src/main/java/cpw/mods/fml/common/FMLContainer.java similarity index 95% rename from fml/src/main/java/cpw/mods/fml/common/FMLDummyContainer.java rename to fml/src/main/java/cpw/mods/fml/common/FMLContainer.java index 9668ebc3b..366bff4bb 100644 --- a/fml/src/main/java/cpw/mods/fml/common/FMLDummyContainer.java +++ b/fml/src/main/java/cpw/mods/fml/common/FMLContainer.java @@ -16,7 +16,6 @@ import java.io.File; import java.security.cert.Certificate; import java.util.Arrays; import java.util.Map; -import java.util.Set; import java.util.logging.Level; import net.minecraft.nbt.NBTBase; @@ -30,16 +29,17 @@ import com.google.common.eventbus.EventBus; import cpw.mods.fml.client.FMLFileResourcePack; import cpw.mods.fml.client.FMLFolderResourcePack; import cpw.mods.fml.common.asm.FMLSanityChecker; +import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.GameData; -import cpw.mods.fml.common.registry.ItemData; +import cpw.mods.fml.relauncher.Side; /** * @author cpw * */ -public class FMLDummyContainer extends DummyModContainer implements WorldAccessContainer +public class FMLContainer extends DummyModContainer implements WorldAccessContainer { - public FMLDummyContainer() + public FMLContainer() { super(new ModMetadata()); ModMetadata meta = getMetadata(); @@ -130,6 +130,7 @@ public class FMLDummyContainer extends DummyModContainer implements WorldAccessC { return FMLSanityChecker.fmlLocation; } + @Override public Class getCustomResourcePackClass() { diff --git a/fml/src/main/java/cpw/mods/fml/common/network/ByteBufUtils.java b/fml/src/main/java/cpw/mods/fml/common/network/ByteBufUtils.java new file mode 100644 index 000000000..3e32bc999 --- /dev/null +++ b/fml/src/main/java/cpw/mods/fml/common/network/ByteBufUtils.java @@ -0,0 +1,62 @@ +package cpw.mods.fml.common.network; + +import org.apache.commons.lang3.Validate; + +import com.google.common.base.Charsets; + +import io.netty.buffer.ByteBuf; + +public class ByteBufUtils { + public static int varIntByteCount(int toCount) + { + return (toCount & -128) == 0 ? 1 : ((toCount & -16384) == 0 ? 2 : ((toCount & -2097152) == 0 ? 3 : ((toCount & -268435456) == 0 ? 4 : 5))); + } + public static int readVarInt(ByteBuf buf, int maxSize) + { + Validate.isTrue(maxSize < 6 && maxSize > 0, "Varint length is between 1 and 5, not %d", maxSize); + int i = 0; + int j = 0; + byte b0; + + do + { + b0 = buf.readByte(); + i |= (b0 & 127) << j++ * 7; + + if (j > maxSize) + { + throw new RuntimeException("VarInt too big"); + } + } + while ((b0 & 128) == 128); + + return i; + } + + public static void writeVarInt(ByteBuf to, int toWrite, int maxSize) + { + Validate.isTrue(varIntByteCount(toWrite) < maxSize, "Integer is too big for %d bytes", maxSize); + while ((toWrite & -128) != 0) + { + to.writeByte(toWrite & 127 | 128); + toWrite >>>= 7; + } + + to.writeByte(toWrite); + } + public static String readUTF8String(ByteBuf from) + { + int len = readVarInt(from,2); + String str = from.toString(from.readerIndex(), len, Charsets.UTF_8); + from.readerIndex(from.readerIndex() + len); + return str; + } + + public static void writeUTF8String(ByteBuf to, String string) + { + byte[] utf8Bytes = string.getBytes(Charsets.UTF_8); + Validate.isTrue(varIntByteCount(utf8Bytes.length) < 3, "The string is too long for this encoding."); + writeVarInt(to, utf8Bytes.length, 2); + to.writeBytes(utf8Bytes); + } +} diff --git a/fml/src/main/java/cpw/mods/fml/common/network/ClientSidePacketHandler.java b/fml/src/main/java/cpw/mods/fml/common/network/ClientSidePacketHandler.java new file mode 100644 index 000000000..262d5732e --- /dev/null +++ b/fml/src/main/java/cpw/mods/fml/common/network/ClientSidePacketHandler.java @@ -0,0 +1,23 @@ +package cpw.mods.fml.common.network; + +import cpw.mods.fml.common.network.NetworkSide.ClientSide; +import net.minecraft.network.play.server.S3FPacketCustomPayload; + +/** + * Handle packets from the server at the client. + * + * @author cpw + * + */ +public abstract class ClientSidePacketHandler implements IPacketHandler { + @Override + public ClientSide side() + { + return NetworkSide.CLIENT; + } + /** + * Handle the custompayload packet + * @param packet + */ + public abstract void handleCustomPayload(S3FPacketCustomPayload packet); +} diff --git a/fml/src/main/java/cpw/mods/fml/common/network/FMLIndexedMessageToMessageCodec.java b/fml/src/main/java/cpw/mods/fml/common/network/FMLIndexedMessageToMessageCodec.java new file mode 100644 index 000000000..b98230bd8 --- /dev/null +++ b/fml/src/main/java/cpw/mods/fml/common/network/FMLIndexedMessageToMessageCodec.java @@ -0,0 +1,49 @@ +package cpw.mods.fml.common.network; + +import java.util.List; + +import gnu.trove.map.hash.TByteObjectHashMap; +import gnu.trove.map.hash.TObjectByteHashMap; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToMessageCodec; + +public abstract class FMLIndexedMessageToMessageCodec extends MessageToMessageCodec { + private TByteObjectHashMap> discriminators = new TByteObjectHashMap>(); + private TObjectByteHashMap> types = new TObjectByteHashMap>(); + + public FMLIndexedMessageToMessageCodec addDiscriminator(byte discriminator, Class type) + { + discriminators.put(discriminator, type); + types.put(type, discriminator); + return this; + } + + public abstract void encodeInto(ChannelHandlerContext ctx, A msg, ByteBuf target) throws Exception; + @Override + protected final void encode(ChannelHandlerContext ctx, A msg, List out) throws Exception + { + ByteBuf buffer = Unpooled.buffer(); + @SuppressWarnings("unchecked") // Stupid unnecessary cast I can't seem to kill + Class clazz = (Class) msg.getClass(); + byte discriminator = types.get(clazz); + buffer.writeByte(discriminator); + encodeInto(ctx, msg, buffer); + FMLProxyPacket proxy = new FMLProxyPacket(buffer, ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get()); + out.add(proxy); + } + + public abstract void decodeInto(ChannelHandlerContext ctx, ByteBuf source, A msg); + + @Override + protected final void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List out) throws Exception + { + ByteBuf payload = msg.payload(); + byte discriminator = payload.readByte(); + Class clazz = discriminators.get(discriminator); + A newMsg = clazz.newInstance(); + decodeInto(ctx, payload.slice(), newMsg); + out.add(newMsg); + } +} diff --git a/fml/src/main/java/cpw/mods/fml/common/network/FMLNetworkHandler.java b/fml/src/main/java/cpw/mods/fml/common/network/FMLNetworkHandler.java index c7127b7b3..488f9dc9d 100644 --- a/fml/src/main/java/cpw/mods/fml/common/network/FMLNetworkHandler.java +++ b/fml/src/main/java/cpw/mods/fml/common/network/FMLNetworkHandler.java @@ -12,6 +12,7 @@ package cpw.mods.fml.common.network; +import cpw.mods.fml.common.network.handshake.NetworkDispatcher; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; diff --git a/fml/src/main/java/cpw/mods/fml/common/network/FMLPacketHandlerFactory.java b/fml/src/main/java/cpw/mods/fml/common/network/FMLPacketHandlerFactory.java deleted file mode 100644 index 09c4433cb..000000000 --- a/fml/src/main/java/cpw/mods/fml/common/network/FMLPacketHandlerFactory.java +++ /dev/null @@ -1,27 +0,0 @@ -package cpw.mods.fml.common.network; - -import net.minecraft.network.INetHandler; -import net.minecraft.network.NetworkManager; - -public class FMLPacketHandlerFactory implements IPacketHandlerFactory { - private static final String[] CHANNEL = new String[] { "FML" }; - @Override - public String[] channels() - { - return CHANNEL; - } - - @Override - public IClientSidePacketHandler makeClientPacketHandler(NetworkMod mod, NetworkManager manager, INetHandler clientPlayHandler, String channel) - { - return null; - } - - @Override - public IServerSidePacketHandler makeServerPacketHandler(NetworkMod mod, NetworkManager manager, INetHandler serverPlayHandler) - { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/fml/src/main/java/cpw/mods/fml/common/network/FMLProxyPacket.java b/fml/src/main/java/cpw/mods/fml/common/network/FMLProxyPacket.java new file mode 100644 index 000000000..412aaca1a --- /dev/null +++ b/fml/src/main/java/cpw/mods/fml/common/network/FMLProxyPacket.java @@ -0,0 +1,77 @@ +package cpw.mods.fml.common.network; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.embedded.EmbeddedChannel; + +import java.io.IOException; + +import net.minecraft.network.INetHandler; +import net.minecraft.network.Packet; +import net.minecraft.network.PacketBuffer; +import net.minecraft.network.play.client.C17PacketCustomPayload; +import net.minecraft.network.play.server.S3FPacketCustomPayload; + +public class FMLProxyPacket extends Packet { + final String channel; + private final ByteBuf payload; + private INetHandler netHandler; + + private FMLProxyPacket(byte[] payload, String channel) + { + this(Unpooled.wrappedBuffer(payload), channel); + } + + public FMLProxyPacket(S3FPacketCustomPayload original) + { + this(original.func_149168_d(), original.func_149169_c()); + } + + public FMLProxyPacket(C17PacketCustomPayload original) + { + this(original.func_149558_e(), original.func_149559_c()); + } + + public FMLProxyPacket(ByteBuf payload, String channel) + { + this.channel = channel; + this.payload = payload; + } + @Override + public void func_148837_a(PacketBuffer packetbuffer) throws IOException + { + // NOOP - we are not built this way + } + + @Override + public void func_148840_b(PacketBuffer packetbuffer) throws IOException + { + // NOOP - we are not built this way + } + + @Override + public void func_148833_a(INetHandler inethandler) + { + this.netHandler = inethandler; + EmbeddedChannel internalChannel = NetworkRegistry.INSTANCE.getChannel(this.channel); + if (internalChannel != null) + { + internalChannel.writeInbound(this); + } + } + + public ByteBuf payload() + { + return payload; + } + + public Packet toC17Packet() + { + return new C17PacketCustomPayload(channel, payload.array()); + } + + public Packet toS3FPacket() + { + return new S3FPacketCustomPayload(channel, payload.array()); + } +} diff --git a/fml/src/main/java/cpw/mods/fml/common/network/IClientSidePacketHandler.java b/fml/src/main/java/cpw/mods/fml/common/network/IClientSidePacketHandler.java deleted file mode 100644 index a12f7723b..000000000 --- a/fml/src/main/java/cpw/mods/fml/common/network/IClientSidePacketHandler.java +++ /dev/null @@ -1,17 +0,0 @@ -package cpw.mods.fml.common.network; - -import net.minecraft.network.play.server.S3FPacketCustomPayload; - -/** - * Handle packets from the server at the client. - * - * @author cpw - * - */ -public interface IClientSidePacketHandler extends IPacketHandler { - /** - * Handle the custompayload packet - * @param packet - */ - public void handleCustomPayload(S3FPacketCustomPayload packet); -} diff --git a/fml/src/main/java/cpw/mods/fml/common/network/IFMLMessage.java b/fml/src/main/java/cpw/mods/fml/common/network/IFMLMessage.java new file mode 100644 index 000000000..41d54a759 --- /dev/null +++ b/fml/src/main/java/cpw/mods/fml/common/network/IFMLMessage.java @@ -0,0 +1,9 @@ +package cpw.mods.fml.common.network; + +import io.netty.buffer.ByteBuf; + +public interface IFMLMessage { + IMessageHandler handler(); + void fromBytes(ByteBuf source); + void toBytes(ByteBuf target); +} diff --git a/fml/src/main/java/cpw/mods/fml/common/network/IMessageHandler.java b/fml/src/main/java/cpw/mods/fml/common/network/IMessageHandler.java new file mode 100644 index 000000000..28ec9f0f8 --- /dev/null +++ b/fml/src/main/java/cpw/mods/fml/common/network/IMessageHandler.java @@ -0,0 +1,14 @@ +package cpw.mods.fml.common.network; + +import cpw.mods.fml.common.network.handshake.NetworkDispatcher; + + +public interface IMessageHandler { + /** + * Unsigned byte for the discriminator + * @return an unsigned byte + */ + short discriminator(); + Class messageType(short discriminator); + void receiveMessage(M message, NetworkDispatcher dispatcher); +} diff --git a/fml/src/main/java/cpw/mods/fml/common/network/IPacketHandler.java b/fml/src/main/java/cpw/mods/fml/common/network/IPacketHandler.java index 46ed2b6a7..600a9ab31 100644 --- a/fml/src/main/java/cpw/mods/fml/common/network/IPacketHandler.java +++ b/fml/src/main/java/cpw/mods/fml/common/network/IPacketHandler.java @@ -1,10 +1,11 @@ package cpw.mods.fml.common.network; + /** * Marker for packet handlers * @author cpw * */ -public interface IPacketHandler { - +public interface IPacketHandler { + S side(); } diff --git a/fml/src/main/java/cpw/mods/fml/common/network/IPacketHandlerFactory.java b/fml/src/main/java/cpw/mods/fml/common/network/IPacketHandlerFactory.java index ad33079c7..6025e328d 100644 --- a/fml/src/main/java/cpw/mods/fml/common/network/IPacketHandlerFactory.java +++ b/fml/src/main/java/cpw/mods/fml/common/network/IPacketHandlerFactory.java @@ -12,6 +12,8 @@ package cpw.mods.fml.common.network; +import cpw.mods.fml.common.network.NetworkSide.ClientSide; +import cpw.mods.fml.common.network.NetworkSide.ServerSide; import net.minecraft.network.INetHandler; import net.minecraft.network.NetworkManager; @@ -38,7 +40,7 @@ public interface IPacketHandlerFactory * @param channel * @return */ - public IClientSidePacketHandler makeClientPacketHandler(NetworkMod mod, NetworkManager manager, INetHandler clientPlayHandler, String channel); + public IPacketHandler makeClientPacketHandler(NetworkManager manager, INetHandler clientPlayHandler, String channel); /** * Return a server side packet handler for the specified channel or null if it is not handled on this side * @param mod @@ -46,5 +48,5 @@ public interface IPacketHandlerFactory * @param serverPlayHandler * @return */ - public IServerSidePacketHandler makeServerPacketHandler(NetworkMod mod, NetworkManager manager, INetHandler serverPlayHandler); + public IPacketHandler makeServerPacketHandler(NetworkManager manager, INetHandler serverPlayHandler, String channel); } diff --git a/fml/src/main/java/cpw/mods/fml/common/network/IServerSidePacketHandler.java b/fml/src/main/java/cpw/mods/fml/common/network/IServerSidePacketHandler.java deleted file mode 100644 index b0fe8a8e5..000000000 --- a/fml/src/main/java/cpw/mods/fml/common/network/IServerSidePacketHandler.java +++ /dev/null @@ -1,13 +0,0 @@ -package cpw.mods.fml.common.network; - -import net.minecraft.network.play.client.C17PacketCustomPayload; - -/** - * Handle packets from the client at the server. - * - * @author cpw - * - */ -public interface IServerSidePacketHandler { - public void handleCustomPayload(C17PacketCustomPayload packet); -} diff --git a/fml/src/main/java/cpw/mods/fml/common/network/NetworkRegistry.java b/fml/src/main/java/cpw/mods/fml/common/network/NetworkRegistry.java index 96a531a3a..c56b32780 100644 --- a/fml/src/main/java/cpw/mods/fml/common/network/NetworkRegistry.java +++ b/fml/src/main/java/cpw/mods/fml/common/network/NetworkRegistry.java @@ -12,39 +12,23 @@ package cpw.mods.fml.common.network; -import java.util.Arrays; -import java.util.List; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.embedded.EmbeddedChannel; +import io.netty.util.AttributeKey; + +import java.util.EnumMap; +import java.util.HashMap; import java.util.Map; -import java.util.Set; import java.util.logging.Level; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.inventory.Container; -import net.minecraft.network.*; -import net.minecraft.network.packet.*; -import net.minecraft.server.MinecraftServer; import net.minecraft.world.World; -import com.google.common.base.Charsets; -import com.google.common.base.Joiner; -import com.google.common.base.Splitter; -import com.google.common.base.Strings; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLLog; -import cpw.mods.fml.common.Loader; -import cpw.mods.fml.common.LoaderException; import cpw.mods.fml.common.ModContainer; -import cpw.mods.fml.common.network.packet.FMLPacket; -import cpw.mods.fml.common.network.packet.FMLPacket.Type; -import cpw.mods.fml.common.network.packet.PacketManager; import cpw.mods.fml.relauncher.Side; /** @@ -54,30 +38,74 @@ import cpw.mods.fml.relauncher.Side; public enum NetworkRegistry { INSTANCE; + private Map channels = Maps.newConcurrentMap(); private Map serverGuiHandlers = Maps.newHashMap(); private Map clientGuiHandlers = Maps.newHashMap(); + /** + * Set in the {@link ChannelHandlerContext} + */ + public static final AttributeKey FML_CHANNEL = new AttributeKey("fml:channelName"); + public static final AttributeKey FML_MESSAGETARGET = new AttributeKey("fml:outboundTarget"); + public static final AttributeKey FML_MESSAGETARGETARGS = new AttributeKey("fml:outboundTargetArgs"); + + public static final byte FML_PROTOCOL = 1; + + private NetworkRegistry() + { + } + + public enum OutboundTarget { + PLAYER, ALL, DIMENSION, ALLAROUNDPOINT; + } + + static class FMLEmbeddedChannel extends EmbeddedChannel { + private final String channelName; + public FMLEmbeddedChannel(String channelName) + { + super(); + this.channelName = channelName; + } + } + + public EmbeddedChannel newChannel(String name) + { + if (channels.containsKey(name) || name.startsWith("MC|") || name.startsWith("\u0001")) + { + throw new RuntimeException("That channel is already registered"); + } + FMLEmbeddedChannel channel = new FMLEmbeddedChannel(name); + channels.put(name,channel); + return channel; + } + + public EmbeddedChannel getChannel(String name) + { + return channels.get(name); + } +/* + *//** * Get the packet 250 channel registration string * @return the {@link Packet250CustomPayload} channel registration string - */ + *//* byte[] getPacketRegistry(Side side) { return Joiner.on('\0').join(Iterables.concat(Arrays.asList("FML"),universalPacketHandlers.keySet(), side.isClient() ? clientPacketHandlers.keySet() : serverPacketHandlers.keySet())).getBytes(Charsets.UTF_8); } - /** + *//** * Is the specified channel active for the player? * @param channel * @param player - */ + *//* public boolean isChannelActive(String channel, Player player) { return activeChannels.containsEntry(player,channel); } - /** + *//** * register a channel to a mod * @param handler the packet handler * @param channelName the channel name to register it with - */ + *//* public void registerChannel(IPacketHandler handler, String channelName) { if (Strings.isNullOrEmpty(channelName) || (channelName!=null && channelName.length()>16)) @@ -111,37 +139,37 @@ public enum NetworkRegistry serverPacketHandlers.put(channelName, handler); } } - /** + *//** * Activate the channel for the player * @param player - */ + *//* void activateChannel(Player player, String channel) { activeChannels.put(player, channel); } - /** + *//** * Deactivate the channel for the player * @param player * @param channel - */ + *//* void deactivateChannel(Player player, String channel) { activeChannels.remove(player, channel); } - /** + *//** * Register a connection handler * * @param handler - */ + *//* public void registerConnectionHandler(IConnectionHandler handler) { connectionHandlers.add(handler); } - /** + *//** * Register a chat listener * @param listener - */ + *//* public void registerChatListener(IChatListener listener) { chatListeners.add(listener); @@ -261,7 +289,7 @@ public enum NetworkRegistry List channels = Lists.newArrayList(Splitter.on('\0').split(request)); return channels; } - +*/ public void registerGuiHandler(Object mod, IGuiHandler handler) { ModContainer mc = FMLCommonHandler.instance().findContainerFor(mod); @@ -281,7 +309,7 @@ public enum NetworkRegistry } clientGuiHandlers.put(mc, handler); } - void openRemoteGui(ModContainer mc, EntityPlayerMP player, int modGuiId, World world, int x, int y, int z) +/* void openRemoteGui(ModContainer mc, EntityPlayerMP player, int modGuiId, World world, int x, int y, int z) { IGuiHandler handler = serverGuiHandlers.get(mc); NetworkModHolder nmh = mc.getNetworkModHolder(); @@ -301,9 +329,14 @@ public enum NetworkRegistry } } } - void openLocalGui(ModContainer mc, EntityPlayer player, int modGuiId, World world, int x, int y, int z) +*/ void openLocalGui(ModContainer mc, EntityPlayer player, int modGuiId, World world, int x, int y, int z) { IGuiHandler handler = clientGuiHandlers.get(mc); FMLCommonHandler.instance().showGuiScreen(handler.getClientGuiElement(modGuiId, player, world, x, y, z)); } + + public boolean hasChannel(String channelName) + { + return channels.containsKey(channelName); + } } diff --git a/fml/src/main/java/cpw/mods/fml/common/network/NetworkSide.java b/fml/src/main/java/cpw/mods/fml/common/network/NetworkSide.java new file mode 100644 index 000000000..05679a00b --- /dev/null +++ b/fml/src/main/java/cpw/mods/fml/common/network/NetworkSide.java @@ -0,0 +1,26 @@ +package cpw.mods.fml.common.network; + +import cpw.mods.fml.relauncher.Side; + +public abstract class NetworkSide { + public static final ServerSide SERVER = new ServerSide(); + public static final ClientSide CLIENT = new ClientSide(); + public final Side side; + NetworkSide(Side side) { + this.side = side; + } + + public static final class ServerSide extends NetworkSide { + private ServerSide() + { + super(Side.SERVER); + } + } + + public static final class ClientSide extends NetworkSide { + private ClientSide() + { + super(Side.CLIENT); + } + } +} diff --git a/fml/src/main/java/cpw/mods/fml/common/network/ServerSidePacketHandler.java b/fml/src/main/java/cpw/mods/fml/common/network/ServerSidePacketHandler.java new file mode 100644 index 000000000..e3d7714f5 --- /dev/null +++ b/fml/src/main/java/cpw/mods/fml/common/network/ServerSidePacketHandler.java @@ -0,0 +1,20 @@ +package cpw.mods.fml.common.network; + +import net.minecraft.network.play.client.C17PacketCustomPayload; +import cpw.mods.fml.common.network.NetworkSide.ServerSide; + +/** + * Handle packets from the client at the server. + * + * @author cpw + * + */ +public abstract class ServerSidePacketHandler implements IPacketHandler { + @Override + public ServerSide side() + { + return NetworkSide.SERVER; + } + + public abstract void handleCustomPayload(C17PacketCustomPayload packet); +} diff --git a/fml/src/main/java/cpw/mods/fml/common/network/handshake/FMLHandshakeClientState.java b/fml/src/main/java/cpw/mods/fml/common/network/handshake/FMLHandshakeClientState.java new file mode 100644 index 000000000..a0eeef075 --- /dev/null +++ b/fml/src/main/java/cpw/mods/fml/common/network/handshake/FMLHandshakeClientState.java @@ -0,0 +1,46 @@ +package cpw.mods.fml.common.network.handshake; + +import java.util.List; + +import io.netty.channel.ChannelHandlerContext; +import cpw.mods.fml.common.FMLLog; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.ModContainer; +import cpw.mods.fml.common.network.NetworkRegistry; + +enum FMLHandshakeClientState implements IHandshakeState +{ + START + { + @Override + public FMLHandshakeClientState accept(ChannelHandlerContext ctx, FMLHandshakeMessage msg) + { + NetworkDispatcher dispatcher = ctx.channel().attr(NetworkDispatcher.FML_DISPATCHER).get(); + dispatcher.clientListenForServerHandshake(); + return HELLO; + } + }, + HELLO + { + @Override + public FMLHandshakeClientState accept(ChannelHandlerContext ctx, FMLHandshakeMessage msg) + { + FMLLog.info("Server protocol version %x", ((FMLHandshakeMessage.ServerHello)msg).protocolVersion()); + ctx.writeAndFlush(new FMLHandshakeMessage.ClientHello()); + ctx.writeAndFlush(new FMLHandshakeMessage.ClientModList(Loader.instance().getActiveModList())); + return COMPLETE; + } + }, + COMPLETE + { + @Override + public FMLHandshakeClientState accept(ChannelHandlerContext ctx, FMLHandshakeMessage msg) + { + NetworkDispatcher dispatcher = ctx.channel().attr(NetworkDispatcher.FML_DISPATCHER).get(); + dispatcher.continueToClientPlayState(); + FMLLog.info("Client side modded connection established"); + ctx.writeAndFlush(new FMLHandshakeMessage.ClientAck()); + return this; + } + }; +} \ No newline at end of file diff --git a/fml/src/main/java/cpw/mods/fml/common/network/handshake/FMLHandshakeCodec.java b/fml/src/main/java/cpw/mods/fml/common/network/handshake/FMLHandshakeCodec.java new file mode 100644 index 000000000..226c45156 --- /dev/null +++ b/fml/src/main/java/cpw/mods/fml/common/network/handshake/FMLHandshakeCodec.java @@ -0,0 +1,27 @@ +package cpw.mods.fml.common.network.handshake; + +import cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec; +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; + +public class FMLHandshakeCodec extends FMLIndexedMessageToMessageCodec { + public FMLHandshakeCodec() + { + addDiscriminator((byte)0, FMLHandshakeMessage.ServerHello.class); + addDiscriminator((byte)1, FMLHandshakeMessage.ClientHello.class); + addDiscriminator((byte)2, FMLHandshakeMessage.ClientModList.class); + addDiscriminator((byte)3, FMLHandshakeMessage.ServerModList.class); + addDiscriminator((byte)-1, FMLHandshakeMessage.ClientAck.class); + } + @Override + public void encodeInto(ChannelHandlerContext ctx, FMLHandshakeMessage msg, ByteBuf target) throws Exception + { + msg.toBytes(target); + } + + @Override + public void decodeInto(ChannelHandlerContext ctx, ByteBuf source, FMLHandshakeMessage msg) + { + msg.fromBytes(source); + } +} diff --git a/fml/src/main/java/cpw/mods/fml/common/network/handshake/FMLHandshakeMessage.java b/fml/src/main/java/cpw/mods/fml/common/network/handshake/FMLHandshakeMessage.java new file mode 100644 index 000000000..b91b7be10 --- /dev/null +++ b/fml/src/main/java/cpw/mods/fml/common/network/handshake/FMLHandshakeMessage.java @@ -0,0 +1,145 @@ +package cpw.mods.fml.common.network.handshake; + +import java.util.List; + +import com.google.common.base.Joiner; +import com.google.common.collect.Lists; + +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.ModContainer; +import cpw.mods.fml.common.network.ByteBufUtils; +import cpw.mods.fml.common.network.NetworkRegistry; + +import io.netty.buffer.ByteBuf; + +public abstract class FMLHandshakeMessage { + public static class ServerHello extends FMLHandshakeMessage { + private byte serverProtocolVersion; + public void toBytes(ByteBuf buffer) + { + buffer.writeByte(NetworkRegistry.FML_PROTOCOL); + } + + public void fromBytes(ByteBuf buffer) + { + serverProtocolVersion = buffer.readByte(); + } + + public byte protocolVersion() + { + return serverProtocolVersion; + } + } + public static class ClientHello extends FMLHandshakeMessage { + private byte serverProtocolVersion; + public void toBytes(ByteBuf buffer) + { + buffer.writeByte(NetworkRegistry.FML_PROTOCOL); + } + + public void fromBytes(ByteBuf buffer) + { + serverProtocolVersion = buffer.readByte(); + } + + public byte protocolVersion() + { + return serverProtocolVersion; + } + } + public static class ServerModList extends FMLHandshakeMessage { + private List modTags = Lists.newArrayList(); + + @Override + public void toBytes(ByteBuf buffer) + { + super.toBytes(buffer); + ByteBufUtils.writeVarInt(buffer, modTags.size(), 2); + for (String modTag: modTags) + { + ByteBufUtils.writeUTF8String(buffer, modTag); + } + } + + @Override + public void fromBytes(ByteBuf buffer) + { + super.fromBytes(buffer); + int modCount = ByteBufUtils.readVarInt(buffer, 2); + for (int i = 0; i < modCount; i++) + { + modTags.add(ByteBufUtils.readUTF8String(buffer)); + } + } + } + + public static class ClientModList extends FMLHandshakeMessage { + public ClientModList() + { + + } + public ClientModList(List modList) + { + for (ModContainer mod : modList) + { + modTags.add(new String[] { mod.getModId(), mod.getVersion() }); + } + } + private List modTags = Lists.newArrayList(); + + @Override + public void toBytes(ByteBuf buffer) + { + super.toBytes(buffer); + ByteBufUtils.writeVarInt(buffer, modTags.size(), 2); + for (String[] modTag: modTags) + { + ByteBufUtils.writeUTF8String(buffer, modTag[0]); + ByteBufUtils.writeUTF8String(buffer, modTag[1]); + } + } + + @Override + public void fromBytes(ByteBuf buffer) + { + super.fromBytes(buffer); + int modCount = ByteBufUtils.readVarInt(buffer, 2); + for (int i = 0; i < modCount; i++) + { + modTags.add(new String[] { ByteBufUtils.readUTF8String(buffer), ByteBufUtils.readUTF8String(buffer)}); + } + } + + public String modListAsString() + { + StringBuffer sb = new StringBuffer(); + sb.append("[ "); + for (int i = 0; i < modTags.size(); i++) + { + String[] mod = modTags.get(i); + sb.append(mod[0]).append("@").append(mod[1]); + if (i < modTags.size() - 1) sb.append(", "); + } + sb.append(" ]"); + return sb.toString(); + } + + public int modListSize() + { + return modTags.size(); + } + } + + public static class ClientAck extends FMLHandshakeMessage { + + } + public void fromBytes(ByteBuf buffer) + { + } + + public void toBytes(ByteBuf buffer) + { + } + + +} diff --git a/fml/src/main/java/cpw/mods/fml/common/network/handshake/FMLHandshakeServerState.java b/fml/src/main/java/cpw/mods/fml/common/network/handshake/FMLHandshakeServerState.java new file mode 100644 index 000000000..1c8c9e94b --- /dev/null +++ b/fml/src/main/java/cpw/mods/fml/common/network/handshake/FMLHandshakeServerState.java @@ -0,0 +1,48 @@ +package cpw.mods.fml.common.network.handshake; + +import io.netty.channel.ChannelHandlerContext; +import cpw.mods.fml.common.FMLLog; + +enum FMLHandshakeServerState implements IHandshakeState +{ + START + { + @Override + public FMLHandshakeServerState accept(ChannelHandlerContext ctx, FMLHandshakeMessage msg) + { + NetworkDispatcher dispatcher = ctx.channel().attr(NetworkDispatcher.FML_DISPATCHER).get(); + dispatcher.serverInitiateHandshake(); + ctx.writeAndFlush(new FMLHandshakeMessage.ServerHello()); + return HELLO; + } + }, + HELLO + { + @Override + public FMLHandshakeServerState accept(ChannelHandlerContext ctx, FMLHandshakeMessage msg) + { + // Hello packet first + if (msg instanceof FMLHandshakeMessage.ClientHello) + { + FMLLog.info("Client protocol version %x", ((FMLHandshakeMessage.ClientHello)msg).protocolVersion()); + return this; + } + + FMLHandshakeMessage.ClientModList client = (FMLHandshakeMessage.ClientModList)msg; + FMLLog.info("Client joining with %d mods : %s", client.modListSize(), client.modListAsString()); + ctx.writeAndFlush(new FMLHandshakeMessage.ServerModList()); + return COMPLETE; + } + }, + COMPLETE + { + @Override + public FMLHandshakeServerState accept(ChannelHandlerContext ctx, FMLHandshakeMessage msg) + { + NetworkDispatcher dispatcher = ctx.channel().attr(NetworkDispatcher.FML_DISPATCHER).get(); + FMLLog.info("Server side modded connection established"); + dispatcher.continueToServerPlayState(); + return this; + } + }; +} \ No newline at end of file diff --git a/fml/src/main/java/cpw/mods/fml/common/network/handshake/HandshakeInjector.java b/fml/src/main/java/cpw/mods/fml/common/network/handshake/HandshakeInjector.java new file mode 100644 index 000000000..3a4e5f998 --- /dev/null +++ b/fml/src/main/java/cpw/mods/fml/common/network/handshake/HandshakeInjector.java @@ -0,0 +1,23 @@ +package cpw.mods.fml.common.network.handshake; + +import cpw.mods.fml.common.network.FMLProxyPacket; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelOutboundHandlerAdapter; +import io.netty.channel.ChannelPromise; + +public class HandshakeInjector extends ChannelOutboundHandlerAdapter { + + private NetworkDispatcher dispatcher; + public HandshakeInjector(NetworkDispatcher networkDispatcher) + { + this.dispatcher = networkDispatcher; + } + @Override + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception + { + if (msg instanceof FMLProxyPacket) + { + this.dispatcher.sendProxy((FMLProxyPacket) msg); + } + } +} diff --git a/fml/src/main/java/cpw/mods/fml/common/network/handshake/HandshakeMessageHandler.java b/fml/src/main/java/cpw/mods/fml/common/network/handshake/HandshakeMessageHandler.java new file mode 100644 index 000000000..db5c22b74 --- /dev/null +++ b/fml/src/main/java/cpw/mods/fml/common/network/handshake/HandshakeMessageHandler.java @@ -0,0 +1,38 @@ +package cpw.mods.fml.common.network.handshake; + +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.util.AttributeKey; + +public class HandshakeMessageHandler & IHandshakeState> extends SimpleChannelInboundHandler { + private static final AttributeKey> STATE = new AttributeKey>("fml:handshake-state"); + private final AttributeKey fmlHandshakeState; + private S initialState; + + @SuppressWarnings("unchecked") + public HandshakeMessageHandler(Class stateType) + { + fmlHandshakeState = (AttributeKey) STATE; + initialState = Enum.valueOf(stateType, "START"); + } + @Override + protected void channelRead0(ChannelHandlerContext ctx, FMLHandshakeMessage msg) throws Exception + { + S state = ctx.attr(fmlHandshakeState).get(); + S newState = state.accept(ctx, msg); + ctx.attr(fmlHandshakeState).set(newState); + } + + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception + { + ctx.attr(fmlHandshakeState).set(initialState); + } + @Override + public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception + { + S state = ctx.attr(fmlHandshakeState).get(); + S newState = state.accept(ctx, null); + ctx.attr(fmlHandshakeState).set(newState); + } +} diff --git a/fml/src/main/java/cpw/mods/fml/common/network/handshake/IHandshakeState.java b/fml/src/main/java/cpw/mods/fml/common/network/handshake/IHandshakeState.java new file mode 100644 index 000000000..9af1cf62f --- /dev/null +++ b/fml/src/main/java/cpw/mods/fml/common/network/handshake/IHandshakeState.java @@ -0,0 +1,7 @@ +package cpw.mods.fml.common.network.handshake; + +import io.netty.channel.ChannelHandlerContext; + +public interface IHandshakeState { + S accept(ChannelHandlerContext ctx, FMLHandshakeMessage msg); +} diff --git a/fml/src/main/java/cpw/mods/fml/common/network/NetworkDispatcher.java b/fml/src/main/java/cpw/mods/fml/common/network/handshake/NetworkDispatcher.java similarity index 66% rename from fml/src/main/java/cpw/mods/fml/common/network/NetworkDispatcher.java rename to fml/src/main/java/cpw/mods/fml/common/network/handshake/NetworkDispatcher.java index 91d5d6f31..1bd8434b2 100644 --- a/fml/src/main/java/cpw/mods/fml/common/network/NetworkDispatcher.java +++ b/fml/src/main/java/cpw/mods/fml/common/network/handshake/NetworkDispatcher.java @@ -1,17 +1,17 @@ -package cpw.mods.fml.common.network; +package cpw.mods.fml.common.network.handshake; + +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.channel.embedded.EmbeddedChannel; +import io.netty.util.AttributeKey; +import io.netty.util.concurrent.Future; +import io.netty.util.concurrent.GenericFutureListener; +import io.netty.util.concurrent.ScheduledFuture; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; -import sun.net.ProgressSource.State; - -import io.netty.channel.ChannelHandler; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; -import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.util.AttributeKey; -import io.netty.util.ReferenceCountUtil; -import io.netty.util.concurrent.ScheduledFuture; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.network.EnumConnectionState; import net.minecraft.network.NetHandlerPlayServer; @@ -19,12 +19,12 @@ import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.client.C17PacketCustomPayload; import net.minecraft.network.play.server.S3FPacketCustomPayload; +import net.minecraft.network.play.server.S40PacketDisconnect; import net.minecraft.server.management.ServerConfigurationManager; - -import com.google.common.collect.ListMultimap; - +import net.minecraft.util.ChatComponentText; import cpw.mods.fml.common.FMLLog; -import cpw.mods.fml.common.network.packet.PacketManager; +import cpw.mods.fml.common.network.FMLProxyPacket; +import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.relauncher.Side; public class NetworkDispatcher extends SimpleChannelInboundHandler { @@ -55,14 +55,14 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler { return net; } - private static final AttributeKey FML_DISPATCHER = new AttributeKey("fml:dispatcher"); - private static final AttributeKey> FML_PACKET_HANDLERS = new AttributeKey>("fml:packet_handlers"); + public static final AttributeKey FML_DISPATCHER = new AttributeKey("fml:dispatcher"); private final NetworkManager manager; private final ServerConfigurationManager scm; private EntityPlayerMP player; private ConnectionState state; private ConnectionType connectionType; - private Side side; + private final Side side; + private final EmbeddedChannel handshakeChannel; public NetworkDispatcher(NetworkManager manager) { @@ -70,6 +70,9 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler { this.manager = manager; this.scm = null; this.side = Side.CLIENT; + this.handshakeChannel = new EmbeddedChannel(new HandshakeInjector(this), new FMLHandshakeCodec(), new HandshakeMessageHandler(FMLHandshakeClientState.class)); + this.handshakeChannel.attr(FML_DISPATCHER).set(this); + this.handshakeChannel.attr(NetworkRegistry.FML_CHANNEL).set("FML|HS"); } public NetworkDispatcher(NetworkManager manager, ServerConfigurationManager scm) @@ -78,6 +81,9 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler { this.manager = manager; this.scm = scm; this.side = Side.SERVER; + this.handshakeChannel = new EmbeddedChannel(new HandshakeInjector(this), new FMLHandshakeCodec(), new HandshakeMessageHandler(FMLHandshakeServerState.class)); + this.handshakeChannel.attr(FML_DISPATCHER).set(this); + this.handshakeChannel.attr(NetworkRegistry.FML_CHANNEL).set("FML|HS"); } public void serverToClientHandshake(EntityPlayerMP player) @@ -102,46 +108,37 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler { public void handlerAdded(ChannelHandlerContext ctx) throws Exception { this.state = ConnectionState.OPENING; - if (side == Side.CLIENT) - { - clientListenForServerHandshake(); - } - else - { - serverInitiateHandshake(); - } + // send ourselves as a user event, to kick the pipeline active + this.handshakeChannel.pipeline().fireUserEventTriggered(this); this.manager.channel().config().setAutoRead(true); } - private void serverInitiateHandshake() + void serverInitiateHandshake() { // Send mod salutation to the client // This will be ignored by vanilla clients this.state = ConnectionState.AWAITING_HANDSHAKE; this.manager.channel().pipeline().addFirst("fml:vanilla_detector", new VanillaTimeoutWaiter()); - this.manager.func_150725_a(new S3FPacketCustomPayload("FML", new byte[0])); } - private void clientListenForServerHandshake() + void clientListenForServerHandshake() { manager.func_150723_a(EnumConnectionState.PLAY); this.state = ConnectionState.AWAITING_HANDSHAKE; } - private void continueToClientPlayState() + void continueToClientPlayState() { this.state = ConnectionState.CONNECTED; this.connectionType = ConnectionType.MODDED; completeClientSideConnection(); - // Send modded ack to server - this.manager.func_150725_a(new C17PacketCustomPayload("FML", new byte[0])); } private void completeClientSideConnection() { } - private void continueToServerPlayState() + void continueToServerPlayState() { this.state = ConnectionState.CONNECTED; this.connectionType = ConnectionType.MODDED; @@ -161,16 +158,16 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler { boolean handled = false; if (msg instanceof C17PacketCustomPayload) { - handled = handleServerSideCustomPacket((C17PacketCustomPayload) msg); + handled = handleServerSideCustomPacket((C17PacketCustomPayload) msg, ctx); } else if (msg instanceof S3FPacketCustomPayload) { - handled = handleClientSideCustomPacket((S3FPacketCustomPayload)msg); + handled = handleClientSideCustomPacket((S3FPacketCustomPayload)msg, ctx); } else if (state != ConnectionState.CONNECTED) { FMLLog.info("Unexpected packet during modded negotiation - assuming vanilla"); - handleVanillaConnection(); + kickVanilla(); } if (!handled) { @@ -184,46 +181,59 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler { if (evt instanceof ConnectionType && side == Side.SERVER) { FMLLog.info("Timeout occurred, assuming a vanilla client"); - handleVanillaConnection(); + kickVanilla(); } } - private void handleVanillaConnection() + private void kickVanilla() { - state = ConnectionState.CONNECTED; - connectionType = ConnectionType.VANILLA; - if (side == Side.CLIENT) + final ChatComponentText chatcomponenttext = new ChatComponentText("This is modded. No modded response received. Bye!"); + manager.func_150725_a(new S40PacketDisconnect(chatcomponenttext), new GenericFutureListener>() { - completeClientSideConnection(); - } - else - { - completeServerSideConnection(); - } + public void operationComplete(Future result) + { + manager.func_150718_a(chatcomponenttext); + } + }); + manager.channel().config().setAutoRead(false); } - private boolean handleClientSideCustomPacket(S3FPacketCustomPayload msg) + private boolean handleClientSideCustomPacket(S3FPacketCustomPayload msg, ChannelHandlerContext context) { - if ("FML".equals(msg.func_149169_c())) + String channelName = msg.func_149169_c(); + if ("FML|HS".equals(channelName)) { - continueToClientPlayState(); - FMLLog.info("Client side modded connection established"); + FMLProxyPacket proxy = new FMLProxyPacket(msg); + handshakeChannel.writeInbound(proxy); + return true; + } + else if (NetworkRegistry.INSTANCE.hasChannel(channelName)) + { + FMLProxyPacket proxy = new FMLProxyPacket(msg); + context.fireChannelRead(proxy); return true; } return false; } - private boolean handleServerSideCustomPacket(C17PacketCustomPayload msg) + private boolean handleServerSideCustomPacket(C17PacketCustomPayload msg, ChannelHandlerContext context) { if (state == ConnectionState.AWAITING_HANDSHAKE) { this.manager.channel().pipeline().remove("fml:vanilla_detector"); state = ConnectionState.HANDSHAKING; } - if ("FML".equals(msg.func_149559_c())) + String channelName = msg.func_149559_c(); + if ("FML|HS".equals(channelName)) { - FMLLog.info("Server side modded connection established"); - continueToServerPlayState(); + FMLProxyPacket proxy = new FMLProxyPacket(msg); + handshakeChannel.writeInbound(proxy); + return true; + } + else if (NetworkRegistry.INSTANCE.hasChannel(channelName)) + { + FMLProxyPacket proxy = new FMLProxyPacket(msg); + context.fireChannelRead(proxy); return true; } return false; @@ -247,7 +257,7 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler { } return null; } - }, 10, TimeUnit.SECONDS); + }, 10, TimeUnit.HOURS); } @Override @@ -256,4 +266,20 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler { future.cancel(true); } } + + /** + * Callback from the networkmanager + * @param fmlProxyPacket + */ + public void dispatch(FMLProxyPacket fmlProxyPacket) + { + } + + public void sendProxy(FMLProxyPacket msg) + { + if (side == Side.CLIENT) + manager.func_150725_a(msg.toC17Packet()); + else + manager.func_150725_a(msg.toS3FPacket()); + } } diff --git a/fml/src/main/java/cpw/mods/fml/common/network/packet/EntitySpawnAdjustmentPacket.java b/fml/src/main/java/cpw/mods/fml/common/network/packet/EntitySpawnAdjustmentPacket.java index 69584c143..8300fa00e 100644 --- a/fml/src/main/java/cpw/mods/fml/common/network/packet/EntitySpawnAdjustmentPacket.java +++ b/fml/src/main/java/cpw/mods/fml/common/network/packet/EntitySpawnAdjustmentPacket.java @@ -22,7 +22,7 @@ import com.google.common.io.ByteStreams; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.network.FMLNetworkHandler; -public class EntitySpawnAdjustmentPacket extends FMLPacket +public class EntitySpawnAdjustmentPacket extends FMLOldPacket { public EntitySpawnAdjustmentPacket() @@ -47,7 +47,7 @@ public class EntitySpawnAdjustmentPacket extends FMLPacket } @Override - public FMLPacket consumePacketData(byte[] data) + public FMLOldPacket consumePacketData(byte[] data) { ByteArrayDataInput dat = ByteStreams.newDataInput(data); entityId = dat.readInt(); diff --git a/fml/src/main/java/cpw/mods/fml/common/network/packet/EntitySpawnPacket.java b/fml/src/main/java/cpw/mods/fml/common/network/packet/EntitySpawnPacket.java index 70147e16a..80acd26ab 100644 --- a/fml/src/main/java/cpw/mods/fml/common/network/packet/EntitySpawnPacket.java +++ b/fml/src/main/java/cpw/mods/fml/common/network/packet/EntitySpawnPacket.java @@ -39,7 +39,7 @@ import cpw.mods.fml.common.registry.EntityRegistry.EntityRegistration; import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData; import cpw.mods.fml.common.registry.IThrowableEntity; -public class EntitySpawnPacket extends FMLPacket +public class EntitySpawnPacket extends FMLOldPacket { public int networkId; @@ -142,7 +142,7 @@ public class EntitySpawnPacket extends FMLPacket } @Override - public FMLPacket consumePacketData(byte[] data) + public FMLOldPacket consumePacketData(byte[] data) { ByteArrayDataInput dat = ByteStreams.newDataInput(data); networkId = dat.readInt(); diff --git a/fml/src/main/java/cpw/mods/fml/common/network/packet/FMLPacket.java b/fml/src/main/java/cpw/mods/fml/common/network/packet/FMLOldPacket.java similarity index 91% rename from fml/src/main/java/cpw/mods/fml/common/network/packet/FMLPacket.java rename to fml/src/main/java/cpw/mods/fml/common/network/packet/FMLOldPacket.java index 6a5b25f2c..9e59e609b 100644 --- a/fml/src/main/java/cpw/mods/fml/common/network/packet/FMLPacket.java +++ b/fml/src/main/java/cpw/mods/fml/common/network/packet/FMLOldPacket.java @@ -30,7 +30,7 @@ import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.network.FMLNetworkException; import cpw.mods.fml.common.network.FMLNetworkHandler; -public abstract class FMLPacket +public abstract class FMLOldPacket { enum Type { @@ -68,20 +68,20 @@ public abstract class FMLPacket MOD_IDMAP(ModIdMapPacket.class, true); - private Class packetType; + private Class packetType; private boolean isMultipart; private String executorClass; - private ConcurrentMap partTracker; + private ConcurrentMap partTracker; - private Type(Class clazz, boolean isMultipart, String executorClass) + private Type(Class clazz, boolean isMultipart, String executorClass) { this.packetType = clazz; this.isMultipart = isMultipart; this.executorClass = executorClass; } - FMLPacket make() + FMLOldPacket make() { try { @@ -100,7 +100,7 @@ public abstract class FMLPacket return isMultipart; } - private FMLPacket findCurrentPart(NetworkManager network) + private FMLOldPacket findCurrentPart(NetworkManager network) { if (partTracker == null) { @@ -138,5 +138,5 @@ public abstract class FMLPacket abstract byte[] generatePacketData(Object... data); - abstract FMLPacket consumePacketData(byte[] data); + abstract FMLOldPacket consumePacketData(byte[] data); } diff --git a/fml/src/main/java/cpw/mods/fml/common/network/packet/ModIdMapPacket.java b/fml/src/main/java/cpw/mods/fml/common/network/packet/ModIdMapPacket.java index 323b3833e..4d2c5409c 100644 --- a/fml/src/main/java/cpw/mods/fml/common/network/packet/ModIdMapPacket.java +++ b/fml/src/main/java/cpw/mods/fml/common/network/packet/ModIdMapPacket.java @@ -12,7 +12,7 @@ package cpw.mods.fml.common.network.packet; -import static cpw.mods.fml.common.network.packet.FMLPacket.Type.MOD_IDMAP; +import static cpw.mods.fml.common.network.packet.FMLOldPacket.Type.MOD_IDMAP; import java.io.IOException; import java.util.Set; @@ -37,7 +37,7 @@ import cpw.mods.fml.common.network.FMLNetworkHandler; import cpw.mods.fml.common.registry.GameData; import cpw.mods.fml.common.registry.ItemData; -public class ModIdMapPacket extends FMLPacket { +public class ModIdMapPacket extends FMLOldPacket { private byte[][] partials; public ModIdMapPacket() @@ -63,7 +63,7 @@ public class ModIdMapPacket extends FMLPacket { } @Override - public FMLPacket consumePacketData(byte[] data) + public FMLOldPacket consumePacketData(byte[] data) { ByteArrayDataInput bdi = ByteStreams.newDataInput(data); int chunkIdx = UnsignedBytes.toInt(bdi.readByte()); diff --git a/fml/src/main/java/cpw/mods/fml/common/network/packet/ModIdentifiersPacket.java b/fml/src/main/java/cpw/mods/fml/common/network/packet/ModIdentifiersPacket.java index b9f16f240..d559e512a 100644 --- a/fml/src/main/java/cpw/mods/fml/common/network/packet/ModIdentifiersPacket.java +++ b/fml/src/main/java/cpw/mods/fml/common/network/packet/ModIdentifiersPacket.java @@ -12,7 +12,7 @@ package cpw.mods.fml.common.network.packet; -import static cpw.mods.fml.common.network.packet.FMLPacket.Type.MOD_IDENTIFIERS; +import static cpw.mods.fml.common.network.packet.FMLOldPacket.Type.MOD_IDENTIFIERS; import java.util.Collection; import java.util.Map; @@ -29,7 +29,7 @@ import com.google.common.io.ByteStreams; import cpw.mods.fml.common.network.FMLNetworkHandler; import cpw.mods.fml.common.network.NetworkModHolder; -public class ModIdentifiersPacket extends FMLPacket +public class ModIdentifiersPacket extends FMLOldPacket { private Map modIds = Maps.newHashMap(); @@ -57,7 +57,7 @@ public class ModIdentifiersPacket extends FMLPacket } @Override - public FMLPacket consumePacketData(byte[] data) + public FMLOldPacket consumePacketData(byte[] data) { ByteArrayDataInput dat = ByteStreams.newDataInput(data); int listSize = dat.readInt(); diff --git a/fml/src/main/java/cpw/mods/fml/common/network/packet/ModListRequestPacket.java b/fml/src/main/java/cpw/mods/fml/common/network/packet/ModListRequestPacket.java index d86bb6941..10396affa 100644 --- a/fml/src/main/java/cpw/mods/fml/common/network/packet/ModListRequestPacket.java +++ b/fml/src/main/java/cpw/mods/fml/common/network/packet/ModListRequestPacket.java @@ -12,8 +12,8 @@ package cpw.mods.fml.common.network.packet; -import static cpw.mods.fml.common.network.packet.FMLPacket.Type.MOD_LIST_REQUEST; -import static cpw.mods.fml.common.network.packet.FMLPacket.Type.MOD_LIST_RESPONSE; +import static cpw.mods.fml.common.network.packet.FMLOldPacket.Type.MOD_LIST_REQUEST; +import static cpw.mods.fml.common.network.packet.FMLOldPacket.Type.MOD_LIST_RESPONSE; import java.util.List; import java.util.Map; @@ -37,7 +37,7 @@ import cpw.mods.fml.common.network.FMLNetworkHandler; import cpw.mods.fml.common.network.NetworkModHolder; import cpw.mods.fml.common.network.PacketDispatcher; -public class ModListRequestPacket extends FMLPacket +public class ModListRequestPacket extends FMLOldPacket { private List sentModList; private byte compatibilityLevel; @@ -62,7 +62,7 @@ public class ModListRequestPacket extends FMLPacket } @Override - public FMLPacket consumePacketData(byte[] data) + public FMLOldPacket consumePacketData(byte[] data) { sentModList = Lists.newArrayList(); ByteArrayDataInput in = ByteStreams.newDataInput(data); @@ -87,7 +87,7 @@ public class ModListRequestPacket extends FMLPacket * This packet is executed on the client to evaluate the server's mod list against * the client * - * @see cpw.mods.fml.common.network.packet.FMLPacket#execute(INetworkManager, FMLNetworkHandler, NetHandler, String) + * @see cpw.mods.fml.common.network.packet.FMLOldPacket#execute(INetworkManager, FMLNetworkHandler, NetHandler, String) */ @Override public void execute(INetworkManager mgr, FMLNetworkHandler handler, NetHandler netHandler, String userName) @@ -127,6 +127,6 @@ public class ModListRequestPacket extends FMLPacket FMLLog.fine("The server has compatibility level %d", compatibilityLevel); FMLCommonHandler.instance().getSidedDelegate().setClientCompatibilityLevel(compatibilityLevel); - mgr.func_74429_a(PacketDispatcher.getPacket("FML", FMLPacket.makePacket(MOD_LIST_RESPONSE, modVersions, missingMods))); + mgr.func_74429_a(PacketDispatcher.getPacket("FML", FMLOldPacket.makePacket(MOD_LIST_RESPONSE, modVersions, missingMods))); } } diff --git a/fml/src/main/java/cpw/mods/fml/common/network/packet/ModListResponsePacket.java b/fml/src/main/java/cpw/mods/fml/common/network/packet/ModListResponsePacket.java index b2eb87ff3..a17721713 100644 --- a/fml/src/main/java/cpw/mods/fml/common/network/packet/ModListResponsePacket.java +++ b/fml/src/main/java/cpw/mods/fml/common/network/packet/ModListResponsePacket.java @@ -12,10 +12,10 @@ package cpw.mods.fml.common.network.packet; -import static cpw.mods.fml.common.network.packet.FMLPacket.Type.MOD_IDENTIFIERS; -import static cpw.mods.fml.common.network.packet.FMLPacket.Type.MOD_IDMAP; -import static cpw.mods.fml.common.network.packet.FMLPacket.Type.MOD_LIST_RESPONSE; -import static cpw.mods.fml.common.network.packet.FMLPacket.Type.MOD_MISSING; +import static cpw.mods.fml.common.network.packet.FMLOldPacket.Type.MOD_IDENTIFIERS; +import static cpw.mods.fml.common.network.packet.FMLOldPacket.Type.MOD_IDMAP; +import static cpw.mods.fml.common.network.packet.FMLOldPacket.Type.MOD_LIST_RESPONSE; +import static cpw.mods.fml.common.network.packet.FMLOldPacket.Type.MOD_MISSING; import java.util.List; import java.util.Map; @@ -42,7 +42,7 @@ import cpw.mods.fml.common.network.NetworkModHolder; import cpw.mods.fml.common.network.PacketDispatcher; import cpw.mods.fml.common.registry.GameData; -public class ModListResponsePacket extends FMLPacket +public class ModListResponsePacket extends FMLOldPacket { private Map modVersions; private List missingMods; @@ -75,7 +75,7 @@ public class ModListResponsePacket extends FMLPacket } @Override - public FMLPacket consumePacketData(byte[] data) + public FMLOldPacket consumePacketData(byte[] data) { ByteArrayDataInput dat = ByteStreams.newDataInput(data); int versionListSize = dat.readInt(); @@ -128,7 +128,7 @@ public class ModListResponsePacket extends FMLPacket pkt.field_73630_a = "FML"; if (missingClientMods.size()>0 || versionIncorrectMods.size() > 0) { - pkt.field_73629_c = FMLPacket.makePacket(MOD_MISSING, missingClientMods, versionIncorrectMods); + pkt.field_73629_c = FMLOldPacket.makePacket(MOD_MISSING, missingClientMods, versionIncorrectMods); Logger.getLogger("Minecraft").info(String.format("User %s connection failed: missing %s, bad versions %s", userName, missingClientMods, versionIncorrectMods)); FMLLog.info("User %s connection failed: missing %s, bad versions %s", userName, missingClientMods, versionIncorrectMods); // Mark this as bad @@ -138,14 +138,14 @@ public class ModListResponsePacket extends FMLPacket } else { - pkt.field_73629_c = FMLPacket.makePacket(MOD_IDENTIFIERS, netHandler); + pkt.field_73629_c = FMLOldPacket.makePacket(MOD_IDENTIFIERS, netHandler); Logger.getLogger("Minecraft").info(String.format("User %s connecting with mods %s", userName, modVersions.keySet())); FMLLog.info("User %s connecting with mods %s", userName, modVersions.keySet()); pkt.field_73628_b = pkt.field_73629_c.length; network.func_74429_a(pkt); NBTTagList itemList = new NBTTagList(); GameData.writeItemData(itemList); - byte[][] registryPackets = FMLPacket.makePacketSet(MOD_IDMAP, itemList); + byte[][] registryPackets = FMLOldPacket.makePacketSet(MOD_IDMAP, itemList); for (int i = 0; i < registryPackets.length; i++) { network.func_74429_a(PacketDispatcher.getPacket("FML", registryPackets[i])); diff --git a/fml/src/main/java/cpw/mods/fml/common/network/packet/ModMissingPacket.java b/fml/src/main/java/cpw/mods/fml/common/network/packet/ModMissingPacket.java index dbe7735d7..599b23df0 100644 --- a/fml/src/main/java/cpw/mods/fml/common/network/packet/ModMissingPacket.java +++ b/fml/src/main/java/cpw/mods/fml/common/network/packet/ModMissingPacket.java @@ -32,7 +32,7 @@ import cpw.mods.fml.common.versioning.VersionRange; import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.NetHandler; -public class ModMissingPacket extends FMLPacket +public class ModMissingPacket extends FMLOldPacket { private List missing; @@ -76,7 +76,7 @@ public class ModMissingPacket extends FMLPacket String modVersion; } @Override - public FMLPacket consumePacketData(byte[] data) + public FMLOldPacket consumePacketData(byte[] data) { ByteArrayDataInput dat = ByteStreams.newDataInput(data); int missingLen = dat.readInt(); diff --git a/fml/src/main/java/cpw/mods/fml/common/network/packet/OpenGuiPacket.java b/fml/src/main/java/cpw/mods/fml/common/network/packet/OpenGuiPacket.java index 207297cfa..9b90bfe54 100644 --- a/fml/src/main/java/cpw/mods/fml/common/network/packet/OpenGuiPacket.java +++ b/fml/src/main/java/cpw/mods/fml/common/network/packet/OpenGuiPacket.java @@ -16,7 +16,7 @@ import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; -public class OpenGuiPacket extends FMLPacket +public class OpenGuiPacket extends FMLOldPacket { int windowId; int networkId; @@ -39,7 +39,7 @@ public class OpenGuiPacket extends FMLPacket } @Override - public FMLPacket consumePacketData(byte[] data) + public FMLOldPacket consumePacketData(byte[] data) { ByteArrayDataInput dat = ByteStreams.newDataInput(data); windowId = dat.readInt(); diff --git a/fml/src/main/java/cpw/mods/fml/common/network/packet/PacketManager.java b/fml/src/main/java/cpw/mods/fml/common/network/packet/PacketManager.java index a0f0ad5c5..f0c8f7ac5 100644 --- a/fml/src/main/java/cpw/mods/fml/common/network/packet/PacketManager.java +++ b/fml/src/main/java/cpw/mods/fml/common/network/packet/PacketManager.java @@ -11,40 +11,41 @@ import net.minecraft.network.play.server.S3FPacketCustomPayload; import com.google.common.collect.Maps; import com.google.common.primitives.UnsignedBytes; -import cpw.mods.fml.common.network.NetworkDispatcher; -import cpw.mods.fml.common.network.packet.FMLPacket.Type; +import cpw.mods.fml.common.network.handshake.NetworkDispatcher; +import cpw.mods.fml.common.network.packet.FMLOldPacket.Type; public enum PacketManager { INSTANCE; - private Map, PacketExecutor> packetExecutors = Maps.newHashMap(); + private Map, PacketExecutor> packetExecutors = Maps.newHashMap(); public C17PacketCustomPayload makeGuiPacket(int windowId, int i, int modGuiId, int x, int y, int z) { - byte[] data = FMLPacket.makePacket(Type.GUIOPEN, windowId, i, modGuiId, x, y, z); + byte[] data = FMLOldPacket.makePacket(Type.GUIOPEN, windowId, i, modGuiId, x, y, z); C17PacketCustomPayload packet = new C17PacketCustomPayload("FML", data); return packet; } - public FMLPacket readPacket(NetworkDispatcher dispatcher, C17PacketCustomPayload clientSentPacket) + public FMLOldPacket readPacket(NetworkDispatcher dispatcher, C17PacketCustomPayload clientSentPacket) { byte[] payload = clientSentPacket.func_149558_e(); return buildPacket(dispatcher, payload); } - public FMLPacket readPacket(NetworkDispatcher dispatcher, S3FPacketCustomPayload serverSentPacket) + + public FMLOldPacket readPacket(NetworkDispatcher dispatcher, S3FPacketCustomPayload serverSentPacket) { byte[] payload = serverSentPacket.func_149168_d(); return buildPacket(dispatcher, payload); } - private FMLPacket buildPacket(NetworkDispatcher dispatcher, byte[] payload) + private FMLOldPacket buildPacket(NetworkDispatcher dispatcher, byte[] payload) { int type = UnsignedBytes.toInt(payload[0]); Type eType = Type.values()[type]; - FMLPacket pkt; + FMLOldPacket pkt; if (eType.isMultipart()) { pkt = eType.findCurrentPart(network); diff --git a/fml/src/main/java/cpw/mods/fml/relauncher/FMLCorePlugin.java b/fml/src/main/java/cpw/mods/fml/relauncher/FMLCorePlugin.java index e7d9e5c36..c03e4383c 100644 --- a/fml/src/main/java/cpw/mods/fml/relauncher/FMLCorePlugin.java +++ b/fml/src/main/java/cpw/mods/fml/relauncher/FMLCorePlugin.java @@ -29,7 +29,7 @@ public class FMLCorePlugin implements IFMLLoadingPlugin @Override public String getModContainerClass() { - return "cpw.mods.fml.common.FMLDummyContainer"; + return "cpw.mods.fml.common.FMLContainer"; } @Override