Fixed many network-related bugs
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import com.badlogic.gdx.utils.OrderedMap;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
|
||||
public class ClientDebug {
|
||||
private OrderedMap<Class<?>, Long> last = new OrderedMap<>();
|
||||
private int syncPlayers = 0;
|
||||
private int syncEnemies = 0;
|
||||
|
||||
public void handle(Object packet){
|
||||
last.put(packet.getClass(), TimeUtils.millis());
|
||||
}
|
||||
|
||||
public void setSyncDebug(int players, int enemies){
|
||||
this.syncEnemies = enemies;
|
||||
this.syncPlayers = players;
|
||||
}
|
||||
|
||||
public String getOut(){
|
||||
StringBuilder build = new StringBuilder();
|
||||
for(Class<?> type : last.orderedKeys()){
|
||||
build.append(elapsed(type));
|
||||
build.append("\n");
|
||||
}
|
||||
build.append("sync.players: ");
|
||||
build.append(syncPlayers);
|
||||
build.append("\n");
|
||||
build.append("sync.enemies: ");
|
||||
build.append(syncEnemies);
|
||||
build.append("\n");
|
||||
return build.toString();
|
||||
}
|
||||
|
||||
private String elapsed(Class<?> type){
|
||||
long t = last.get(type, -1L);
|
||||
if(t == -1){
|
||||
return ClassReflection.getSimpleName(type) + ": <never>";
|
||||
}else{
|
||||
float el = TimeUtils.timeSinceMillis(t) / 1000f;
|
||||
String tu;
|
||||
if(el > 1f){
|
||||
tu = (int)el + "s";
|
||||
}else{
|
||||
tu = (int)(el * 60) + "f";
|
||||
}
|
||||
return ClassReflection.getSimpleName(type) + ": " + tu;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,10 @@ import io.anuke.ucore.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.headless;
|
||||
import static io.anuke.mindustry.Vars.ui;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Net{
|
||||
public static final int version = 13;
|
||||
public static final int version = 14;
|
||||
|
||||
private static boolean server;
|
||||
private static boolean active;
|
||||
@@ -141,6 +140,8 @@ public class Net{
|
||||
|
||||
/**Call to handle a packet being recieved for the client.*/
|
||||
public static void handleClientReceived(Object object){
|
||||
if(debugNet) clientDebug.handle(object);
|
||||
|
||||
if(object instanceof StreamBegin) {
|
||||
StreamBegin b = (StreamBegin) object;
|
||||
streams.put(b.id, new StreamBuilder(b));
|
||||
@@ -170,6 +171,8 @@ public class Net{
|
||||
|
||||
/**Call to handle a packet being recieved for the server.*/
|
||||
public static void handleServerReceived(int connection, Object object){
|
||||
if(debugNet) serverDebug.handle(object);
|
||||
|
||||
if(serverListeners.get(object.getClass()) != null || listeners.get(object.getClass()) != null){
|
||||
if(serverListeners.get(object.getClass()) != null) serverListeners.get(object.getClass()).accept(connection, object);
|
||||
if(listeners.get(object.getClass()) != null) listeners.get(object.getClass()).accept(object);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
public class ServerDebug {
|
||||
|
||||
public void handle(Object packet){
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user