From b56976955be1950e6073700b09f0cb787406984f Mon Sep 17 00:00:00 2001 From: LAX1DUDE Date: Wed, 30 Mar 2022 17:13:38 -0700 Subject: [PATCH] added timeout for NetClientHandler --- .../java/net/minecraft/src/NetClientHandler.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/minecraft/src/NetClientHandler.java b/src/main/java/net/minecraft/src/NetClientHandler.java index 664730e..b24e3a3 100644 --- a/src/main/java/net/minecraft/src/NetClientHandler.java +++ b/src/main/java/net/minecraft/src/NetClientHandler.java @@ -44,6 +44,8 @@ public class NetClientHandler extends NetHandler { public List playerInfoList = new ArrayList(); public int currentServerMaxPlayers = 20; private GuiScreen field_98183_l = null; + private int updateCounter = 0; + private int lastKeepAlive = 0; /** RNG. */ EaglercraftRandom rand = new EaglercraftRandom(); @@ -77,6 +79,14 @@ public class NetClientHandler extends NetHandler { * function. */ public void processReadPackets() { + ++this.updateCounter; + if(updateCounter - lastKeepAlive > 500 || !EaglerAdapter.connectionOpen()) { + this.mc.displayGuiScreen(new GuiDisconnected(new GuiMultiplayer(new GuiMainMenu()), "disconnect.disconnected", "disconnect." + (EaglerAdapter.connectionOpen() ? "endOfStream" :" timeout"), null)); + this.netManager.closeConnections(); + this.disconnected = true; + this.mc.loadWorld((WorldClient) null); + return; + } if (!this.disconnected && this.netManager != null) { this.netManager.processReadPackets(); } @@ -87,7 +97,6 @@ public class NetClientHandler extends NetHandler { } public void handleServerAuthData(Packet253ServerAuthData par1Packet253ServerAuthData) { - this.addToSendQueue(new Packet252SharedKey()); } @@ -1067,6 +1076,7 @@ public class NetClientHandler extends NetHandler { * Handle a keep alive packet. */ public void handleKeepAlive(Packet0KeepAlive par1Packet0KeepAlive) { + lastKeepAlive = updateCounter; this.addToSendQueue(new Packet0KeepAlive(par1Packet0KeepAlive.randomId)); }