Fixed #10329 by timing out when UDP snapshots are not received
This commit is contained in:
@@ -10,6 +10,11 @@ import mindustry.gen.*;
|
||||
public class MissileAI extends AIController{
|
||||
public @Nullable Unit shooter;
|
||||
|
||||
@Override
|
||||
protected void resetTimers(){
|
||||
timer.reset(timerTarget, Mathf.random(3f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMovement(){
|
||||
unloadPayloads();
|
||||
|
||||
@@ -4127,7 +4127,7 @@ public class Blocks{
|
||||
hitEffect = despawnEffect = Fx.hitSquaresColor;
|
||||
buildingDamageMultiplier = 0.2f;
|
||||
}},
|
||||
Items.silicon, new BasicBulletType(8f, 34){{
|
||||
Items.silicon, new BasicBulletType(8f, 35){{
|
||||
knockback = 3f;
|
||||
width = 25f;
|
||||
hitSize = 7f;
|
||||
@@ -4980,7 +4980,7 @@ public class Blocks{
|
||||
fragLifeMin = 0.1f;
|
||||
fragBullets = 5;
|
||||
fragRandomSpread = 0f;
|
||||
fragSpread = 37f;
|
||||
fragSpread = 30f;
|
||||
fragBullet = new BulletType(){{
|
||||
shootEffect = Fx.shootBig;
|
||||
smokeEffect = Fx.shootSmokeMissileColor;
|
||||
|
||||
@@ -34,6 +34,7 @@ import java.util.zip.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class NetClient implements ApplicationListener{
|
||||
private static final long entitySnapshotTimeout = 1000 * 20;
|
||||
private static final float dataTimeout = 60 * 30;
|
||||
/** ticks between syncs, e.g. 5 means 60/5 = 12 syncs/sec*/
|
||||
private static final float playerSyncTime = 4;
|
||||
@@ -50,6 +51,8 @@ public class NetClient implements ApplicationListener{
|
||||
private boolean quietReset = false;
|
||||
/** Counter for data timeout. */
|
||||
private float timeoutTime = 0f;
|
||||
/** Timestamp for last UDP state snapshot received. */
|
||||
private long lastSnapshotTimestamp;
|
||||
/** Last sent client snapshot ID. */
|
||||
private int lastSent;
|
||||
|
||||
@@ -478,6 +481,7 @@ public class NetClient implements ApplicationListener{
|
||||
@Remote(variants = Variant.one, priority = PacketPriority.low, unreliable = true)
|
||||
public static void entitySnapshot(short amount, byte[] data){
|
||||
try{
|
||||
netClient.lastSnapshotTimestamp = Time.millis();
|
||||
netClient.byteStream.setBytes(data);
|
||||
DataInputStream input = netClient.dataStream;
|
||||
|
||||
@@ -575,7 +579,18 @@ public class NetClient implements ApplicationListener{
|
||||
if(!net.client()) return;
|
||||
|
||||
if(state.isGame()){
|
||||
if(!connecting) sync();
|
||||
if(!connecting){
|
||||
sync();
|
||||
|
||||
//timeout if UDP snapshot packets are not received for a while
|
||||
if(lastSnapshotTimestamp > 0 && Time.timeSinceMillis(lastSnapshotTimestamp) > entitySnapshotTimeout){
|
||||
Log.err("Timed out after not received UDP snapshots.");
|
||||
quiet = true;
|
||||
ui.showErrorMessage("@disconnect.snapshottimeout");
|
||||
net.disconnect();
|
||||
lastSnapshotTimestamp = 0;
|
||||
}
|
||||
}
|
||||
}else if(!connecting){
|
||||
net.disconnect();
|
||||
}else{ //...must be connecting
|
||||
@@ -612,6 +627,7 @@ public class NetClient implements ApplicationListener{
|
||||
Core.app.post(Call::connectConfirm);
|
||||
Time.runTask(40f, platform::updateRPC);
|
||||
Core.app.post(ui.loadfrag::hide);
|
||||
lastSnapshotTimestamp = Time.millis();
|
||||
}
|
||||
|
||||
private void reset(){
|
||||
@@ -622,6 +638,7 @@ public class NetClient implements ApplicationListener{
|
||||
quietReset = false;
|
||||
quiet = false;
|
||||
lastSent = 0;
|
||||
lastSnapshotTimestamp = 0;
|
||||
|
||||
Groups.clear();
|
||||
ui.chatfrag.clearMessages();
|
||||
|
||||
@@ -1082,7 +1082,7 @@ public class NetServer implements ApplicationListener{
|
||||
try{
|
||||
writeEntitySnapshot(player);
|
||||
}catch(IOException e){
|
||||
e.printStackTrace();
|
||||
Log.err(e);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -28,8 +28,12 @@ public class AIController implements UnitController{
|
||||
protected Teamc target;
|
||||
|
||||
{
|
||||
timer.reset(0, Mathf.random(40f));
|
||||
timer.reset(1, Mathf.random(60f));
|
||||
resetTimers();
|
||||
}
|
||||
|
||||
protected void resetTimers(){
|
||||
timer.reset(timerTarget, Mathf.random(40f));
|
||||
timer.reset(timerTarget2, Mathf.random(60f));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user