Fire a user event down the channels when a handshake has occured.
This commit is contained in:
parent
69ce79e1d7
commit
041054ea8b
3 changed files with 36 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<String, FMLEmbeddedChannel> channel : channels.get(origin).entrySet())
|
||||
{
|
||||
channel.getValue().pipeline().fireUserEventTriggered(handshake);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ enum FMLHandshakeServerState implements IHandshakeState<FMLHandshakeServerState>
|
|||
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;
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue