Fire simple network connect/disconnect gameevents.

This commit is contained in:
Christian 2013-12-28 17:51:40 -05:00
parent 7b7b8245db
commit e27b438f7d
3 changed files with 69 additions and 0 deletions

View file

@ -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);
}
}

View file

@ -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<T extends INetHandler> extends Event {
public final T handler;
public final NetworkManager manager;
@SuppressWarnings("unused")
private final Class<T> type;
FMLNetworkEvent(T thing, Class<T> type, NetworkManager manager)
{
this.handler = thing;
this.type = type;
this.manager = manager;
}
public static class ClientConnectedToServerEvent extends FMLNetworkEvent<INetHandlerPlayClient> {
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<INetHandlerPlayServer> {
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<INetHandlerPlayServer> {
public ServerDisconnectionFromClientEvent(NetworkManager manager)
{
super((INetHandlerPlayServer) manager.func_150729_e(), INetHandlerPlayServer.class, manager);
}
}
public static class ClientDisconnectionFromServerEvent extends FMLNetworkEvent<INetHandlerPlayClient> {
public ClientDisconnectionFromServerEvent(NetworkManager manager)
{
super((INetHandlerPlayClient) manager.func_150729_e(), INetHandlerPlayClient.class, manager);
}
}
}

View file

@ -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<Packet> 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<Packet> 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<Packet> 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);
}