Merge branch 'master' of https://github.com/Anuken/Mindustry into async-ping
Conflicts: core/src/mindustry/net/ArcNetProvider.java gradle.properties
This commit is contained in:
@@ -49,7 +49,7 @@ public class ArcNetProvider implements NetProvider{
|
||||
packetSpamLimit = Config.packetSpamLimit.num();
|
||||
});
|
||||
|
||||
client = new Client(8192, 8192, new PacketSerializer());
|
||||
client = new Client(8192, 16384, new PacketSerializer());
|
||||
client.setDiscoveryPacket(packetSupplier);
|
||||
client.addListener(new NetListener(){
|
||||
@Override
|
||||
@@ -91,7 +91,9 @@ public class ArcNetProvider implements NetProvider{
|
||||
server.setMulticast(multicastGroup, multicastPort);
|
||||
server.setDiscoveryHandler((address, handler) -> {
|
||||
ByteBuffer buffer = NetworkIO.writeServerData();
|
||||
int length = buffer.position();
|
||||
buffer.position(0);
|
||||
buffer.limit(length);
|
||||
handler.respond(buffer);
|
||||
});
|
||||
|
||||
@@ -114,14 +116,14 @@ public class ArcNetProvider implements NetProvider{
|
||||
|
||||
Log.debug("&bReceived connection: @", c.addressTCP);
|
||||
|
||||
connection.setArbitraryData(kn);
|
||||
connections.add(kn);
|
||||
Core.app.post(() -> net.handleServerReceived(kn, c));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected(Connection connection, DcReason reason){
|
||||
ArcConnection k = getByArcID(connection.getID());
|
||||
if(k == null) return;
|
||||
if(!(connection.getArbitraryData() instanceof ArcConnection k)) return;
|
||||
|
||||
Disconnect c = new Disconnect();
|
||||
c.reason = reason.toString();
|
||||
@@ -134,8 +136,7 @@ public class ArcNetProvider implements NetProvider{
|
||||
|
||||
@Override
|
||||
public void received(Connection connection, Object object){
|
||||
ArcConnection k = getByArcID(connection.getID());
|
||||
if(!(object instanceof Packet pack) || k == null) return;
|
||||
if(!(connection.getArbitraryData() instanceof ArcConnection k) || !(object instanceof Packet pack)) return;
|
||||
|
||||
if(packetSpamLimit > 0 && !k.packetRate.allow(3000, packetSpamLimit)){
|
||||
Log.warn("Blacklisting IP '@' as potential DOS attack - packet spam.", k.address);
|
||||
@@ -155,6 +156,16 @@ public class ArcNetProvider implements NetProvider{
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConnectFilter(Server.ServerConnectFilter connectFilter){
|
||||
server.setConnectFilter(connectFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ServerConnectFilter getConnectFilter(){
|
||||
return server.getConnectFilter();
|
||||
}
|
||||
|
||||
private static boolean isLocal(InetAddress addr){
|
||||
if(addr.isAnyLocalAddress() || addr.isLoopbackAddress()) return true;
|
||||
|
||||
@@ -319,17 +330,6 @@ public class ArcNetProvider implements NetProvider{
|
||||
mainExecutor.submit(server::stop);
|
||||
}
|
||||
|
||||
ArcConnection getByArcID(int id){
|
||||
for(int i = 0; i < connections.size(); i++){
|
||||
ArcConnection con = connections.get(i);
|
||||
if(con.connection != null && con.connection.getID() == id){
|
||||
return con;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
class ArcConnection extends NetConnection{
|
||||
public final Connection connection;
|
||||
|
||||
@@ -345,7 +345,7 @@ public class ArcNetProvider implements NetProvider{
|
||||
|
||||
@Override
|
||||
public void sendStream(Streamable stream){
|
||||
connection.addListener(new InputStreamSender(stream.stream, 512){
|
||||
connection.addListener(new InputStreamSender(stream.stream, 1024){
|
||||
int id;
|
||||
|
||||
@Override
|
||||
@@ -381,8 +381,9 @@ public class ArcNetProvider implements NetProvider{
|
||||
Log.info("Error sending packet. Disconnecting invalid client!");
|
||||
connection.close(DcReason.error);
|
||||
|
||||
ArcConnection k = getByArcID(connection.getID());
|
||||
if(k != null) connections.remove(k);
|
||||
if(connection.getArbitraryData() instanceof ArcConnection k){
|
||||
connections.remove(k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -463,7 +464,7 @@ public class ArcNetProvider implements NetProvider{
|
||||
byteBuffer.put((byte)-2); //code for framework message
|
||||
writeFramework(byteBuffer, msg);
|
||||
}else{
|
||||
if(!(o instanceof Packet pack)) throw new RuntimeException("All sent objects must implement be Packets! Class: " + o.getClass());
|
||||
if(!(o instanceof Packet pack)) throw new RuntimeException("All sent objects must extend Packet! Class: " + o.getClass());
|
||||
byte id = Net.getPacketId(pack);
|
||||
byteBuffer.put(id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user