diff --git a/minecraft_server/Alpha.jar b/minecraft_server/Alpha.jar index 09d82ba..3412d79 100644 Binary files a/minecraft_server/Alpha.jar and b/minecraft_server/Alpha.jar differ diff --git a/minecraft_server/src/net/minecraft/src/NetServerHandler.java b/minecraft_server/src/net/minecraft/src/NetServerHandler.java index 00b668b..52283de 100644 --- a/minecraft_server/src/net/minecraft/src/NetServerHandler.java +++ b/minecraft_server/src/net/minecraft/src/NetServerHandler.java @@ -25,7 +25,10 @@ public class NetServerHandler extends NetHandler implements ICommandListener { } public void func_42_a() { - this.netManager.processReadPackets(); + if(!field_18_c) { + this.netManager.processReadPackets(); + } + if(this.field_15_f++ % 20 == 0) { this.netManager.addToSendQueue(new Packet0KeepAlive()); } diff --git a/minecraft_server/src/net/minecraft/src/NetworkManager.java b/minecraft_server/src/net/minecraft/src/NetworkManager.java index 8ec33bf..6c5c807 100644 --- a/minecraft_server/src/net/minecraft/src/NetworkManager.java +++ b/minecraft_server/src/net/minecraft/src/NetworkManager.java @@ -26,6 +26,7 @@ public class NetworkManager { private DataInputStream socketInputStream; private DataOutputStream socketOutputStream; private boolean isRunning = true; + private List readPackets = Collections.synchronizedList(new ArrayList()); private List dataPackets = Collections.synchronizedList(new ArrayList()); private List chunkDataPackets = Collections.synchronizedList(new ArrayList()); private NetHandler netHandler; @@ -151,7 +152,38 @@ public class NetworkManager { } catch(IOException e) { e.printStackTrace(); } - readChunks.add(ByteBuffer.wrap(packet)); + + int cap = 0; + ByteBuffer b = ByteBuffer.wrap(packet); + cap += b.limit(); + ByteBuffer stream = ByteBuffer.allocate(cap); + + stream.put(b); + stream.flip(); + DataInputStream packetStream = new DataInputStream(new ByteBufferDirectInputStream(stream)); + while(stream.hasRemaining()) { + stream.mark(); + try { + Packet pkt = Packet.readPacket(packetStream); + if(pkt == null) { + this.networkShutdown("End of Stream"); + } + readPackets.add(pkt); + } catch (EOFException e) { + stream.reset(); + break; + } catch (IOException e) { + continue; + } catch(ArrayIndexOutOfBoundsException e) { + continue; + } catch(NullPointerException e) { + continue; + } catch(Exception e) { + continue; + } catch(Throwable t) { + continue; + } + } } } else { this.networkShutdown("End of stream"); @@ -201,58 +233,31 @@ public class NetworkManager { if(this.sendQueueByteLength > 1048576) { this.networkShutdown("Send buffer overflow"); } - - if(!readChunks.isEmpty()) { - this.timeSinceLastRead = 0; - int cap = 0; - for(ByteBuffer b : readChunks) { - cap += b.limit(); - } - ByteBuffer stream = ByteBuffer.allocate(cap); - Iterator iterator = readChunks.iterator(); - while(iterator.hasNext()) { - ByteBuffer b = iterator.next(); - stream.put(b); - iterator.remove(); - } - stream.flip(); - - DataInputStream packetStream = new DataInputStream(new ByteBufferDirectInputStream(stream)); - int var1 = 100; - while(stream.hasRemaining() && var1-- > 0) { - stream.mark(); - //Literally ignore all errors lol - try { - Packet pkt = Packet.readPacket(packetStream); - if(pkt == null) { - this.networkShutdown("End of Stream"); - } - pkt.processPacket(this.netHandler); - } catch (EOFException e) { - stream.reset(); - break; - } catch (IOException e) { - continue; - } catch(ArrayIndexOutOfBoundsException e) { - continue; - } catch(NullPointerException e) { - continue; - } catch(Exception e) { - continue; - } catch(Throwable t) { - continue; - } - } - } else { + if(this.readPackets.isEmpty()) { if(this.timeSinceLastRead++ == 1200) { this.networkShutdown("Timed out"); } + } else { + this.timeSinceLastRead = 0; } - if(this.isTerminating && this.readChunks.isEmpty()) { + int var1 = 100; + while(!this.readPackets.isEmpty() && var1-- >= 0) { + try { + Packet var2 = (Packet)this.readPackets.remove(0); + var2.processPacket(this.netHandler); + } catch(Exception e) { + continue; + } catch(Throwable t) { + continue; + } + } + + if(this.isTerminating && this.readPackets.isEmpty()) { this.netHandler.handleErrorMessage(this.terminationReason); } + } public SocketAddress getRemoteAddress() {