From 041054ea8b8a27e9f0b05d475774f3a8439b03e4 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 16 Dec 2013 20:00:01 -0500 Subject: [PATCH] Fire a user event down the channels when a handshake has occured. --- .../network/NetworkHandshakeEstablished.java | 24 +++++++++++++++++++ .../fml/common/network/NetworkRegistry.java | 11 +++++++++ .../handshake/FMLHandshakeServerState.java | 1 + 3 files changed, 36 insertions(+) create mode 100644 fml/src/main/java/cpw/mods/fml/common/network/NetworkHandshakeEstablished.java diff --git a/fml/src/main/java/cpw/mods/fml/common/network/NetworkHandshakeEstablished.java b/fml/src/main/java/cpw/mods/fml/common/network/NetworkHandshakeEstablished.java new file mode 100644 index 000000000..4d8593a49 --- /dev/null +++ b/fml/src/main/java/cpw/mods/fml/common/network/NetworkHandshakeEstablished.java @@ -0,0 +1,24 @@ +package cpw.mods.fml.common.network; + +import cpw.mods.fml.common.network.handshake.NetworkDispatcher; +import cpw.mods.fml.relauncher.Side; + +/** + * This message is sent through all channels affected by a currently occurring handshake. It is guaranteed to + * be able to send a custom payload packet, however, interaction with minecraft and world state is NOT assured + * as it is likely this is fired on a netty handler thread, not a world processing thread. + * + * If you wish to send an outbound message through your channel, bind the {@link FMLOutboundHandler#FML_MESSAGETARGET} + * property of your channel to the supplied dispatcher. + * @author cpw + * + */ +public class NetworkHandshakeEstablished { + public final NetworkDispatcher dispatcher; + public final Side side; + public NetworkHandshakeEstablished(NetworkDispatcher dispatcher, Side origin) + { + this.dispatcher = dispatcher; + this.side = origin; + } +} 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 dc27e812d..eb7a16ab0 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 @@ -20,6 +20,7 @@ import io.netty.util.AttributeKey; import java.util.EnumMap; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import org.apache.logging.log4j.Level; @@ -34,6 +35,7 @@ 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.network.handshake.NetworkDispatcher; import cpw.mods.fml.common.network.internal.FMLProxyPacket; import cpw.mods.fml.common.network.internal.NetworkModHolder; import cpw.mods.fml.relauncher.Side; @@ -423,4 +425,13 @@ public enum NetworkRegistry { return channels.get(side).keySet(); } + + public void fireNetworkHandshake(NetworkDispatcher networkDispatcher, Side origin) + { + NetworkHandshakeEstablished handshake = new NetworkHandshakeEstablished(networkDispatcher, origin); + for (Entry channel : channels.get(origin).entrySet()) + { + channel.getValue().pipeline().fireUserEventTriggered(handshake); + } + } } 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 index 9f6f7d327..de01c8b4e 100644 --- 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 @@ -58,6 +58,7 @@ enum FMLHandshakeServerState implements IHandshakeState ctx.writeAndFlush(new FMLHandshakeMessage.ModIdData(GameData.buildItemDataList())); } ctx.writeAndFlush(new FMLHandshakeMessage.HandshakeAck()); + NetworkRegistry.INSTANCE.fireNetworkHandshake(ctx.channel().attr(NetworkDispatcher.FML_DISPATCHER).get(), Side.SERVER); return COMPLETE; } },