mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 19:39:22 +00:00
Fix problem with connecting to vanilla.
SHOW what's modded and what's vanilla in the list. Hooks that make the blocking work to come
This commit is contained in:
1 parent
0d810c01fa
commit
d5bfd69e35
12 files changed
+283
-21
No files matched your search
@@ -0,0 +1,16 @@
|
||||
package cpw.mods.fml.client;
|
||||
|
||||
public class ExtendedServerListData {
|
||||
public final String type;
|
||||
public final boolean isCompatible;
|
||||
public final int modCount;
|
||||
public final boolean isBlocked;
|
||||
|
||||
public ExtendedServerListData(String type, boolean isCompatible, int modCount, boolean isBlocked)
|
||||
{
|
||||
this.type = type;
|
||||
this.isCompatible = isCompatible;
|
||||
this.modCount = modCount;
|
||||
this.isBlocked = isBlocked;
|
||||
}
|
||||
}
|
||||
@@ -14,15 +14,19 @@ package cpw.mods.fml.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.logging.Logger;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiIngameMenu;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiSelectWorld;
|
||||
import net.minecraft.client.gui.ServerListEntryNormal;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.client.renderer.entity.Render;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
@@ -34,7 +38,9 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraft.network.INetHandler;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.ServerStatusResponse;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.base.Throwables;
|
||||
@@ -43,6 +49,7 @@ import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.JsonObject;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
import cpw.mods.fml.common.DummyModContainer;
|
||||
import cpw.mods.fml.common.DuplicateModsFoundException;
|
||||
@@ -124,6 +131,9 @@ public class FMLClientHandler implements IFMLSidedHandler
|
||||
|
||||
private BiMap<ModContainer, IModGuiFactory> guiFactories;
|
||||
|
||||
private Map<ServerStatusResponse,JsonObject> extraServerListData;
|
||||
private Map<ServerData, ExtendedServerListData> serverDataTag;
|
||||
|
||||
/**
|
||||
* Called to start the whole game off
|
||||
*
|
||||
@@ -544,4 +554,97 @@ public class FMLClientHandler implements IFMLSidedHandler
|
||||
{
|
||||
return guiFactories.get(selectedMod);
|
||||
}
|
||||
|
||||
|
||||
public void setupServerList()
|
||||
{
|
||||
extraServerListData = Collections.synchronizedMap(Maps.<ServerStatusResponse,JsonObject>newHashMap());
|
||||
serverDataTag = Collections.synchronizedMap(Maps.<ServerData,ExtendedServerListData>newHashMap());
|
||||
}
|
||||
|
||||
public void captureAdditionalData(ServerStatusResponse serverstatusresponse, JsonObject jsonobject)
|
||||
{
|
||||
if (jsonobject.has("modinfo"))
|
||||
{
|
||||
JsonObject fmlData = jsonobject.get("modinfo").getAsJsonObject();
|
||||
extraServerListData.put(serverstatusresponse, fmlData);
|
||||
}
|
||||
}
|
||||
public void bindServerListData(ServerData data, ServerStatusResponse originalResponse)
|
||||
{
|
||||
if (extraServerListData.containsKey(originalResponse))
|
||||
{
|
||||
JsonObject jsonData = extraServerListData.get(originalResponse);
|
||||
String type = jsonData.get("type").getAsString();
|
||||
int modCount = jsonData.get("modList").getAsJsonArray().size();
|
||||
boolean moddedClientAllowed = jsonData.has("clientModsAllowed") ? jsonData.get("clientModsAllowed").getAsBoolean() : true;
|
||||
serverDataTag.put(data, new ExtendedServerListData(type, true, modCount, !moddedClientAllowed));
|
||||
}
|
||||
else
|
||||
{
|
||||
String serverDescription = data.field_78843_d;
|
||||
boolean moddedClientAllowed = true;
|
||||
if (!Strings.isNullOrEmpty(serverDescription))
|
||||
{
|
||||
moddedClientAllowed = !serverDescription.endsWith(":NOFML§r");
|
||||
}
|
||||
serverDataTag.put(data, new ExtendedServerListData("VANILLA", false, -1, !moddedClientAllowed));
|
||||
}
|
||||
}
|
||||
|
||||
private static final ResourceLocation iconSheet = new ResourceLocation("fml:textures/gui/icons.png");
|
||||
|
||||
public String enhanceServerListEntry(ServerListEntryNormal serverListEntry, ServerData serverEntry, int x, int width, int y, int relativeMouseX, int relativeMouseY)
|
||||
{
|
||||
String tooltip;
|
||||
int idx;
|
||||
boolean blocked = false;
|
||||
if (serverDataTag.containsKey(serverEntry))
|
||||
{
|
||||
ExtendedServerListData extendedData = serverDataTag.get(serverEntry);
|
||||
if ("FML".equals(extendedData.type) && extendedData.isCompatible)
|
||||
{
|
||||
idx = 0;
|
||||
tooltip = String.format("Compatible FML modded server\n%d mods present", extendedData.modCount);
|
||||
}
|
||||
else if ("FML".equals(extendedData.type) && !extendedData.isCompatible)
|
||||
{
|
||||
idx = 16;
|
||||
tooltip = String.format("Incompatible FML modded server\n%d mods present", extendedData.modCount);
|
||||
}
|
||||
else if ("BUKKIT".equals(extendedData.type))
|
||||
{
|
||||
idx = 32;
|
||||
tooltip = String.format("Bukkit modded server");
|
||||
}
|
||||
else if ("VANILLA".equals(extendedData.type))
|
||||
{
|
||||
idx = 48;
|
||||
tooltip = String.format("Vanilla server");
|
||||
}
|
||||
else
|
||||
{
|
||||
idx = 64;
|
||||
tooltip = String.format("Unknown server data");
|
||||
}
|
||||
blocked = extendedData.isBlocked;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
this.client.func_110434_K().func_110577_a(iconSheet);
|
||||
Gui.func_146110_a(x + width - 18, y + 10, 0, (float)idx, 16, 16, 256.0f, 256.0f);
|
||||
if (blocked)
|
||||
{
|
||||
Gui.func_146110_a(x + width - 18, y + 10, 0, 80, 16, 16, 256.0f, 256.0f);
|
||||
}
|
||||
|
||||
return relativeMouseX > width - 15 && relativeMouseX < width && relativeMouseY > 10 && relativeMouseY < 26 ? tooltip : null;
|
||||
}
|
||||
|
||||
public String fixDescription(String description)
|
||||
{
|
||||
return description.endsWith(":NOFML§r") ? description.substring(0, description.length() - 8)+"§r" : description;
|
||||
}
|
||||
}
|
||||
@@ -20,10 +20,12 @@ public class FMLNetworkEvent<T extends INetHandler> extends Event {
|
||||
}
|
||||
public static class ClientConnectedToServerEvent extends FMLNetworkEvent<INetHandlerPlayClient> {
|
||||
public final boolean isLocal;
|
||||
public ClientConnectedToServerEvent(NetworkManager manager)
|
||||
public final String connectionType;
|
||||
public ClientConnectedToServerEvent(NetworkManager manager, String connectionType)
|
||||
{
|
||||
super((INetHandlerPlayClient) manager.func_150729_e(), INetHandlerPlayClient.class, manager);
|
||||
isLocal = manager.func_150731_c();
|
||||
this.isLocal = manager.func_150731_c();
|
||||
this.connectionType = connectionType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +34,7 @@ public class FMLNetworkEvent<T extends INetHandler> extends Event {
|
||||
public ServerConnectionFromClientEvent(NetworkManager manager)
|
||||
{
|
||||
super((INetHandlerPlayServer) manager.func_150729_e(), INetHandlerPlayServer.class, manager);
|
||||
isLocal = manager.func_150731_c();
|
||||
this.isLocal = manager.func_150731_c();
|
||||
}
|
||||
}
|
||||
public static class ServerDisconnectionFromClientEvent extends FMLNetworkEvent<INetHandlerPlayServer> {
|
||||
|
||||
@@ -37,8 +37,17 @@ enum FMLHandshakeClientState implements IHandshakeState<FMLHandshakeClientState>
|
||||
@Override
|
||||
public FMLHandshakeClientState accept(ChannelHandlerContext ctx, FMLHandshakeMessage msg)
|
||||
{
|
||||
FMLLog.info("Server protocol version %x", ((FMLHandshakeMessage.ServerHello)msg).protocolVersion());
|
||||
// write our custom packet registration, always
|
||||
ctx.writeAndFlush(FMLHandshakeMessage.makeCustomChannelRegistration(NetworkRegistry.INSTANCE.channelNamesFor(Side.CLIENT)));
|
||||
if (msg == null)
|
||||
{
|
||||
NetworkDispatcher dispatcher = ctx.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
|
||||
dispatcher.abortClientHandshake("VANILLA");
|
||||
// VANILLA login
|
||||
return DONE;
|
||||
}
|
||||
|
||||
FMLLog.info("Server protocol version %x", ((FMLHandshakeMessage.ServerHello)msg).protocolVersion());
|
||||
ctx.writeAndFlush(new FMLHandshakeMessage.ClientHello());
|
||||
ctx.writeAndFlush(new FMLHandshakeMessage.ModList(Loader.instance().getActiveModList()));
|
||||
return WAITINGSERVERDATA;
|
||||
|
||||
@@ -12,6 +12,7 @@ import io.netty.util.concurrent.GenericFutureListener;
|
||||
import io.netty.util.concurrent.ScheduledFuture;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
@@ -21,6 +22,7 @@ import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.client.C17PacketCustomPayload;
|
||||
import net.minecraft.network.play.server.S01PacketJoinGame;
|
||||
import net.minecraft.network.play.server.S3FPacketCustomPayload;
|
||||
import net.minecraft.network.play.server.S40PacketDisconnect;
|
||||
import net.minecraft.server.management.ServerConfigurationManager;
|
||||
@@ -69,7 +71,6 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler<Packet> imple
|
||||
private final ServerConfigurationManager scm;
|
||||
private EntityPlayerMP player;
|
||||
private ConnectionState state;
|
||||
@SuppressWarnings("unused")
|
||||
private ConnectionType connectionType;
|
||||
private final Side side;
|
||||
private final EmbeddedChannel handshakeChannel;
|
||||
@@ -151,19 +152,19 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler<Packet> imple
|
||||
this.state = ConnectionState.AWAITING_HANDSHAKE;
|
||||
}
|
||||
|
||||
private void completeClientSideConnection()
|
||||
private void completeClientSideConnection(ConnectionType type)
|
||||
{
|
||||
FMLLog.info("[%s] Client side modded connection established", Thread.currentThread().getName());
|
||||
this.connectionType = type;
|
||||
FMLLog.info("[%s] Client side %s connection established", Thread.currentThread().getName(), this.connectionType.name().toLowerCase(Locale.ENGLISH));
|
||||
this.state = ConnectionState.CONNECTED;
|
||||
this.connectionType = ConnectionType.MODDED;
|
||||
FMLCommonHandler.instance().bus().post(new FMLNetworkEvent.ClientConnectedToServerEvent(manager));
|
||||
FMLCommonHandler.instance().bus().post(new FMLNetworkEvent.ClientConnectedToServerEvent(manager, this.connectionType.name()));
|
||||
}
|
||||
|
||||
private void completeServerSideConnection()
|
||||
private void completeServerSideConnection(ConnectionType type)
|
||||
{
|
||||
FMLLog.info("[%s] Server side modded connection established", Thread.currentThread().getName());
|
||||
this.connectionType = type;
|
||||
FMLLog.info("[%s] Server side %s connection established", Thread.currentThread().getName(), this.connectionType.name().toLowerCase(Locale.ENGLISH));
|
||||
this.state = ConnectionState.CONNECTED;
|
||||
this.connectionType = ConnectionType.MODDED;
|
||||
FMLCommonHandler.instance().bus().post(new FMLNetworkEvent.ServerConnectionFromClientEvent(manager));
|
||||
scm.func_72355_a(manager, player, serverHandler);
|
||||
}
|
||||
@@ -181,7 +182,7 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler<Packet> imple
|
||||
}
|
||||
else if (state != ConnectionState.CONNECTED && state != ConnectionState.HANDSHAKECOMPLETE)
|
||||
{
|
||||
FMLLog.info("Unexpected packet during modded negotiation - assuming vanilla or keepalives : %s", msg.getClass().getName());
|
||||
handled = handleVanilla(msg);
|
||||
}
|
||||
if (!handled)
|
||||
{
|
||||
@@ -189,6 +190,19 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler<Packet> imple
|
||||
}
|
||||
}
|
||||
|
||||
private boolean handleVanilla(Packet msg)
|
||||
{
|
||||
if (state == ConnectionState.AWAITING_HANDSHAKE && msg instanceof S01PacketJoinGame)
|
||||
{
|
||||
handshakeChannel.pipeline().fireUserEventTriggered(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
FMLLog.info("Unexpected packet during modded negotiation - assuming vanilla or keepalives : %s", msg.getClass().getName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public INetHandler getNetHandler()
|
||||
{
|
||||
return netHandler;
|
||||
@@ -399,11 +413,11 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler<Packet> imple
|
||||
}
|
||||
if (side == Side.CLIENT)
|
||||
{
|
||||
completeClientSideConnection();
|
||||
completeClientSideConnection(ConnectionType.MODDED);
|
||||
}
|
||||
else
|
||||
{
|
||||
completeServerSideConnection();
|
||||
completeServerSideConnection(ConnectionType.MODDED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,4 +425,9 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler<Packet> imple
|
||||
{
|
||||
state = ConnectionState.HANDSHAKECOMPLETE;
|
||||
}
|
||||
|
||||
public void abortClientHandshake(String type)
|
||||
{
|
||||
completeClientSideConnection(ConnectionType.valueOf(type));
|
||||
}
|
||||
}
|
||||
@@ -29,9 +29,12 @@ import net.minecraft.server.management.ServerConfigurationManager;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.logging.log4j.core.helpers.Integers;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.FMLContainer;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.network.FMLEmbeddedChannel;
|
||||
import cpw.mods.fml.common.network.FMLOutboundHandler;
|
||||
@@ -176,4 +179,20 @@ public class FMLNetworkHandler
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public static void enhanceStatusQuery(JsonObject jsonobject)
|
||||
{
|
||||
JsonObject fmlData = new JsonObject();
|
||||
fmlData.addProperty("type", "FML");
|
||||
JsonArray modList = new JsonArray();
|
||||
for (ModContainer mc : Loader.instance().getActiveModList())
|
||||
{
|
||||
JsonObject modData = new JsonObject();
|
||||
modData.addProperty("modid", mc.getModId());
|
||||
modData.addProperty("version", mc.getVersion());
|
||||
modList.add(modData);
|
||||
}
|
||||
fmlData.add("modList", modList);
|
||||
jsonobject.add("modinfo", fmlData);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user