Fixed server crashes, android client error, ping system rewrite

This commit is contained in:
Anuken
2018-03-08 18:59:11 -05:00
parent a7096720d6
commit b0086082d0
10 changed files with 153 additions and 130 deletions

View File

@@ -6,6 +6,7 @@ import com.badlogic.gdx.utils.ByteArray;
import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.io.Version;
import io.anuke.mindustry.resource.Upgrade;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.*;
@@ -16,6 +17,7 @@ import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.Entities;
import java.io.*;
import java.nio.ByteBuffer;
import static io.anuke.mindustry.Vars.*;
@@ -340,4 +342,46 @@ public class NetworkIO {
throw new RuntimeException(e);
}
}
public static ByteBuffer writeServerData(){
int maxlen = 32;
String host = (headless ? "Server" : player.name);
String map = world.getMap().name;
host = host.substring(0, Math.min(host.length(), maxlen));
map = map.substring(0, Math.min(map.length(), maxlen));
ByteBuffer buffer = ByteBuffer.allocate(128);
buffer.put((byte)host.getBytes().length);
buffer.put(host.getBytes());
buffer.put((byte)map.getBytes().length);
buffer.put(map.getBytes());
buffer.putInt(playerGroup.size());
buffer.putInt(state.wave);
buffer.putInt(Version.build);
return buffer;
}
public static Host readServerData(String hostAddress, ByteBuffer buffer){
byte hlength = buffer.get();
byte[] hb = new byte[hlength];
buffer.get(hb);
byte mlength = buffer.get();
byte[] mb = new byte[mlength];
buffer.get(mb);
String host = new String(hb);
String map = new String(mb);
int players = buffer.getInt();
int wave = buffer.getInt();
int version = buffer.getInt();
return new Host(host, hostAddress, map, wave, players, version);
}
}

View File

@@ -6,6 +6,7 @@ import com.badlogic.gdx.utils.TimeUtils;
import com.badlogic.gdx.utils.reflect.ClassReflection;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.net.Packets.Disconnect;
import io.anuke.ucore.util.Log;
import static io.anuke.mindustry.Vars.playerGroup;
@@ -13,12 +14,16 @@ public class ServerDebug {
private IntMap<OrderedMap<Class<?>, Long>> last = new IntMap<>();
public void handle(int connection, Object packet){
if(!last.containsKey(connection))
last.put(connection, new OrderedMap<>());
if(packet instanceof Disconnect)
last.remove(connection);
else
last.get(connection).put(packet.getClass(), TimeUtils.millis());
try {
if (!last.containsKey(connection))
last.put(connection, new OrderedMap<>());
if (packet instanceof Disconnect)
last.remove(connection);
else
last.get(connection).put(packet.getClass(), TimeUtils.millis());
}catch (Exception e){
Log.err("<An internal debug error has occurred.>");
}
}
public String getOut(){