mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-02 12:23:47 +07:00
Fixed #5519
This commit is contained in:
parent
f7e4936445
commit
2ea1671739
@ -391,15 +391,7 @@ public class ArcNetProvider implements NetProvider{
|
|||||||
//no compression, copy over buffer
|
//no compression, copy over buffer
|
||||||
if(compression == 0){
|
if(compression == 0){
|
||||||
buffer.position(0).limit(length);
|
buffer.position(0).limit(length);
|
||||||
if(byteBuffer.hasArray()){
|
|
||||||
buffer.put(byteBuffer.array(), byteBuffer.position(), length);
|
buffer.put(byteBuffer.array(), byteBuffer.position(), length);
|
||||||
}else{
|
|
||||||
byte[] readcopy = new byte[length];
|
|
||||||
int pos = byteBuffer.position();
|
|
||||||
byteBuffer.get(readcopy);
|
|
||||||
byteBuffer.position(pos);
|
|
||||||
buffer.put(readcopy);
|
|
||||||
}
|
|
||||||
buffer.position(0);
|
buffer.position(0);
|
||||||
packet.read(reads.get(), length);
|
packet.read(reads.get(), length);
|
||||||
//move read packets forward
|
//move read packets forward
|
||||||
|
@ -9,6 +9,7 @@ import arc.util.async.*;
|
|||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.net.Packets.*;
|
import mindustry.net.Packets.*;
|
||||||
import mindustry.net.Streamable.*;
|
import mindustry.net.Streamable.*;
|
||||||
|
import net.jpountz.lz4.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
@ -97,7 +98,7 @@ public class Net{
|
|||||||
|
|
||||||
if(e instanceof BufferUnderflowException || e instanceof BufferOverflowException){
|
if(e instanceof BufferUnderflowException || e instanceof BufferOverflowException){
|
||||||
error = Core.bundle.get("error.io");
|
error = Core.bundle.get("error.io");
|
||||||
}else if(error.equals("mismatch") || (e instanceof IndexOutOfBoundsException && e.getStackTrace()[0].getClassName().contains("java.nio"))){
|
}else if(error.equals("mismatch") || e instanceof LZ4Exception || (e instanceof IndexOutOfBoundsException && e.getStackTrace()[0].getClassName().contains("java.nio"))){
|
||||||
error = Core.bundle.get("error.mismatch");
|
error = Core.bundle.get("error.mismatch");
|
||||||
}else if(error.contains("port out of range") || error.contains("invalid argument") || (error.contains("invalid") && error.contains("address")) || Strings.neatError(e).contains("address associated")){
|
}else if(error.contains("port out of range") || error.contains("invalid argument") || (error.contains("invalid") && error.contains("address")) || Strings.neatError(e).contains("address associated")){
|
||||||
error = Core.bundle.get("error.invalidaddress");
|
error = Core.bundle.get("error.invalidaddress");
|
||||||
|
@ -31,6 +31,7 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback,
|
|||||||
final PacketSerializer serializer = new PacketSerializer();
|
final PacketSerializer serializer = new PacketSerializer();
|
||||||
final ByteBuffer writeBuffer = ByteBuffer.allocateDirect(16384);
|
final ByteBuffer writeBuffer = ByteBuffer.allocateDirect(16384);
|
||||||
final ByteBuffer readBuffer = ByteBuffer.allocateDirect(16384);
|
final ByteBuffer readBuffer = ByteBuffer.allocateDirect(16384);
|
||||||
|
final ByteBuffer readCopyBuffer = ByteBuffer.allocate(writeBuffer.capacity());
|
||||||
|
|
||||||
final CopyOnWriteArrayList<SteamConnection> connections = new CopyOnWriteArrayList<>();
|
final CopyOnWriteArrayList<SteamConnection> connections = new CopyOnWriteArrayList<>();
|
||||||
final IntMap<SteamConnection> steamConnections = new IntMap<>(); //maps steam ID -> valid net connection
|
final IntMap<SteamConnection> steamConnections = new IntMap<>(); //maps steam ID -> valid net connection
|
||||||
@ -51,10 +52,15 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback,
|
|||||||
public void update(){
|
public void update(){
|
||||||
while((length = snet.isP2PPacketAvailable(0)) != 0){
|
while((length = snet.isP2PPacketAvailable(0)) != 0){
|
||||||
try{
|
try{
|
||||||
readBuffer.position(0);
|
readBuffer.position(0).limit(readBuffer.capacity());
|
||||||
snet.readP2PPacket(from, readBuffer, 0);
|
//lz4 chokes on direct buffers, so copy the bytes over
|
||||||
|
int len = snet.readP2PPacket(from, readBuffer, 0);
|
||||||
|
readBuffer.limit(len);
|
||||||
|
readCopyBuffer.position(0);
|
||||||
|
readCopyBuffer.put(readBuffer);
|
||||||
|
readCopyBuffer.position(0);
|
||||||
int fromID = from.getAccountID();
|
int fromID = from.getAccountID();
|
||||||
Object output = serializer.read(readBuffer);
|
Object output = serializer.read(readCopyBuffer);
|
||||||
|
|
||||||
//it may be theoretically possible for this to be a framework message, if the packet is malicious or corrupted
|
//it may be theoretically possible for this to be a framework message, if the packet is malicious or corrupted
|
||||||
if(!(output instanceof Packet)) return;
|
if(!(output instanceof Packet)) return;
|
||||||
|
Loading…
Reference in New Issue
Block a user