Fix large packets on LAN connections causing End of Stream (RIP).

This commit is contained in:
ayunami2000 2022-08-28 18:58:44 -04:00
parent c0e081c699
commit 47a81e6589
18 changed files with 90655 additions and 90620 deletions

4
.gitignore vendored
View File

@ -7,7 +7,6 @@ eaglercraftbungee/.idea
eaglercraftbungee/bin
eaglercraftbungee/rundir
eaglercraftbungee/test
eaglercraftbungee/minecrafthtml5bungee.iml
eaglercraftbungee/src/main/java/META-INF
eaglercraftbungee/out
epkcompiler/bin
@ -26,11 +25,10 @@ sp-server/bin
stable-download/_repl*
lwjgl-rundir/_eagstorage*
*.bak
sp-relay/sp-relay.iml
sp-relay/out
sp-relay/test
sp-relay/.idea
sp-relay/src/main/java/META-INF
zip-generator/zip-generator.iml
zip-generator/out
zip-generator/src/main/java/META-INF
*.iml

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="EclipseModuleManager">
<conelement value="org.eclipse.buildship.core.gradleclasspathcontainer" />
<src_description expected_position="0">
<src_folder value="file://$MODULE_DIR$/src/main/java" expected_position="0" />
<src_folder value="file://$MODULE_DIR$/src/teavm/java" expected_position="1" />
<src_folder value="file://$MODULE_DIR$/sp-server/src/ipc/java" expected_position="2" />
</src_description>
</component>
</module>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -7,4 +7,4 @@
* in the user manual at https://docs.gradle.org/6.0/userguide/multi_project_builds.html
*/
rootProject.name = 'eaglercraft-sp'
rootProject.name = 'eaglercraft'

View File

@ -6,7 +6,7 @@ public class ConfigConstants {
public static boolean profanity = false;
public static final String version = "22w34a";
public static final String version = "22w34b";
public static final String mainMenuString = "eaglercraft " + version;
public static final String forkMe = "https://github.com/lax1dude/eaglercraft";

View File

@ -244,6 +244,8 @@ public class LANClientNetworkManager implements INetworkManager {
// no
}
private byte[] fragmentedPacket = new byte[0];
@Override
public void processReadPackets() {
@ -260,7 +262,25 @@ public class LANClientNetworkManager implements INetworkManager {
if(this.theNetHandler != null) {
byte[] data;
while((data = EaglerAdapter.clientLANReadPacket()) != null) {
ByteArrayInputStream bai = new ByteArrayInputStream(data);
byte[] fullData;
if (data[0] == 0) {
fullData = new byte[fragmentedPacket.length + data.length - 1];
System.arraycopy(fragmentedPacket, 0, fullData, 0, fragmentedPacket.length);
System.arraycopy(data, 1, fullData, fragmentedPacket.length, data.length - 1);
fragmentedPacket = new byte[0];
} else if (data[0] == 1) {
fullData = new byte[fragmentedPacket.length + data.length - 1];
System.arraycopy(fragmentedPacket, 0, fullData, 0, fragmentedPacket.length);
System.arraycopy(data, 1, fullData, fragmentedPacket.length, data.length - 1);
fragmentedPacket = fullData;
continue;
} else {
continue;
}
ByteArrayInputStream bai = new ByteArrayInputStream(fullData);
int pktId = bai.read();
if(pktId == -1) {
@ -274,7 +294,7 @@ public class LANClientNetworkManager implements INetworkManager {
System.err.println("Recieved invalid '" + pktId + "' packet");
continue;
}
try {
pkt.readPacketData(new DataInputStream(bai));
pkt.processPacket(theNetHandler);

View File

@ -23,7 +23,7 @@ public class LANServerList {
public void update() {
long millis = System.currentTimeMillis();
if(millis - lastRefresh > 10000l) {
if(++refreshCounter < 25) {
if(++refreshCounter < 10) {
refresh();
}else {
lastRefresh = millis;

View File

@ -3919,10 +3919,26 @@ public class EaglerAdapterImpl2 {
}
}
private static final int fragmentSize = 16384;
public static final void serverLANWritePacket(String peer, byte[] data) {
ArrayBuffer arr = ArrayBuffer.create(data.length);
Uint8Array.create(arr).set(data);
rtcLANServer.sendPacketToRemoteClient(peer, arr);
if (data.length > fragmentSize) {
for (int i = 0; i < data.length; i += fragmentSize) {
byte[] fragData = new byte[((i + fragmentSize > data.length) ? (data.length % fragmentSize) : fragmentSize) + 1];
System.arraycopy(data, i, fragData, 1, fragData.length - 1);
fragData[0] = (i + fragmentSize < data.length) ? (byte) 1 : (byte) 0;
ArrayBuffer arr = ArrayBuffer.create(fragData.length);
Uint8Array.create(arr).set(fragData);
rtcLANServer.sendPacketToRemoteClient(peer, arr);
}
} else {
byte[] sendData = new byte[data.length + 1];
sendData[0] = 0;
System.arraycopy(data, 0, sendData, 1, data.length);
ArrayBuffer arr = ArrayBuffer.create(sendData.length);
Uint8Array.create(arr).set(sendData);
rtcLANServer.sendPacketToRemoteClient(peer, arr);
}
}
public static final void serverLANCreatePeer(String peer) {

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long