Non-blocking connect / Localized connect error messages
This commit is contained in:
@@ -18,7 +18,6 @@ import io.anuke.ucore.scene.ui.layout.Cell;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.scene.utils.UIUtils;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
@@ -300,34 +299,11 @@ public class JoinDialog extends FloatingDialog{
|
||||
});
|
||||
|
||||
Timers.runTask(2f, () -> {
|
||||
try{
|
||||
Vars.netClient.beginConnecting();
|
||||
Net.connect(ip, port);
|
||||
Vars.netClient.beginConnecting();
|
||||
Net.connect(ip, port, () -> {
|
||||
hide();
|
||||
add.hide();
|
||||
}catch(Exception e){
|
||||
Throwable t = e;
|
||||
while(t.getCause() != null){
|
||||
t = t.getCause();
|
||||
}
|
||||
//TODO localize
|
||||
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!\nmake sure the host has port forwarding set up,\nand that the address is correct!";
|
||||
}else{
|
||||
error = Strings.parseException(e, false);
|
||||
}
|
||||
ui.showError(Bundles.format("text.connectfail", error));
|
||||
ui.loadfrag.hide();
|
||||
|
||||
Log.err(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user