From e27b438f7dc3657fa2cf1eb51c94886cefab0d2b Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 28 Dec 2013 17:51:40 -0500 Subject: [PATCH] Fire simple network connect/disconnect gameevents. --- .../cpw/mods/fml/client/FMLClientHandler.java | 6 +++ .../fml/common/network/FMLNetworkEvent.java | 50 +++++++++++++++++++ .../network/handshake/NetworkDispatcher.java | 13 +++++ 3 files changed, 69 insertions(+) create mode 100644 fml/src/main/java/cpw/mods/fml/common/network/FMLNetworkEvent.java diff --git a/fml/src/main/java/cpw/mods/fml/client/FMLClientHandler.java b/fml/src/main/java/cpw/mods/fml/client/FMLClientHandler.java index 4da09ce66..034809fb9 100644 --- a/fml/src/main/java/cpw/mods/fml/client/FMLClientHandler.java +++ b/fml/src/main/java/cpw/mods/fml/client/FMLClientHandler.java @@ -21,6 +21,7 @@ import java.util.logging.Logger; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityClientPlayerMP; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.GuiSelectWorld; import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.entity.RenderManager; @@ -496,4 +497,9 @@ public class FMLClientHandler implements IFMLSidedHandler GameData.revertToFrozen(); } } + + public void tryLoadWorld(GuiSelectWorld selectWorldGUI, int selectedIndex) + { + selectWorldGUI.func_146615_e(selectedIndex); + } } diff --git a/fml/src/main/java/cpw/mods/fml/common/network/FMLNetworkEvent.java b/fml/src/main/java/cpw/mods/fml/common/network/FMLNetworkEvent.java new file mode 100644 index 000000000..cf721e3de --- /dev/null +++ b/fml/src/main/java/cpw/mods/fml/common/network/FMLNetworkEvent.java @@ -0,0 +1,50 @@ +package cpw.mods.fml.common.network; + +import net.minecraft.network.INetHandler; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.play.INetHandlerPlayClient; +import net.minecraft.network.play.INetHandlerPlayServer; +import cpw.mods.fml.common.eventhandler.Event; + +public class FMLNetworkEvent extends Event { + public final T handler; + public final NetworkManager manager; + @SuppressWarnings("unused") + private final Class type; + + FMLNetworkEvent(T thing, Class type, NetworkManager manager) + { + this.handler = thing; + this.type = type; + this.manager = manager; + } + public static class ClientConnectedToServerEvent extends FMLNetworkEvent { + public final boolean isLocal; + public ClientConnectedToServerEvent(NetworkManager manager) + { + super((INetHandlerPlayClient) manager.func_150729_e(), INetHandlerPlayClient.class, manager); + isLocal = manager.func_150731_c(); + } + } + + public static class ServerConnectionFromClientEvent extends FMLNetworkEvent { + public final boolean isLocal; + public ServerConnectionFromClientEvent(NetworkManager manager) + { + super((INetHandlerPlayServer) manager.func_150729_e(), INetHandlerPlayServer.class, manager); + isLocal = manager.func_150731_c(); + } + } + public static class ServerDisconnectionFromClientEvent extends FMLNetworkEvent { + public ServerDisconnectionFromClientEvent(NetworkManager manager) + { + super((INetHandlerPlayServer) manager.func_150729_e(), INetHandlerPlayServer.class, manager); + } + } + public static class ClientDisconnectionFromServerEvent extends FMLNetworkEvent { + public ClientDisconnectionFromServerEvent(NetworkManager manager) + { + super((INetHandlerPlayClient) manager.func_150729_e(), INetHandlerPlayClient.class, manager); + } + } +} diff --git a/fml/src/main/java/cpw/mods/fml/common/network/handshake/NetworkDispatcher.java b/fml/src/main/java/cpw/mods/fml/common/network/handshake/NetworkDispatcher.java index 0c4b7e9e3..7ed17a94b 100644 --- a/fml/src/main/java/cpw/mods/fml/common/network/handshake/NetworkDispatcher.java +++ b/fml/src/main/java/cpw/mods/fml/common/network/handshake/NetworkDispatcher.java @@ -21,12 +21,15 @@ import net.minecraft.network.EnumConnectionState; import net.minecraft.network.NetHandlerPlayServer; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; +import net.minecraft.network.play.INetHandlerPlayClient; 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 net.minecraft.util.ChatComponentText; +import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLLog; +import cpw.mods.fml.common.network.FMLNetworkEvent; import cpw.mods.fml.common.network.FMLNetworkException; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.internal.FMLMessage; @@ -151,6 +154,7 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler imple FMLLog.info("[%s] Client side modded connection established", Thread.currentThread().getName()); this.state = ConnectionState.CONNECTED; this.connectionType = ConnectionType.MODDED; + FMLCommonHandler.instance().bus().post(new FMLNetworkEvent.ClientConnectedToServerEvent(manager)); } private void completeServerSideConnection() @@ -158,6 +162,7 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler imple FMLLog.info("[%s] Server side modded connection established", Thread.currentThread().getName()); this.state = ConnectionState.CONNECTED; this.connectionType = ConnectionType.MODDED; + FMLCommonHandler.instance().bus().post(new FMLNetworkEvent.ServerConnectionFromClientEvent(manager)); scm.func_72355_a(manager, player, serverHandler); } @Override @@ -326,6 +331,14 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler imple @Override public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + if (side == Side.CLIENT) + { + FMLCommonHandler.instance().bus().post(new FMLNetworkEvent.ClientDisconnectionFromServerEvent(manager)); + } + else + { + FMLCommonHandler.instance().bus().post(new FMLNetworkEvent.ServerDisconnectionFromClientEvent(manager)); + } ctx.disconnect(promise); }