From 7347daf20302ed426816c52485a9468c9e94af7f Mon Sep 17 00:00:00 2001 From: md_5 Date: Tue, 8 Jul 2014 15:16:22 +1000 Subject: [PATCH] Delay kicks in initial handler. See source for reasoning --- .../bungee/connection/InitialHandler.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java index cdc411ae..bf71eff8 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java @@ -13,6 +13,7 @@ import java.util.logging.Level; import javax.crypto.SecretKey; import com.google.gson.Gson; +import java.util.concurrent.TimeUnit; import lombok.Getter; import lombok.RequiredArgsConstructor; import net.md_5.bungee.*; @@ -426,20 +427,29 @@ public class InitialHandler extends PacketHandler implements PendingConnection @Override public void disconnect(String reason) { - if ( !ch.isClosed() ) - { - unsafe().sendPacket( new Kick( ComponentSerializer.toString( TextComponent.fromLegacyText( reason ) ) ) ); - ch.close(); - } + disconnect( TextComponent.fromLegacyText( reason ) ); } @Override - public void disconnect(BaseComponent... reason) + public void disconnect(final BaseComponent... reason) { if ( !ch.isClosed() ) { - unsafe().sendPacket( new Kick( ComponentSerializer.toString( reason ) ) ); - ch.close(); + // Why do we have to delay this you might ask? Well the simple reason is MOJANG. + // Despite many a bug report posted, ever since the 1.7 protocol rewrite, the client STILL has a race condition upon switching protocols. + // As such, despite the protocol switch packets already having been sent, there is the possibility of a client side exception + // To help combat this we will wait half a second before actually sending the disconnected packet so that whoever is on the other + // end has a somewhat better chance of receiving the proper packet. + ch.getHandle().eventLoop().schedule( new Runnable() + { + + @Override + public void run() + { + unsafe().sendPacket( new Kick( ComponentSerializer.toString( reason ) ) ); + ch.close(); + } + }, 500, TimeUnit.MILLISECONDS ); } }