diff --git a/fml/client/cpw/mods/fml/client/FMLClientHandler.java b/fml/client/cpw/mods/fml/client/FMLClientHandler.java index 3c255afad..8a119e550 100644 --- a/fml/client/cpw/mods/fml/client/FMLClientHandler.java +++ b/fml/client/cpw/mods/fml/client/FMLClientHandler.java @@ -139,8 +139,6 @@ public class FMLClientHandler implements IFMLSidedHandler private TexturePackBase fallbackTexturePack; - private NetClientHandler networkClient; - private boolean firstTick; /** * Called to start the whole game off from diff --git a/fml/common/cpw/mods/fml/common/modloader/ModLoaderConnectionHandler.java b/fml/common/cpw/mods/fml/common/modloader/ModLoaderConnectionHandler.java index b208667cd..987bbccec 100644 --- a/fml/common/cpw/mods/fml/common/modloader/ModLoaderConnectionHandler.java +++ b/fml/common/cpw/mods/fml/common/modloader/ModLoaderConnectionHandler.java @@ -1,8 +1,10 @@ package cpw.mods.fml.common.modloader; +import net.minecraft.src.IntegratedServer; import net.minecraft.src.NetHandler; import net.minecraft.src.NetLoginHandler; import net.minecraft.src.NetworkManager; +import net.minecraft.src.Packet1Login; import cpw.mods.fml.common.network.IConnectionHandler; import cpw.mods.fml.common.network.Player; @@ -21,4 +23,32 @@ public class ModLoaderConnectionHandler implements IConnectionHandler return null; } + @Override + public void connectionOpened(NetHandler netClientHandler, String server, int port, NetworkManager manager) + { + // TODO Auto-generated method stub + + } + + @Override + public void connectionOpened(NetHandler netClientHandler, IntegratedServer server, NetworkManager manager) + { + // TODO Auto-generated method stub + + } + + @Override + public void connectionClosed(NetworkManager manager) + { + // TODO Auto-generated method stub + + } + + @Override + public void clientLoggedIn(NetworkManager manager, Packet1Login login) + { + // TODO Auto-generated method stub + + } + } diff --git a/fml/common/cpw/mods/fml/common/network/FMLNetworkHandler.java b/fml/common/cpw/mods/fml/common/network/FMLNetworkHandler.java index e15261a5b..a78156013 100644 --- a/fml/common/cpw/mods/fml/common/network/FMLNetworkHandler.java +++ b/fml/common/cpw/mods/fml/common/network/FMLNetworkHandler.java @@ -1,45 +1,33 @@ package cpw.mods.fml.common.network; -import static cpw.mods.fml.common.network.FMLPacket.Type.*; +import static cpw.mods.fml.common.network.FMLPacket.Type.MOD_LIST_REQUEST; import java.net.SocketAddress; -import java.util.List; import java.util.Map; import java.util.Set; -import java.util.WeakHashMap; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.BiMap; -import com.google.common.collect.ListMultimap; -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 com.google.common.hash.Hashing; -import com.google.common.io.ByteStreams; - -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.FMLLog; -import cpw.mods.fml.common.Loader; -import cpw.mods.fml.common.ModContainer; -import cpw.mods.fml.common.discovery.ASMDataTable; -import cpw.mods.fml.common.discovery.ASMDataTable.ASMData; -import cpw.mods.fml.relauncher.FMLRelaunchLog; import net.minecraft.server.MinecraftServer; import net.minecraft.src.EntityPlayerMP; import net.minecraft.src.EnumGameType; +import net.minecraft.src.IntegratedServer; import net.minecraft.src.NetHandler; import net.minecraft.src.NetLoginHandler; import net.minecraft.src.NetServerHandler; import net.minecraft.src.NetworkManager; -import net.minecraft.src.Packet; import net.minecraft.src.Packet1Login; import net.minecraft.src.Packet250CustomPayload; import net.minecraft.src.ServerConfigurationManager; -import net.minecraft.src.TcpConnection; import net.minecraft.src.WorldType; +import com.google.common.collect.Maps; +import com.google.common.hash.Hashing; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.ModContainer; +import cpw.mods.fml.common.discovery.ASMDataTable; +import cpw.mods.fml.relauncher.FMLRelaunchLog; + public class FMLNetworkHandler { private static final int FML_HASH = Hashing.murmur3_32().hashString("FML").asInt(); @@ -70,13 +58,18 @@ public class FMLNetworkHandler } } + public static void onConnectionEstablishedToServer(NetworkManager manager, Packet1Login login) + { + NetworkRegistry.instance().clientLoggedIn(manager, login); + } + private void handleFMLPacket(Packet250CustomPayload packet, NetworkManager network, NetHandler netHandler) { FMLPacket pkt = FMLPacket.readPacket(packet.field_73629_c); String userName = null; if (netHandler instanceof NetLoginHandler) { - userName = ((NetLoginHandler)netHandler).field_72543_h; + userName = ((NetLoginHandler) netHandler).field_72543_h; } else { @@ -101,7 +94,7 @@ public class FMLNetworkHandler netLoginHandler.completeConnection("You don't have FML installed, or your installation is too old"); return; } - + } // Are we ready to negotiate with the client? if (loginStates.get(netLoginHandler) == 1) @@ -127,13 +120,15 @@ public class FMLNetworkHandler netLoginHandler.field_72538_b.func_74429_a(getModListRequestPacket()); loginStates.put(netLoginHandler, 2); } - // We must be good to go - the ModIdentifiers packet was sent and the continuation signal was indicated + // We must be good to go - the ModIdentifiers packet was sent and the + // continuation signal was indicated else if (loginStates.get(netLoginHandler) == 2) { netLoginHandler.completeConnection(null); loginStates.remove(netLoginHandler); } - // We have to abort this connection - there was a negotiation problem (most likely missing mods) + // We have to abort this connection - there was a negotiation problem + // (most likely missing mods) else { netLoginHandler.completeConnection("There was a problem during FML negotiation"); @@ -154,7 +149,7 @@ public class FMLNetworkHandler ServerConfigurationManager playerList = server.func_71203_ab(); String kickReason = playerList.func_72399_a(address, userName); - if (kickReason!=null) + if (kickReason != null) { netLoginHandler.completeConnection(kickReason); } @@ -166,13 +161,15 @@ public class FMLNetworkHandler if (login.field_73561_a == FML_HASH && login.field_73558_e == PROTOCOL_VERSION) { FMLRelaunchLog.finest("Received valid FML login packet from %s", handler.field_72538_b.func_74430_c()); - instance().loginStates.put(handler,1); + instance().loginStates.put(handler, 1); } else { - FMLRelaunchLog.fine("Received invalid FML login packet %d, %d from %s", login.field_73561_a, login.field_73558_e, handler.field_72538_b.func_74430_c()); + FMLRelaunchLog.fine("Received invalid FML login packet %d, %d from %s", login.field_73561_a, login.field_73558_e, + handler.field_72538_b.func_74430_c()); } } + public static FMLNetworkHandler instance() { return INSTANCE; @@ -189,6 +186,7 @@ public class FMLNetworkHandler fake.field_73559_b = WorldType.field_77139_a[0]; return fake; } + public Packet250CustomPayload getModListRequestPacket() { Packet250CustomPayload pkt = new Packet250CustomPayload(); @@ -246,6 +244,21 @@ public class FMLNetworkHandler Map mods = Loader.instance().getIndexedModList(); NetworkModHandler handler = findNetworkModHandler(mods.get(key)); handler.setNetworkId(value); - networkIdLookup.put(value,handler); + networkIdLookup.put(value, handler); + } + + public static void onClientConnectionToRemoteServer(NetHandler netClientHandler, String server, int port, NetworkManager networkManager) + { + NetworkRegistry.instance().connectionOpened(netClientHandler, server, port, networkManager); + } + + public static void onClientConnectionToIntegratedServer(NetHandler netClientHandler, IntegratedServer server, NetworkManager networkManager) + { + NetworkRegistry.instance().connectionOpened(netClientHandler, server, networkManager); + } + + public static void onConnectionClosed(NetworkManager manager) + { + NetworkRegistry.instance().connectionClosed(manager); } } \ No newline at end of file diff --git a/fml/common/cpw/mods/fml/common/network/IConnectionHandler.java b/fml/common/cpw/mods/fml/common/network/IConnectionHandler.java index b4c0213c3..c690db710 100644 --- a/fml/common/cpw/mods/fml/common/network/IConnectionHandler.java +++ b/fml/common/cpw/mods/fml/common/network/IConnectionHandler.java @@ -2,15 +2,18 @@ package cpw.mods.fml.common.network; import net.minecraft.src.EntityPlayer; import net.minecraft.src.EntityPlayerMP; +import net.minecraft.src.IntegratedServer; import net.minecraft.src.NetHandler; import net.minecraft.src.NetLoginHandler; import net.minecraft.src.NetServerHandler; import net.minecraft.src.NetworkManager; +import net.minecraft.src.Packet1Login; public interface IConnectionHandler { /** * Called when a player logs into the server + * SERVER SIDE * * @param player * @param netHandler @@ -23,10 +26,51 @@ public interface IConnectionHandler * If you do, you can do other stuff here- note no FML negotiation has occured yet * though the client is verified as having FML installed * + * SERVER SIDE + * * @param netHandler * @param manager * @return */ String connectionReceived(NetLoginHandler netHandler, NetworkManager manager); + /** + * Fired when a remote connection is opened + * CLIENT SIDE + * + * @param netClientHandler + * @param server + * @param port + */ + void connectionOpened(NetHandler netClientHandler, String server, int port, NetworkManager manager); + /** + * + * Fired when a local connection is opened + * + * CLIENT SIDE + * + * @param netClientHandler + * @param server + */ + void connectionOpened(NetHandler netClientHandler, IntegratedServer server, NetworkManager manager); + + /** + * Fired when a connection closes + * + * ALL SIDES + * + * @param manager + */ + void connectionClosed(NetworkManager manager); + + /** + * Fired when the client established the connection to the server + * + * CLIENT SIDE + * + * @param manager + * @param login + */ + void clientLoggedIn(NetworkManager manager, Packet1Login login); + } diff --git a/fml/common/cpw/mods/fml/common/network/NetworkRegistry.java b/fml/common/cpw/mods/fml/common/network/NetworkRegistry.java index 9780094a2..a71bb9bd6 100644 --- a/fml/common/cpw/mods/fml/common/network/NetworkRegistry.java +++ b/fml/common/cpw/mods/fml/common/network/NetworkRegistry.java @@ -10,10 +10,12 @@ import java.util.logging.Level; import net.minecraft.src.EntityPlayer; import net.minecraft.src.EntityPlayerMP; +import net.minecraft.src.IntegratedServer; import net.minecraft.src.NetHandler; import net.minecraft.src.NetLoginHandler; import net.minecraft.src.NetServerHandler; import net.minecraft.src.NetworkManager; +import net.minecraft.src.Packet1Login; import net.minecraft.src.Packet250CustomPayload; import com.google.common.base.Charsets; @@ -129,6 +131,38 @@ public class NetworkRegistry return null; } + void connectionOpened(NetHandler netClientHandler, String server, int port, NetworkManager networkManager) + { + for (IConnectionHandler handler : connectionHandlers) + { + handler.connectionOpened(netClientHandler, server, port, networkManager); + } + } + + void connectionOpened(NetHandler netClientHandler, IntegratedServer server, NetworkManager networkManager) + { + for (IConnectionHandler handler : connectionHandlers) + { + handler.connectionOpened(netClientHandler, server, networkManager); + } + } + + public void clientLoggedIn(NetworkManager manager, Packet1Login login) + { + for (IConnectionHandler handler : connectionHandlers) + { + handler.clientLoggedIn(manager, login); + } + } + + void connectionClosed(NetworkManager manager) + { + for (IConnectionHandler handler : connectionHandlers) + { + handler.connectionClosed(manager); + } + } + void generateChannelRegistration(EntityPlayer player, NetHandler netHandler, NetworkManager manager) { Packet250CustomPayload pkt = new Packet250CustomPayload(); diff --git a/fml/patches/minecraft/net/minecraft/src/NetClientHandler.java.patch b/fml/patches/minecraft/net/minecraft/src/NetClientHandler.java.patch index 54fade9ca..94107bd7a 100644 --- a/fml/patches/minecraft/net/minecraft/src/NetClientHandler.java.patch +++ b/fml/patches/minecraft/net/minecraft/src/NetClientHandler.java.patch @@ -10,7 +10,23 @@ public class NetClientHandler extends NetHandler { private boolean field_72554_f = false; -@@ -116,6 +119,7 @@ +@@ -39,6 +42,7 @@ + this.field_72563_h = p_i3103_1_; + Socket var4 = new Socket(InetAddress.getByName(p_i3103_2_), p_i3103_3_); + this.field_72555_g = new TcpConnection(var4, "Client", this); ++ FMLNetworkHandler.onClientConnectionToRemoteServer(this, p_i3103_2_, p_i3103_3_, this.field_72555_g); + } + + public NetClientHandler(Minecraft p_i3104_1_, IntegratedServer p_i3104_2_) throws IOException +@@ -46,6 +50,7 @@ + this.field_72563_h = p_i3104_1_; + this.field_72555_g = new MemoryConnection(this); + p_i3104_2_.func_71343_a().func_71754_a((MemoryConnection)this.field_72555_g, p_i3104_1_.field_71449_j.field_74286_b); ++ FMLNetworkHandler.onClientConnectionToIntegratedServer(this, p_i3104_2_, this.field_72555_g); + } + + public void func_72547_c() +@@ -116,6 +121,7 @@ public void func_72513_a(Packet252SharedKey p_72513_1_) { @@ -18,7 +34,15 @@ this.func_72552_c(new Packet205ClientCommand(0)); } -@@ -1164,6 +1168,11 @@ +@@ -131,6 +137,7 @@ + this.field_72563_h.field_71439_g.field_70157_k = p_72455_1_.field_73561_a; + this.field_72556_d = p_72455_1_.field_73562_h; + this.field_72563_h.field_71442_b.func_78746_a(p_72455_1_.field_73557_d); ++ FMLNetworkHandler.onConnectionEstablishedToServer(field_72555_g, p_72455_1_); + this.func_72552_c(new Packet204ClientInfo(this.field_72563_h.field_71474_y.field_74363_ab, this.field_72563_h.field_71474_y.field_74339_e, this.field_72563_h.field_71474_y.field_74343_n, this.field_72563_h.field_71474_y.field_74344_o, this.field_72563_h.field_71474_y.field_74318_M)); + } + +@@ -1164,6 +1171,11 @@ public void func_72501_a(Packet250CustomPayload p_72501_1_) { @@ -30,7 +54,7 @@ if ("MC|TPack".equals(p_72501_1_.field_73630_a)) { String[] var2 = (new String(p_72501_1_.field_73629_c)).split("\u0000"); -@@ -1208,4 +1217,10 @@ +@@ -1208,4 +1220,10 @@ { return this.field_72555_g; }