From 4a92959cc18de0cf234fd3d9fe55312fbe2c80b4 Mon Sep 17 00:00:00 2001 From: Lex Manos Date: Fri, 28 Nov 2014 10:37:55 -0800 Subject: [PATCH] Finalize modded handshakes in the World tick thread. Prevents potential CMEs when login event takes to long to fire. --- .../common/WrongMinecraftVersionException.java | 2 +- .../network/handshake/NetworkDispatcher.java | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/fml/src/main/java/net/minecraftforge/fml/common/WrongMinecraftVersionException.java b/fml/src/main/java/net/minecraftforge/fml/common/WrongMinecraftVersionException.java index 4037fb7cd..f093ab378 100644 --- a/fml/src/main/java/net/minecraftforge/fml/common/WrongMinecraftVersionException.java +++ b/fml/src/main/java/net/minecraftforge/fml/common/WrongMinecraftVersionException.java @@ -19,7 +19,7 @@ public class WrongMinecraftVersionException extends RuntimeException public WrongMinecraftVersionException(ModContainer mod) { - super(String.format("Wrong Minecraft vbersion for %s", mod.getModId())); + super(String.format("Wrong Minecraft version for %s", mod.getModId())); this.mod = mod; } 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 9f6a2e410..2260b3307 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 @@ -47,7 +47,7 @@ import net.minecraftforge.fml.relauncher.Side; public class NetworkDispatcher extends SimpleChannelInboundHandler implements ChannelOutboundHandler { private static boolean DEBUG_HANDSHAKE = Boolean.parseBoolean(System.getProperty("fml.debugNetworkHandshake", "false")); private static enum ConnectionState { - OPENING, AWAITING_HANDSHAKE, HANDSHAKING, HANDSHAKECOMPLETE, CONNECTED; + OPENING, AWAITING_HANDSHAKE, HANDSHAKING, HANDSHAKECOMPLETE, FINALIZING, CONNECTED; } private static enum ConnectionType { @@ -161,7 +161,18 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler imple // This will be ignored by vanilla clients this.state = ConnectionState.AWAITING_HANDSHAKE; // Need to start the handler here, so we can send custompayload packets - serverHandler = new NetHandlerPlayServer(scm.getServerInstance(), manager, player); + serverHandler = new NetHandlerPlayServer(scm.getServerInstance(), manager, player) + { + @Override + public void update() + { + if (NetworkDispatcher.this.state == ConnectionState.FINALIZING) + { + completeServerSideConnection(ConnectionType.MODDED); + } + super.update(); + } + }; this.netHandler = serverHandler; // NULL the play server here - we restore it further on. If not, there are packets sent before the login player.playerNetServerHandler = null; @@ -478,7 +489,7 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler imple } else { - completeServerSideConnection(ConnectionType.MODDED); + this.state = ConnectionState.FINALIZING; //Delay and finalize in the world tick loop. } }