From 9ec5d8b5dfc544a6873aa1bb48a07deedd1751fb Mon Sep 17 00:00:00 2001 From: Tahg Date: Fri, 27 May 2011 11:01:37 -0400 Subject: [PATCH] Improved packet handling --- src/main/java/net/minecraft/server/NetworkManager.java | 3 ++- src/main/java/net/minecraft/server/Packet.java | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/minecraft/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java index f2bcbb727c..b995864ae5 100644 --- a/src/main/java/net/minecraft/server/NetworkManager.java +++ b/src/main/java/net/minecraft/server/NetworkManager.java @@ -105,7 +105,8 @@ public class NetworkManager { flag = true; } - if (this.z-- <= 0 && !this.o.isEmpty() && (this.f == 0 || System.currentTimeMillis() - ((Packet) this.o.get(0)).timestamp >= (long) this.f)) { + // CraftBukkit - add 'flag' + if ((!flag || this.z-- <= 0) && !this.o.isEmpty() && (this.f == 0 || System.currentTimeMillis() - ((Packet) this.o.get(0)).timestamp >= (long) this.f)) { object = this.g; synchronized (this.g) { packet = (Packet) this.o.remove(0); diff --git a/src/main/java/net/minecraft/server/Packet.java b/src/main/java/net/minecraft/server/Packet.java index 620017ebc3..291bc721ae 100644 --- a/src/main/java/net/minecraft/server/Packet.java +++ b/src/main/java/net/minecraft/server/Packet.java @@ -69,6 +69,11 @@ public abstract class Packet { int i; try { + // CraftBukkit start - sleep while nothing to do + while(datainputstream.available() <= 0) { + Thread.sleep(10); + } + // CraftBukkit end i = datainputstream.read(); if (i == -1) { return null; @@ -97,6 +102,10 @@ public abstract class Packet { System.out.println("Connection reset"); return null; } + catch (InterruptedException exception) { + System.out.println("Thread exception"); + return null; + } // CraftBukkit end PacketCounter packetcounter = (PacketCounter) e.get(Integer.valueOf(i));