Fixed instant disconnect due to UDP flood, extremely jumpy interpolation

This commit is contained in:
Anuken
2018-05-05 12:48:50 -04:00
parent 1f439b4b0c
commit fab22a152c
6 changed files with 18 additions and 16 deletions

View File

@ -41,12 +41,14 @@ import static io.anuke.mindustry.Vars.*;
public class NetClient extends Module {
private final static float dataTimeout = 60*18; //18 seconds timeout
private final static float playerSyncTime = 2;
private final static int maxRequests = 50;
private Timer timer = new Timer(5);
private boolean connecting = false;
private boolean kicked = false;
private IntSet recieved = new IntSet();
private IntMap<Entity> recent = new IntMap<>();
private int requests = 0;
private float timeoutTime = 0f; //data timeout counter
public NetClient(){
@ -137,11 +139,12 @@ public class NetClient extends Module {
if(entity instanceof Enemy) enemies ++;
if (entity == null || id == player.id) {
if (id != player.id) {
if (id != player.id && requests < maxRequests) {
EntityRequestPacket req = new EntityRequestPacket();
req.id = id;
req.group = groupid;
Net.send(req, SendMode.udp);
requests ++;
}
data.position(data.position() + SyncEntity.getWriteSize((Class<? extends SyncEntity>) group.getType()));
} else {
@ -362,6 +365,7 @@ public class NetClient extends Module {
}
void sync(){
requests = 0;
if(timer.get(0, playerSyncTime)){

View File

@ -267,15 +267,15 @@ public class Renderer extends RendererModule{
if(!player.isLocal && !player.isDead()){
layout.setText(Core.font, player.name);
Draw.color(0f, 0f, 0f, 0.3f);
Draw.rect("blank", player.x, player.y + 8 - layout.height/2, layout.width + 2, layout.height + 2);
Draw.rect("blank", player.getDrawPosition().x, player.getDrawPosition().y + 8 - layout.height/2, layout.width + 2, layout.height + 2);
Draw.color();
Draw.tcolor(player.getColor());
Draw.text(player.name, player.x, player.y + 8);
Draw.text(player.name, player.getDrawPosition().x, player.getDrawPosition().y + 8);
if(player.isAdmin){
Draw.color(player.getColor());
float s = 3f;
Draw.rect("icon-admin-small", player.x + layout.width/2f + 2 + 1, player.y + 7f, s, s);
Draw.rect("icon-admin-small", player.getDrawPosition().x + layout.width/2f + 2 + 1, player.getDrawPosition().y + 7f, s, s);
}
Draw.reset();
}

View File

@ -122,6 +122,8 @@ public abstract class SyncEntity extends DestructibleEntity{
time += 1f / spacing * Math.min(Timers.delta(), 1f);
time = Mathf.clamp(time, 0, 2f);
Mathf.lerp2(pos.set(last), target, time);
angle = Mathf.slerpDelta(angle, targetrot, 0.6f);

View File

@ -162,7 +162,7 @@ public class Packets {
public int color;
}
public static class ShootPacket implements Packet{
public static class ShootPacket implements Packet, UnimportantPacket{
public byte weaponid;
public float x, y, rotation;
public int playerid;
@ -186,7 +186,7 @@ public class Packets {
}
}
public static class BulletPacket implements Packet{
public static class BulletPacket implements Packet, UnimportantPacket{
public int type, owner;
public float x, y, angle;
public short damage;

View File

@ -3,7 +3,6 @@ package io.anuke.mindustry.world.blocks.types.distribution;
import io.anuke.mindustry.resource.Liquid;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.LiquidBlock;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
public class LiquidJunction extends Conduit{
@ -26,10 +25,8 @@ public class LiquidJunction extends Conduit{
dir = (dir+4)%4;
Tile to = tile.getNearby(dir);
Timers.run(20f, () -> {
if(to.block() instanceof LiquidBlock && ((LiquidBlock)to.block()).acceptLiquid(to, tile, liquid, amount))
((LiquidBlock)to.block()).handleLiquid(to, tile, liquid, amount);
});
if(to.block() instanceof LiquidBlock && ((LiquidBlock)to.block()).acceptLiquid(to, tile, liquid, amount))
((LiquidBlock)to.block()).handleLiquid(to, tile, liquid, amount);
}
@Override

View File

@ -6,6 +6,7 @@ import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.ObjectSet;
import com.esotericsoftware.kryonet.*;
import com.esotericsoftware.kryonet.Listener.LagListener;
import com.esotericsoftware.minlog.Log;
import io.anuke.mindustry.net.Host;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.Net.ClientProvider;
@ -70,6 +71,7 @@ public class KryoClient implements ClientProvider{
Disconnect c = new Disconnect();
Gdx.app.postRunnable(() -> Net.handleClientReceived(c));
if(connection.getLastProtocolError() != null) Log.error("\n\n\n\nProtocol error: " + connection.getLastProtocolError() + "\n\n\n\n");
}
@Override
@ -80,6 +82,7 @@ public class KryoClient implements ClientProvider{
try{
Net.handleClientReceived(object);
}catch (Exception e){
e.printStackTrace();
if(e instanceof KryoNetException && e.getMessage() != null && e.getMessage().toLowerCase().contains("incorrect")) {
Net.showError("$text.server.mismatch");
netClient.disconnectQuietly();
@ -159,11 +162,7 @@ public class KryoClient implements ClientProvider{
ByteBuffer buffer = ByteBuffer.wrap(packet.getData());
Host host = NetworkIO.readServerData(packet.getAddress().getHostAddress(), buffer);
if (host != null) {
Gdx.app.postRunnable(() -> valid.accept(host));
} else {
Gdx.app.postRunnable(() -> invalid.accept(new IOException("Outdated server.")));
}
Gdx.app.postRunnable(() -> valid.accept(host));
} catch (Exception e) {
Gdx.app.postRunnable(() -> invalid.accept(e));
}