From 4a8dc723745480482827d1f88a909a3158d380d7 Mon Sep 17 00:00:00 2001 From: PeytonPlayz595 <106421860+PeytonPlayz595@users.noreply.github.com> Date: Fri, 26 Apr 2024 19:38:00 -0400 Subject: [PATCH] Fix more server-side bugs --- .../src/net/minecraft/src/NetworkManager.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/minecraft_server/src/net/minecraft/src/NetworkManager.java b/minecraft_server/src/net/minecraft/src/NetworkManager.java index 9192804..281c8b3 100644 --- a/minecraft_server/src/net/minecraft/src/NetworkManager.java +++ b/minecraft_server/src/net/minecraft/src/NetworkManager.java @@ -94,7 +94,9 @@ public class NetworkManager { Packet.writePacket(var2, yee); yee.flush(); try { - socketOutputStream.write(sendBuffer.toByteArray()); + if(this.isConnectionOpen()) { + socketOutputStream.write(sendBuffer.toByteArray()); + } } catch(SocketException e) { if (e.getMessage().contains("connection abort") || e.getMessage().contains("connection reset")) { this.networkShutdown("Connection reset"); @@ -105,7 +107,9 @@ public class NetworkManager { } } sendBuffer.flush(); - socketOutputStream.flush(); + if(this.isConnectionOpen()) { + socketOutputStream.flush(); + } } catch(Exception e) { e.printStackTrace(); this.sendQueueByteLength = oldSendQueue; @@ -128,7 +132,9 @@ public class NetworkManager { Packet.writePacket(var2, yee); yee.flush(); try { - socketOutputStream.write(sendBuffer.toByteArray()); + if(this.isConnectionOpen()) { + socketOutputStream.write(sendBuffer.toByteArray()); + } } catch(SocketException e) { if (e.getMessage().contains("connection abort") || e.getMessage().contains("connection reset")) { this.networkShutdown("Connection reset"); @@ -139,7 +145,9 @@ public class NetworkManager { } } sendBuffer.flush(); - socketOutputStream.flush(); + if(this.isConnectionOpen()) { + socketOutputStream.flush(); + } this.chunkDataSendCounter = 50; } catch(Exception e) { e.printStackTrace(); @@ -317,7 +325,7 @@ public class NetworkManager { } boolean isConnectionOpen() { - return networkSocket.isConnected(); + return networkSocket != null && networkSocket.isConnected(); } static Thread getReadThread(NetworkManager var0) { @@ -336,7 +344,7 @@ public class NetworkManager { byte[] data = bytesRead == buffer.length ? buffer : new byte[bytesRead]; System.arraycopy(buffer, 0, data, 0, data.length); return new ByteArrayInputStream(data); - } catch (Exception e) { + } catch (Throwable e) { return null; } }