Fixed Kryo crash

This commit is contained in:
Anuken
2018-01-01 18:01:24 -05:00
parent 20eea3b385
commit c8e41c08ea
6 changed files with 33 additions and 11 deletions

View File

@ -7,7 +7,6 @@ import android.os.Bundle;
import android.telephony.TelephonyManager;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.esotericsoftware.minlog.Log;
import io.anuke.kryonet.KryoClient;
import io.anuke.kryonet.KryoServer;
import io.anuke.mindustry.io.PlatformFunction;
@ -65,8 +64,6 @@ public class AndroidLauncher extends AndroidApplication{
config.hideStatusBar = true;
Log.set(Log.LEVEL_DEBUG);
Net.setClientProvider(new KryoClient());
Net.setServerProvider(new KryoServer());

View File

@ -95,6 +95,8 @@ public class NetServer extends Module{
Gdx.app.postRunnable(() -> Vars.ui.showInfo(Bundles.format("text.server.disconnected", player.name)));
player.remove();
DisconnectPacket dc = new DisconnectPacket();
dc.playerid = player.id;

View File

@ -3,7 +3,6 @@ package io.anuke.mindustry.desktop;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.badlogic.gdx.utils.Array;
import com.esotericsoftware.minlog.Log;
import io.anuke.kryonet.KryoClient;
import io.anuke.kryonet.KryoServer;
import io.anuke.mindustry.Mindustry;
@ -59,8 +58,6 @@ public class DesktopLauncher {
Mindustry.args = Array.with(arg);
Log.set(Log.LEVEL_DEBUG);
Net.setClientProvider(new KryoClient());
Net.setServerProvider(new KryoServer());

View File

@ -26,13 +26,25 @@ public class KryoClient implements ClientProvider{
Connect c = new Connect();
c.id = connection.getID();
c.addressTCP = connection.getRemoteAddressTCP().toString();
Net.handleClientReceived(c);
try{
Net.handleClientReceived(c);
}catch (Exception e){
Gdx.app.exit();
throw new RuntimeException(e);
}
}
@Override
public void disconnected (Connection connection) {
Disconnect c = new Disconnect();
Net.handleClientReceived(c);
try{
Net.handleClientReceived(c);
}catch (Exception e){
Gdx.app.exit();
throw new RuntimeException(e);
}
}
@Override

View File

@ -31,20 +31,34 @@ public class KryoServer implements ServerProvider {
thread.setDaemon(true);
thread.start();
server.addListener(new Listener(){
@Override
public void connected (Connection connection) {
Connect c = new Connect();
c.id = connection.getID();
c.addressTCP = connection.getRemoteAddressTCP().toString();
Net.handleServerReceived(c, c.id);
connections.add(c.id);
try {
Net.handleServerReceived(c, c.id);
connections.add(c.id);
}catch (Exception e){
Gdx.app.exit();
throw new RuntimeException(e);
}
}
@Override
public void disconnected (Connection connection) {
Disconnect c = new Disconnect();
c.id = connection.getID();
Net.handleServerReceived(c, c.id);
try{
Net.handleServerReceived(c, c.id);
}catch (Exception e){
Gdx.app.exit();
throw new RuntimeException(e);
}
connections.removeValue(c.id);
}