Fix some server-side crashes

This commit is contained in:
PeytonPlayz595 2024-03-27 15:18:50 -04:00
parent a88c4221f9
commit 72e60b2259
3 changed files with 54 additions and 46 deletions

Binary file not shown.

View File

@ -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());
}

View File

@ -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");
@ -202,57 +234,30 @@ public class NetworkManager {
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<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;
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() {