Fixed crash when connnecting, improved error messages

This commit is contained in:
Anuken
2018-01-12 20:03:52 -05:00
parent 77d8464623
commit 5e2173fc54
10 changed files with 52 additions and 12 deletions

View File

@@ -42,7 +42,7 @@ public class KryoClient implements ClientProvider{
}
});
client.start();
client.addListener(new Listener(){
@Override
public void connected (Connection connection) {
@@ -75,7 +75,13 @@ public class KryoClient implements ClientProvider{
try{
Net.handleClientReceived(object);
}catch (Exception e){
Gdx.app.postRunnable(() -> {throw new RuntimeException(e);});
if(e instanceof KryoNetException && e.getMessage() != null && e.getMessage().toLowerCase().contains("incorrect")) {
UCore.log("Mismatch!");
}else{
Gdx.app.postRunnable(() -> {
throw new RuntimeException(e);
});
}
}
}
@@ -86,6 +92,19 @@ public class KryoClient implements ClientProvider{
@Override
public void connect(String ip, int port) throws IOException {
//just in case
client.stop();
Thread updateThread = new Thread(() -> {
try{
client.run();
}catch (Exception e){
handleException(e);
}
}, "Kryonet Client");
updateThread.setDaemon(true);
updateThread.start();
client.connect(5000, ip, port, port);
}
@@ -145,4 +164,14 @@ public class KryoClient implements ClientProvider{
}
}
private void handleException(Exception e){
e.printStackTrace();
if(e instanceof KryoNetException){
Gdx.app.postRunnable(() -> Vars.ui.showError("$text.server.mismatch"));
}else{
//TODO better exception handling.
disconnect();
}
}
}