Beginning work on grouped servers
This commit is contained in:
Binary file not shown.
@@ -67,7 +67,7 @@ public class Vars implements Loadable{
|
|||||||
/** URL of the github issue report template.*/
|
/** URL of the github issue report template.*/
|
||||||
public static final String reportIssueURL = "https://github.com/Anuken/Mindustry/issues/new?labels=bug&template=bug_report.md";
|
public static final String reportIssueURL = "https://github.com/Anuken/Mindustry/issues/new?labels=bug&template=bug_report.md";
|
||||||
/** list of built-in servers.*/
|
/** list of built-in servers.*/
|
||||||
public static final Seq<String> defaultServers = Seq.with();
|
public static final Seq<ServerGroup> defaultServers = Seq.with();
|
||||||
/** maximum distance between mine and core that supports automatic transferring */
|
/** maximum distance between mine and core that supports automatic transferring */
|
||||||
public static final float mineTransferRange = 220f;
|
public static final float mineTransferRange = 220f;
|
||||||
/** max chat message length */
|
/** max chat message length */
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
package mindustry.net;
|
package mindustry.net;
|
||||||
|
|
||||||
public class ServerGroup{
|
public class ServerGroup{
|
||||||
public String[] addresses;
|
|
||||||
public String name;
|
public String name;
|
||||||
|
public String[] addresses;
|
||||||
|
|
||||||
|
public ServerGroup(String name, String[] addresses){
|
||||||
|
this.name = name;
|
||||||
|
this.addresses = addresses;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServerGroup(){
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -334,17 +334,36 @@ public class JoinDialog extends BaseDialog{
|
|||||||
|
|
||||||
global.clear();
|
global.clear();
|
||||||
global.background(null);
|
global.background(null);
|
||||||
for(String host : defaultServers){
|
for(ServerGroup group : defaultServers){
|
||||||
String resaddress = host.contains(":") ? host.split(":")[0] : host;
|
//table containing all groups
|
||||||
int resport = host.contains(":") ? Strings.parseInt(host.split(":")[1]) : port;
|
global.table(g -> {
|
||||||
net.pingHost(resaddress, resport, res -> {
|
//TODO groups
|
||||||
if(refreshes != cur) return;
|
for(String address : group.addresses){
|
||||||
res.port = resport;
|
String resaddress = address.contains(":") ? address.split(":")[0] : address;
|
||||||
addGlobalHost(res);
|
int resport = address.contains(":") ? Strings.parseInt(address.split(":")[1]) : port;
|
||||||
}, e -> {});
|
net.pingHost(resaddress, resport, res -> {
|
||||||
|
if(refreshes != cur) return;
|
||||||
|
res.port = resport;
|
||||||
|
addGlobalHost(res, g);
|
||||||
|
|
||||||
|
g.margin(5f);
|
||||||
|
g.pack();
|
||||||
|
}, e -> {});
|
||||||
|
}
|
||||||
|
}).row();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addGlobalHost(Host host, Table container){
|
||||||
|
global.background(null);
|
||||||
|
float w = targetWidth();
|
||||||
|
|
||||||
|
container.button(b -> buildServer(host, b), Styles.cleart, () -> {
|
||||||
|
Events.fire(new ClientPreConnectEvent(host));
|
||||||
|
safeConnect(host.address, host.port, host.version);
|
||||||
|
}).width(w).row();
|
||||||
|
}
|
||||||
|
|
||||||
void finishLocalHosts(){
|
void finishLocalHosts(){
|
||||||
if(totalHosts == 0){
|
if(totalHosts == 0){
|
||||||
local.clear();
|
local.clear();
|
||||||
@@ -367,26 +386,10 @@ public class JoinDialog extends BaseDialog{
|
|||||||
|
|
||||||
local.row();
|
local.row();
|
||||||
|
|
||||||
TextButton button = local.button("", Styles.cleart, () -> {
|
local.button(b -> buildServer(host, b), Styles.cleart, () -> {
|
||||||
Events.fire(new ClientPreConnectEvent(host));
|
Events.fire(new ClientPreConnectEvent(host));
|
||||||
safeConnect(host.address, host.port, host.version);
|
safeConnect(host.address, host.port, host.version);
|
||||||
}).width(w).pad(5f).get();
|
}).width(w);
|
||||||
button.clearChildren();
|
|
||||||
buildServer(host, button);
|
|
||||||
}
|
|
||||||
|
|
||||||
void addGlobalHost(Host host){
|
|
||||||
global.background(null);
|
|
||||||
float w = targetWidth();
|
|
||||||
|
|
||||||
global.row();
|
|
||||||
|
|
||||||
TextButton button = global.button("", Styles.cleart, () -> {
|
|
||||||
Events.fire(new ClientPreConnectEvent(host));
|
|
||||||
safeConnect(host.address, host.port, host.version);
|
|
||||||
}).width(w).pad(5f).get();
|
|
||||||
button.clearChildren();
|
|
||||||
buildServer(host, button);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connect(String ip, int port){
|
public void connect(String ip, int port){
|
||||||
@@ -443,7 +446,16 @@ public class JoinDialog extends BaseDialog{
|
|||||||
Core.app.post(() -> {
|
Core.app.post(() -> {
|
||||||
try{
|
try{
|
||||||
defaultServers.clear();
|
defaultServers.clear();
|
||||||
val.asArray().each(child -> defaultServers.add(child.getString("address", "<invalid>")));
|
val.asArray().each(child -> {
|
||||||
|
String name = child.getString("name", "");
|
||||||
|
String[] addresses;
|
||||||
|
if(child.has("addresses")){
|
||||||
|
addresses = child.get("addresses").asArray().map(Jval::asString).toArray(String.class);
|
||||||
|
}else{
|
||||||
|
addresses = new String[]{child.getString("addresses", "<invalid>")};
|
||||||
|
}
|
||||||
|
defaultServers.add(new ServerGroup(name, addresses));
|
||||||
|
});
|
||||||
Log.info("Fetched @ global servers.", defaultServers.size);
|
Log.info("Fetched @ global servers.", defaultServers.size);
|
||||||
}catch(Throwable ignored){
|
}catch(Throwable ignored){
|
||||||
Log.err("Failed to parse community servers.");
|
Log.err("Failed to parse community servers.");
|
||||||
|
|||||||
@@ -429,7 +429,7 @@ public class SettingsMenuDialog extends SettingsDialog{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
graphics.checkPref("linear", true, b -> {
|
graphics.checkPref("linear", !mobile, b -> {
|
||||||
for(Texture tex : Core.atlas.getTextures()){
|
for(Texture tex : Core.atlas.getTextures()){
|
||||||
TextureFilter filter = b ? TextureFilter.linear : TextureFilter.nearest;
|
TextureFilter filter = b ? TextureFilter.linear : TextureFilter.nearest;
|
||||||
tex.setFilter(filter, filter);
|
tex.setFilter(filter, filter);
|
||||||
|
|||||||
@@ -108,7 +108,6 @@ public class MenuFragment extends Fragment{
|
|||||||
editor = new MobileButton(Icon.terrain, "@editor", () -> checkPlay(ui.maps::show)),
|
editor = new MobileButton(Icon.terrain, "@editor", () -> checkPlay(ui.maps::show)),
|
||||||
tools = new MobileButton(Icon.settings, "@settings", ui.settings::show),
|
tools = new MobileButton(Icon.settings, "@settings", ui.settings::show),
|
||||||
mods = new MobileButton(Icon.book, "@mods", ui.mods::show),
|
mods = new MobileButton(Icon.book, "@mods", ui.mods::show),
|
||||||
donate = new MobileButton(Icon.link, "@website", () -> Core.app.openURI("https://anuke.itch.io/mindustry")),
|
|
||||||
exit = new MobileButton(Icon.exit, "@quit", () -> Core.app.exit());
|
exit = new MobileButton(Icon.exit, "@quit", () -> Core.app.exit());
|
||||||
|
|
||||||
if(!Core.graphics.isPortrait()){
|
if(!Core.graphics.isPortrait()){
|
||||||
@@ -195,6 +194,7 @@ public class MenuFragment extends Fragment{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkPlay(Runnable run){
|
private void checkPlay(Runnable run){
|
||||||
|
|
||||||
if(!mods.hasContentErrors()){
|
if(!mods.hasContentErrors()){
|
||||||
run.run();
|
run.run();
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
Reference in New Issue
Block a user