Fix some server-side crashes
This commit is contained in:
parent
a88c4221f9
commit
72e60b2259
Binary file not shown.
|
@ -25,7 +25,10 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void func_42_a() {
|
public void func_42_a() {
|
||||||
|
if(!field_18_c) {
|
||||||
this.netManager.processReadPackets();
|
this.netManager.processReadPackets();
|
||||||
|
}
|
||||||
|
|
||||||
if(this.field_15_f++ % 20 == 0) {
|
if(this.field_15_f++ % 20 == 0) {
|
||||||
this.netManager.addToSendQueue(new Packet0KeepAlive());
|
this.netManager.addToSendQueue(new Packet0KeepAlive());
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ public class NetworkManager {
|
||||||
private DataInputStream socketInputStream;
|
private DataInputStream socketInputStream;
|
||||||
private DataOutputStream socketOutputStream;
|
private DataOutputStream socketOutputStream;
|
||||||
private boolean isRunning = true;
|
private boolean isRunning = true;
|
||||||
|
private List readPackets = Collections.synchronizedList(new ArrayList());
|
||||||
private List dataPackets = Collections.synchronizedList(new ArrayList());
|
private List dataPackets = Collections.synchronizedList(new ArrayList());
|
||||||
private List chunkDataPackets = Collections.synchronizedList(new ArrayList());
|
private List chunkDataPackets = Collections.synchronizedList(new ArrayList());
|
||||||
private NetHandler netHandler;
|
private NetHandler netHandler;
|
||||||
|
@ -151,7 +152,38 @@ public class NetworkManager {
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
e.printStackTrace();
|
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 {
|
} else {
|
||||||
this.networkShutdown("End of stream");
|
this.networkShutdown("End of stream");
|
||||||
|
@ -202,57 +234,30 @@ public class NetworkManager {
|
||||||
this.networkShutdown("Send buffer overflow");
|
this.networkShutdown("Send buffer overflow");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!readChunks.isEmpty()) {
|
if(this.readPackets.isEmpty()) {
|
||||||
|
if(this.timeSinceLastRead++ == 1200) {
|
||||||
|
this.networkShutdown("Timed out");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
this.timeSinceLastRead = 0;
|
this.timeSinceLastRead = 0;
|
||||||
int cap = 0;
|
|
||||||
for(ByteBuffer b : readChunks) {
|
|
||||||
cap += b.limit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer stream = ByteBuffer.allocate(cap);
|
|
||||||
Iterator<ByteBuffer> 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;
|
int var1 = 100;
|
||||||
while(stream.hasRemaining() && var1-- > 0) {
|
while(!this.readPackets.isEmpty() && var1-- >= 0) {
|
||||||
stream.mark();
|
|
||||||
//Literally ignore all errors lol
|
|
||||||
try {
|
try {
|
||||||
Packet pkt = Packet.readPacket(packetStream);
|
Packet var2 = (Packet)this.readPackets.remove(0);
|
||||||
if(pkt == null) {
|
var2.processPacket(this.netHandler);
|
||||||
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) {
|
} catch(Exception e) {
|
||||||
continue;
|
continue;
|
||||||
} catch(Throwable t) {
|
} catch(Throwable t) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if(this.timeSinceLastRead++ == 1200) {
|
|
||||||
this.networkShutdown("Timed out");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.isTerminating && this.readChunks.isEmpty()) {
|
if(this.isTerminating && this.readPackets.isEmpty()) {
|
||||||
this.netHandler.handleErrorMessage(this.terminationReason);
|
this.netHandler.handleErrorMessage(this.terminationReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SocketAddress getRemoteAddress() {
|
public SocketAddress getRemoteAddress() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user