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