Fixed crashes for inputting IP and port
This commit is contained in:
@@ -302,7 +302,7 @@ public class Control extends Module{
|
|||||||
|
|
||||||
Timers.run(18, ()-> ui.hideLoading());
|
Timers.run(18, ()-> ui.hideLoading());
|
||||||
|
|
||||||
Mindustry.platforms.onSceneChange("Playing on map: " + map.name, "Wave 0", "fight");
|
Mindustry.platforms.onSceneChange("Playing on map: " + map.name, "Wave 1", "fight");
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameMode getMode(){
|
public GameMode getMode(){
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ import io.anuke.ucore.scene.ui.layout.Table;
|
|||||||
import io.anuke.ucore.util.Bundles;
|
import io.anuke.ucore.util.Bundles;
|
||||||
import io.anuke.ucore.util.Strings;
|
import io.anuke.ucore.util.Strings;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class JoinDialog extends FloatingDialog {
|
public class JoinDialog extends FloatingDialog {
|
||||||
Dialog join;
|
Dialog join;
|
||||||
Table hosts = new Table();
|
Table hosts = new Table();
|
||||||
@@ -45,8 +43,8 @@ public class JoinDialog extends FloatingDialog {
|
|||||||
join.buttons().defaults().size(140f, 60f).pad(4f);
|
join.buttons().defaults().size(140f, 60f).pad(4f);
|
||||||
join.buttons().addButton("$text.cancel", join::hide);
|
join.buttons().addButton("$text.cancel", join::hide);
|
||||||
join.buttons().addButton("$text.ok", () ->
|
join.buttons().addButton("$text.ok", () ->
|
||||||
connect(Settings.getString("port"), Integer.parseInt(Settings.getString("port")))
|
connect(Settings.getString("ip"), Strings.parseInt(Settings.getString("port")))
|
||||||
).disabled(b -> Settings.getString("ip").isEmpty() || Integer.parseInt(Settings.getString("port")) == Integer.MIN_VALUE);
|
).disabled(b -> Settings.getString("ip").isEmpty() || Strings.parseInt(Settings.getString("port")) == Integer.MIN_VALUE);
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
@@ -105,9 +103,27 @@ public class JoinDialog extends FloatingDialog {
|
|||||||
Timers.runTask(2f, () -> {
|
Timers.runTask(2f, () -> {
|
||||||
try{
|
try{
|
||||||
Net.connect(ip, port);
|
Net.connect(ip, port);
|
||||||
}catch (IOException e) {
|
}catch (Exception e) {
|
||||||
Vars.ui.showError(Bundles.format("text.connectfail", Strings.parseException(e, false)));
|
Throwable t = e;
|
||||||
|
while(t.getCause() != null){
|
||||||
|
t = t.getCause();
|
||||||
|
}
|
||||||
|
String error = t.getMessage() == null ? "" : t.getMessage().toLowerCase();
|
||||||
|
if(error.contains("connection refused")) {
|
||||||
|
error = "connection refused";
|
||||||
|
}else if(error.contains("port out of range")){
|
||||||
|
error = "invalid port!";
|
||||||
|
}else if(error.contains("invalid argument")) {
|
||||||
|
error = "invalid IP or port!";
|
||||||
|
}else if(t.getClass().toString().toLowerCase().contains("sockettimeout")){
|
||||||
|
error = "timed out!";
|
||||||
|
}else{
|
||||||
|
error = Strings.parseException(e, false);
|
||||||
|
}
|
||||||
|
Vars.ui.showError(Bundles.format("text.connectfail", error));
|
||||||
Vars.ui.hideLoading();
|
Vars.ui.hideLoading();
|
||||||
|
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user