From 6f19fd15134aca1c054b018c796695a2dfd7a9d8 Mon Sep 17 00:00:00 2001 From: Lumien Date: Sat, 6 Dec 2014 16:31:58 +0100 Subject: [PATCH] Save the mod list of players in their NetworkDispatcher (Make it accessable for mods) --- .../handshake/FMLHandshakeServerState.java | 3 ++- .../network/handshake/NetworkDispatcher.java | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/fml/src/main/java/net/minecraftforge/fml/common/network/handshake/FMLHandshakeServerState.java b/fml/src/main/java/net/minecraftforge/fml/common/network/handshake/FMLHandshakeServerState.java index e7586cda3..b800429f9 100644 --- a/fml/src/main/java/net/minecraftforge/fml/common/network/handshake/FMLHandshakeServerState.java +++ b/fml/src/main/java/net/minecraftforge/fml/common/network/handshake/FMLHandshakeServerState.java @@ -41,11 +41,12 @@ enum FMLHandshakeServerState implements IHandshakeState } FMLHandshakeMessage.ModList client = (FMLHandshakeMessage.ModList)msg; + NetworkDispatcher dispatcher = ctx.channel().attr(NetworkDispatcher.FML_DISPATCHER).get(); + dispatcher.setModList(client.modList()); FMLLog.info("Client attempting to join with %d mods : %s", client.modListSize(), client.modListAsString()); String result = FMLNetworkHandler.checkModList(client, Side.CLIENT); if (result != null) { - NetworkDispatcher dispatcher = ctx.channel().attr(NetworkDispatcher.FML_DISPATCHER).get(); dispatcher.rejectHandshake(result); return ERROR; } diff --git a/fml/src/main/java/net/minecraftforge/fml/common/network/handshake/NetworkDispatcher.java b/fml/src/main/java/net/minecraftforge/fml/common/network/handshake/NetworkDispatcher.java index 2260b3307..1be6617d8 100644 --- a/fml/src/main/java/net/minecraftforge/fml/common/network/handshake/NetworkDispatcher.java +++ b/fml/src/main/java/net/minecraftforge/fml/common/network/handshake/NetworkDispatcher.java @@ -13,8 +13,10 @@ import io.netty.util.concurrent.GenericFutureListener; import java.io.IOException; import java.net.SocketAddress; import java.nio.channels.ClosedChannelException; +import java.util.Collections; import java.util.List; import java.util.Locale; +import java.util.Map; import org.apache.logging.log4j.Level; @@ -85,6 +87,7 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler imple private final EmbeddedChannel handshakeChannel; private NetHandlerPlayServer serverHandler; private INetHandler netHandler; + private Map modList; public NetworkDispatcher(NetworkManager manager) { @@ -133,6 +136,11 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler imple this.completeServerSideConnection(ConnectionType.VANILLA); } } + + protected void setModList(Map modList) + { + this.modList = modList; + } private void insertIntoChannel() { @@ -245,6 +253,16 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler imple { return netHandler; } + + /** + * The mod list returned by this method is in no way reliable because it is provided by the client + * + * @return a map that will contain String keys and values listing all mods and their versions + */ + public Map getModList() + { + return Collections.unmodifiableMap(modList); + } @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception