Netcode updates

This commit is contained in:
Anuken
2021-06-02 16:51:52 -04:00
parent eba6514fb5
commit 462a64bf21
4 changed files with 44 additions and 13 deletions

View File

@@ -385,7 +385,6 @@ public class ArcNetProvider implements NetProvider{
return readFramework(byteBuffer);
}else{
//read length int, followed by compressed lz4 data
//TODO not thread safe!!!
Packet packet = Net.newPacket(id);
var buffer = decompressBuffer.get();
int length = byteBuffer.getShort() & 0xffff;
@@ -396,7 +395,7 @@ public class ArcNetProvider implements NetProvider{
buffer.position(0).limit(length);
buffer.put(byteBuffer.array(), byteBuffer.position(), length);
buffer.position(0);
packet.read(reads.get());
packet.read(reads.get(), length);
//move read packets forward
byteBuffer.position(byteBuffer.position() + buffer.position());
}else{
@@ -405,7 +404,7 @@ public class ArcNetProvider implements NetProvider{
buffer.position(0);
buffer.limit(length);
packet.read(reads.get());
packet.read(reads.get(), length);
//move buffer forward based on bytes read by decompressor
byteBuffer.position(byteBuffer.position() + read);
}

View File

@@ -2,7 +2,17 @@ package mindustry.net;
import arc.util.io.*;
import java.io.*;
public abstract class Packet{
//internally used by generated code
//TODO intermediate buffers should ONLY be needed for:
//readObject
//readBuilding
//readUnit (possibly)
protected static final ReusableByteInStream BAIS = new ReusableByteInStream();
protected static final Reads READ = new Reads(new DataInputStream(BAIS));
//these are constants because I don't want to bother making an enum to mirror the annotation enum
/** Does not get handled unless client is connected. */
@@ -15,6 +25,10 @@ public abstract class Packet{
public void read(Reads read){}
public void write(Writes write){}
public void read(Reads read, int length){
read(read);
}
public int getPriority(){
return priorityNormal;
}

View File

@@ -2,7 +2,6 @@ package mindustry.net;
import arc.*;
import arc.struct.*;
import arc.util.*;
import arc.util.io.*;
import arc.util.serialization.*;
import mindustry.core.*;
@@ -131,8 +130,6 @@ public class Packets{
crc.update(Base64Coder.decode(uuid), 0, b.length);
buffer.l(crc.getValue());
Log.info("CRC value sent: @", Long.toHexString(crc.getValue()));
buffer.b(mobile ? (byte)1 : 0);
buffer.i(color);
buffer.b((byte)mods.size);