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
+2 -2
View File
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.anuke.mindustry"
android:versionCode="53"
android:versionName="3.3b5" >
android:versionCode="54"
android:versionName="3.3b6" >
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+1
View File
@@ -17,6 +17,7 @@ text.name=Name:
text.public=Public
text.players={0} players online
text.players.single={0} player online
text.server.mismatch=Packet error: possible client/server version mismatch.\nMake sure you and the host have the\nlatest version of Mindustry!
text.server.closing=[accent]Closing server...
text.server.kicked.kick=You have been kicked from the server!
text.server.kicked.invalidPassword=Invalid password!
@@ -47,6 +47,7 @@ public class NetClient extends Module {
public NetClient(){
Net.handle(Connect.class, packet -> {
Net.setClientLoaded(false);
requests.clear();
connecting = true;
gotData = false;
@@ -99,6 +100,7 @@ public class NetClient extends Module {
Net.send(new ConnectConfirmPacket(), SendMode.tcp);
GameState.set(State.playing);
Net.setClientLoaded(true);
});
});
+4
View File
@@ -180,6 +180,10 @@ public class UI extends SceneModule{
}
public void showError(String text){
if(hasDialog()){
Dialog dialog = scene.getScrollFocus() instanceof Dialog ? (Dialog)scene.getScrollFocus() : (Dialog)scene.getKeyboardFocus();
dialog.hide();
}
new Dialog("$text.error.title", "dialog"){{
content().margin(15).add(text);
buttons().addButton("$text.ok", this::hide).size(90, 50).pad(4);
@@ -51,6 +51,10 @@ public class Saves {
}
public void update(){
if(GameState.is(State.menu)){
current = null;
}
if(!GameState.is(State.menu) && !Vars.control.isGameOver() && current != null && current.isAutosave()){
time += Timers.delta();
if(time > Settings.getInt("saveinterval")*60) {
+6 -1
View File
@@ -18,6 +18,7 @@ import java.io.IOException;
public class Net{
private static boolean server;
private static boolean active;
private static boolean clientLoaded;
private static ObjectMap<Class<?>, Consumer> clientListeners = new ObjectMap<>();
private static ObjectMap<Class<?>, Consumer> serverListeners = new ObjectMap<>();
private static ClientProvider clientProvider;
@@ -26,6 +27,10 @@ public class Net{
private static int lastConnection = -1;
private static IntMap<StreamBuilder> streams = new IntMap<>();
private static AsyncExecutor executor = new AsyncExecutor(4);
public static void setClientLoaded(boolean loaded){
clientLoaded = loaded;
}
/**Connect to an address.*/
public static void connect(String ip, int port) throws IOException{
@@ -141,7 +146,7 @@ public class Net{
handleClientReceived(builder.build());
}
}else if(clientListeners.get(object.getClass()) != null){
clientListeners.get(object.getClass()).accept(object);
if(clientLoaded) clientListeners.get(object.getClass()).accept(object);
}else{
Gdx.app.error("Mindustry::Net", "Unhandled packet type: '" + object.getClass() + "'!");
}
@@ -7,7 +7,6 @@ import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.net.Packets.*;
import io.anuke.mindustry.net.Streamable.StreamBegin;
import io.anuke.mindustry.net.Streamable.StreamChunk;
import io.anuke.mindustry.resource.Mech;
import io.anuke.ucore.entities.Entity;
public class Registrator {
@@ -47,15 +46,11 @@ public class Registrator {
int[].class,
int[][].class,
Entity[].class,
Player[].class,
Array.class,
Vector2.class,
EnemySpawnPacket[].class,
Entity.class,
Player.class,
Mech.class,
Enemy.class
};
}
@@ -25,6 +25,7 @@ public class HostDialog extends FloatingDialog{
Vars.player.name = text;
Settings.put("name", text);
Settings.save();
Vars.ui.listfrag.rebuild();
}).grow().pad(8);
}).width(w).height(70f).pad(4);
@@ -48,8 +48,7 @@ public class Sorter extends Junction{
public void handleItem(Item item, Tile tile, Tile source){
Tile to = getTileTarget(item, tile, source, true);
Timers.run(15, ()->{
if(to == null || to.entity == null) return;
Timers.run(15, () -> {
to.block().handleItem(item, to, tile);
});
+31 -2
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();
}
}
}